@luminascale/shepherd 0.0.0-stage → 0.6.1
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.
- package/.agents/agents/README.md +12 -0
- package/.agents/agents/planner.md +38 -0
- package/.agents/agents/reviewer.md +38 -0
- package/.agents/agents/scout.md +43 -0
- package/.agents/agents/worker.md +33 -0
- package/.agents/skills/smoke-test/SKILL.md +155 -0
- package/.agents/skills/smoke-test/references/forensics.md +46 -0
- package/.agents/skills/smoke-test/scripts/live-smoke-poll.mjs +130 -0
- package/.github/workflows/publish.yml +77 -0
- package/.pi/prompts/release.md +21 -0
- package/.prettierrc +10 -0
- package/AGENTS.md +88 -0
- package/CONTRIBUTING.md +177 -0
- package/LICENSE +201 -0
- package/README.md +397 -2
- package/docs/README.md +26 -0
- package/docs/guides/agent-definitions.md +42 -0
- package/docs/guides/diagnostics.md +199 -0
- package/docs/guides/installation.md +61 -0
- package/docs/guides/tool-reference.md +55 -0
- package/docs/manual-tests/ping-pong-peer-messaging.md +147 -0
- package/docs/plans/agent-labels.md +257 -0
- package/docs/plans/architecture.md +110 -0
- package/docs/plans/settings-scope.md +163 -0
- package/docs/plans/tool-surface-split.md +278 -0
- package/docs/reference/dictionary +26 -0
- package/docs/releasing.md +47 -0
- package/docs/specs/005-agent-messaging-and-task-lifecycle/baseline.md +115 -0
- package/docs/specs/005-agent-messaging-and-task-lifecycle/handoff.md +564 -0
- package/docs/specs/005-agent-messaging-and-task-lifecycle/phase10-notes.md +109 -0
- package/docs/specs/005-agent-messaging-and-task-lifecycle/phase6-notes.md +69 -0
- package/docs/specs/005-agent-messaging-and-task-lifecycle/phase7-notes.md +100 -0
- package/docs/specs/005-agent-messaging-and-task-lifecycle/phase8-notes.md +127 -0
- package/docs/specs/005-agent-messaging-and-task-lifecycle/phase9-notes.md +104 -0
- package/docs/specs/005-agent-messaging-and-task-lifecycle/plan.md +1093 -0
- package/docs/specs/005-agent-messaging-and-task-lifecycle/spec.md +583 -0
- package/docs/specs/005-agent-messaging-and-task-lifecycle/tasks.md +838 -0
- package/docs/specs/006-shepherd-tool-rendering/plan.md +175 -0
- package/docs/specs/006-shepherd-tool-rendering/spec.md +469 -0
- package/index.ts +602 -0
- package/package.json +112 -4
- package/scripts/capture-system-prompt.mjs +45 -0
- package/scripts/extract-pi-system-prompt.mjs +277 -0
- package/scripts/host-impact.mjs +74 -0
- package/scripts/resolve-agent.mjs +43 -0
- package/scripts/show-shepherd-orchestrator.mjs +58 -0
- package/scripts/show-shepherd-prompt.mjs +96 -0
- package/scripts/verify-suites.mjs +67 -0
- package/specs/001-artifacts/spec.md +436 -0
- package/specs/002-simplify-agent-orchestration/plan.md +287 -0
- package/specs/002-simplify-agent-orchestration/spec.md +323 -0
- package/specs/002-simplify-agent-orchestration/tasks.md +212 -0
- package/specs/003-orchestrator-session-artifacts/plan.md +396 -0
- package/specs/003-orchestrator-session-artifacts/spec.md +453 -0
- package/specs/003-orchestrator-session-artifacts/tasks.md +141 -0
- package/specs/004-asynchronous-prompt-watchers/plan.md +139 -0
- package/specs/004-asynchronous-prompt-watchers/spec.md +202 -0
- package/specs/004-asynchronous-prompt-watchers/tasks.md +126 -0
- package/specs/005-per-workspace-settings/plan.md +230 -0
- package/specs/005-per-workspace-settings/spec.md +368 -0
- package/specs/005-per-workspace-settings/tasks.md +178 -0
- package/specs/006-dual-runtime-herdr-durable/intent.md +86 -0
- package/specs/006-dual-runtime-herdr-durable/journal.md +80 -0
- package/specs/006-dual-runtime-herdr-durable/plan.md +242 -0
- package/specs/006-dual-runtime-herdr-durable/spec.md +389 -0
- package/specs/006-dual-runtime-herdr-durable/tasks.md +199 -0
- package/specs/007-unwatched-completion-notice/journal.md +145 -0
- package/specs/007-unwatched-completion-notice/plan.md +186 -0
- package/specs/007-unwatched-completion-notice/spec.md +284 -0
- package/specs/007-unwatched-completion-notice/tasks.md +147 -0
- package/specs/008-remote-machine-sheep/intent.md +174 -0
- package/specs/008-remote-machine-sheep/journal.md +57 -0
- package/specs/008-remote-machine-sheep/prerequisites.md +219 -0
- package/specs/009-hc-runtime/intent.md +44 -0
- package/specs/009-hc-runtime/plan.md +49 -0
- package/specs/009-hc-runtime/spec.md +118 -0
- package/specs/009-hc-runtime/tasks.md +62 -0
- package/specs/010-unseen-watch-parity/intent.md +57 -0
- package/specs/010-unseen-watch-parity/journal.md +172 -0
- package/specs/010-unseen-watch-parity/plan.md +74 -0
- package/specs/010-unseen-watch-parity/spec.md +191 -0
- package/specs/010-unseen-watch-parity/tasks.md +119 -0
- package/specs/011-hc-background-poll/intent.md +57 -0
- package/specs/011-hc-background-poll/journal.md +95 -0
- package/specs/011-hc-background-poll/plan.md +87 -0
- package/specs/011-hc-background-poll/spec.md +141 -0
- package/specs/011-hc-background-poll/tasks.md +83 -0
- package/specs/012-steer-default/intent.md +12 -0
- package/specs/012-steer-default/journal.md +40 -0
- package/specs/012-steer-default/plan.md +7 -0
- package/specs/012-steer-default/spec.md +42 -0
- package/specs/012-steer-default/tasks.md +6 -0
- package/specs/013-opencode-shepherd/handoff-t011.md +94 -0
- package/specs/013-opencode-shepherd/intent.md +59 -0
- package/specs/013-opencode-shepherd/plan.md +204 -0
- package/specs/013-opencode-shepherd/spec.md +258 -0
- package/specs/013-opencode-shepherd/tasks.md +263 -0
- package/src/core/artifact-sessions.ts +835 -0
- package/src/core/config.ts +329 -0
- package/src/core/discovery.ts +342 -0
- package/src/core/herdr.ts +1 -0
- package/src/core/host.ts +77 -0
- package/src/core/ids.ts +78 -0
- package/src/core/lifecycle.ts +1 -0
- package/src/core/messaging.ts +1 -0
- package/src/core/migration.ts +55 -0
- package/src/core/orchestration.ts +1 -0
- package/src/core/types.ts +143 -0
- package/src/core/unseen-completions.ts +114 -0
- package/src/extension/cli.ts +417 -0
- package/src/extension/config.ts +1 -0
- package/src/extension/settings-ui.ts +296 -0
- package/src/extension/shepherd-done.ts +768 -0
- package/src/extension/shepherd.ts +2548 -0
- package/src/extension/system-prompt.ts +38 -0
- package/src/extension/unseen-completions.ts +237 -0
- package/src/opencode/actions.ts +794 -0
- package/src/opencode/bridge.ts +777 -0
- package/src/opencode/display.ts +36 -0
- package/src/opencode/fieldnotes.ts +60 -0
- package/src/opencode/host.ts +62 -0
- package/src/opencode/orphans.ts +162 -0
- package/src/opencode/server.ts +458 -0
- package/src/runtimes/backend.ts +119 -0
- package/src/runtimes/detect.ts +102 -0
- package/src/runtimes/hc/hc.ts +527 -0
- package/src/runtimes/hc/runtime.ts +1898 -0
- package/src/runtimes/herdr/herdr.ts +912 -0
- package/src/runtimes/herdr/lifecycle.ts +1712 -0
- package/src/runtimes/herdr/messaging.ts +703 -0
- package/src/runtimes/herdr/orchestration.ts +1583 -0
- package/src/runtimes/herdr/runtime.ts +224 -0
- package/src/runtimes/runtime.ts +133 -0
- package/src/runtimes/settle-observations.ts +114 -0
- package/test/fixtures/context-project/AGENTS.md +2 -0
- package/test/fixtures/home/.agents/agents/same.md +6 -0
- package/test/fixtures/home/.agents/agents/shared-only.md +6 -0
- package/test/fixtures/home/.pi/agent/agents/invalid-thinking.md +6 -0
- package/test/fixtures/home/.pi/agent/agents/model-empty.md +7 -0
- package/test/fixtures/home/.pi/agent/agents/model-explicit.md +7 -0
- package/test/fixtures/home/.pi/agent/agents/omit-context-absent.md +5 -0
- package/test/fixtures/home/.pi/agent/agents/omit-context-false.md +6 -0
- package/test/fixtures/home/.pi/agent/agents/omit-context-invalid.md +6 -0
- package/test/fixtures/home/.pi/agent/agents/omit-context-true.md +6 -0
- package/test/fixtures/home/.pi/agent/agents/omit-false.md +6 -0
- package/test/fixtures/home/.pi/agent/agents/omit-invalid.md +6 -0
- package/test/fixtures/home/.pi/agent/agents/omit-pi-docs.md +7 -0
- package/test/fixtures/home/.pi/agent/agents/omit-true.md +6 -0
- package/test/fixtures/home/.pi/agent/agents/only-user.md +9 -0
- package/test/fixtures/home/.pi/agent/agents/same.md +6 -0
- package/test/fixtures/proj/.agents/agents/proj-shared.md +6 -0
- package/test/fixtures/proj/.pi/agents/project-pi.md +6 -0
- package/test/fixtures/proj/.pi/agents/same.md +6 -0
- package/test/helpers/fake-clock.mjs +39 -0
- package/test/helpers/feature-contracts.mjs +44 -0
- package/test/helpers/test-utils.mjs +44 -0
- package/test/verify-artifact-sessions.mjs +258 -0
- package/test/verify-backend.mjs +297 -0
- package/test/verify-child-mislabel.mjs +135 -0
- package/test/verify-child-surface.mjs +321 -0
- package/test/verify-cli.mjs +197 -0
- package/test/verify-command-ux.mjs +100 -0
- package/test/verify-compat.mjs +32 -0
- package/test/verify-cross-host-notes.mjs +128 -0
- package/test/verify-delegate.mjs +161 -0
- package/test/verify-detect.mjs +151 -0
- package/test/verify-discovery.mjs +239 -0
- package/test/verify-done-nudge.mjs +238 -0
- package/test/verify-effective-prompt.mjs +98 -0
- package/test/verify-hc-matrix.mjs +246 -0
- package/test/verify-hc-poll.mjs +260 -0
- package/test/verify-host-docs.mjs +66 -0
- package/test/verify-host-impact.mjs +49 -0
- package/test/verify-ids.mjs +141 -0
- package/test/verify-launch.mjs +183 -0
- package/test/verify-message-routing.mjs +560 -0
- package/test/verify-messaging.mjs +303 -0
- package/test/verify-migration-notice.mjs +74 -0
- package/test/verify-multi-wait.mjs +42 -0
- package/test/verify-opencode-display.mjs +47 -0
- package/test/verify-opencode-fieldnotes.mjs +121 -0
- package/test/verify-opencode-notice.mjs +77 -0
- package/test/verify-opencode-nudge.mjs +116 -0
- package/test/verify-opencode-orphans.mjs +160 -0
- package/test/verify-opencode-surface.mjs +107 -0
- package/test/verify-packaging.mjs +82 -0
- package/test/verify-parent-surface.mjs +118 -0
- package/test/verify-phase0.mjs +95 -0
- package/test/verify-registry.mjs +124 -0
- package/test/verify-rename-migration.mjs +111 -0
- package/test/verify-rendering.mjs +379 -0
- package/test/verify-session-boundary.mjs +146 -0
- package/test/verify-settings.mjs +260 -0
- package/test/verify-stale-wait.mjs +339 -0
- package/test/verify-status-widget.mjs +377 -0
- package/test/verify-status.mjs +172 -0
- package/test/verify-task-completion.mjs +156 -0
- package/test/verify-task-failures.mjs +201 -0
- package/test/verify-task-mislabel.mjs +143 -0
- package/test/verify-task-registry.mjs +194 -0
- package/test/verify-task-watchers.mjs +217 -0
- package/test/verify-tool-schemas.mjs +120 -0
- package/test/verify-unseen-completions.mjs +1211 -0
- package/test/verify-watchers.mjs +181 -0
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Status widget render-path regression + Phase 9 task awareness.
|
|
4
|
+
*
|
|
5
|
+
* Reproduces the historical crash: the "below the editor" subagent widget's
|
|
6
|
+
* render closure referenced `shepherdCommandCwd`, a local of the export
|
|
7
|
+
* default body — invisible from inside registerSubagentStatusWidget(). The
|
|
8
|
+
* ReferenceError surfaced only once a live working agent made the snapshot
|
|
9
|
+
* non-empty and pi measured/rendered the widget.
|
|
10
|
+
*
|
|
11
|
+
* The probe drives the real render path: a sandboxed agent dir
|
|
12
|
+
* (PI_CODING_AGENT_DIR) + a fake `herdr` CLI serve this session's own panes
|
|
13
|
+
* plus a foreign working agent owned by another shepherd session, which the
|
|
14
|
+
* widget must filter out. HERDR_ENV=1 forces Herdr availability so
|
|
15
|
+
* workingOrWaitingSubagents() -> listHerdrAgents() -> shim.
|
|
16
|
+
*
|
|
17
|
+
* Phase 9 adds task awareness to the projection:
|
|
18
|
+
* - an IDLE process that owns a WAITING task is still shown (the child is
|
|
19
|
+
* parked on a required reply, not done) — rendered as "waiting (stale)"
|
|
20
|
+
* with the elapsed-wait and pending-recipient markers;
|
|
21
|
+
* - a working process with a RUNNING task is shown with the task state;
|
|
22
|
+
* - once the waiting task completes, the idle pane drops out of the widget.
|
|
23
|
+
*
|
|
24
|
+
* Phase 1: render right after session_start (default emojiSheep=true → 🐑).
|
|
25
|
+
* Phase 2: session_start re-fired with a second cwd that has
|
|
26
|
+
* `.shepherd/config.json` with emojiSheep=false → the sheep glyph switches to
|
|
27
|
+
* the plain "o".
|
|
28
|
+
* Phase 3: the waiting task is settled completed → the idle pane is gone.
|
|
29
|
+
*/
|
|
30
|
+
import assert from 'node:assert/strict';
|
|
31
|
+
import { chmodSync, mkdirSync, mkdtempSync, writeFileSync } from 'node:fs';
|
|
32
|
+
import { spawnSync } from 'node:child_process';
|
|
33
|
+
import { tmpdir } from 'node:os';
|
|
34
|
+
import * as path from 'node:path';
|
|
35
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
36
|
+
import { visibleWidth } from '@earendil-works/pi-tui';
|
|
37
|
+
|
|
38
|
+
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
39
|
+
const indexUrl = pathToFileURL(path.join(root, 'index.ts')).href;
|
|
40
|
+
const sandbox = mkdtempSync(path.join(tmpdir(), 'pi-shepherd-widget-'));
|
|
41
|
+
const agentDir = path.join(sandbox, 'agent');
|
|
42
|
+
const homeCwd = path.join(sandbox, 'home');
|
|
43
|
+
const otherCwd = path.join(sandbox, 'other');
|
|
44
|
+
for (const dir of [
|
|
45
|
+
agentDir,
|
|
46
|
+
path.join(agentDir, 'pi-shepherd'),
|
|
47
|
+
homeCwd,
|
|
48
|
+
otherCwd,
|
|
49
|
+
path.join(otherCwd, '.shepherd'),
|
|
50
|
+
]) {
|
|
51
|
+
mkdirSync(dir, { recursive: true });
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Sandbox user layer: the default emojiSheep=true applies to the first
|
|
55
|
+
// session. Project scope is activated by the project file itself.
|
|
56
|
+
writeFileSync(
|
|
57
|
+
path.join(agentDir, 'pi-shepherd', 'config.json'),
|
|
58
|
+
JSON.stringify({ emojiSheep: true }, null, 2)
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
// Project layer for the second session cwd: emojiSheep=false is observable in
|
|
62
|
+
// the rendered rows (the walking sheep glyph switches from 🐑 to "o").
|
|
63
|
+
writeFileSync(
|
|
64
|
+
path.join(otherCwd, '.shepherd', 'config.json'),
|
|
65
|
+
JSON.stringify({ projectScope: true, emojiSheep: false }, null, 2)
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
// Sandboxed created-panes registry: three of this probe session's panes —
|
|
69
|
+
// PANE_ID (working process, no task), PANE_ID_TASK (working process with a
|
|
70
|
+
// running task), PANE_ID_WAIT (idle process with a waiting, stale task) —
|
|
71
|
+
// plus a foreign pane owned by another shepherd session, which the widget
|
|
72
|
+
// must filter out.
|
|
73
|
+
const PANE_ID = 'test-pane-1';
|
|
74
|
+
const PANE_ID_TASK = 'test-pane-task';
|
|
75
|
+
const PANE_ID_WAIT = 'test-pane-wait';
|
|
76
|
+
const FOREIGN_PANE_ID = 'test-pane-foreign'; // owned by another shepherd session
|
|
77
|
+
const PROBE_SESSION = 'widget-probe-session';
|
|
78
|
+
writeFileSync(
|
|
79
|
+
path.join(agentDir, 'pi-shepherd', 'created-panes.json'),
|
|
80
|
+
JSON.stringify(
|
|
81
|
+
[
|
|
82
|
+
{
|
|
83
|
+
paneId: PANE_ID,
|
|
84
|
+
tabId: 'test-tab-1',
|
|
85
|
+
name: 'worker',
|
|
86
|
+
cwd: otherCwd,
|
|
87
|
+
createdAt: Date.now(),
|
|
88
|
+
ownerSession: PROBE_SESSION,
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
paneId: PANE_ID_TASK,
|
|
92
|
+
tabId: 'test-tab-task',
|
|
93
|
+
name: 'planner',
|
|
94
|
+
cwd: otherCwd,
|
|
95
|
+
createdAt: Date.now(),
|
|
96
|
+
ownerSession: PROBE_SESSION,
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
paneId: PANE_ID_WAIT,
|
|
100
|
+
tabId: 'test-tab-wait',
|
|
101
|
+
name: 'scout',
|
|
102
|
+
cwd: otherCwd,
|
|
103
|
+
createdAt: Date.now(),
|
|
104
|
+
ownerSession: PROBE_SESSION,
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
null,
|
|
108
|
+
2
|
|
109
|
+
)
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
// Fake herdr CLI: satisfies isHerdrCliPresent (`herdr --version`) and serves
|
|
113
|
+
// the agent list (`herdr agent list`) with the three owned panes (two working,
|
|
114
|
+
// one idle) plus the foreign working pane owned by another session.
|
|
115
|
+
const agentListOut = JSON.stringify({
|
|
116
|
+
result: {
|
|
117
|
+
agents: [
|
|
118
|
+
{
|
|
119
|
+
agent: 'pi',
|
|
120
|
+
agent_status: 'working',
|
|
121
|
+
pane_id: PANE_ID,
|
|
122
|
+
tab_id: 'test-tab-1',
|
|
123
|
+
workspace_id: 'test-ws-1',
|
|
124
|
+
foreground_cwd: otherCwd,
|
|
125
|
+
focused: false,
|
|
126
|
+
terminal_title: 'pi',
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
agent: 'pi',
|
|
130
|
+
agent_status: 'working',
|
|
131
|
+
pane_id: PANE_ID_TASK,
|
|
132
|
+
tab_id: 'test-tab-task',
|
|
133
|
+
workspace_id: 'test-ws-1',
|
|
134
|
+
foreground_cwd: otherCwd,
|
|
135
|
+
focused: false,
|
|
136
|
+
terminal_title: 'pi',
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
agent: 'pi',
|
|
140
|
+
agent_status: 'idle',
|
|
141
|
+
pane_id: PANE_ID_WAIT,
|
|
142
|
+
tab_id: 'test-tab-wait',
|
|
143
|
+
workspace_id: 'test-ws-1',
|
|
144
|
+
foreground_cwd: otherCwd,
|
|
145
|
+
focused: false,
|
|
146
|
+
terminal_title: 'pi',
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
agent: 'pi',
|
|
150
|
+
agent_status: 'working',
|
|
151
|
+
pane_id: FOREIGN_PANE_ID,
|
|
152
|
+
tab_id: 'test-tab-foreign',
|
|
153
|
+
workspace_id: 'test-ws-1',
|
|
154
|
+
foreground_cwd: otherCwd,
|
|
155
|
+
focused: false,
|
|
156
|
+
terminal_title: 'pi',
|
|
157
|
+
},
|
|
158
|
+
],
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
const binDir = path.join(sandbox, 'bin');
|
|
162
|
+
mkdirSync(binDir, { recursive: true });
|
|
163
|
+
writeFileSync(
|
|
164
|
+
path.join(binDir, 'herdr'),
|
|
165
|
+
`#!/bin/sh
|
|
166
|
+
case "$1" in
|
|
167
|
+
--version)
|
|
168
|
+
echo "herdr 9.9.9-test"
|
|
169
|
+
exit 0 ;;
|
|
170
|
+
agent)
|
|
171
|
+
if [ "$2" = "list" ]; then
|
|
172
|
+
echo '${agentListOut}'
|
|
173
|
+
exit 0
|
|
174
|
+
fi
|
|
175
|
+
exit 0 ;;
|
|
176
|
+
esac
|
|
177
|
+
exit 0
|
|
178
|
+
`
|
|
179
|
+
);
|
|
180
|
+
chmodSync(path.join(binDir, 'herdr'), 0o755);
|
|
181
|
+
|
|
182
|
+
const probe = `
|
|
183
|
+
const calls = { events: [], widgets: [] };
|
|
184
|
+
const pi = {
|
|
185
|
+
registerTool() {},
|
|
186
|
+
registerCommand() {},
|
|
187
|
+
registerMessageRenderer() {},
|
|
188
|
+
on(event, handler) { calls.events.push({ event, handler }); },
|
|
189
|
+
};
|
|
190
|
+
const mod = await import(${JSON.stringify(indexUrl)});
|
|
191
|
+
mod.default(pi);
|
|
192
|
+
|
|
193
|
+
// Seed the global lifecycle registry with the two tasks the fake Herdr
|
|
194
|
+
// panes will own. sessionOwner() picks up PI_SHEPHERD_OWNER_SESSION (set in
|
|
195
|
+
// runProbe), so activeTasksByPane()/workingOrWaitingSubagents() scope to
|
|
196
|
+
// exactly these panes, and the foreign pane stays excluded.
|
|
197
|
+
const { lifecycleRegistry } = await import(${JSON.stringify(pathToFileURL(path.join(root, 'src/core/orchestration.ts')).href)});
|
|
198
|
+
const taskAgent = lifecycleRegistry.registerAgent({ agent: "planner", label: "worker-2", paneId: ${JSON.stringify(PANE_ID_TASK)} });
|
|
199
|
+
const waitingAgent = lifecycleRegistry.registerAgent({ agent: "scout", label: "stale-scout", paneId: ${JSON.stringify(PANE_ID_WAIT)} });
|
|
200
|
+
const runningTask = lifecycleRegistry.createTask(taskAgent, "Draft the rollout plan.");
|
|
201
|
+
lifecycleRegistry.setTaskRunning(runningTask.id);
|
|
202
|
+
const waitingTask = lifecycleRegistry.createTask(waitingAgent, "Chase the missing retry backoff.");
|
|
203
|
+
lifecycleRegistry.setTaskRunning(waitingTask.id);
|
|
204
|
+
lifecycleRegistry.openPendingRequest(waitingTask.id, {
|
|
205
|
+
messageId: "msg-pending-1",
|
|
206
|
+
targetAgentId: taskAgent.id,
|
|
207
|
+
text: "What is the retry backoff?",
|
|
208
|
+
});
|
|
209
|
+
lifecycleRegistry.markStaleNotified(waitingTask);
|
|
210
|
+
|
|
211
|
+
const handlers = calls.events.filter(e => e.event === "session_start");
|
|
212
|
+
const fakeUi = { setWidget(id, factory) { calls.widgets.push({ id, factory }); } };
|
|
213
|
+
const driveSessionStart = (cwd) => {
|
|
214
|
+
for (const { handler } of handlers) handler(null, { hasUI: true, cwd, ui: fakeUi });
|
|
215
|
+
};
|
|
216
|
+
driveSessionStart(${JSON.stringify(homeCwd)});
|
|
217
|
+
const widget = calls.widgets.find(w => w.id === "pi-shepherd-working");
|
|
218
|
+
assert.ok(widget, "status widget is registered on session_start");
|
|
219
|
+
const theme = { fg: (_c, t) => t };
|
|
220
|
+
function renderOnce() {
|
|
221
|
+
const w = widget.factory({ requestRender() {} }, theme);
|
|
222
|
+
const lines = w.render(140);
|
|
223
|
+
w.dispose();
|
|
224
|
+
return lines;
|
|
225
|
+
}
|
|
226
|
+
const phase1 = renderOnce();
|
|
227
|
+
driveSessionStart(${JSON.stringify(otherCwd)});
|
|
228
|
+
const phase2 = renderOnce();
|
|
229
|
+
// The waiting task completes: the idle pane must drop out of the widget.
|
|
230
|
+
lifecycleRegistry.settleTask(waitingTask, { status: "completed", ok: true, text: "got the backoff" });
|
|
231
|
+
const phase3 = renderOnce();
|
|
232
|
+
console.log("PHASE1 " + JSON.stringify(phase1));
|
|
233
|
+
console.log("PHASE2 " + JSON.stringify(phase2));
|
|
234
|
+
console.log("PHASE3 " + JSON.stringify(phase3));
|
|
235
|
+
`;
|
|
236
|
+
|
|
237
|
+
function runProbe() {
|
|
238
|
+
const env = {
|
|
239
|
+
...process.env,
|
|
240
|
+
PI_CODING_AGENT_DIR: agentDir,
|
|
241
|
+
HERDR_ENV: '1',
|
|
242
|
+
PATH: `${binDir}:${process.env.PATH}`,
|
|
243
|
+
};
|
|
244
|
+
// Deterministic parent (non-worker) surface regardless of the calling env.
|
|
245
|
+
delete env.PI_SHEPHERD_SESSION;
|
|
246
|
+
// This probe session's identity; the registered panes carry the same owner
|
|
247
|
+
// so they are included, while the foreign pane must be filtered out.
|
|
248
|
+
delete env.PI_SHEPHERD_OWNER_SESSION;
|
|
249
|
+
env.PI_SHEPHERD_OWNER_SESSION = PROBE_SESSION;
|
|
250
|
+
return {
|
|
251
|
+
cwd: homeCwd,
|
|
252
|
+
encoding: 'utf8',
|
|
253
|
+
env,
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const result = spawnSync(
|
|
258
|
+
process.execPath,
|
|
259
|
+
[
|
|
260
|
+
'--experimental-strip-types',
|
|
261
|
+
'--disable-warning=ExperimentalWarning',
|
|
262
|
+
'--input-type=module',
|
|
263
|
+
'--eval',
|
|
264
|
+
probe,
|
|
265
|
+
],
|
|
266
|
+
runProbe()
|
|
267
|
+
);
|
|
268
|
+
assert.equal(
|
|
269
|
+
result.status,
|
|
270
|
+
0,
|
|
271
|
+
`widget probe failed:\nstdout: ${result.stdout}\nstderr: ${result.stderr}`
|
|
272
|
+
);
|
|
273
|
+
const outLines = result.stdout.trim().split('\n');
|
|
274
|
+
const parsePhase = name => {
|
|
275
|
+
const line = outLines.find(l => l.startsWith(`${name} `));
|
|
276
|
+
assert.ok(line, `probe did not emit ${name}`);
|
|
277
|
+
return JSON.parse(line.slice(name.length + 1));
|
|
278
|
+
};
|
|
279
|
+
const phase1 = parsePhase('PHASE1');
|
|
280
|
+
const phase2 = parsePhase('PHASE2');
|
|
281
|
+
const phase3 = parsePhase('PHASE3');
|
|
282
|
+
// The box frames use truecolor ANSI, so compare structure on stripped text.
|
|
283
|
+
const stripAnsi = s => s.replace(/\u001b\[[0-9;]*m/g, '');
|
|
284
|
+
const p1 = phase1.map(stripAnsi);
|
|
285
|
+
const p2 = phase2.map(stripAnsi);
|
|
286
|
+
const p3 = phase3.map(stripAnsi);
|
|
287
|
+
|
|
288
|
+
// The crash regression: render must produce the bordered box, not throw.
|
|
289
|
+
assert.ok(
|
|
290
|
+
Array.isArray(p1) && p1.length === 5,
|
|
291
|
+
'render returns top border, three agent rows, bottom border'
|
|
292
|
+
);
|
|
293
|
+
assert.match(p1[0], /shepherd/, 'top border shows the title');
|
|
294
|
+
assert.match(p1[0], /2 working/, 'top border counts the working processes');
|
|
295
|
+
assert.match(p1[0], /1 waiting/, 'top border counts the waiting tasks');
|
|
296
|
+
assert.match(p1.at(-1), /╰─+╯/, 'bottom border present');
|
|
297
|
+
|
|
298
|
+
// Row 1: plain working process (no task).
|
|
299
|
+
const rowWorker = p1[1];
|
|
300
|
+
assert.match(rowWorker, /worker/, 'row names the recorded agent kind');
|
|
301
|
+
assert.match(rowWorker, /working/, 'working process shows the working state');
|
|
302
|
+
assert.ok(!rowWorker.includes('⏳'), 'no wait marker on a plain working process');
|
|
303
|
+
|
|
304
|
+
// Row 2: working process with a running task — the task state is projected.
|
|
305
|
+
const rowTask = p1[2];
|
|
306
|
+
assert.match(rowTask, /planner/, 'row names the recorded agent kind');
|
|
307
|
+
assert.match(
|
|
308
|
+
rowTask,
|
|
309
|
+
/running/,
|
|
310
|
+
'working process with a running task shows the running task state'
|
|
311
|
+
);
|
|
312
|
+
|
|
313
|
+
// Row 3: IDLE process with a WAITING, STALE task — still visible, rendered
|
|
314
|
+
// distinctly with the elapsed wait and the waiting-on recipient.
|
|
315
|
+
const rowWait = p1[3];
|
|
316
|
+
assert.match(
|
|
317
|
+
rowWait,
|
|
318
|
+
/\bscout\b/,
|
|
319
|
+
'idle process owning a waiting task is still shown (agent kind)'
|
|
320
|
+
);
|
|
321
|
+
assert.match(rowWait, /waiting\s*\(stale\)/, 'stale waiting task renders distinctly');
|
|
322
|
+
assert.ok(rowWait.includes('⏳'), 'waiting row surfaces the elapsed wait');
|
|
323
|
+
assert.ok(rowWait.includes('←'), 'waiting row surfaces the waiting-on recipient');
|
|
324
|
+
|
|
325
|
+
// Every row fits the viewport width (visible width), across all phases.
|
|
326
|
+
for (const line of [...p1, ...p2, ...p3]) {
|
|
327
|
+
const w = visibleWidth(line);
|
|
328
|
+
assert.ok(
|
|
329
|
+
w <= 140,
|
|
330
|
+
`row fits the viewport width (visible width ${w} for ${JSON.stringify(line)})`
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// Session scoping: the foreign pane (registered by another shepherd session)
|
|
335
|
+
// is detected by Herdr but must not appear in this session's widget.
|
|
336
|
+
for (const line of [...p1, ...p2]) {
|
|
337
|
+
assert.ok(!line.includes(FOREIGN_PANE_ID), 'foreign-session pane never appears in this widget');
|
|
338
|
+
}
|
|
339
|
+
assert.equal(p1.length, 5, 'exactly three rows: foreign sheep filtered out');
|
|
340
|
+
|
|
341
|
+
// Parent/child (session) separation: the widget content never leaks raw pane
|
|
342
|
+
// ids or opaque task ids — public views only.
|
|
343
|
+
for (const line of [...p1, ...p2]) {
|
|
344
|
+
assert.ok(!line.includes('test-pane-'), 'raw Herdr pane ids stay internal');
|
|
345
|
+
assert.ok(!line.includes('shepherd-task-'), 'opaque task ids are not painted into rows');
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// emojiSheep is read from the active session cwd at render time.
|
|
349
|
+
assert.ok(rowWorker.includes('🐑'), 'phase 1 renders the emoji sheep (default emojiSheep=true)');
|
|
350
|
+
assert.ok(
|
|
351
|
+
!p2.some(line => line.includes('🐑')),
|
|
352
|
+
'phase 2 no longer renders the emoji sheep after the session cwd changes'
|
|
353
|
+
);
|
|
354
|
+
assert.match(p2[1], /\bo\b/, 'phase 2 renders the plain walking glyph on the working row');
|
|
355
|
+
assert.equal(p2.length, 5, 'phase 2 still renders the full box');
|
|
356
|
+
|
|
357
|
+
// Completed-task removal: settling the waiting task (completed) clears the
|
|
358
|
+
// active task; the idle pane then drops out because it is idle with no task.
|
|
359
|
+
assert.equal(p3.length, 4, 'phase 3: waiting row disappears after the task completes');
|
|
360
|
+
assert.ok(
|
|
361
|
+
p3.every(line => !line.includes('⏳') && !line.includes('stale')),
|
|
362
|
+
'no wait/stale markers remain'
|
|
363
|
+
);
|
|
364
|
+
assert.match(p3[0], /2 working/, 'phase 3 header counts only the two working processes');
|
|
365
|
+
assert.ok(
|
|
366
|
+
p3.every(line => !line.includes('stale-scout')),
|
|
367
|
+
"completed waiting task's idle pane is removed"
|
|
368
|
+
);
|
|
369
|
+
|
|
370
|
+
console.log('PASS widget render survives a non-empty snapshot (no out-of-scope ReferenceError)');
|
|
371
|
+
console.log('PASS widget honors the active session cwd after session_start');
|
|
372
|
+
console.log('PASS widget shows only the sheep owned by this shepherd session');
|
|
373
|
+
console.log('PASS idle process with a waiting task stays visible (distinct from working)');
|
|
374
|
+
console.log('PASS stale waiting task renders distinctly with recipient and elapsed wait');
|
|
375
|
+
console.log('PASS working process with a running task projects the task state');
|
|
376
|
+
console.log('PASS completed waiting task drops the idle pane from the widget');
|
|
377
|
+
console.log('All status widget assertions passed.');
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Phase 9 verification — status model.
|
|
4
|
+
*
|
|
5
|
+
* `shepherd_status` now reports process state and task state **independently**:
|
|
6
|
+
* an idle process can own a `waiting` task and a working process a `running`
|
|
7
|
+
* one. The public view carries only opaque ids (no Herdr pane identity); the
|
|
8
|
+
* pane id stays an internal diagnostic. Parent/child separation is enforced
|
|
9
|
+
* one layer up (workers never register the parent control plane — see
|
|
10
|
+
* verify-parent-surface.mjs); this probe covers the status payload itself.
|
|
11
|
+
*/
|
|
12
|
+
import assert from 'node:assert/strict';
|
|
13
|
+
import { chmodSync, mkdtempSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
14
|
+
import { tmpdir } from 'node:os';
|
|
15
|
+
import * as path from 'node:path';
|
|
16
|
+
import { lifecycleRegistry } from '../src/core/orchestration.ts';
|
|
17
|
+
import { statusAgent } from '../src/core/lifecycle.ts';
|
|
18
|
+
import { doAction } from '../src/extension/shepherd.ts';
|
|
19
|
+
import { withFakeDateNow } from './helpers/fake-clock.mjs';
|
|
20
|
+
|
|
21
|
+
const ONE_MIN = 60_000;
|
|
22
|
+
|
|
23
|
+
await withFakeDateNow(0, async clock => {
|
|
24
|
+
const idle = lifecycleRegistry.registerAgent({ agent: 'scout', label: 'status-scout' });
|
|
25
|
+
const worker = lifecycleRegistry.registerAgent({ agent: 'worker', label: 'status-worker' });
|
|
26
|
+
const target = lifecycleRegistry.registerAgent({ agent: 'planner', label: 'status-planner' });
|
|
27
|
+
|
|
28
|
+
// Idle process + waiting task → both independent.
|
|
29
|
+
const waitingTask = lifecycleRegistry.createTask(idle, 'Chase the missing retry backoff.');
|
|
30
|
+
lifecycleRegistry.setTaskRunning(waitingTask.id);
|
|
31
|
+
lifecycleRegistry.openPendingRequest(waitingTask.id, {
|
|
32
|
+
messageId: 'msg-status-1',
|
|
33
|
+
targetAgentId: target.id,
|
|
34
|
+
text: 'What is the retry backoff?',
|
|
35
|
+
});
|
|
36
|
+
clock.advance(65_000);
|
|
37
|
+
|
|
38
|
+
const probe = agentId => statusAgent({ id: agentId });
|
|
39
|
+
const idleStatus = probe(idle.id);
|
|
40
|
+
// The process is idle (agent_end/turn ended) while its task keeps waiting.
|
|
41
|
+
assert.equal(idleStatus.state, 'idle', 'process state is idle');
|
|
42
|
+
assert.ok(idleStatus.task, 'an idle process still reports its active task');
|
|
43
|
+
assert.equal(idleStatus.task.id, waitingTask.id, 'task id is included');
|
|
44
|
+
assert.equal(idleStatus.task.state, 'waiting', 'task state is reported independently');
|
|
45
|
+
assert.ok(idleStatus.task.waitingSince !== undefined, 'waiting origin is included');
|
|
46
|
+
assert.ok(idleStatus.task.waitingMs >= 65_000, 'waiting age is included');
|
|
47
|
+
assert.equal(
|
|
48
|
+
idleStatus.task.pendingRequestMessageId,
|
|
49
|
+
'msg-status-1',
|
|
50
|
+
'pending request id is included'
|
|
51
|
+
);
|
|
52
|
+
assert.equal(
|
|
53
|
+
idleStatus.task.waitingRecipient,
|
|
54
|
+
'planner: status-planner',
|
|
55
|
+
'waiting recipient is included'
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
// Stale flag appears only after the one-time reminder has been emitted.
|
|
59
|
+
assert.equal(idleStatus.task.stale, undefined, 'no stale flag before the reminder');
|
|
60
|
+
lifecycleRegistry.markStaleNotified(waitingTask);
|
|
61
|
+
const staleStatus = probe(idle.id);
|
|
62
|
+
assert.equal(staleStatus.task.stale, true, 'stale flag is included when applicable');
|
|
63
|
+
|
|
64
|
+
// Working process + running task → both present and consistent.
|
|
65
|
+
const runningTask = lifecycleRegistry.createTask(worker, 'Write the rollout plan.');
|
|
66
|
+
lifecycleRegistry.setTaskRunning(runningTask.id);
|
|
67
|
+
lifecycleRegistry.setAgentState(worker, 'working');
|
|
68
|
+
const workerStatus = probe(worker.id);
|
|
69
|
+
assert.equal(workerStatus.state, 'working', 'process state is working');
|
|
70
|
+
assert.equal(workerStatus.task.id, runningTask.id);
|
|
71
|
+
assert.equal(workerStatus.task.state, 'running', 'running task is reported');
|
|
72
|
+
assert.equal(workerStatus.task.waitingMs, undefined, 'no waiting age for a running task');
|
|
73
|
+
assert.equal(
|
|
74
|
+
workerStatus.task.pendingRequestMessageId,
|
|
75
|
+
undefined,
|
|
76
|
+
'no pending request for a running task'
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
// A reply resumes the task: waiting fields disappear, the stale flag is gone.
|
|
80
|
+
lifecycleRegistry.resolveReplyForTask(waitingTask.id, 'msg-status-1');
|
|
81
|
+
const resumed = probe(idle.id);
|
|
82
|
+
assert.equal(resumed.task.state, 'running', 'the task returns to running after the reply');
|
|
83
|
+
assert.equal(resumed.task.waitingMs, undefined, 'waiting age is cleared on resume');
|
|
84
|
+
assert.equal(resumed.task.stale, undefined, 'stale flag is cleared on resume');
|
|
85
|
+
|
|
86
|
+
// Completed task → dropped from the task view; the owning process becomes
|
|
87
|
+
// "done" (the agent's work finished). Process and task states were tracked
|
|
88
|
+
// independently up to that point.
|
|
89
|
+
lifecycleRegistry.settleTask(waitingTask.id, { status: 'completed', ok: true, text: 'resolved' });
|
|
90
|
+
const completed = probe(idle.id);
|
|
91
|
+
assert.equal(completed.state, 'done', 'the owning process transitions to done');
|
|
92
|
+
assert.equal(completed.task, undefined, 'a completed task is removed from the status view');
|
|
93
|
+
|
|
94
|
+
// An agent with no task reports process state only (pane id stays internal).
|
|
95
|
+
const plain = probe(target.id);
|
|
96
|
+
assert.equal(plain.task, undefined, 'no task field when the agent owns no task');
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// Public doAction mapping: opaque ids only, pane identity never leaks, and the
|
|
100
|
+
// summary text names the process state and the task state independently.
|
|
101
|
+
{
|
|
102
|
+
const idle = lifecycleRegistry.registerAgent({ agent: 'scout', label: 'doaction-scout' });
|
|
103
|
+
const target = lifecycleRegistry.registerAgent({ agent: 'planner', label: 'doaction-planner' });
|
|
104
|
+
const task = lifecycleRegistry.createTask(idle, 'Wait for the mapping test.');
|
|
105
|
+
lifecycleRegistry.setTaskRunning(task.id);
|
|
106
|
+
lifecycleRegistry.openPendingRequest(task.id, {
|
|
107
|
+
messageId: 'msg-map-1',
|
|
108
|
+
targetAgentId: target.id,
|
|
109
|
+
text: 'ping?',
|
|
110
|
+
});
|
|
111
|
+
lifecycleRegistry.markStaleNotified(task);
|
|
112
|
+
|
|
113
|
+
// Phase 2: `shepherd_status` routes through the resolved runtime. Pin the
|
|
114
|
+
// sandbox user layer to the pane backend so this herdr-agent status keeps
|
|
115
|
+
// proving pane behavior deterministically (an explicit pin wins over
|
|
116
|
+
// caller detection). A pinned backend must be reachable, so a fake `herdr`
|
|
117
|
+
// answers `--version` + `status server` on a sandbox PATH (same precedent
|
|
118
|
+
// as the unseen-completions close test); the status path itself never
|
|
119
|
+
// shells out for these pane-less agents.
|
|
120
|
+
const previousAgentDir = process.env.PI_CODING_AGENT_DIR;
|
|
121
|
+
const previousPath = process.env.PATH;
|
|
122
|
+
const statusSandbox = mkdtempSync(path.join(tmpdir(), 'pi-shepherd-status-'));
|
|
123
|
+
mkdirSync(path.join(statusSandbox, 'pi-shepherd'), { recursive: true });
|
|
124
|
+
mkdirSync(path.join(statusSandbox, 'bin'), { recursive: true });
|
|
125
|
+
writeFileSync(
|
|
126
|
+
path.join(statusSandbox, 'pi-shepherd', 'config.json'),
|
|
127
|
+
JSON.stringify({ backend: 'herdr' })
|
|
128
|
+
);
|
|
129
|
+
writeFileSync(
|
|
130
|
+
path.join(statusSandbox, 'bin', 'herdr'),
|
|
131
|
+
'#!/bin/sh\ncase "$1 $2" in\n "status server") printf \'status: running\\n\' ;;\n *) printf \'%s\\n\' \'{\"result\":{}}\' ;;\nesac\nexit 0\n'
|
|
132
|
+
);
|
|
133
|
+
chmodSync(path.join(statusSandbox, 'bin', 'herdr'), 0o755);
|
|
134
|
+
process.env.PI_CODING_AGENT_DIR = statusSandbox;
|
|
135
|
+
process.env.PATH = `${path.join(statusSandbox, 'bin')}${path.delimiter}${previousPath ?? ''}`;
|
|
136
|
+
let result;
|
|
137
|
+
try {
|
|
138
|
+
result = await doAction({ action: 'status', id: idle.id }, { cwd: process.cwd() });
|
|
139
|
+
} finally {
|
|
140
|
+
if (previousAgentDir === undefined) delete process.env.PI_CODING_AGENT_DIR;
|
|
141
|
+
else process.env.PI_CODING_AGENT_DIR = previousAgentDir;
|
|
142
|
+
if (previousPath === undefined) delete process.env.PATH;
|
|
143
|
+
else process.env.PATH = previousPath;
|
|
144
|
+
}
|
|
145
|
+
const details = result.details;
|
|
146
|
+
assert.ok(details && typeof details === 'object', 'status result carries structured details');
|
|
147
|
+
const status = details.status;
|
|
148
|
+
assert.equal(status.id, idle.id, 'public result keeps the opaque agent id');
|
|
149
|
+
assert.equal(status.state, 'idle', 'process state is exposed');
|
|
150
|
+
assert.ok(status.task, 'task state is exposed on the public result');
|
|
151
|
+
assert.equal(status.task.id, task.id, 'task id is exposed');
|
|
152
|
+
assert.equal(status.task.state, 'waiting');
|
|
153
|
+
assert.ok(status.task.waitingMs !== undefined, 'waiting age is exposed');
|
|
154
|
+
assert.equal(status.task.pendingRequest, 'msg-map-1', 'pending request id is exposed');
|
|
155
|
+
assert.equal(status.task.waitingOn, 'planner: doaction-planner', 'waiting recipient is exposed');
|
|
156
|
+
assert.equal(status.task.stale, true, 'stale flag is exposed');
|
|
157
|
+
// Herdr pane identity stays an internal diagnostic, never a public field.
|
|
158
|
+
assert.equal(status.paneId, undefined, 'pane id is not in the public status');
|
|
159
|
+
const serialized = JSON.stringify(details);
|
|
160
|
+
assert.ok(!serialized.includes('pane'), 'no pane reference leaks into status details');
|
|
161
|
+
const text = result.content.find(c => c.type === 'text').text;
|
|
162
|
+
assert.match(text, /agent idle; task /, 'summary names both the process and the task state');
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
console.log('PASS status reports process state and task state independently');
|
|
166
|
+
console.log(
|
|
167
|
+
'PASS status includes task id, waiting age, pending request, recipient, and stale flag'
|
|
168
|
+
);
|
|
169
|
+
console.log('PASS a reply clears the waiting/stale fields');
|
|
170
|
+
console.log('PASS a completed task is removed from the status view');
|
|
171
|
+
console.log('PASS the public status result exposes opaque ids only (pane id stays internal)');
|
|
172
|
+
console.log('All status model assertions passed.');
|