opencode-agent-orchestration-kit 1.0.38 → 1.0.40

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 (49) hide show
  1. package/README.md +12 -3
  2. package/docker/open-design/Dockerfile +3 -1
  3. package/docker/open-design/entrypoint.mjs +61 -0
  4. package/docs/docker-open-design.md +5 -0
  5. package/docs/models.md +1 -1
  6. package/docs/open-design.md +8 -0
  7. package/docs/performance/native-tools-benchmark.md +33 -0
  8. package/docs/releases/v1.0.39.md +44 -0
  9. package/docs/releases/v1.0.40.md +55 -0
  10. package/docs/sync-boundary.md +27 -0
  11. package/opencode/commands/loop-status.md +24 -0
  12. package/opencode/commands/loop.md +8 -0
  13. package/opencode/docs/ai/harness/agents.md +8 -0
  14. package/opencode/docs/ai/harness/checks.md +6 -0
  15. package/opencode/docs/ai/harness/commands.md +10 -0
  16. package/opencode/docs/ai/harness/orchestration-contracts.json +9 -1
  17. package/opencode/docs/ai/specs/mission-runtime.md +44 -0
  18. package/opencode/plugins/mission-runtime.test.mjs +46 -0
  19. package/opencode/plugins/mission-runtime.ts +41 -0
  20. package/opencode/scripts/check-harness.mjs +111 -0
  21. package/opencode/scripts/check-harness.test.mjs +37 -1
  22. package/opencode/scripts/loop-state.mjs +5 -0
  23. package/opencode/scripts/loop-state.test.mjs +13 -0
  24. package/opencode/scripts/mission-runtime-observer.d.mts +25 -0
  25. package/opencode/scripts/mission-runtime-observer.mjs +124 -0
  26. package/opencode/scripts/mission-runtime.test.mjs +97 -0
  27. package/opencode/scripts/mission-status.mjs +136 -0
  28. package/opencode/scripts/mission-status.test.mjs +196 -0
  29. package/opencode/scripts/project-capability-snapshot.mjs +2 -1
  30. package/opencode/scripts/project-capability-snapshot.test.mjs +17 -0
  31. package/opencode/scripts/runtime-permission-policy.mjs +72 -0
  32. package/opencode/scripts/runtime-permission-policy.test.mjs +89 -0
  33. package/opencode/tools/open-design-http.d.mts +45 -0
  34. package/opencode/tools/open-design-http.mjs +387 -0
  35. package/opencode/tools/open_design.ts +2 -103
  36. package/package.json +3 -3
  37. package/scripts/benchmark-tool-paths.mjs +226 -0
  38. package/scripts/benchmark-tool-paths.test.mjs +29 -0
  39. package/scripts/check-public-boundary.mjs +89 -0
  40. package/scripts/check-public-boundary.test.mjs +32 -0
  41. package/scripts/check.sh +17 -10
  42. package/scripts/install-smoke.sh +17 -0
  43. package/scripts/manage-installation.mjs +90 -7
  44. package/scripts/manage-installation.test.mjs +36 -0
  45. package/scripts/open-design-entrypoint.test.mjs +54 -0
  46. package/scripts/open-design-http.test.mjs +211 -0
  47. package/scripts/package-smoke.mjs +52 -3
  48. package/scripts/package-smoke.test.mjs +6 -6
  49. package/scripts/version.test.mjs +2 -2
package/README.md CHANGED
@@ -327,7 +327,7 @@ After a tagged release is published, you can install the same CLI directly
327
327
  from GitHub without keeping a checkout:
328
328
 
329
329
  ```bash
330
- npm install --global "git+https://github.com/jcarlosrodicio/opencode-agent-orchestration-kit.git#v1.0.38"
330
+ npm install --global "git+https://github.com/jcarlosrodicio/opencode-agent-orchestration-kit.git#v1.0.40"
331
331
  oc-switch
332
332
  ```
333
333
 
@@ -407,6 +407,12 @@ An explicit `--target` wins over a non-empty `OPENCODE_CONFIG_DIR`, which wins o
407
407
 
408
408
  The installer inventories the payload, computes a complete plan, and tracks ownership in `TARGET/.oak/manifest.json`. A dry run performs no writes. A real operation recomputes the plan under an exclusive lock and commits through a durable journal with one rollback generation.
409
409
 
410
+ Release packages also record a safe `release_provenance` block in that manifest:
411
+ the source projection commit, public commit, canonical kit version, packaged
412
+ payload digest, and a passed-checks marker. Existing manifests without that
413
+ optional block remain readable; the release package smoke requires it for new
414
+ release evidence and never stores paths, provider settings, or credentials.
415
+
410
416
  The root `package.json` is the canonical kit-version source. Display the same
411
417
  identity through the manager or any lifecycle wrapper:
412
418
 
@@ -724,7 +730,10 @@ This runs the fast contract checker and every bundled `node:test` suite. For a
724
730
  fast structural check while editing documentation or contracts, use
725
731
  `npm run check:quick`. Before a release, use `npm run check:release`; it performs
726
732
  a frozen dependency install and also runs typechecking, dependency integrity,
727
- audit/signature checks, installation smoke, and the exact package smoke.
733
+ audit/signature checks, installation smoke, and the exact package smoke. The
734
+ package smoke extracts the tarball, recomputes the packaged OpenCode payload
735
+ digest, uses an isolated `OPENCODE_CONFIG_DIR`, preserves a user configuration,
736
+ and exercises `doctor` plus rollback before reporting release provenance.
728
737
  Publication remains separately authorized; follow the reviewed artifact and
729
738
  checksum procedure in [the supply-chain policy](docs/supply-chain.md).
730
739
 
@@ -732,7 +741,7 @@ Validate only the canonical identity and current release note with:
732
741
 
733
742
  ```bash
734
743
  npm run check:version
735
- node scripts/version.mjs --check-tag v1.0.38
744
+ node scripts/version.mjs --check-tag v1.0.40
736
745
  ```
737
746
 
738
747
  Tag validation compares an explicitly supplied tag with the package identity.
@@ -37,6 +37,8 @@ NODE
37
37
  RUN pnpm --filter @open-design/daemon build \
38
38
  && (pnpm build || pnpm -r build)
39
39
 
40
+ COPY entrypoint.mjs /usr/local/bin/open-design-entrypoint.mjs
41
+
40
42
  ENV OD_HOST=0.0.0.0
41
43
  ENV OD_PORT=7456
42
44
  ENV OPENCODE_CONFIG_DIR=/home/opencode/.config/opencode
@@ -47,4 +49,4 @@ RUN mkdir -p /home/opencode/.config/opencode /home/opencode/.local/share/opencod
47
49
  USER opencode
48
50
  EXPOSE 7456
49
51
 
50
- CMD ["sh", "-lc", "node apps/daemon/dist/cli.js --port ${OD_PORT:-7456} --no-open"]
52
+ ENTRYPOINT ["node", "/usr/local/bin/open-design-entrypoint.mjs"]
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { spawn } from "node:child_process";
4
+ import path from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+
7
+ const DEFAULT_PORT = "7456";
8
+ const DAEMON_ENTRYPOINT = "apps/daemon/dist/cli.js";
9
+
10
+ export function parsePort(rawPort) {
11
+ if (typeof rawPort !== "string" || !/^[0-9]+$/.test(rawPort)) {
12
+ throw new Error("OD_PORT must be a decimal TCP port between 1 and 65535");
13
+ }
14
+
15
+ const port = Number(rawPort);
16
+ if (!Number.isSafeInteger(port) || port < 1 || port > 65535) {
17
+ throw new Error("OD_PORT must be a decimal TCP port between 1 and 65535");
18
+ }
19
+
20
+ return port;
21
+ }
22
+
23
+ export function daemonArguments(port) {
24
+ return [DAEMON_ENTRYPOINT, "--port", String(port), "--no-open"];
25
+ }
26
+
27
+ function main() {
28
+ let port;
29
+ try {
30
+ port = parsePort(process.env.OD_PORT ?? DEFAULT_PORT);
31
+ } catch (error) {
32
+ console.error(`Open Design startup failed: ${error.message}`);
33
+ process.exitCode = 1;
34
+ return;
35
+ }
36
+
37
+ const daemon = spawn(process.execPath, daemonArguments(port), { stdio: "inherit" });
38
+ const forwardSignal = (signal) => daemon.kill(signal);
39
+ const cleanup = () => {
40
+ process.removeListener("SIGINT", onSigint);
41
+ process.removeListener("SIGTERM", onSigterm);
42
+ };
43
+ const onSigint = () => forwardSignal("SIGINT");
44
+ const onSigterm = () => forwardSignal("SIGTERM");
45
+
46
+ process.once("SIGINT", onSigint);
47
+ process.once("SIGTERM", onSigterm);
48
+ daemon.once("error", (error) => {
49
+ cleanup();
50
+ console.error(`Open Design daemon failed to start: ${error.message}`);
51
+ process.exitCode = 1;
52
+ });
53
+ daemon.once("exit", (code, signal) => {
54
+ cleanup();
55
+ process.exitCode = signal ? 1 : (code ?? 1);
56
+ });
57
+ }
58
+
59
+ if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
60
+ main();
61
+ }
@@ -45,6 +45,11 @@ The compose file mounts:
45
45
 
46
46
  Do not commit `data` or `opencode-auth`.
47
47
 
48
+ `OD_PORT` must be a decimal TCP port from `1` to `65535`; it defaults to
49
+ `7456`. The image validates this value before starting the daemon and passes it
50
+ as a separate argument without a shell. Invalid values stop the container with
51
+ a deterministic startup error.
52
+
48
53
  ## HTTP LAN and crypto.randomUUID
49
54
 
50
55
  Some browser APIs require a secure context. If Open Design frontend code calls `crypto.randomUUID` and your browser blocks it over HTTP LAN, prefer HTTPS. Only patch upstream frontend code as a local operational workaround.
package/docs/models.md CHANGED
@@ -26,7 +26,7 @@ oc-switch
26
26
  Once a release tag exists, a checkout is optional:
27
27
 
28
28
  ```bash
29
- npm install --global "git+https://github.com/jcarlosrodicio/opencode-agent-orchestration-kit.git#v1.0.38"
29
+ npm install --global "git+https://github.com/jcarlosrodicio/opencode-agent-orchestration-kit.git#v1.0.40"
30
30
  oc-switch
31
31
  ```
32
32
 
@@ -23,3 +23,11 @@ Do not use project or file URLs.
23
23
  ## Security
24
24
 
25
25
  Do not expose Open Design directly to the Internet without authentication, VPN, Tailscale, WireGuard, or a secure reverse proxy.
26
+
27
+ ## Runtime budgets
28
+
29
+ The Open Design client uses fixed safety budgets for remote calls: 5 seconds to
30
+ receive response headers, 15 seconds of read-idle time, 120 seconds total per
31
+ request, 1 MiB for JSON responses, 8 MiB for SSE responses, 2 MiB per stdout or
32
+ stderr channel, and 10,000 SSE events. Oversized, stalled, or incomplete
33
+ responses fail with a bounded diagnostic instead of being retained indefinitely.
@@ -0,0 +1,33 @@
1
+ # Native tool-path benchmark
2
+
3
+ This benchmark measures the current dependency-free Node path before deciding
4
+ whether a native Rust helper is justified. It is evidence collection, not a
5
+ Rust implementation or a release blocker.
6
+
7
+ Run it with at least two iterations per operation:
8
+
9
+ ```bash
10
+ node scripts/benchmark-tool-paths.mjs --iterations 5 > /tmp/oak-native-benchmark.json
11
+ ```
12
+
13
+ It exercises two synthetic fixtures and, by default, this repository. Each
14
+ fixture measures file listing, text search, Node parse checking, capability
15
+ snapshot generation, and installation through the same manager used by the
16
+ package. The report contains p50/p95 elapsed time, p50 CPU, and p95 RSS for
17
+ each path. RSS is the benchmark runner's process value; child-command memory is
18
+ not isolated, so the result must not be presented as a process-level peak for
19
+ `node --check`.
20
+
21
+ ## Adoption threshold
22
+
23
+ Keep the Node implementation unless a Rust replacement demonstrates, on both
24
+ fixtures and two consecutive runs:
25
+
26
+ - at least 2x lower p95 latency for one material hot path;
27
+ - no regression above 10% in p95 RSS or installation time;
28
+ - equivalent portable behavior and failure semantics;
29
+ - a reviewable multi-platform distribution and checksum plan.
30
+
31
+ The current repository has no Rust candidate or cross-platform artifact to
32
+ compare. Until that evidence exists, adding Rust would increase distribution
33
+ and supply-chain surface without a measured product benefit.
@@ -0,0 +1,44 @@
1
+ # v1.0.39 - Safe lifecycle and canonical release identity
2
+
3
+ This release hardens the Open Design HTTP and SSE transport and its Docker
4
+ entrypoint for bounded, fail-closed operation.
5
+
6
+ ## Highlights
7
+
8
+ - Bound Open Design connection, total, and idle-read timeouts.
9
+ - Bound JSON response bodies, SSE bytes, event counts, and captured output.
10
+ - Keep transport failures and diagnostics from returning unbounded remote data.
11
+ - Harden the Open Design Docker entrypoint's startup and signal lifecycle.
12
+
13
+ ## Installation or upgrade
14
+
15
+ Install or upgrade the public kit using the normal manifest-owned flow:
16
+
17
+ ```bash
18
+ ./install.sh --dry-run
19
+ ./install.sh
20
+ ./upgrade.sh --dry-run
21
+ ./upgrade.sh
22
+ ```
23
+
24
+ After installation, run `oak check` and review the installed target before
25
+ using the harness.
26
+
27
+ ## Migration
28
+
29
+ No migration is required. Existing Open Design configuration remains valid;
30
+ requests that exceed the transport budgets now fail closed with bounded error
31
+ messages.
32
+
33
+ ## Validation performed
34
+
35
+ The public contract checker, unit and script tests, type checks, dependency
36
+ audits, signature checks, installation smoke, package smoke, and canonical
37
+ version/tag checks pass for this release.
38
+
39
+ ## Public safety boundary
40
+
41
+ The public release excludes private OpenCode and Pi configuration, local
42
+ providers and MCP wiring, credentials, authentication files, raw transcripts,
43
+ private evidence, absolute machine paths, and runtime state. Pi uses its own
44
+ native model catalog and is not included in this OpenCode package.
@@ -0,0 +1,55 @@
1
+ # v1.0.40 - Safe lifecycle and canonical release identity
2
+
3
+ This release publishes the reviewed portable mission runtime and strengthens
4
+ the boundary between the public orchestration kit and private harness
5
+ configuration.
6
+
7
+ ## Highlights
8
+
9
+ - Add a durable mission-status projection for bounded loop workflows, including
10
+ iteration state, blocking cause, session identity, and the next safe action.
11
+ - Add a read-only mission runtime observer that tracks root sessions, ignores
12
+ child-session noise and duplicate events, and reports optional TUI activity
13
+ without writing durable loop state.
14
+ - Add a closed runtime permission policy and harness checks that keep agent
15
+ identities, tool decisions, delegation, and frontmatter contracts aligned.
16
+ - Add an explicit public synchronization boundary and checks for excluding
17
+ private providers, MCP wiring, credentials, endpoints, paths, and raw runtime
18
+ evidence.
19
+ - Improve package provenance, isolated installation and package smoke coverage,
20
+ rollback verification, and native tool-path performance baselines.
21
+
22
+ ## Installation or upgrade
23
+
24
+ Install or upgrade the public kit using the normal manifest-owned flow:
25
+
26
+ ```bash
27
+ ./install.sh --dry-run
28
+ ./install.sh
29
+ ./upgrade.sh --dry-run
30
+ ./upgrade.sh
31
+ ./doctor.sh
32
+ ```
33
+
34
+ After installation, run `oak check` and review the installed target before
35
+ using the harness.
36
+
37
+ ## Migration
38
+
39
+ No migration is required. Existing installation manifests without the optional
40
+ release provenance block remain readable, and the new mission runtime state is
41
+ created only by an explicit loop workflow.
42
+
43
+ ## Validation performed
44
+
45
+ Release readiness passed with the public contract checks, 1,067 unit and
46
+ script tests, typechecking, dependency vulnerability and signature audits,
47
+ installation smoke, package smoke, rollback checks, compatibility checks, and
48
+ the public-boundary leak scan.
49
+
50
+ ## Public safety boundary
51
+
52
+ The public release excludes private OpenCode and Pi configuration, local
53
+ providers and MCP wiring, credentials, authentication files, raw transcripts,
54
+ private evidence, absolute machine paths, and runtime state. Pi uses its own
55
+ native model catalog and is not included in this OpenCode package.
@@ -0,0 +1,27 @@
1
+ # Public synchronization boundary
2
+
3
+ This repository publishes a reviewed public projection of a fuller private
4
+ harness. The public payload contains portable agents, commands, skills,
5
+ contracts, tests, and read-only runtime helpers under `opencode/`, plus the
6
+ installation and release tooling required to distribute them.
7
+
8
+ The projection is deliberately not a private checkout mirror. Provider
9
+ discovery, local model assignment, credentials, authentication files, MCP
10
+ servers, private endpoints, sessions, transcripts, logs, and raw runtime
11
+ evidence stay outside this repository. Public files must use portable relative
12
+ paths and example service URLs only.
13
+
14
+ <!-- projection-source-commit: 1ca607adcbae12cd16de1772662d942852b32502 -->
15
+
16
+ The marker above identifies the reviewed source projection for release
17
+ provenance. It is a commit identity only; it does not disclose the source
18
+ checkout, its providers, or its runtime evidence.
19
+
20
+ The source-side manifest classifies changes as `copy`, `translate`,
21
+ `transform`, `exclude`, or `generated`. The private comparator verifies that
22
+ classification before a change reaches this repository. This repository's
23
+ `check-public-boundary.mjs` then verifies the required projection surfaces and
24
+ reuses the same private-marker scan as `check.sh`.
25
+
26
+ The boundary check is read-only. It does not install dependencies, publish a
27
+ package, create a release, or synchronize a target checkout.
@@ -0,0 +1,24 @@
1
+ ---
2
+ description: "Consulta el estado durable de una misión sin adquirir locks ni escribir archivos."
3
+ agent: lead
4
+ ---
5
+
6
+ # Estado de misión
7
+
8
+ Usa esta consulta para inspeccionar un loop existente sin reanudarlo ni
9
+ modificarlo.
10
+
11
+ ```bash
12
+ node scripts/mission-status.mjs --root /ruta/absoluta/al/repo --slug <slug>
13
+ node scripts/mission-status.mjs --root /ruta/absoluta/al/repo --slug <slug> --json
14
+ ```
15
+
16
+ La salida proyecta el snapshot canónico y el último evento validado:
17
+ `status`, `iteration/planned`, último paso, causa de bloqueo, sesión, timestamp
18
+ y siguiente acción segura. `--root` debe ser una ruta absoluta y `--slug` un
19
+ identificador kebab-case válido.
20
+
21
+ Si falta el estado, el snapshot está desfasado o el historial está corrupto,
22
+ detente y reporta el código durable (`state_missing`, `snapshot_stale` o
23
+ `history_corrupt`). No ejecutes `resume`, `repair` ni `release` como sustituto
24
+ automático.
@@ -16,6 +16,8 @@ automation.
16
16
  ```text
17
17
  approval_gate: explicit_before_writes
18
18
  max_iterations_per_invocation: 3
19
+ planned_iteration_budget: task_specific_1_to_6
20
+ hard_safety_ceiling: 6
19
21
  completion_authority: reviewer_only
20
22
  canonical_review_policy: code-review-and-quality/references/review-policy.md
21
23
  final_review_authority: reviewer
@@ -26,6 +28,12 @@ human_view_path: .opencode/loops/<slug>.md
26
28
  worktree_mode: explicit_opt_in
27
29
  ```
28
30
 
31
+ The three-iteration value limits one invocation. The persisted
32
+ `planned_iteration_budget` (`planned_iterations` in canonical state) is the total budget for the mission and may not
33
+ exceed the hard ceiling of six; `current_iteration` may never exceed that
34
+ budget. Once the total budget is exhausted, the loop must stop as `blocked` or
35
+ `completed` rather than injecting another continuation.
36
+
29
37
  The durable `handoff_packet` (`.opencode/handoffs/<slug>.md` with
30
38
  `approval_status`) persists human approval to survive session restarts. `/loop`
31
39
  keeps `.opencode/loops/<slug>.json` as canonical state,
@@ -83,6 +83,14 @@ generate or modify frontmatter.
83
83
  - `evaluator`, `debugger`, and `evolver` are optional sidecars.
84
84
  - `evolver` works only on the OpenCode harness.
85
85
 
86
+ ## Mission runtime projection
87
+
88
+ `mission-status` is a read-only view over the durable loop snapshot and
89
+ append-only history. It validates canonical state before displaying progress
90
+ and never becomes a second authority. The runtime observer is ephemeral; it
91
+ may report activity, but durable transitions still require the loop state
92
+ runtime and its locks.
93
+
86
94
  ## Bounded local autonomy
87
95
 
88
96
  `/autonomous` uses one explicit user invocation for a local objective, not a
@@ -64,6 +64,12 @@ Slice 2.4 adds durable structured state for `/loop`. Run its focused tests with:
64
64
  node --test scripts/loop-state.test.mjs
65
65
  ```
66
66
 
67
+ The mission runtime projection is read-only: `mission-status.mjs` validates
68
+ the canonical snapshot and history, while `mission-runtime` observes ephemeral
69
+ events without writing an alternative state. The Open Design boundary requires
70
+ `OPEN_DESIGN_URL` to be a base URL and rejects project or file URLs; the checker
71
+ also rejects private endpoints and UUID-specific crypto dependencies.
72
+
67
73
  The dependency-free runtime maintains a JSON snapshot, append-only JSONL
68
74
  history, and exclusive lock. Tests cover crash recovery, same-session
69
75
  contention, symlink boundaries, journal continuity, migration, and explicit
@@ -174,6 +174,16 @@ Criteria:
174
174
  - No auto-merge, scheduling, write-enabled MCP connectors, parallel execution,
175
175
  or implicit worktree creation.
176
176
 
177
+ ## `/loop-status`
178
+
179
+ Contract: `lead` read-only projection.
180
+
181
+ `/loop-status --slug <slug>` inspects the canonical snapshot and append-only
182
+ history without acquiring a write lock or changing files. Use
183
+ `node scripts/mission-status.mjs --root /absolute/repository --slug <slug>`
184
+ when an explicit repository root is needed. If state is missing, stale, or
185
+ corrupt, report the durable error and do not repair or resume automatically.
186
+
177
187
  ## `/autonomous`
178
188
 
179
189
  Contract: explicit invocation -> `developer -> reviewer -> developer (state sync)`.
@@ -210,6 +210,12 @@
210
210
  "subtask": false,
211
211
  "workflow": "loop"
212
212
  },
213
+ {
214
+ "id": "loop-status",
215
+ "root_agent": "lead",
216
+ "subtask": false,
217
+ "workflow": "loop"
218
+ },
213
219
  {
214
220
  "id": "mvp-spec",
215
221
  "root_agent": "scoper",
@@ -643,7 +649,8 @@
643
649
  {
644
650
  "id": "loop",
645
651
  "entrypoints": [
646
- "loop"
652
+ "loop",
653
+ "loop-status"
647
654
  ],
648
655
  "stages": [
649
656
  {
@@ -908,6 +915,7 @@
908
915
  "implement",
909
916
  "init",
910
917
  "loop",
918
+ "loop-status",
911
919
  "mvp-spec",
912
920
  "plan",
913
921
  "research",
@@ -0,0 +1,44 @@
1
+ ---
2
+ title: "Proyección runtime de misión"
3
+ status: proposed
4
+ date: 2026-08-21
5
+ feature: mission-runtime
6
+ ---
7
+
8
+ # Runtime de misión
9
+
10
+ ## Autoridad
11
+
12
+ `scripts/loop-state.mjs` es la única autoridad de ejecución. El snapshot
13
+ `.opencode/loops/<slug>.json` y su historial append-only
14
+ `.opencode/loops/<slug>.history.jsonl` se leen y validan; la proyección nunca
15
+ los modifica ni mantiene un segundo estado durable.
16
+
17
+ ## Proyección read-only
18
+
19
+ `mission-status.mjs` expone `slug`, `status`, `current_iteration`,
20
+ `planned_iterations`, `last_completed_step`, `blocking_cause`, `session_id`,
21
+ `updated_at` y `next_action`. `session_id` usa el lease activo cuando existe y
22
+ el último session id canónico en caso contrario. `updated_at` procede del último
23
+ evento validado del historial.
24
+
25
+ Los estados canónicos son `approved`, `running`, `paused`, `blocked` y
26
+ `completed`. La proyección no inventa transiciones: si el snapshot está
27
+ desfasado o el historial está corrupto, devuelve el error durable de
28
+ `loop-state`.
29
+
30
+ ## Observación de eventos
31
+
32
+ El observador opcional usa únicamente eventos que el SDK local expone:
33
+ `session.created`, `session.status`, `tool.execute.before`,
34
+ `tool.execute.after`, `session.compacted`, `session.error` y `session.idle`.
35
+ La actividad derivada (`running`, `idle` o `blocked`) es efímera y nunca
36
+ sustituye al `status` canónico.
37
+
38
+ Las sesiones con `parentID` distinto de la sesión raíz se ignoran. Los eventos
39
+ duplicados se descartan por una clave efímera de sesión, tipo y payload; perder
40
+ esa deduplicación al reiniciar no altera el snapshot ni el historial.
41
+
42
+ La compaction conserva el session id. Un error de notificación no bloquea el
43
+ loop ni se convierte en una transición durable. Las transiciones reales siguen
44
+ requiriendo `loop-state.mjs` y sus locks, hashes, `action_id` y presupuesto.
@@ -0,0 +1,46 @@
1
+ import assert from "node:assert/strict";
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ import test from "node:test";
5
+ import { fileURLToPath } from "node:url";
6
+
7
+ import { createMissionObserver } from "../scripts/mission-runtime-observer.mjs";
8
+
9
+ const root = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
10
+
11
+ test("observer ignores child sessions and duplicate root events", async () => {
12
+ const observations = [];
13
+ const observer = createMissionObserver({ notify: async value => observations.push(value) });
14
+
15
+ await observer.observe({
16
+ type: "session.created",
17
+ properties: { info: { id: "root", parentID: null } },
18
+ });
19
+ await observer.observe({
20
+ type: "session.created",
21
+ properties: { info: { id: "child", parentID: "root" } },
22
+ });
23
+ const rootStatus = {
24
+ type: "session.status",
25
+ properties: { sessionID: "root", status: { type: "busy" } },
26
+ };
27
+ await observer.observe(rootStatus);
28
+ await observer.observe(rootStatus);
29
+ await observer.observe({
30
+ type: "session.status",
31
+ properties: { sessionID: "child", status: { type: "busy" } },
32
+ });
33
+
34
+ assert.equal(observations.length, 1);
35
+ assert.equal(observations[0].session_id, "root");
36
+ assert.deepEqual(observer.stats().child_session_ids, ["child"]);
37
+ });
38
+
39
+ test("plugin has event and notification hooks but no durable state writes", () => {
40
+ const source = fs.readFileSync(path.join(root, "plugins/mission-runtime.ts"), "utf8");
41
+ assert.match(source, /MissionRuntimePlugin/);
42
+ assert.match(source, /event:/);
43
+ assert.match(source, /chat\.message/);
44
+ assert.match(source, /showToast/);
45
+ assert.doesNotMatch(source, /writeFile|appendFile|rename|\.opencode\/loops/);
46
+ });
@@ -0,0 +1,41 @@
1
+ import type { Plugin } from "@opencode-ai/plugin"
2
+
3
+ import { createMissionObserver } from "../scripts/mission-runtime-observer.mjs"
4
+
5
+ const TOAST_DURATION_MS = 1_500
6
+
7
+ function toastVariant(activity: string) {
8
+ if (activity === "blocked") return "error" as const
9
+ if (activity === "idle") return "info" as const
10
+ return "success" as const
11
+ }
12
+
13
+ export const MissionRuntimePlugin: Plugin = async ({ client, directory }) => {
14
+ const observer = createMissionObserver({
15
+ notify: async observation => {
16
+ if (!client?.tui?.showToast) return
17
+ await client.tui.showToast({
18
+ body: {
19
+ title: "Mission runtime",
20
+ message: `${observation.activity}: ${observation.session_id}`,
21
+ variant: toastVariant(observation.activity),
22
+ duration: TOAST_DURATION_MS,
23
+ },
24
+ query: { directory },
25
+ })
26
+ },
27
+ log: message => console.warn(message),
28
+ })
29
+
30
+ return {
31
+ "chat.message": async ({ sessionID }) => {
32
+ await observer.observe({
33
+ type: "chat.message",
34
+ properties: { sessionID },
35
+ })
36
+ },
37
+ event: async ({ event }) => {
38
+ await observer.observe(event)
39
+ },
40
+ }
41
+ }