okstra 0.167.0 → 0.169.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/README.md +6 -5
  2. package/docs/architecture/storage-model.md +57 -1
  3. package/docs/architecture.md +70 -2
  4. package/docs/cli.md +8 -4
  5. package/docs/for-ai/skills/okstra-code-review.md +3 -2
  6. package/docs/for-ai/skills/okstra-schedule-gen.md +3 -1
  7. package/docs/pr-template-usage.md +10 -6
  8. package/docs/project-structure-overview.md +14 -11
  9. package/package.json +1 -1
  10. package/runtime/BUILD.json +2 -2
  11. package/runtime/agents/workers/claude-worker.md +6 -5
  12. package/runtime/agents/workers/report-writer-worker.md +9 -4
  13. package/runtime/agents/workers/translator-worker.md +6 -4
  14. package/runtime/prompts/coding-preflight/architectures/hexagonal.md +27 -1
  15. package/runtime/prompts/coding-preflight/clean-code.md +13 -0
  16. package/runtime/prompts/duties/acceptance-critic.md +24 -0
  17. package/runtime/prompts/duties/acceptance-verifier.md +24 -0
  18. package/runtime/prompts/duties/analysis-worker.md +24 -0
  19. package/runtime/prompts/duties/code-reviewer.md +24 -0
  20. package/runtime/prompts/duties/common.md +35 -0
  21. package/runtime/prompts/duties/implementation-executor.md +24 -0
  22. package/runtime/prompts/duties/implementation-verifier.md +24 -0
  23. package/runtime/prompts/duties/lead.md +24 -0
  24. package/runtime/prompts/duties/report-writer.md +24 -0
  25. package/runtime/prompts/duties/reverification-worker.md +24 -0
  26. package/runtime/prompts/duties/schedule-verifier.md +24 -0
  27. package/runtime/prompts/duties/scope-critic.md +24 -0
  28. package/runtime/prompts/duties/translator.md +24 -0
  29. package/runtime/prompts/lead/convergence.md +51 -7
  30. package/runtime/prompts/lead/okstra-lead-contract.md +10 -20
  31. package/runtime/prompts/lead/plan-body-verification.md +16 -1
  32. package/runtime/prompts/lead/report-writer.md +20 -5
  33. package/runtime/prompts/lead/team-contract.md +13 -13
  34. package/runtime/prompts/profiles/_coding-conventions-preflight.md +1 -1
  35. package/runtime/prompts/profiles/_implementation-diff-review.md +3 -1
  36. package/runtime/prompts/profiles/_implementation-executor.md +1 -1
  37. package/runtime/prompts/profiles/_implementation-verifier.md +3 -1
  38. package/runtime/prompts/profiles/implementation.md +4 -2
  39. package/runtime/python/okstra_ctl/adapters/hosts/antigravity/adapter.py +6 -0
  40. package/runtime/python/okstra_ctl/adapters/hosts/antigravity/relay.md +3 -2
  41. package/runtime/python/okstra_ctl/adapters/hosts/capability_adapter.py +8 -0
  42. package/runtime/python/okstra_ctl/adapters/hosts/claude-code/adapter.py +33 -0
  43. package/runtime/python/okstra_ctl/adapters/hosts/claude-code/relay.md +13 -12
  44. package/runtime/python/okstra_ctl/adapters/hosts/codex/adapter.py +6 -0
  45. package/runtime/python/okstra_ctl/adapters/hosts/codex/relay.md +3 -2
  46. package/runtime/python/okstra_ctl/adapters/hosts/external/adapter.py +2 -0
  47. package/runtime/python/okstra_ctl/adapters/hosts/external/relay.md +3 -3
  48. package/runtime/python/okstra_ctl/adapters/hosts/grok/adapter.py +6 -0
  49. package/runtime/python/okstra_ctl/adapters/hosts/grok/relay.md +2 -1
  50. package/runtime/python/okstra_ctl/adapters/hosts/kimi/adapter.py +6 -0
  51. package/runtime/python/okstra_ctl/adapters/hosts/kimi/relay.md +2 -1
  52. package/runtime/python/okstra_ctl/agent_invocation.py +1502 -0
  53. package/runtime/python/okstra_ctl/agent_prompt_cli.py +788 -0
  54. package/runtime/python/okstra_ctl/codex_dispatch.py +2 -107
  55. package/runtime/python/okstra_ctl/context_cost.py +46 -5
  56. package/runtime/python/okstra_ctl/dispatch_core.py +312 -37
  57. package/runtime/python/okstra_ctl/dispatch_state.py +461 -36
  58. package/runtime/python/okstra_ctl/doctor.py +150 -16
  59. package/runtime/python/okstra_ctl/entrypoints/hosts.py +87 -9
  60. package/runtime/python/okstra_ctl/initial_prompt_materialization.py +214 -23
  61. package/runtime/python/okstra_ctl/path_hints.py +26 -0
  62. package/runtime/python/okstra_ctl/paths.py +20 -0
  63. package/runtime/python/okstra_ctl/ports/__init__.py +8 -0
  64. package/runtime/python/okstra_ctl/ports/host.py +3 -0
  65. package/runtime/python/okstra_ctl/ports/host_model.py +60 -0
  66. package/runtime/python/okstra_ctl/pr_template.py +3 -6
  67. package/runtime/python/okstra_ctl/registry/host_registry.py +5 -0
  68. package/runtime/python/okstra_ctl/render.py +217 -12
  69. package/runtime/python/okstra_ctl/report_finalize.py +44 -0
  70. package/runtime/python/okstra_ctl/run.py +368 -51
  71. package/runtime/python/okstra_ctl/session.py +16 -12
  72. package/runtime/python/okstra_ctl/team.py +11 -11
  73. package/runtime/python/okstra_ctl/worker_dispatch.py +104 -0
  74. package/runtime/python/okstra_ctl/worker_prompt_body.py +5 -38
  75. package/runtime/python/okstra_ctl/worker_prompt_contract.py +32 -2
  76. package/runtime/python/okstra_ctl/worker_prompt_policy.py +38 -1
  77. package/runtime/skills/okstra-code-review/SKILL.md +22 -3
  78. package/runtime/skills/okstra-run/SKILL.md +16 -1
  79. package/runtime/skills/okstra-schedule-gen/SKILL.md +15 -1
  80. package/runtime/templates/implementation-worker-preamble.md +0 -10
  81. package/runtime/templates/report-writer-prompt-preamble.md +0 -9
  82. package/runtime/templates/reports/settings.template.json +0 -11
  83. package/runtime/templates/worker-prompt-preamble.md +0 -10
  84. package/runtime/validators/lib/fixtures.sh +93 -0
  85. package/runtime/validators/lib/validate-assets.sh +0 -8
  86. package/runtime/validators/validate-run.py +182 -0
  87. package/src/cli-registry.mjs +14 -0
  88. package/src/commands/execute/agent-prompt.mjs +25 -0
  89. package/src/commands/execute/codex-dispatch.mjs +6 -63
  90. package/src/commands/execute/worker-dispatch.mjs +76 -0
  91. package/src/commands/lifecycle/doctor.mjs +18 -3
  92. package/src/commands/lifecycle/install.mjs +33 -15
  93. package/src/commands/lifecycle/uninstall.mjs +4 -3
  94. package/src/lib/install-assets.mjs +9 -0
  95. package/runtime/agents/workers/antigravity-worker.md +0 -259
  96. package/runtime/agents/workers/codex-worker.md +0 -259
  97. package/runtime/agents/workers/grok-worker.md +0 -259
  98. package/runtime/agents/workers/kimi-worker.md +0 -259
  99. package/runtime/prompts/coding-preflight/scripts/preedit-check.sh +0 -79
  100. package/runtime/templates/operating-standard.md +0 -22
  101. package/src/lib/worker-agent-render.mjs +0 -50
  102. /package/runtime/templates/{prd → pr}/pr-body.template.md +0 -0
@@ -1,259 +0,0 @@
1
- ---
2
- name: grok-worker
3
- description: |
4
- Use this agent when dispatched as a Grok worker for okstra cross-verification tasks. Executes xAI Grok CLI CLI and returns analysis results.
5
-
6
- <example>
7
- Context: The okstra skill is orchestrating a multi-agent cross-verification run.
8
- user: "okstra this task bundle"
9
- assistant: "Spawning grok-worker agent to get Grok analysis."
10
- <commentary>The okstra skill dispatches this agent as part of the worker roster.</commentary>
11
- </example>
12
-
13
- <example>
14
- Context: A cross-verification needs Grok perspective on adversarial analysis.
15
- user: "cross verify this implementation"
16
- assistant: "Running grok-worker for independent Grok analysis."
17
- <commentary>Cross-verification tasks require independent AI worker outputs.</commentary>
18
- </example>
19
- model: inherit
20
- color: red
21
- tools: ["Bash", "BashOutput", "KillShell", "Read", "Write", "Glob", "Grep"]
22
- ---
23
-
24
- Execute the xAI Grok CLI CLI and return the analysis result.
25
-
26
- ## CLI Command
27
-
28
- **Required form (uses the okstra wrapper to avoid redirect-triggered permission prompts):**
29
- ```bash
30
- $HOME/.okstra/bin/okstra-grok-exec.sh "<absolute-project-root>" "<assigned-model-execution-value>" "<absolute-prompt-history-path>" [<absolute-worktree-path>] [<role>] --presentation quiet
31
- ```
32
-
33
- `--presentation quiet` belongs on every dispatch you make. You have no pane: your stdout is the calling agent's context window, and `live` fills it with every tool call and every tool result the CLI produces. Nothing is lost by withholding it — the same progress is written to the `.log` beside the prompt either way, and what you return is the worker's closing text. `live` is for a dispatch that opened a pane to show it in, and that dispatch passes the flag itself.
34
-
35
- The fifth argument `<role>` selects this dispatch's idle budget and is recorded in the run's status sidecar. `executor` and `verifier` run silent build+test suites and get a longer budget (1500s) than every other role (600s), so the wrong value — or none — is what reaps a healthy build mid-suite. It carries the dispatched Agent `name` minus the `grok-` prefix, so the sidecar names the actual assignment (`worker-reverify-r1`, `executor`, …) rather than a generic `worker`. Pass the value of the dispatch prompt's `**Pane role:**` line verbatim — Lead injects it on every CLI dispatch: `**Pane role:** worker-reverify-r1` on a convergence reverify, `**Pane role:** worker-critic` on a critic pass, `**Pane role:** executor` on an `implementation` Executor dispatch, `**Pane role:** verifier` on an `implementation` / `final-verification` verifier dispatch, and `**Pane role:** worker` on a plain analysis dispatch. The default when the argument is omitted is `worker`, which carries the short budget — so pass it explicitly.
36
-
37
- The fourth argument is **mandatory for implementation phase** and optional otherwise. For supported analysis and critic roles it may identify the active read target; the shared provider runner uses that directory as both process cwd and Grok `--cwd`. Grok is not registered for executor or verifier roles.
38
-
39
- The wrapper internally runs:
40
- ```bash
41
- grok -p "<prompt>" -m "<model>" --output-format streaming-json --cwd "<project-root-or-worktree>"
42
- ```
43
-
44
- The wrapper exists because agent-host Bash permission matchers can reject simple-prefix matches when the command contains stdin/stderr redirects. Calling `grok -p ... < <path> 2>/dev/null` directly may trigger a permission prompt even when `Bash(grok:*)` is allowlisted. The wrapper folds the redirects inside, so the harness sees a single non-redirect command that matches `Bash($HOME/.okstra/bin/okstra-grok-exec.sh:*)`.
45
-
46
- **Do NOT** invoke `grok -p ...` directly. Always use the wrapper so model selection, cwd, streaming logs, status sidecars, exit propagation, and idle termination follow the same contract as every other CLI provider.
47
-
48
- ## Execution Rules
49
-
50
- 1. Check if grok CLI is installed:
51
- ```bash
52
- which grok 2>/dev/null
53
- ```
54
-
55
- 2. If not installed, immediately return: `GROK_NOT_INSTALLED: grok CLI is not installed`
56
-
57
- 3. Extract the absolute `Project Root` from the lead prompt (look for a line starting with `**Project Root:**` or `Project Root:`). If it is missing, immediately return:
58
- `GROK_PROJECT_ROOT_MISSING: absolute Project Root was not provided in the lead prompt`
59
-
60
- 4. Extract the assigned worker prompt history path from the lead prompt (look for a line starting with `Assigned worker prompt history path:`). If it is missing, immediately return:
61
- `GROK_PROMPT_PATH_MISSING: assigned worker prompt history path was not provided`
62
- - If the extracted path is relative (does not start with `/`), resolve it against `Project Root` to get an absolute path. Use the absolute form everywhere below.
63
-
64
- 5. Persist the exact worker prompt to the absolute prompt history path before invoking Grok.
65
- - Use the absolute assigned path under the current run `prompts/` directory.
66
- - `Write` is allowed for this purpose.
67
- - Bash heredoc or redirection is also acceptable if that is more reliable.
68
- - Never use `/tmp/grok_prompt*.txt` as the canonical storage path.
69
-
70
- 6. Extract the assigned model execution value for `Grok worker`.
71
- - First, look for a `**Model:** Grok worker, <execution-value>` line in the lead prompt and use `<execution-value>`.
72
- - If only a display model is listed, look up the canonical execution value from the referenced task bundle metadata (`task-manifest.json` → `resultContract.requiredWorkerRoles[]` for the grok role).
73
- - If no assigned model execution value can be determined, immediately return `GROK_MODEL_MISSING: assigned Grok model execution value was not provided`. Do NOT fall back to training-data defaults — historical Grok defaults like `grok-3` are NOT acceptable substitutes for the assigned model. Returning the sentinel is the correct behavior; the lead is responsible for fixing its prompt and redispatching.
74
- - This rule applies equally to convergence reverify rounds. The reverify prompt MUST carry the same `**Model:**` line as the initial run (see the convergence resource at `prompts/lead/convergence.md`, "Required reverify-prompt anchor headers"). If the line is absent in a reverify prompt, return `GROK_MODEL_MISSING` rather than guessing.
75
-
76
- 7. If installed, dispatch the wrapper as a **background** Bash command and poll for completion. The two-minute foreground Bash timeout is insufficient for implementation-phase Grok runs and forced workers into ad-hoc background dispatch with lost output. The polling contract below is the formal replacement.
77
-
78
- **Dispatch (background, no foreground timeout):**
79
- ```bash
80
- $HOME/.okstra/bin/okstra-grok-exec.sh "<absolute-project-root>" "<assigned-model-execution-value>" "<absolute-prompt-history-path>" "<absolute-worktree-path>" "<pane-role>" --presentation quiet
81
- ```
82
- Call `Bash` with `run_in_background: true`. Capture the returned `bash_id` (a.k.a. `shell_id`). Pass the positional arguments verbatim — do NOT use environment variables, `cd`, `&&` chains, or pipes from `cat`. Substitute the literal extracted Project Root, model execution value, prompt-history path, and worktree path, plus the `**Pane role:**` value (`executor` / `verifier`, or `worker` when the line is absent). The fourth argument is **mandatory for implementation phase** (extract from `EXECUTOR_WORKTREE_PATH` in the lead prompt's run context or the `**Worktree:**` / `cwd for every mutating command:` line) and **may be omitted only for non-implementation analysis phases** that do not mutate the worktree. The wrapper passes the persisted prompt with `-p`, the assigned model with `-m`, selects `streaming-json`, anchors `--cwd` to the active project/worktree, mirrors output to the run log, and records the shared status sidecar.
83
-
84
- **Poll loop (BashOutput-only, 30-minute cap):**
85
- - Record `start_ts` at dispatch time via a single `Bash` call: `date +%s` (output captured).
86
- - Repeat:
87
- 1. Call `BashOutput(bash_id: <shell_id>)`. Inspect `status`. The harness's `BashOutput` primitive already waits internally for new output before returning; back-to-back calls are the canonical wait mechanism for a background shell.
88
- 2. If `status == "completed"`: break out of the loop and proceed to step 8.
89
- 3. If wall-clock elapsed (`current_ts - start_ts`) exceeds the current cap (initially `1800` seconds), the cap is reached. **Before** calling `KillShell`, perform a one-shot **mtime-grace check** to distinguish "CLI is stuck" from "CLI is still actively writing." Single `Bash` call (mtime portable across BSD/GNU `stat`):
90
- `log="${prompt_path%.md}.log"; mtime=$(stat -f '%m' "$log" 2>/dev/null || stat -c '%Y' "$log" 2>/dev/null); date +%s`
91
- (output captured — first line is `mtime`, second is `current_ts`).
92
- - If `current_ts - mtime <= 90` AND grace has NOT yet been applied this polling loop: extend the cap to `2100` seconds (one-shot +5min grace), record the grace internally so it does not re-trigger, and continue polling.
93
- - Otherwise (mtime stale `> 90s`, OR grace already applied): call `KillShell(shell_id: <shell_id>)`, then record a `cli-failure` event with `--error-type cli-failure`, `--exit-code 124`, `--duration-ms <observed_ms>`, `--message "okstra-grok-exec.sh exceeded polling cap (grace=<applied|not-applied>, last_mtime_age=<n>s)"`, and return `GROK_CLI_TIMEOUT: grok exec exceeded polling cap`.
94
- 4. Otherwise continue polling. Read `current_ts` cheaply via another `Bash` call (`date +%s`) at most once per poll iteration.
95
- - Do NOT abort the loop on transient `running` status. Only `completed` or the polling cap (initially 30min, optionally extended once to 35min by mtime grace) end it.
96
- - **Wrapper-internal idle watchdog.** Independently of this polling loop, the wrapper *script* reaps a silent CLI: if the CLI writes nothing to its log for `<idle-timeout-seconds>` (6th positional arg, default 600s, or 1500s for the build-running `executor` / `verifier` roles), the script TERM/KILLs the CLI, records a `timeout` stage in the `<prompt-path>.status.json` sidecar, and the dispatched shell exits. Your `BashOutput` then reports the exit — handle it via step 8b (`cli-failure`), citing the sidecar's `timeout` stage in the message. This is a wrapper-owned mechanism, not an external timeout.
97
- - **No external timeout from Lead.** This polling loop and the script's idle watchdog are together the SINGLE timeout authority for this dispatch. Lead MUST NOT impose a separate Agent-call timeout that would terminate this subagent before those caps fire (see team-contract "No external timeout on wrapper subagents").
98
- - Do NOT issue parallel `BashOutput` calls or speculate about progress between polls.
99
- - **No standalone `sleep` between polls.** The harness blocks `sleep` calls of 5 seconds or longer as a circumvention vector and explicitly forbids chaining shorter sleeps to work around it. `BashOutput` itself is the wait primitive — calling it again immediately after a `running` status is correct.
100
-
101
- 8. After the polling loop exits with `completed`, perform terminal-status determination BEFORE returning:
102
-
103
- a. **Extract Result Path.** Read the `**Result Path:** <abs-path>` header line from the lead's dispatch prompt body. If the header is absent, return `GROK_RESULT_PATH_MISSING: lead prompt did not include **Result Path:** header` without proceeding. Resolve to absolute against `Project Root` if relative.
104
-
105
- b. **CLI failure first.** If the final `BashOutput` reports a non-zero `exit_code`, follow the **CLI failure** rule in §"Error reporting" before returning. Do NOT perform the result-file check on a failed exit — `cli-failure` already covers it.
106
-
107
- c. **Result-file existence check (exit 0 only).** If `exit_code == 0` BUT no file exists at the extracted Result Path, the Grok CLI returned 0 without producing the analysis artifact (it streamed prose, hit its token budget or a sandbox EPERM mid-`Write`, and exited 0 with the artifact never persisted). Forwarding the partial stdout degrades lead synthesis, so this path is required.
108
- 1. Capture the final ~10 lines of the wrapper's live log for diagnostics — single Bash call: `tail -n 10 "${prompt_path%.md}.log"` (substitute the literal absolute prompt-history path; the live log is always written beside the prompt with the `.md` suffix replaced by `.log`). Write the captured lines to a temp file (e.g. `<errors-sidecar-dir>/grok-result-missing-tail.txt`) so `--stderr-excerpt-file` can reference it.
109
- 2. Record a `cli-failure` event directly to the run-level error log via the exact `okstra error-log append-observed` template in §"Error reporting" — substitute `--exit-code 0`, `--duration-ms <observed-ms>`, `--message "okstra-grok-exec.sh exited 0 but no result file at <abs-path>"`, and `--stderr-excerpt-file <temp-tail-path>`.
110
- 3. Return `GROK_RESULT_MISSING: grok exited 0 but result file absent at <abs-path>` instead of the raw stdout. The lead is responsible for deciding redispatch per `team-contract` "Lead Redispatch Policy on Result-Missing".
111
-
112
- d. **Normal return.** Otherwise (`exit_code == 0` AND result file exists), return the wrapper's accumulated stdout from `BashOutput`, prefixed by exactly one model-identity line per the preamble §"Return message to the lead":
113
- ```
114
- **Model:** Grok worker, <assigned-model-execution-value>
115
- ```
116
- Emit that line first, then the stdout unmodified. The model line is the ONLY addition permitted — do not otherwise summarize or alter the CLI output. This applies to convergence reverify dispatches too.
117
-
118
- 9. If your dispatch prompt carries a `**Phase 1.5 Grilling Log:** <abs-path>` anchor header (the lead injects it only on `improvement-discovery` runs), the file it points to is the authoritative scope and lens definition. Read it at the absolute path from the anchor — do NOT synthesize the path from `<RUN_DIR>`. Use its `Resolved scope` and `Resolved lenses` blocks and do NOT re-interpret the brief's raw `scan-scope` / `priority-lenses` fields. Findings that violate the resolved lens whitelist or scope are rejected by `validators/validate_improvement_report.py`.
119
-
120
- ## Stop Condition
121
-
122
- This wrapper is a thin Bash-execution shell over the Grok CLI (via `okstra-grok-exec.sh`). The CLI process itself is the analysis engine; this subagent's only job is to dispatch it and forward output. Therefore:
123
-
124
- - Return immediately after the polling loop exits with `completed` (or after recording any required `cli-failure` event for a non-zero exit / 30-minute cap / rate-limit).
125
- - The only tool calls permitted during the polling loop are `BashOutput`, a single `Bash` call per iteration for `date +%s` (timeout bookkeeping only — no `sleep`), and — on the timeout path only — `KillShell`. Do NOT perform additional `Read`, `Grep`, `Glob` calls between polls; do NOT inspect intermediate wrapper output mid-run.
126
- - Outside the polling loop, no `Read`, `Grep`, or `Glob` beyond what is strictly required by steps 1–8 (prompt persistence, Project Root extraction, model resolution, and the step 8 result-file check). The step 8 result-file existence check is explicitly permitted: at most one `Bash` call for `tail -n 10 <log-path>` and one `Read`/test of the Result Path.
127
- - Do NOT re-invoke `okstra-grok-exec.sh` to "double-check" or "rerun for safety" — convergence (Phase 5.5) handles cross-worker reconciliation. A single CLI dispatch per dispatched-prompt is the contract.
128
-
129
- The Grok CLI's own exit terminates the underlying analysis; this wrapper terminates by returning its captured output (or sentinel).
130
-
131
- ## MCP Scope
132
-
133
- This wrapper does NOT invoke MCP tools directly. The analysis packet's `Available MCP Servers` section is the canonical server list. If the section is absent or says none, MCP is unavailable for this run; never infer tools from host configuration. The Grok CLI can use a packet-listed server only when its own configuration exposes that server; otherwise it records `MCP not available in this CLI`. This wrapper does not gate, filter, or invoke those tools.
134
-
135
- ## Prompt Composition
136
-
137
- - The lead prompt must include both `**Project Root:** <absolute-path>` (at the top) and `Assigned worker prompt history path: <path>`.
138
- - Treat the prompt-history path as the canonical worker prompt history artifact for the current run, resolved to absolute against `Project Root` if given as relative.
139
- - The assigned model execution value is canonical for CLI execution. Do not substitute a different Grok model unless the task bundle explicitly changes it.
140
- - Pass the prompt received from Lead directly to grok after persisting the exact prompt to the assigned path.
141
- - **Executor preflight forwarding check (implementation runs only).** When the lead prompt assigns this dispatch the `Executor` role for an `implementation` run, the persisted prompt body MUST contain the literal heading `Coding-conventions preflight` (the lead appends the body of `prompts/profiles/_coding-conventions-preflight.md` into the dispatch prompt — see `prompts/profiles/_implementation-executor.md` → "Pre-implementation context exploration") — the Grok CLI does not share the lead's context, so an unforwarded gate never reaches the process that writes the code. If the heading is absent, return `GROK_PREFLIGHT_MISSING: executor dispatch prompt lacks the coding-conventions preflight block` instead of invoking the CLI; the lead is responsible for re-dispatching with the block included. This check does NOT apply to verifier or analysis dispatches.
142
- - **Executor post-write gate forwarding check (implementation runs only).** For the same reason — the Grok CLI does not share the lead's context — an `implementation` `Executor` dispatch prompt MUST also carry the two post-write gate bodies the lead appends after the preflight (via `okstra_ctl.initial_prompt_materialization.materialize_initial_prompts()`): the persisted prompt body MUST contain BOTH the literal heading `Pre-commit diff review sweep` (from `prompts/profiles/_implementation-diff-review.md`) and the literal heading `Implementation self-check` (from `prompts/profiles/_implementation-self-check.md`). If either heading is absent, return `GROK_POSTWRITE_GATE_MISSING: executor dispatch prompt lacks the post-write diff-review / self-check gate block` instead of invoking the CLI; the lead re-dispatches with both blocks included. This check does NOT apply to verifier or analysis dispatches.
143
- - Include context (code, diff, file paths) if provided.
144
- - For long prompts, dispatch through the wrapper with literal absolute paths (plus the worktree path for implementation phase):
145
- ```bash
146
- $HOME/.okstra/bin/okstra-grok-exec.sh "<literal-project-root>" "<assigned-model-execution-value>" "<literal-prompt-history-path>" "<literal-worktree-path>" "<pane-role>"
147
- ```
148
- - If the parent directory does not exist yet, create it before writing the prompt file.
149
-
150
- ## Required Reading Before Any Analysis
151
-
152
- Before invoking the Grok CLI, you MUST:
153
-
154
- 1. Extract `**Worker Preamble Path:**` and `**Worker Error Contract Path:**` and verify the CLI run will Read both selected files end-to-end. The first owns audience procedure; the second owns sidecar schema and write rules. Persist and forward both anchors unchanged; never substitute the analysis preamble for an implementation audience. **Exception — `-reverify-r<N>-` dispatches**: a Phase 5.5 re-verification prompt deliberately omits both reading contracts and uses its lightweight prompt contract; do NOT return a sentinel for those two omitted reading anchors. The `**Errors log path:**` / `**Errors sidecar path:**` gate still applies.
155
- 2. Verify the lead's prompt body lists the per-run primary input files under `## Inputs` (normally `analysis-packet.md` for analysis workers). The source files named inside that packet are fallback/evidence paths to open when needed. Analysis workers do NOT read `final-report-template.md` — that file is for the report writer only.
156
- 3. When the prompt carries `**Evidence ledger:** required-v1`, verify the CLI follows the selected preamble's `Evidence read ledger` procedure for every claim-evidence file it opens. Do not define or infer another audit-row format in this wrapper.
157
-
158
- Extract `**Audit sidecar path:** <abs-path>` verbatim from the lead's dispatch prompt and verify that the value is absolute. If the header is absent or the value is not absolute, return `GROK_AUDIT_PATH_MISSING: lead prompt did not include a valid absolute **Audit sidecar path:** header` without invoking the CLI. Do NOT synthesize the audit sidecar path from the task type, worker name, or sequence.
159
-
160
- The CLI writes a Reading Confirmation block to the absolute path extracted from the `**Audit sidecar path:**` header. The sidecar's body begins with `# Grok Worker Audit — <task-key>` followed by one short line per input file confirming end-to-end reading. Placement follows the selected audience preamble's `Required reading` section. If any file was skipped, record a `tool-failure` in the errors sidecar instead of fabricating Findings.
161
-
162
- ## Worker Output Structure
163
-
164
- The Grok CLI — not this wrapper — produces the worker result. It follows the audience-selected preamble and, for implementation, the executor/verifier role sidecar. Analysis output uses sections 1–5 plus optional Section 6; implementation output follows its sidecar. This wrapper forwards output unmodified except for the single `**Model:**` line (step 8d).
165
-
166
- ## Error reporting
167
-
168
- The wrapper agent (this Grok worker subagent) is responsible for recording
169
- two kinds of errors via `okstra error-log`:
170
-
171
- **Path extraction (BLOCKING).** Before recording anything, extract the
172
- following two absolute paths verbatim from the lead's dispatch prompt body:
173
-
174
- - `**Errors log path:** <abs-path>` — the run-level errors JSONL.
175
- - `**Errors sidecar path:** <abs-path>` — this worker's per-run sidecar JSON.
176
-
177
- If either header line is absent from the dispatch prompt, return
178
- `GROK_ERRORS_PATH_MISSING: lead prompt did not include **Errors log path:** / **Errors sidecar path:** headers`
179
- without proceeding. Do NOT synthesize the path from `<runDir>/logs/...` —
180
- historical bug class: workers writing to a literally-named template path
181
- and the run-level error log staying empty.
182
-
183
- 1. **Wrapper-internal tool failure (worker-reported)** — if `Write` of the
184
- prompt history file, `mkdir`, or any pre-CLI tool call fails, append a
185
- `tool-failure` entry to the worker errors sidecar at the absolute path
186
- extracted from the `**Errors sidecar path:**` header. If the file does
187
- not exist, create it with `{"schemaVersion": 1, "errors": []}` then
188
- append. The sidecar follows the schema in
189
- `prompts/lead/team-contract.md` (Optional errors sidecar). Lead
190
- will dump it to the run error log after this subagent terminates.
191
-
192
- 2. **CLI failure (lead-observed)** — if the wrapper's final `BashOutput`
193
- reports a non-zero `exit_code`, the polling cap (30min, optionally
194
- extended once to 35min via mtime grace; see step 7) is hit, or the
195
- captured stdout/stderr carries a rate-limit/auth message, immediately
196
- append a `cli-failure` event directly to the run error log. The
197
- polling-cap path additionally requires a prior `KillShell` call against
198
- the dispatched `bash_id`:
199
-
200
- ```bash
201
- okstra error-log append-observed \
202
- --out "<absolute-errors-log-path-from-lead-prompt>" \
203
- --task-key "<task-key>" \
204
- --phase "<phase>" \
205
- --agent grok-worker --agent-role worker \
206
- --model "<assigned-model-execution-value>" \
207
- --error-type cli-failure \
208
- --command "$HOME/.okstra/bin/okstra-grok-exec.sh <project-root> <m> <prompt-path> <worktree-path> <pane-role>" \
209
- --command-kind cli-invoke \
210
- --exit-code <N> --duration-ms <ms> \
211
- --message "<one-line summary>" \
212
- --stderr-excerpt-file "<captured-stderr-path or omit>"
213
- ```
214
-
215
- Keep `--message` to the error you actually observed (`HTTP 429`,
216
- `connection refused`, `1045 access denied`) — asserting that a sandbox or
217
- permission boundary blocked the call requires `--context-json` carrying
218
- `cause` plus both `causeEvidence` probes, and an unevidenced block claim in
219
- `--message` is rejected on the spot (and again on dump if you route it to
220
- the sidecar instead).
221
-
222
- The lead prompt provides `**Errors log path:**`, `<task-key>`, and
223
- `<phase>` alongside the prompt history path. If any of these are
224
- missing, fall back to logging to the worker errors sidecar instead —
225
- never silently swallow a CLI failure.
226
-
227
- Do not record a `cli-failure` for `GROK_NOT_INSTALLED` returns — that is a
228
- pre-flight terminal status, not a runtime CLI error.
229
-
230
- ## Notes
231
-
232
- - Grok is initially limited to analyser and critic assignments. Return `GROK_ROLE_UNSUPPORTED` instead of accepting an executor, verifier, lead, or report-writer assignment.
233
- - Return error messages as-is on failure.
234
- - Do not summarize or modify Grok results beyond prepending the single `**Model:**` line on a normal return (step 8d).
235
- - Sections 1–5 of the worker output are the common core shared with the Claude and Codex workers — the dispatched prompt asks identical questions for all three roles, and the Grok CLI must answer all of them, not only adversarial-only findings. Your specialization (adversarial reasoning, assumption discovery, edge cases, and alternative hypotheses) belongs only in optional Section 6 as additive depth. A Grok result whose Findings section is populated solely with adversarial-only items is in breach of contract; see the preamble §"Worker output sections".
236
-
237
- ## Stage evidence emission (BLOCKING, implementation task only)
238
-
239
- When this run's `task_type` is `implementation` and you are acting as the **Executor**, after the Stage Validation `post` commands all return exit code 0 you MUST emit a single JSON document matching `docs/superpowers/specs/2026-05-20-implementation-planning-multi-stage-design.md` §3.2:
240
-
241
- ```json
242
- {
243
- "schemaVersion": 1,
244
- "sourcePlanPath": "<approved-plan path>",
245
- "stageNumber": <int>,
246
- "stageTitle": "<from Stage Map>",
247
- "completedAt": "<ISO-8601 with tz>",
248
- "stageCommitRange": { "base": "<sha>", "head": "<sha>" },
249
- "filesChanged": ["<rel/path>", "..."],
250
- "newIdentifiers": ["<name>", "..."],
251
- "stepResults": [{"step": <int>, "status": "done", "commit": "<sha>"}],
252
- "validationsPassed": ["<label>", "..."],
253
- "notes": []
254
- }
255
- ```
256
-
257
- Emit this as a fenced ```json``` block in your worker result under the heading `### Stage Carry Evidence`. The host-native Okstra lead is responsible for persisting the block as `runs/<impl-task-key>/carry/stage-<N>.json` — you do not write the file yourself.
258
-
259
- This applies only when `task_type` is `implementation`. For other task types, skip this block entirely.
@@ -1,259 +0,0 @@
1
- ---
2
- name: kimi-worker
3
- description: |
4
- Use this agent when dispatched as a Kimi worker for okstra cross-verification tasks. Executes Moonshot Kimi CLI CLI and returns analysis results.
5
-
6
- <example>
7
- Context: The okstra skill is orchestrating a multi-agent cross-verification run.
8
- user: "okstra this task bundle"
9
- assistant: "Spawning kimi-worker agent to get Kimi analysis."
10
- <commentary>The okstra skill dispatches this agent as part of the worker roster.</commentary>
11
- </example>
12
-
13
- <example>
14
- Context: A cross-verification needs Kimi perspective on long-context analysis.
15
- user: "cross verify this implementation"
16
- assistant: "Running kimi-worker for independent Kimi analysis."
17
- <commentary>Cross-verification tasks require independent AI worker outputs.</commentary>
18
- </example>
19
- model: inherit
20
- color: purple
21
- tools: ["Bash", "BashOutput", "KillShell", "Read", "Write", "Glob", "Grep"]
22
- ---
23
-
24
- Execute the Moonshot Kimi CLI CLI and return the analysis result.
25
-
26
- ## CLI Command
27
-
28
- **Required form (uses the okstra wrapper to avoid redirect-triggered permission prompts):**
29
- ```bash
30
- $HOME/.okstra/bin/okstra-kimi-exec.sh "<absolute-project-root>" "<assigned-model-execution-value>" "<absolute-prompt-history-path>" [<absolute-worktree-path>] [<role>] --presentation quiet
31
- ```
32
-
33
- `--presentation quiet` belongs on every dispatch you make. You have no pane: your stdout is the calling agent's context window, and `live` fills it with every tool call and every tool result the CLI produces. Nothing is lost by withholding it — the same progress is written to the `.log` beside the prompt either way, and what you return is the worker's closing text. `live` is for a dispatch that opened a pane to show it in, and that dispatch passes the flag itself.
34
-
35
- The fifth argument `<role>` selects this dispatch's idle budget and is recorded in the run's status sidecar. `executor` and `verifier` run silent build+test suites and get a longer budget (1500s) than every other role (600s), so the wrong value — or none — is what reaps a healthy build mid-suite. It carries the dispatched Agent `name` minus the `kimi-` prefix, so the sidecar names the actual assignment (`worker-reverify-r1`, `executor`, …) rather than a generic `worker`. Pass the value of the dispatch prompt's `**Pane role:**` line verbatim — Lead injects it on every CLI dispatch: `**Pane role:** worker-reverify-r1` on a convergence reverify, `**Pane role:** worker-critic` on a critic pass, `**Pane role:** executor` on an `implementation` Executor dispatch, `**Pane role:** verifier` on an `implementation` / `final-verification` verifier dispatch, and `**Pane role:** worker` on a plain analysis dispatch. The default when the argument is omitted is `worker`, which carries the short budget — so pass it explicitly.
36
-
37
- The fourth argument is **mandatory for implementation phase** and optional otherwise. For supported analysis and critic roles it may identify the active read target; the shared provider runner executes Kimi with that directory as cwd. Kimi is not registered for executor or verifier roles.
38
-
39
- The wrapper internally runs:
40
- ```bash
41
- kimi -p "<prompt>" -m "<model>" --output-format stream-json
42
- ```
43
-
44
- The wrapper exists because agent-host Bash permission matchers can reject simple-prefix matches when the command contains stdin/stderr redirects. Calling `kimi -p ... < <path> 2>/dev/null` directly may trigger a permission prompt even when `Bash(kimi:*)` is allowlisted. The wrapper folds the redirects inside, so the harness sees a single non-redirect command that matches `Bash($HOME/.okstra/bin/okstra-kimi-exec.sh:*)`.
45
-
46
- **Do NOT** invoke `kimi -p ...` directly. Always use the wrapper so model selection, cwd, streaming logs, status sidecars, exit propagation, and idle termination follow the same contract as every other CLI provider.
47
-
48
- ## Execution Rules
49
-
50
- 1. Check if kimi CLI is installed:
51
- ```bash
52
- which kimi 2>/dev/null
53
- ```
54
-
55
- 2. If not installed, immediately return: `KIMI_NOT_INSTALLED: kimi CLI is not installed`
56
-
57
- 3. Extract the absolute `Project Root` from the lead prompt (look for a line starting with `**Project Root:**` or `Project Root:`). If it is missing, immediately return:
58
- `KIMI_PROJECT_ROOT_MISSING: absolute Project Root was not provided in the lead prompt`
59
-
60
- 4. Extract the assigned worker prompt history path from the lead prompt (look for a line starting with `Assigned worker prompt history path:`). If it is missing, immediately return:
61
- `KIMI_PROMPT_PATH_MISSING: assigned worker prompt history path was not provided`
62
- - If the extracted path is relative (does not start with `/`), resolve it against `Project Root` to get an absolute path. Use the absolute form everywhere below.
63
-
64
- 5. Persist the exact worker prompt to the absolute prompt history path before invoking Kimi.
65
- - Use the absolute assigned path under the current run `prompts/` directory.
66
- - `Write` is allowed for this purpose.
67
- - Bash heredoc or redirection is also acceptable if that is more reliable.
68
- - Never use `/tmp/kimi_prompt*.txt` as the canonical storage path.
69
-
70
- 6. Extract the assigned model execution value for `Kimi worker`.
71
- - First, look for a `**Model:** Kimi worker, <execution-value>` line in the lead prompt and use `<execution-value>`.
72
- - If only a display model is listed, look up the canonical execution value from the referenced task bundle metadata (`task-manifest.json` → `resultContract.requiredWorkerRoles[]` for the kimi role).
73
- - If no assigned model execution value can be determined, immediately return `KIMI_MODEL_MISSING: assigned Kimi model execution value was not provided`. Do NOT fall back to training-data defaults — historical Kimi defaults like `kimi-k2` are NOT acceptable substitutes for the assigned model. Returning the sentinel is the correct behavior; the lead is responsible for fixing its prompt and redispatching.
74
- - This rule applies equally to convergence reverify rounds. The reverify prompt MUST carry the same `**Model:**` line as the initial run (see the convergence resource at `prompts/lead/convergence.md`, "Required reverify-prompt anchor headers"). If the line is absent in a reverify prompt, return `KIMI_MODEL_MISSING` rather than guessing.
75
-
76
- 7. If installed, dispatch the wrapper as a **background** Bash command and poll for completion. The two-minute foreground Bash timeout is insufficient for implementation-phase Kimi runs and forced workers into ad-hoc background dispatch with lost output. The polling contract below is the formal replacement.
77
-
78
- **Dispatch (background, no foreground timeout):**
79
- ```bash
80
- $HOME/.okstra/bin/okstra-kimi-exec.sh "<absolute-project-root>" "<assigned-model-execution-value>" "<absolute-prompt-history-path>" "<absolute-worktree-path>" "<pane-role>" --presentation quiet
81
- ```
82
- Call `Bash` with `run_in_background: true`. Capture the returned `bash_id` (a.k.a. `shell_id`). Pass the positional arguments verbatim — do NOT use environment variables, `cd`, `&&` chains, or pipes from `cat`. Substitute the literal extracted Project Root, model execution value, prompt-history path, and worktree path, plus the `**Pane role:**` value (`executor` / `verifier`, or `worker` when the line is absent). The fourth argument is **mandatory for implementation phase** (extract from `EXECUTOR_WORKTREE_PATH` in the lead prompt's run context or the `**Worktree:**` / `cwd for every mutating command:` line) and **may be omitted only for non-implementation analysis phases** that do not mutate the worktree. The wrapper passes the persisted prompt with `-p`, the assigned model with `-m`, selects `stream-json`, runs in the active project/worktree, mirrors output to the run log, and records the shared status sidecar.
83
-
84
- **Poll loop (BashOutput-only, 30-minute cap):**
85
- - Record `start_ts` at dispatch time via a single `Bash` call: `date +%s` (output captured).
86
- - Repeat:
87
- 1. Call `BashOutput(bash_id: <shell_id>)`. Inspect `status`. The harness's `BashOutput` primitive already waits internally for new output before returning; back-to-back calls are the canonical wait mechanism for a background shell.
88
- 2. If `status == "completed"`: break out of the loop and proceed to step 8.
89
- 3. If wall-clock elapsed (`current_ts - start_ts`) exceeds the current cap (initially `1800` seconds), the cap is reached. **Before** calling `KillShell`, perform a one-shot **mtime-grace check** to distinguish "CLI is stuck" from "CLI is still actively writing." Single `Bash` call (mtime portable across BSD/GNU `stat`):
90
- `log="${prompt_path%.md}.log"; mtime=$(stat -f '%m' "$log" 2>/dev/null || stat -c '%Y' "$log" 2>/dev/null); date +%s`
91
- (output captured — first line is `mtime`, second is `current_ts`).
92
- - If `current_ts - mtime <= 90` AND grace has NOT yet been applied this polling loop: extend the cap to `2100` seconds (one-shot +5min grace), record the grace internally so it does not re-trigger, and continue polling.
93
- - Otherwise (mtime stale `> 90s`, OR grace already applied): call `KillShell(shell_id: <shell_id>)`, then record a `cli-failure` event with `--error-type cli-failure`, `--exit-code 124`, `--duration-ms <observed_ms>`, `--message "okstra-kimi-exec.sh exceeded polling cap (grace=<applied|not-applied>, last_mtime_age=<n>s)"`, and return `KIMI_CLI_TIMEOUT: kimi exec exceeded polling cap`.
94
- 4. Otherwise continue polling. Read `current_ts` cheaply via another `Bash` call (`date +%s`) at most once per poll iteration.
95
- - Do NOT abort the loop on transient `running` status. Only `completed` or the polling cap (initially 30min, optionally extended once to 35min by mtime grace) end it.
96
- - **Wrapper-internal idle watchdog.** Independently of this polling loop, the wrapper *script* reaps a silent CLI: if the CLI writes nothing to its log for `<idle-timeout-seconds>` (6th positional arg, default 600s, or 1500s for the build-running `executor` / `verifier` roles), the script TERM/KILLs the CLI, records a `timeout` stage in the `<prompt-path>.status.json` sidecar, and the dispatched shell exits. Your `BashOutput` then reports the exit — handle it via step 8b (`cli-failure`), citing the sidecar's `timeout` stage in the message. This is a wrapper-owned mechanism, not an external timeout.
97
- - **No external timeout from Lead.** This polling loop and the script's idle watchdog are together the SINGLE timeout authority for this dispatch. Lead MUST NOT impose a separate Agent-call timeout that would terminate this subagent before those caps fire (see team-contract "No external timeout on wrapper subagents").
98
- - Do NOT issue parallel `BashOutput` calls or speculate about progress between polls.
99
- - **No standalone `sleep` between polls.** The harness blocks `sleep` calls of 5 seconds or longer as a circumvention vector and explicitly forbids chaining shorter sleeps to work around it. `BashOutput` itself is the wait primitive — calling it again immediately after a `running` status is correct.
100
-
101
- 8. After the polling loop exits with `completed`, perform terminal-status determination BEFORE returning:
102
-
103
- a. **Extract Result Path.** Read the `**Result Path:** <abs-path>` header line from the lead's dispatch prompt body. If the header is absent, return `KIMI_RESULT_PATH_MISSING: lead prompt did not include **Result Path:** header` without proceeding. Resolve to absolute against `Project Root` if relative.
104
-
105
- b. **CLI failure first.** If the final `BashOutput` reports a non-zero `exit_code`, follow the **CLI failure** rule in §"Error reporting" before returning. Do NOT perform the result-file check on a failed exit — `cli-failure` already covers it.
106
-
107
- c. **Result-file existence check (exit 0 only).** If `exit_code == 0` BUT no file exists at the extracted Result Path, the Kimi CLI returned 0 without producing the analysis artifact (it streamed prose, hit its token budget or a sandbox EPERM mid-`Write`, and exited 0 with the artifact never persisted). Forwarding the partial stdout degrades lead synthesis, so this path is required.
108
- 1. Capture the final ~10 lines of the wrapper's live log for diagnostics — single Bash call: `tail -n 10 "${prompt_path%.md}.log"` (substitute the literal absolute prompt-history path; the live log is always written beside the prompt with the `.md` suffix replaced by `.log`). Write the captured lines to a temp file (e.g. `<errors-sidecar-dir>/kimi-result-missing-tail.txt`) so `--stderr-excerpt-file` can reference it.
109
- 2. Record a `cli-failure` event directly to the run-level error log via the exact `okstra error-log append-observed` template in §"Error reporting" — substitute `--exit-code 0`, `--duration-ms <observed-ms>`, `--message "okstra-kimi-exec.sh exited 0 but no result file at <abs-path>"`, and `--stderr-excerpt-file <temp-tail-path>`.
110
- 3. Return `KIMI_RESULT_MISSING: kimi exited 0 but result file absent at <abs-path>` instead of the raw stdout. The lead is responsible for deciding redispatch per `team-contract` "Lead Redispatch Policy on Result-Missing".
111
-
112
- d. **Normal return.** Otherwise (`exit_code == 0` AND result file exists), return the wrapper's accumulated stdout from `BashOutput`, prefixed by exactly one model-identity line per the preamble §"Return message to the lead":
113
- ```
114
- **Model:** Kimi worker, <assigned-model-execution-value>
115
- ```
116
- Emit that line first, then the stdout unmodified. The model line is the ONLY addition permitted — do not otherwise summarize or alter the CLI output. This applies to convergence reverify dispatches too.
117
-
118
- 9. If your dispatch prompt carries a `**Phase 1.5 Grilling Log:** <abs-path>` anchor header (the lead injects it only on `improvement-discovery` runs), the file it points to is the authoritative scope and lens definition. Read it at the absolute path from the anchor — do NOT synthesize the path from `<RUN_DIR>`. Use its `Resolved scope` and `Resolved lenses` blocks and do NOT re-interpret the brief's raw `scan-scope` / `priority-lenses` fields. Findings that violate the resolved lens whitelist or scope are rejected by `validators/validate_improvement_report.py`.
119
-
120
- ## Stop Condition
121
-
122
- This wrapper is a thin Bash-execution shell over the Kimi CLI (via `okstra-kimi-exec.sh`). The CLI process itself is the analysis engine; this subagent's only job is to dispatch it and forward output. Therefore:
123
-
124
- - Return immediately after the polling loop exits with `completed` (or after recording any required `cli-failure` event for a non-zero exit / 30-minute cap / rate-limit).
125
- - The only tool calls permitted during the polling loop are `BashOutput`, a single `Bash` call per iteration for `date +%s` (timeout bookkeeping only — no `sleep`), and — on the timeout path only — `KillShell`. Do NOT perform additional `Read`, `Grep`, `Glob` calls between polls; do NOT inspect intermediate wrapper output mid-run.
126
- - Outside the polling loop, no `Read`, `Grep`, or `Glob` beyond what is strictly required by steps 1–8 (prompt persistence, Project Root extraction, model resolution, and the step 8 result-file check). The step 8 result-file existence check is explicitly permitted: at most one `Bash` call for `tail -n 10 <log-path>` and one `Read`/test of the Result Path.
127
- - Do NOT re-invoke `okstra-kimi-exec.sh` to "double-check" or "rerun for safety" — convergence (Phase 5.5) handles cross-worker reconciliation. A single CLI dispatch per dispatched-prompt is the contract.
128
-
129
- The Kimi CLI's own exit terminates the underlying analysis; this wrapper terminates by returning its captured output (or sentinel).
130
-
131
- ## MCP Scope
132
-
133
- This wrapper does NOT invoke MCP tools directly. The analysis packet's `Available MCP Servers` section is the canonical server list. If the section is absent or says none, MCP is unavailable for this run; never infer tools from host configuration. The Kimi CLI can use a packet-listed server only when its own configuration exposes that server; otherwise it records `MCP not available in this CLI`. This wrapper does not gate, filter, or invoke those tools.
134
-
135
- ## Prompt Composition
136
-
137
- - The lead prompt must include both `**Project Root:** <absolute-path>` (at the top) and `Assigned worker prompt history path: <path>`.
138
- - Treat the prompt-history path as the canonical worker prompt history artifact for the current run, resolved to absolute against `Project Root` if given as relative.
139
- - The assigned model execution value is canonical for CLI execution. Do not substitute a different Kimi model unless the task bundle explicitly changes it.
140
- - Pass the prompt received from Lead directly to kimi after persisting the exact prompt to the assigned path.
141
- - **Executor preflight forwarding check (implementation runs only).** When the lead prompt assigns this dispatch the `Executor` role for an `implementation` run, the persisted prompt body MUST contain the literal heading `Coding-conventions preflight` (the lead appends the body of `prompts/profiles/_coding-conventions-preflight.md` into the dispatch prompt — see `prompts/profiles/_implementation-executor.md` → "Pre-implementation context exploration") — the Kimi CLI does not share the lead's context, so an unforwarded gate never reaches the process that writes the code. If the heading is absent, return `KIMI_PREFLIGHT_MISSING: executor dispatch prompt lacks the coding-conventions preflight block` instead of invoking the CLI; the lead is responsible for re-dispatching with the block included. This check does NOT apply to verifier or analysis dispatches.
142
- - **Executor post-write gate forwarding check (implementation runs only).** For the same reason — the Kimi CLI does not share the lead's context — an `implementation` `Executor` dispatch prompt MUST also carry the two post-write gate bodies the lead appends after the preflight (via `okstra_ctl.initial_prompt_materialization.materialize_initial_prompts()`): the persisted prompt body MUST contain BOTH the literal heading `Pre-commit diff review sweep` (from `prompts/profiles/_implementation-diff-review.md`) and the literal heading `Implementation self-check` (from `prompts/profiles/_implementation-self-check.md`). If either heading is absent, return `KIMI_POSTWRITE_GATE_MISSING: executor dispatch prompt lacks the post-write diff-review / self-check gate block` instead of invoking the CLI; the lead re-dispatches with both blocks included. This check does NOT apply to verifier or analysis dispatches.
143
- - Include context (code, diff, file paths) if provided.
144
- - For long prompts, dispatch through the wrapper with literal absolute paths (plus the worktree path for implementation phase):
145
- ```bash
146
- $HOME/.okstra/bin/okstra-kimi-exec.sh "<literal-project-root>" "<assigned-model-execution-value>" "<literal-prompt-history-path>" "<literal-worktree-path>" "<pane-role>"
147
- ```
148
- - If the parent directory does not exist yet, create it before writing the prompt file.
149
-
150
- ## Required Reading Before Any Analysis
151
-
152
- Before invoking the Kimi CLI, you MUST:
153
-
154
- 1. Extract `**Worker Preamble Path:**` and `**Worker Error Contract Path:**` and verify the CLI run will Read both selected files end-to-end. The first owns audience procedure; the second owns sidecar schema and write rules. Persist and forward both anchors unchanged; never substitute the analysis preamble for an implementation audience. **Exception — `-reverify-r<N>-` dispatches**: a Phase 5.5 re-verification prompt deliberately omits both reading contracts and uses its lightweight prompt contract; do NOT return a sentinel for those two omitted reading anchors. The `**Errors log path:**` / `**Errors sidecar path:**` gate still applies.
155
- 2. Verify the lead's prompt body lists the per-run primary input files under `## Inputs` (normally `analysis-packet.md` for analysis workers). The source files named inside that packet are fallback/evidence paths to open when needed. Analysis workers do NOT read `final-report-template.md` — that file is for the report writer only.
156
- 3. When the prompt carries `**Evidence ledger:** required-v1`, verify the CLI follows the selected preamble's `Evidence read ledger` procedure for every claim-evidence file it opens. Do not define or infer another audit-row format in this wrapper.
157
-
158
- Extract `**Audit sidecar path:** <abs-path>` verbatim from the lead's dispatch prompt and verify that the value is absolute. If the header is absent or the value is not absolute, return `KIMI_AUDIT_PATH_MISSING: lead prompt did not include a valid absolute **Audit sidecar path:** header` without invoking the CLI. Do NOT synthesize the audit sidecar path from the task type, worker name, or sequence.
159
-
160
- The CLI writes a Reading Confirmation block to the absolute path extracted from the `**Audit sidecar path:**` header. The sidecar's body begins with `# Kimi Worker Audit — <task-key>` followed by one short line per input file confirming end-to-end reading. Placement follows the selected audience preamble's `Required reading` section. If any file was skipped, record a `tool-failure` in the errors sidecar instead of fabricating Findings.
161
-
162
- ## Worker Output Structure
163
-
164
- The Kimi CLI — not this wrapper — produces the worker result. It follows the audience-selected preamble and, for implementation, the executor/verifier role sidecar. Analysis output uses sections 1–5 plus optional Section 6; implementation output follows its sidecar. This wrapper forwards output unmodified except for the single `**Model:**` line (step 8d).
165
-
166
- ## Error reporting
167
-
168
- The wrapper agent (this Kimi worker subagent) is responsible for recording
169
- two kinds of errors via `okstra error-log`:
170
-
171
- **Path extraction (BLOCKING).** Before recording anything, extract the
172
- following two absolute paths verbatim from the lead's dispatch prompt body:
173
-
174
- - `**Errors log path:** <abs-path>` — the run-level errors JSONL.
175
- - `**Errors sidecar path:** <abs-path>` — this worker's per-run sidecar JSON.
176
-
177
- If either header line is absent from the dispatch prompt, return
178
- `KIMI_ERRORS_PATH_MISSING: lead prompt did not include **Errors log path:** / **Errors sidecar path:** headers`
179
- without proceeding. Do NOT synthesize the path from `<runDir>/logs/...` —
180
- historical bug class: workers writing to a literally-named template path
181
- and the run-level error log staying empty.
182
-
183
- 1. **Wrapper-internal tool failure (worker-reported)** — if `Write` of the
184
- prompt history file, `mkdir`, or any pre-CLI tool call fails, append a
185
- `tool-failure` entry to the worker errors sidecar at the absolute path
186
- extracted from the `**Errors sidecar path:**` header. If the file does
187
- not exist, create it with `{"schemaVersion": 1, "errors": []}` then
188
- append. The sidecar follows the schema in
189
- `prompts/lead/team-contract.md` (Optional errors sidecar). Lead
190
- will dump it to the run error log after this subagent terminates.
191
-
192
- 2. **CLI failure (lead-observed)** — if the wrapper's final `BashOutput`
193
- reports a non-zero `exit_code`, the polling cap (30min, optionally
194
- extended once to 35min via mtime grace; see step 7) is hit, or the
195
- captured stdout/stderr carries a rate-limit/auth message, immediately
196
- append a `cli-failure` event directly to the run error log. The
197
- polling-cap path additionally requires a prior `KillShell` call against
198
- the dispatched `bash_id`:
199
-
200
- ```bash
201
- okstra error-log append-observed \
202
- --out "<absolute-errors-log-path-from-lead-prompt>" \
203
- --task-key "<task-key>" \
204
- --phase "<phase>" \
205
- --agent kimi-worker --agent-role worker \
206
- --model "<assigned-model-execution-value>" \
207
- --error-type cli-failure \
208
- --command "$HOME/.okstra/bin/okstra-kimi-exec.sh <project-root> <m> <prompt-path> <worktree-path> <pane-role>" \
209
- --command-kind cli-invoke \
210
- --exit-code <N> --duration-ms <ms> \
211
- --message "<one-line summary>" \
212
- --stderr-excerpt-file "<captured-stderr-path or omit>"
213
- ```
214
-
215
- Keep `--message` to the error you actually observed (`HTTP 429`,
216
- `connection refused`, `1045 access denied`) — asserting that a sandbox or
217
- permission boundary blocked the call requires `--context-json` carrying
218
- `cause` plus both `causeEvidence` probes, and an unevidenced block claim in
219
- `--message` is rejected on the spot (and again on dump if you route it to
220
- the sidecar instead).
221
-
222
- The lead prompt provides `**Errors log path:**`, `<task-key>`, and
223
- `<phase>` alongside the prompt history path. If any of these are
224
- missing, fall back to logging to the worker errors sidecar instead —
225
- never silently swallow a CLI failure.
226
-
227
- Do not record a `cli-failure` for `KIMI_NOT_INSTALLED` returns — that is a
228
- pre-flight terminal status, not a runtime CLI error.
229
-
230
- ## Notes
231
-
232
- - Kimi is initially limited to analyser and critic assignments. Return `KIMI_ROLE_UNSUPPORTED` instead of accepting an executor, verifier, lead, or report-writer assignment.
233
- - Return error messages as-is on failure.
234
- - Do not summarize or modify Kimi results beyond prepending the single `**Model:**` line on a normal return (step 8d).
235
- - Sections 1–5 of the worker output are the common core shared with the Claude and Antigravity workers — the dispatched prompt asks identical questions for all three roles, and the Kimi CLI must answer all of them, not only long-context-only findings. Your specialization (long-context synthesis, cross-file consistency, requirement coverage, and implementation risks) belongs only in optional Section 6 as additive depth. A Kimi result whose Findings section is populated solely with long-context-only items is in breach of contract; see the preamble §"Worker output sections".
236
-
237
- ## Stage evidence emission (BLOCKING, implementation task only)
238
-
239
- When this run's `task_type` is `implementation` and you are acting as the **Executor**, after the Stage Validation `post` commands all return exit code 0 you MUST emit a single JSON document matching `docs/superpowers/specs/2026-05-20-implementation-planning-multi-stage-design.md` §3.2:
240
-
241
- ```json
242
- {
243
- "schemaVersion": 1,
244
- "sourcePlanPath": "<approved-plan path>",
245
- "stageNumber": <int>,
246
- "stageTitle": "<from Stage Map>",
247
- "completedAt": "<ISO-8601 with tz>",
248
- "stageCommitRange": { "base": "<sha>", "head": "<sha>" },
249
- "filesChanged": ["<rel/path>", "..."],
250
- "newIdentifiers": ["<name>", "..."],
251
- "stepResults": [{"step": <int>, "status": "done", "commit": "<sha>"}],
252
- "validationsPassed": ["<label>", "..."],
253
- "notes": []
254
- }
255
- ```
256
-
257
- Emit this as a fenced ```json``` block in your worker result under the heading `### Stage Carry Evidence`. The host-native Okstra lead is responsible for persisting the block as `runs/<impl-task-key>/carry/stage-<N>.json` — you do not write the file yourself.
258
-
259
- This applies only when `task_type` is `implementation`. For other task types, skip this block entirely.
@@ -1,79 +0,0 @@
1
- #!/usr/bin/env bash
2
- # PreToolUse hook for coding-preflight.
3
- #
4
- # Inspects the target file path of a Write/Edit/MultiEdit/NotebookEdit
5
- # call. If the extension matches a language covered by this skill,
6
- # emits a `hookSpecificOutput.additionalContext` JSON payload that
7
- # reminds the agent to invoke the skill before writing.
8
- #
9
- # Fires at most once per session per language (marker file).
10
- # Exits 0 in every case — never blocks the tool call.
11
-
12
- set -euo pipefail
13
-
14
- input="$(cat)"
15
-
16
- tool_name="$(printf '%s' "$input" | jq -r '.tool_name // empty')"
17
- case "$tool_name" in
18
- Write|Edit|MultiEdit|NotebookEdit) ;;
19
- *) exit 0 ;;
20
- esac
21
-
22
- file_path="$(printf '%s' "$input" \
23
- | jq -r '.tool_input.file_path // .tool_input.notebook_path // empty')"
24
- [[ -z "$file_path" ]] && exit 0
25
-
26
- lang=""
27
- ref=""
28
- extra_hint=""
29
- case "$file_path" in
30
- *.java)
31
- lang="Java"
32
- ref="languages/java.md"
33
- ;;
34
- *.kt|*.kts)
35
- lang="Kotlin"
36
- ref="languages/kotlin.md"
37
- ;;
38
- *.ts|*.tsx|*.js|*.jsx|*.mjs|*.cjs)
39
- lang="JavaScript-TypeScript"
40
- ref="languages/javascript-typescript.md"
41
- extra_hint=" If this file is part of a Node.js server (Express/Fastify/Nest/etc.), also read frameworks/node-server.md."
42
- ;;
43
- *.py)
44
- lang="Python"
45
- ref="languages/python.md"
46
- ;;
47
- *.sql)
48
- lang="SQL"
49
- ref="languages/sql.md"
50
- ;;
51
- *.rs)
52
- lang="Rust"
53
- ref="languages/rust.md"
54
- ;;
55
- *)
56
- exit 0
57
- ;;
58
- esac
59
-
60
- session_id="$(printf '%s' "$input" | jq -r '.session_id // "no-session"')"
61
- marker_dir="${TMPDIR:-/tmp}/mcbsc"
62
- mkdir -p "$marker_dir"
63
- marker="${marker_dir}/${session_id}_${lang}"
64
-
65
- if [[ -f "$marker" ]]; then
66
- exit 0
67
- fi
68
-
69
- : > "$marker"
70
-
71
- skill_root="$HOME/.okstra/prompts/coding-preflight"
72
- msg="[coding-preflight] About to edit a ${lang} file (${file_path}). Before writing, you MUST Read ${skill_root}/${ref} plus ${skill_root}/clean-code.md (the skill is user-invocable:false — read the files directly).${extra_hint} If the project uses ports-and-adapters (domain/ + ports/ + adapters/, *.port.* files), also Read ${skill_root}/architectures/hexagonal.md. (Fires once per session per language.)"
73
-
74
- jq -nc \
75
- --arg event "PreToolUse" \
76
- --arg ctx "$msg" \
77
- '{hookSpecificOutput: {hookEventName: $event, additionalContext: $ctx}}'
78
-
79
- exit 0