@spexcode/spec-cli 0.6.7 → 0.7.0-next.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 (97) hide show
  1. package/bin/spex.mjs +175 -21
  2. package/dist/cli.js +121 -59
  3. package/dist/client.d.ts +1 -3
  4. package/dist/client.js +49 -30
  5. package/dist/codex-runtime-generations.d.ts +11 -0
  6. package/dist/codex-runtime-generations.js +46 -9
  7. package/dist/delivery-lock.d.ts +2 -0
  8. package/dist/delivery-lock.js +58 -0
  9. package/dist/doctor.js +53 -11
  10. package/dist/file-write.js +14 -2
  11. package/dist/gateway-hub.js +2 -1
  12. package/dist/gateway.js +6 -3
  13. package/dist/graphCache.js +32 -2
  14. package/dist/graphSnapshot.js +57 -2
  15. package/dist/graphStream.d.ts +2 -0
  16. package/dist/graphStream.js +83 -3
  17. package/dist/guide.js +29 -18
  18. package/dist/harness-select.js +16 -3
  19. package/dist/harness.d.ts +24 -6
  20. package/dist/harness.js +510 -72
  21. package/dist/help.js +11 -8
  22. package/dist/hook-prompts.js +8 -0
  23. package/dist/host-resources.js +29 -8
  24. package/dist/host.d.ts +7 -0
  25. package/dist/host.js +98 -1
  26. package/dist/index.js +294 -36
  27. package/dist/init.js +1 -1
  28. package/dist/lint.js +70 -35
  29. package/dist/listen.d.ts +3 -2
  30. package/dist/listen.js +14 -2
  31. package/dist/machine-peer.d.ts +2 -1
  32. package/dist/machine-peer.js +46 -15
  33. package/dist/materialize.d.ts +2 -2
  34. package/dist/materialize.js +176 -35
  35. package/dist/opencode.js +10 -2
  36. package/dist/pi-harness.js +18 -5
  37. package/dist/pi-headless.d.ts +2 -0
  38. package/dist/pi-headless.js +27 -0
  39. package/dist/pty-bridge.js +14 -14
  40. package/dist/reviews.js +12 -7
  41. package/dist/runtime-ownership.d.ts +11 -0
  42. package/dist/runtime-ownership.js +79 -1
  43. package/dist/session-application.d.ts +23 -0
  44. package/dist/session-application.js +189 -0
  45. package/dist/session-declarations.js +13 -1
  46. package/dist/session-files.d.ts +6 -0
  47. package/dist/session-files.js +13 -1
  48. package/dist/session-follow.js +39 -22
  49. package/dist/session-record-lock.d.ts +3 -0
  50. package/dist/session-record-lock.js +94 -0
  51. package/dist/session-runtime-adapter.d.ts +44 -0
  52. package/dist/session-runtime-adapter.js +37 -0
  53. package/dist/session-timeline.d.ts +25 -2
  54. package/dist/session-timeline.js +68 -11
  55. package/dist/session-transcript.d.ts +57 -0
  56. package/dist/session-transcript.js +137 -0
  57. package/dist/session-web.js +4 -4
  58. package/dist/sessions.d.ts +112 -15
  59. package/dist/sessions.js +1553 -764
  60. package/dist/shim-runtime.js +14 -0
  61. package/dist/source-list.d.ts +13 -0
  62. package/dist/source-list.js +99 -0
  63. package/dist/source-read.d.ts +16 -0
  64. package/dist/source-read.js +84 -0
  65. package/dist/spec-attachments.d.ts +7 -0
  66. package/dist/spec-attachments.js +89 -0
  67. package/dist/spec-body-edit.d.ts +23 -0
  68. package/dist/spec-body-edit.js +138 -0
  69. package/dist/supervise.js +15 -6
  70. package/hooks/dispatch.sh +19 -31
  71. package/hooks/harness.sh +6 -6
  72. package/package.json +8 -6
  73. package/templates/hooks/post-checkout +4 -2
  74. package/templates/hooks/post-merge +2 -1
  75. package/templates/hooks/pre-commit +5 -3
  76. package/templates/hooks/reference-transaction +5 -3
  77. package/templates/spec/project/.plugins/commands/spec.md +2 -7
  78. package/templates/spec/project/.plugins/core/idle/idle.sh +4 -10
  79. package/templates/spec/project/.plugins/core/idle/spec.md +1 -1
  80. package/templates/spec/project/.plugins/core/mark-active/mark-active.sh +22 -24
  81. package/templates/spec/project/.plugins/core/mark-active/spec.md +10 -2
  82. package/templates/spec/project/.plugins/core/session-fail/fail.sh +8 -7
  83. package/templates/spec/project/.plugins/core/session-fail/spec.md +3 -1
  84. package/templates/spec/project/.plugins/core/session-listen/session-listen.sh +133 -0
  85. package/templates/spec/project/.plugins/core/session-listen/spec.md +36 -0
  86. package/templates/spec/project/.plugins/core/spec.md +2 -0
  87. package/templates/spec/project/.plugins/core/stop-gate/spec.md +1 -1
  88. package/templates/spec/project/.plugins/core/stop-gate/stop-gate.sh +17 -20
  89. package/templates/spec/project/.plugins/skills/merge/spec.md +33 -0
  90. package/templates/spec/project/.plugins/skills/spec.md +2 -6
  91. package/templates/spec/project/.plugins/spec.md +7 -0
  92. package/dist/execution-trace.d.ts +0 -26
  93. package/dist/execution-trace.js +0 -475
  94. package/dist/session-execution.d.ts +0 -10
  95. package/dist/session-execution.js +0 -70
  96. package/hooks/compat/mark-active-0.5.2-eef1.fixture +0 -53
  97. package/hooks/compat/mark-active-sed-v0.fixture +0 -46
@@ -1,70 +0,0 @@
1
- import { streamSSE } from 'hono/streaming';
2
- import { harnessById } from './harness.js';
3
- import { readAliasedRawRecord } from '@spexcode/spec-core';
4
- import { currentHumanTurn } from './session-timeline.js';
5
- const absentExecution = (turn = null) => ({ revision: `turn:${turn?.token ?? '0'}`, turnId: turn?.token ?? null, workingNote: null, steps: [] });
6
- // This is deliberately a read projection. Native transcript bytes stay within the adapter, while the API owns
7
- // only enough information for the frontend's fixed renderer to paint the current execution slice.
8
- export function readSessionExecution(id) {
9
- let record;
10
- try {
11
- record = readAliasedRawRecord(id);
12
- }
13
- catch {
14
- return null;
15
- }
16
- if (!record?.governed)
17
- return null;
18
- const turn = currentHumanTurn(id);
19
- const threadId = typeof record.harness_session_id === 'string' ? record.harness_session_id : '';
20
- if (!threadId)
21
- return absentExecution(turn);
22
- try {
23
- const trace = harnessById(typeof record.harness === 'string' && record.harness ? record.harness : 'claude')
24
- .executionTrace(threadId, turn);
25
- return trace || absentExecution(turn);
26
- }
27
- catch {
28
- // A missing/unreadable native source is an absent transient trace, not a synthetic conversation failure.
29
- return absentExecution(turn);
30
- }
31
- }
32
- const TRACE_TICK_MS = 500;
33
- const HEARTBEAT_TICKS = 20;
34
- export async function sessionExecutionStream(c) {
35
- const id = c.req.param('id') || '';
36
- if (!readSessionExecution(id))
37
- return c.json({ error: 'no such session' }, 404);
38
- return streamSSE(c, async (stream) => {
39
- let aborted = false;
40
- let lastRevision = '';
41
- let ticks = 0;
42
- const publish = async () => {
43
- const execution = readSessionExecution(id);
44
- if (!execution)
45
- return false;
46
- if (execution.revision === lastRevision)
47
- return true;
48
- lastRevision = execution.revision;
49
- await stream.writeSSE({ event: 'execution', data: JSON.stringify(execution) });
50
- return true;
51
- };
52
- stream.onAbort(() => { aborted = true; });
53
- try {
54
- if (!await publish())
55
- return;
56
- while (!aborted) {
57
- await stream.sleep(TRACE_TICK_MS);
58
- if (aborted)
59
- break;
60
- if (!await publish())
61
- break;
62
- if (++ticks % HEARTBEAT_TICKS === 0)
63
- await stream.writeSSE({ event: 'ping', data: 'x' });
64
- }
65
- }
66
- catch {
67
- // EventSource reconnects a dropped stream. A native trace read must never take down the session server.
68
- }
69
- });
70
- }
@@ -1,53 +0,0 @@
1
- #!/usr/bin/env bash
2
- # @@@ mark-active - the SINGLE freshness hook, wired to BOTH UserPromptSubmit and PreToolUse. It branches
3
- # on ONE structured signal read straight from the hook payload (stdin JSON), so the state is HARD — never
4
- # text-sniffed from the TUI:
5
- # the agent is pausing to ask the HUMAN (hp_is_ask) → status: asking, with the question text as the note
6
- # (the deterministic capture of a question).
7
- # any other tool, or a prompt submit → the agent is working → status: active (drop a now-stale proposal/note).
8
- # WHAT counts as "asking" is the [[harness-adapter]]'s call (Claude: the AskUserQuestion tool; Codex: the
9
- # request_user_input tool) — read via hp_is_ask, so this hook never names a harness tool.
10
- # Fires BEFORE the tool runs, so a `spex session done` declaration (itself a tool) lands AFTER this and wins;
11
- # the next real tool flips back to active, forcing a fresh Stop-gate declaration. Pure shell (no node/tsx) so
12
- # it stays cheap on every tool call — it value-replaces status/proposal/note in session.json with sed, never jq.
13
- # @@@ global store - state lives NOT in the worktree but in the per-session GLOBAL record session.json, keyed
14
- # by the harness session_id, grouped per-project (see hp_store_dir). GATED on `governed`: a user-self-launched
15
- # (non-governed) session has no board to feed, so this no-ops on it. cwd = the session worktree.
16
- . "${SPEXCODE_HARNESS_LIB:?harness.sh not exported by dispatch.sh}"
17
- payload=$(cat 2>/dev/null)
18
- # an IN-PROCESS SUBAGENT's tool call (Claude's Task tool) fires the parent's hooks with the PARENT's
19
- # session_id — flipping here let a supervising parent's own subagents erase its declared park/ask within
20
- # seconds and race the stop-gate into "undeclared stop" (issue #60). A subagent working is not the parent
21
- # agent ACTING, so its calls never touch the record; the parent's own next tool call still flips. The
22
- # discriminator is the payload's own top-level agent_id stamp (hp_is_subagent) — deterministic, never a
23
- # timing window.
24
- [ -n "$(hp_is_subagent "$payload")" ] && exit 0
25
- sid=$(hp_session_id "$payload"); [ -n "$sid" ] || exit 0
26
- sdir=$(hp_store_dir "$sid") || exit 0
27
- rec="$sdir/session.json"
28
- # board-lifecycle gate: only a GOVERNED (dashboard-launched) session has a board state to maintain.
29
- grep -q '"governed"[[:space:]]*:[[:space:]]*true' "$rec" 2>/dev/null || exit 0
30
-
31
- jget() { sed -n "s/.*\"$1\"[[:space:]]*:[[:space:]]*\"\([^\"]*\)\".*/\1/p" "$rec" 2>/dev/null | head -1; }
32
-
33
- if [ -n "$(hp_is_ask "$payload")" ]; then
34
- status=asking
35
- note=$(hp_ask_note "$payload") # first question's text → the note (best-effort)
36
- else
37
- status=active
38
- note=
39
- fi
40
-
41
- # cheap path: already active with nothing stale to clear → no-op (the common every-tool case).
42
- [ "$status" = active ] && [ "$(jget status)" = active ] && [ -z "$(jget proposal)" ] && [ -z "$(jget note)" ] && exit 0
43
-
44
- # value-replace status + clear proposal + (re)set note, in place. The record is written one-field-per-line
45
- # with these keys ALWAYS present (sessions.ts writeRecord), so each is a single value substitution — no key
46
- # add/remove, no JSON parser. Escape \ / & in the note for the sed REPLACEMENT (the note never contains ").
47
- note_esc=$(printf '%s' "$note" | sed 's/[\\/&]/\\&/g')
48
- tmp=$(mktemp) || exit 0
49
- sed -e "s/\(\"status\"[[:space:]]*:[[:space:]]*\)\"[^\"]*\"/\1\"$status\"/" \
50
- -e "s/\(\"proposal\"[[:space:]]*:[[:space:]]*\)\"[^\"]*\"/\1\"\"/" \
51
- -e "s/\(\"note\"[[:space:]]*:[[:space:]]*\)\"[^\"]*\"/\1\"$note_esc\"/" \
52
- "$rec" > "$tmp" && mv "$tmp" "$rec"
53
- exit 0
@@ -1,46 +0,0 @@
1
- #!/usr/bin/env bash
2
- # @@@ mark-active - the SINGLE freshness hook, wired to BOTH UserPromptSubmit and PreToolUse. It branches
3
- # on ONE structured signal read straight from the hook payload (stdin JSON), so the state is HARD — never
4
- # text-sniffed from the TUI:
5
- # the agent is pausing to ask the HUMAN (hp_is_ask) → status: asking, with the question text as the note
6
- # (the deterministic capture of a question).
7
- # any other tool, or a prompt submit → the agent is working → status: active (drop a now-stale proposal/note).
8
- # WHAT counts as "asking" is the [[harness-adapter]]'s call (Claude: the AskUserQuestion tool; Codex: the
9
- # request_user_input tool) — read via hp_is_ask, so this hook never names a harness tool.
10
- # Fires BEFORE the tool runs, so a `spex session done` declaration (itself a tool) lands AFTER this and wins;
11
- # the next real tool flips back to active, forcing a fresh Stop-gate declaration. Pure shell (no node/tsx) so
12
- # it stays cheap on every tool call — it value-replaces status/proposal/note in session.json with sed, never jq.
13
- # @@@ global store - state lives NOT in the worktree but in the per-session GLOBAL record session.json, keyed
14
- # by the harness session_id, grouped per-project (see hp_store_dir). GATED on `governed`: a user-self-launched
15
- # (non-governed) session has no board to feed, so this no-ops on it. cwd = the session worktree.
16
- . "${SPEXCODE_HARNESS_LIB:?harness.sh not exported by dispatch.sh}"
17
- payload=$(cat 2>/dev/null)
18
- sid=$(hp_session_id "$payload"); [ -n "$sid" ] || exit 0
19
- sdir=$(hp_store_dir "$sid") || exit 0
20
- rec="$sdir/session.json"
21
- # board-lifecycle gate: only a GOVERNED (dashboard-launched) session has a board state to maintain.
22
- grep -q '"governed"[[:space:]]*:[[:space:]]*true' "$rec" 2>/dev/null || exit 0
23
-
24
- jget() { sed -n "s/.*\"$1\"[[:space:]]*:[[:space:]]*\"\([^\"]*\)\".*/\1/p" "$rec" 2>/dev/null | head -1; }
25
-
26
- if [ -n "$(hp_is_ask "$payload")" ]; then
27
- status=asking
28
- note=$(hp_ask_note "$payload") # first question's text → the note (best-effort)
29
- else
30
- status=active
31
- note=
32
- fi
33
-
34
- # cheap path: already active with nothing stale to clear → no-op (the common every-tool case).
35
- [ "$status" = active ] && [ "$(jget status)" = active ] && [ -z "$(jget proposal)" ] && [ -z "$(jget note)" ] && exit 0
36
-
37
- # value-replace status + clear proposal + (re)set note, in place. The record is written one-field-per-line
38
- # with these keys ALWAYS present (sessions.ts writeRecord), so each is a single value substitution — no key
39
- # add/remove, no JSON parser. Escape \ / & in the note for the sed REPLACEMENT (the note never contains ").
40
- note_esc=$(printf '%s' "$note" | sed 's/[\\/&]/\\&/g')
41
- tmp=$(mktemp) || exit 0
42
- sed -e "s/\(\"status\"[[:space:]]*:[[:space:]]*\)\"[^\"]*\"/\1\"$status\"/" \
43
- -e "s/\(\"proposal\"[[:space:]]*:[[:space:]]*\)\"[^\"]*\"/\1\"\"/" \
44
- -e "s/\(\"note\"[[:space:]]*:[[:space:]]*\)\"[^\"]*\"/\1\"$note_esc\"/" \
45
- "$rec" > "$tmp" && mv "$tmp" "$rec"
46
- exit 0