From 46bed2a75b3436b6ef63eaa39793c9b8eade3706 Mon Sep 17 00:00:00 2001 From: thePR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> Date: Wed, 25 Feb 2026 13:32:29 -0500 Subject: [PATCH] Fix scheduler prompts for host-repo TORCH execution context --- src/prompts/META_PROMPTS.md | 90 ++++++++++++++++++++++------------- src/prompts/scheduler-flow.md | 54 +++++++++++++-------- 2 files changed, 89 insertions(+), 55 deletions(-) diff --git a/src/prompts/META_PROMPTS.md b/src/prompts/META_PROMPTS.md index f3a8c39..3dddae7 100644 --- a/src/prompts/META_PROMPTS.md +++ b/src/prompts/META_PROMPTS.md @@ -13,31 +13,42 @@ Authority model: **scheduler-owned completion/logging**. Spawned agents must not Follow `src/prompts/scheduler-flow.md` exactly. +MUST 0: Normalize execution context before any other step: +- If `src/prompts/scheduler-flow.md` exists in the current working directory, run in TORCH-root mode: + - `script_prefix = npm run` + - `path_prefix = ` (empty) +- Else if `torch/src/prompts/scheduler-flow.md` exists, run in host-repo mode: + - `script_prefix = npm run --prefix torch` + - `path_prefix = torch/` +- Else stop and report: `Unable to locate TORCH scheduler files (checked src/prompts and torch/src/prompts).` +- Apply `script_prefix` to every `lock:*` command below and apply `path_prefix` to every repository path below. + MUST 1: Set cadence config to: - cadence = daily -- log_dir = task-logs/daily/ +- log_dir = task-logs/daily/ - branch_prefix = agents/daily/ -- prompt_dir = src/prompts/daily/ +- prompt_dir = src/prompts/daily/ MUST 2: Run preflight to get the exclusion set: -npm run lock:check:daily -- --json --quiet + lock:check:daily -- --json --quiet Use `excluded` from the JSON output as the canonical exclusion set. If `excluded` is unavailable, fallback to the union of `locked`, `paused`, and `completed`. MUST 3: Run these commands in this order: -1) test -f TORCH.md && cat TORCH.md || echo "No TORCH.md found; continuing" (missing TORCH.md is non-fatal) -2) mkdir -p task-logs/daily task-logs/weekly -3) ls -1 task-logs/daily/ | sort | tail -n 1 +1) test -f TORCH.md && cat TORCH.md || echo "No TORCH.md found; continuing" (missing TORCH.md is non-fatal) +2) mkdir -p task-logs/daily task-logs/weekly +3) ls -1 task-logs/daily/ | sort | tail -n 1 4) Select next roster agent using this exact algorithm: - Read roster from src/prompts/roster.json (`daily` key). + - Resolve the roster path as `src/prompts/roster.json`. - Find `latest_file` from step 3. - Derive `previous_agent` from that file with precedence: a) YAML frontmatter key `agent`. b) Filename format `____.md`. - If no valid previous log exists (missing file, parse failure, or agent not in roster): - - Read `scheduler.firstPromptByCadence.daily` from `torch-config.json` if present. + - Read `scheduler.firstPromptByCadence.daily` from `torch-config.json` if present. - If that agent is in roster, start there. - Otherwise set `start_index = 0`. - Else set `start_index = (index(previous_agent)+1) mod roster_length`. @@ -49,9 +60,9 @@ MUST 3: Run these commands in this order: - excluded: `{const-refactor-agent, docs-agent}` - start at next after `ci-health-agent`, skip excluded `const-refactor-agent`, choose `content-audit-agent`. 5) Claim via repository lock: - AGENT_PLATFORM= npm run lock:lock -- --agent --cadence daily + AGENT_PLATFORM= lock:lock -- --agent --cadence daily Exit 0 = lock acquired, proceed. Exit 3 = race lost, go back to step 3. -6) Execute selected prompt from src/prompts/daily/ (spawned agent work only; completion publish and final task log writing remain scheduler-owned) +6) Execute selected prompt from src/prompts/daily/ (spawned agent work only; completion publish and final task log writing remain scheduler-owned) 7) Run required memory workflow for this cadence: - Before execution, run the retrieval command if configured: `scheduler.memoryPolicyByCadence.daily.retrieveCommand` @@ -66,7 +77,7 @@ MUST 3: Run these commands in this order: - If any validation command exits non-zero, do not call `lock:complete`. - Instead, write `_failed.md` with the failing command and reason, then stop. 10) Publish completion before writing `_completed.md` (only after step 9 passes): - AGENT_PLATFORM= npm run lock:complete -- --agent --cadence daily + AGENT_PLATFORM= lock:complete -- --agent --cadence daily (Equivalent command allowed: torch-lock complete --agent --cadence daily) - Exit 0: continue. - Exit non-zero: fail the run, write `_failed.md` with a clear completion-publish failure reason and retry guidance, then stop. @@ -79,18 +90,18 @@ MUST 3: Run these commands in this order: - Learnings: [Content of the memory update file or "No learnings recorded"] Worked example (required order): - - `AGENT_PLATFORM=codex npm run lock:lock -- --agent content-audit-agent --cadence daily` + - `AGENT_PLATFORM=codex lock:lock -- --agent content-audit-agent --cadence daily` - execute selected prompt work - - `AGENT_PLATFORM=codex npm run lock:complete -- --agent content-audit-agent --cadence daily` (complete, permanent) - - write `task-logs/daily/__content-audit-agent__completed.md` + - `AGENT_PLATFORM=codex lock:complete -- --agent content-audit-agent --cadence daily` (complete, permanent) + - write `task-logs/daily/__content-audit-agent__completed.md` - print final summary (Status: Success, Learnings: ) Worked example (failed validation, no completion publish): - - `AGENT_PLATFORM=codex npm run lock:lock -- --agent content-audit-agent --cadence daily` + - `AGENT_PLATFORM=codex lock:lock -- --agent content-audit-agent --cadence daily` - execute selected prompt work - - `npm run lint` exits non-zero (or `npm test` exits non-zero) - - write `task-logs/daily/__content-audit-agent__failed.md` with failure reason - - stop without running `AGENT_PLATFORM=codex npm run lock:complete -- --agent content-audit-agent --cadence daily` + - ` lint` exits non-zero (or ` test` exits non-zero) + - write `task-logs/daily/__content-audit-agent__failed.md` with failure reason + - stop without running `AGENT_PLATFORM=codex lock:complete -- --agent content-audit-agent --cadence daily` - print final summary (Status: Failed, Reason: ) MUST 4: If all daily agents are excluded, stop and write `_failed.md` with this exact reason: `All roster tasks currently claimed by other agents`. @@ -105,31 +116,42 @@ Authority model: **scheduler-owned completion/logging**. Spawned agents must not Follow `src/prompts/scheduler-flow.md` exactly. +MUST 0: Normalize execution context before any other step: +- If `src/prompts/scheduler-flow.md` exists in the current working directory, run in TORCH-root mode: + - `script_prefix = npm run` + - `path_prefix = ` (empty) +- Else if `torch/src/prompts/scheduler-flow.md` exists, run in host-repo mode: + - `script_prefix = npm run --prefix torch` + - `path_prefix = torch/` +- Else stop and report: `Unable to locate TORCH scheduler files (checked src/prompts and torch/src/prompts).` +- Apply `script_prefix` to every `lock:*` command below and apply `path_prefix` to every repository path below. + MUST 1: Set cadence config to: - cadence = weekly -- log_dir = task-logs/weekly/ +- log_dir = task-logs/weekly/ - branch_prefix = agents/weekly/ -- prompt_dir = src/prompts/weekly/ +- prompt_dir = src/prompts/weekly/ MUST 2: Run preflight to get the exclusion set: -npm run lock:check:weekly -- --json --quiet + lock:check:weekly -- --json --quiet Use `excluded` from the JSON output as the canonical exclusion set. If `excluded` is unavailable, fallback to the union of `locked`, `paused`, and `completed`. MUST 3: Run these commands in this order: -1) test -f TORCH.md && cat TORCH.md || echo "No TORCH.md found; continuing" (missing TORCH.md is non-fatal) -2) mkdir -p task-logs/daily task-logs/weekly -3) ls -1 task-logs/weekly/ | sort | tail -n 1 +1) test -f TORCH.md && cat TORCH.md || echo "No TORCH.md found; continuing" (missing TORCH.md is non-fatal) +2) mkdir -p task-logs/daily task-logs/weekly +3) ls -1 task-logs/weekly/ | sort | tail -n 1 4) Select next roster agent using this exact algorithm: - Read roster from src/prompts/roster.json (`weekly` key). + - Resolve the roster path as `src/prompts/roster.json`. - Find `latest_file` from step 3. - Derive `previous_agent` from that file with precedence: a) YAML frontmatter key `agent`. b) Filename format `____.md`. - If no valid previous log exists (missing file, parse failure, or agent not in roster): - - Read `scheduler.firstPromptByCadence.weekly` from `torch-config.json` if present. + - Read `scheduler.firstPromptByCadence.weekly` from `torch-config.json` if present. - If that agent is in roster, start there. - Otherwise set `start_index = 0`. - Else set `start_index = (index(previous_agent)+1) mod roster_length`. @@ -141,9 +163,9 @@ MUST 3: Run these commands in this order: - excluded: `{}` - previous agent is final roster entry, so wrap to index 0 and choose `bug-reproducer-agent`. 5) Claim via repository lock: - AGENT_PLATFORM= npm run lock:lock -- --agent --cadence weekly + AGENT_PLATFORM= lock:lock -- --agent --cadence weekly Exit 0 = lock acquired, proceed. Exit 3 = race lost, go back to step 3. -6) Execute selected prompt from src/prompts/weekly/ (spawned agent work only; completion publish and final task log writing remain scheduler-owned) +6) Execute selected prompt from src/prompts/weekly/ (spawned agent work only; completion publish and final task log writing remain scheduler-owned) 7) Run required memory workflow for this cadence: - Before execution, run the retrieval command if configured: `scheduler.memoryPolicyByCadence.weekly.retrieveCommand` @@ -158,7 +180,7 @@ MUST 3: Run these commands in this order: - If any validation command exits non-zero, do not call `lock:complete`. - Instead, write `_failed.md` with the failing command and reason, then stop. 10) Publish completion before writing `_completed.md` (only after step 9 passes): - AGENT_PLATFORM= npm run lock:complete -- --agent --cadence weekly + AGENT_PLATFORM= lock:complete -- --agent --cadence weekly (Equivalent command allowed: torch-lock complete --agent --cadence weekly) - Exit 0: continue. - Exit non-zero: fail the run, write `_failed.md` with a clear completion-publish failure reason and retry guidance, then stop. @@ -171,18 +193,18 @@ MUST 3: Run these commands in this order: - Learnings: [Content of the memory update file or "No learnings recorded"] Worked example (required order): - - `AGENT_PLATFORM=codex npm run lock:lock -- --agent bug-reproducer-agent --cadence weekly` + - `AGENT_PLATFORM=codex lock:lock -- --agent bug-reproducer-agent --cadence weekly` - execute selected prompt work - - `AGENT_PLATFORM=codex npm run lock:complete -- --agent bug-reproducer-agent --cadence weekly` (complete, permanent) - - write `task-logs/weekly/__bug-reproducer-agent__completed.md` + - `AGENT_PLATFORM=codex lock:complete -- --agent bug-reproducer-agent --cadence weekly` (complete, permanent) + - write `task-logs/weekly/__bug-reproducer-agent__completed.md` - print final summary (Status: Success, Learnings: ) Worked example (failed validation, no completion publish): - - `AGENT_PLATFORM=codex npm run lock:lock -- --agent bug-reproducer-agent --cadence weekly` + - `AGENT_PLATFORM=codex lock:lock -- --agent bug-reproducer-agent --cadence weekly` - execute selected prompt work - - `npm run lint` exits non-zero (or `npm test` exits non-zero) - - write `task-logs/weekly/__bug-reproducer-agent__failed.md` with failure reason - - stop without running `AGENT_PLATFORM=codex npm run lock:complete -- --agent bug-reproducer-agent --cadence weekly` + - ` lint` exits non-zero (or ` test` exits non-zero) + - write `task-logs/weekly/__bug-reproducer-agent__failed.md` with failure reason + - stop without running `AGENT_PLATFORM=codex lock:complete -- --agent bug-reproducer-agent --cadence weekly` - print final summary (Status: Failed, Reason: ) MUST 4: If all weekly agents are excluded, stop and write `_failed.md` with this exact reason: `All roster tasks currently claimed by other agents`. diff --git a/src/prompts/scheduler-flow.md b/src/prompts/scheduler-flow.md index 80ead39..56bb61f 100644 --- a/src/prompts/scheduler-flow.md +++ b/src/prompts/scheduler-flow.md @@ -66,29 +66,39 @@ Every agent prompt invoked by the schedulers (daily/weekly) MUST enforce this co ## Numbered MUST Procedure +0. Normalize execution context before any command: + - If `src/prompts/scheduler-flow.md` exists in the current working directory: + - `script_prefix = npm run` + - `path_prefix = ` (empty) + - Else if `torch/src/prompts/scheduler-flow.md` exists: + - `script_prefix = npm run --prefix torch` + - `path_prefix = torch/` + - Else stop with: `Unable to locate TORCH scheduler files (checked src/prompts and torch/src/prompts).` + - Apply `script_prefix` to all `lock:*` invocations and apply `path_prefix` to scheduler paths. + 1. Set cadence variables before any command: - `cadence` = `daily` or `weekly` - - `log_dir` = `task-logs//` - - `prompt_dir` = `src/prompts//` + - `log_dir` = `task-logs//` + - `prompt_dir` = `src/prompts//` Note: branch naming (for example `agents//`) is orchestration-level behavior and is not used by `run-scheduler-cycle.mjs`. 2. Run preflight to build the exclusion set: ```bash - if daily: `npm run lock:check:daily -- --json --quiet`; if weekly: `npm run lock:check:weekly -- --json --quiet` + if daily: ` lock:check:daily -- --json --quiet`; if weekly: ` lock:check:weekly -- --json --quiet` ``` Canonical exclusion rule: - - Use `excluded` from the `npm run lock:check:` JSON output. + - Use `excluded` from the ` lock:check:` JSON output. - If `excluded` is unavailable, fallback to the union of `locked`, `paused`, and `completed` from that same JSON payload. - Goose Desktop note: `npm run lock:check:` can emit large hermit wrapper logs. Use `--json --quiet` (as documented above). If the command still fails due to Goose hermit issues, apply the PATH workaround in `KNOWN_ISSUES.md` before rerunning. + Goose Desktop note: ` lock:check:` can emit large hermit wrapper logs. Use `--json --quiet` (as documented above). If the command still fails due to Goose hermit issues, apply the PATH workaround in `KNOWN_ISSUES.md` before rerunning. 3. Read policy file(s) once before the run loop. This step is conditional: if `TORCH.md` is missing, continue without failing. ```bash - test -f TORCH.md && cat TORCH.md || echo "No TORCH.md found; continuing" + test -f TORCH.md && cat TORCH.md || echo "No TORCH.md found; continuing" ``` 4. Bootstrap log directories before listing files: @@ -100,7 +110,7 @@ Every agent prompt invoked by the schedulers (daily/weekly) MUST enforce this co 5. When lock health preflight is enabled (`scheduler.lockHealthPreflight: true` or env `SCHEDULER_LOCK_HEALTH_PREFLIGHT=1`), verify relay/query health before selecting an agent or calling `lock:lock`: ```bash - npm run lock:health -- --cadence + lock:health -- --cadence ``` - Escape hatch: set `SCHEDULER_SKIP_LOCK_HEALTH_PREFLIGHT=1` to skip this check for local/offline workflows. @@ -121,6 +131,7 @@ Every agent prompt invoked by the schedulers (daily/weekly) MUST enforce this co Selection algorithm (MUST be followed exactly): - Roster source: `src/prompts/roster.json` and the key matching ``. + - Resolve that source path as `src/prompts/roster.json`. - Let `roster` be that ordered array and `excluded` be the set from step 2's canonical exclusion rule. - Let `latest_file` be the lexicographically last filename in ``. - Determine `previous_agent` from `latest_file` using this precedence: @@ -129,6 +140,7 @@ Every agent prompt invoked by the schedulers (daily/weekly) MUST enforce this co - If no valid `latest_file` exists, or parsing fails, or `previous_agent` is not in `roster`, treat as first run fallback. - First run fallback: - Read `scheduler.firstPromptByCadence.` from `torch-config.json` if present. + - In host-repo mode, resolve this as `torch-config.json`. - If that agent exists in `roster`, set `start_index = index(configured_agent)`. - Otherwise set `start_index = 0`. - Otherwise: `start_index = (index(previous_agent in roster) + 1) mod len(roster)`. @@ -163,7 +175,7 @@ Every agent prompt invoked by the schedulers (daily/weekly) MUST enforce this co ```bash AGENT_PLATFORM= \ - npm run lock:lock -- --agent --cadence + lock:lock -- --agent --cadence ``` - Exit `0`: lock acquired, continue. @@ -179,7 +191,7 @@ Every agent prompt invoked by the schedulers (daily/weekly) MUST enforce this co - `lock_stderr_excerpt` (redacted stderr snippet) - `lock_stdout_excerpt` (redacted stdout snippet) - Include `failure_class: backend_unavailable` and `failure_category: lock_backend_error` for both deferred and failed backend-unavailable lock outcomes. - - Include recommended auto-remediation text in `detail`: retry window, `npm run lock:health -- --cadence `, and incident runbook link. + - Include recommended auto-remediation text in `detail`: retry window, ` lock:health -- --cadence `, and incident runbook link. - Keep generic reason text for compatibility, but append actionable retry guidance in `detail` using the command from `lock_command`. 9. Execute `/` end-to-end via configured handoff command. @@ -217,7 +229,7 @@ Every agent prompt invoked by the schedulers (daily/weekly) MUST enforce this co - Scheduler runs `node scripts/agent/verify-run-artifacts.mjs --since --check-failure-notes`. - If artifact verification exits non-zero: write `_failed.md` and stop. -12. Run repository checks (for example: `npm run lint`). +12. Run repository checks (for example: ` lint`). - If any validation command exits non-zero: **fail the run immediately**, write `_failed.md` with the failing command and reason, and stop. - step 12 MUST NOT be executed (`lock:complete` is forbidden until validation passes). @@ -227,13 +239,13 @@ Every agent prompt invoked by the schedulers (daily/weekly) MUST enforce this co ```bash AGENT_PLATFORM= \ - npm run lock:complete -- --agent --cadence + lock:complete -- --agent --cadence ``` (Equivalent invocation is allowed: `torch-lock complete --agent --cadence `.) - Exit `0`: completion published successfully; continue to step 14. - - Exit non-zero: **fail the run**, write `_failed.md` with a clear reason that completion publish failed and retry guidance (for example: `Retry npm run lock:complete -- --agent --cadence after verifying relay connectivity`), then stop. + - Exit non-zero: **fail the run**, write `_failed.md` with a clear reason that completion publish failed and retry guidance (for example: `Retry lock:complete -- --agent --cadence after verifying relay connectivity`), then stop. 14. Create final task log only after step 13 succeeds (scheduler-owned): @@ -260,19 +272,19 @@ Every agent prompt invoked by the schedulers (daily/weekly) MUST enforce this co Worked post-task example (MUST order): -1. `AGENT_PLATFORM=codex npm run lock:lock -- --agent content-audit-agent --cadence daily` -2. Execute `src/prompts/daily/content-audit-agent.md` +1. `AGENT_PLATFORM=codex lock:lock -- --agent content-audit-agent --cadence daily` +2. Execute `src/prompts/daily/content-audit-agent.md` 3. `node scripts/agent/verify-run-artifacts.mjs --since --check-failure-notes` -4. `AGENT_PLATFORM=codex npm run lock:complete -- --agent content-audit-agent --cadence daily` (complete, permanent) -5. Write `task-logs/daily/2026-02-14T10-00-00Z__content-audit-agent__completed.md` +4. `AGENT_PLATFORM=codex lock:complete -- --agent content-audit-agent --cadence daily` (complete, permanent) +5. Write `task-logs/daily/2026-02-14T10-00-00Z__content-audit-agent__completed.md` 6. Print final summary (Status: Success, Learnings: ) Worked validation-failure example (MUST behavior): -1. `AGENT_PLATFORM=codex npm run lock:lock -- --agent content-audit-agent --cadence daily` -2. Execute `src/prompts/daily/content-audit-agent.md` +1. `AGENT_PLATFORM=codex lock:lock -- --agent content-audit-agent --cadence daily` +2. Execute `src/prompts/daily/content-audit-agent.md` 3. `node scripts/agent/verify-run-artifacts.mjs --since --check-failure-notes` passes -4. `npm run lint` exits non-zero (or `npm test` exits non-zero) -5. Write `task-logs/daily/2026-02-14T10-00-00Z__content-audit-agent__failed.md` with the failing command and reason -6. Stop the run **without** calling `npm run lock:complete -- --agent content-audit-agent --cadence daily` +4. ` lint` exits non-zero (or ` test` exits non-zero) +5. Write `task-logs/daily/2026-02-14T10-00-00Z__content-audit-agent__failed.md` with the failing command and reason +6. Stop the run **without** calling ` lock:complete -- --agent content-audit-agent --cadence daily` 7. Print final summary (Status: Failed, Reason: )