@luminascale/shepherd 0.0.0-stage → 0.6.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.
- 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 +424 -2
- package/docs/README.md +25 -0
- package/docs/guides/agent-definitions.md +42 -0
- package/docs/guides/diagnostics.md +199 -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 +599 -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 +259 -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 +35 -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 +69 -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,303 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/** Phase 2 verification for the parent-owned filesystem mailbox. */
|
|
3
|
+
import assert from 'node:assert/strict';
|
|
4
|
+
import * as fs from 'node:fs';
|
|
5
|
+
import * as path from 'node:path';
|
|
6
|
+
import {
|
|
7
|
+
MessagingError,
|
|
8
|
+
closeBrokerWhenChildrenGone,
|
|
9
|
+
createChildBroker,
|
|
10
|
+
createEnvelope,
|
|
11
|
+
createParentBroker,
|
|
12
|
+
pollChildInbox,
|
|
13
|
+
pollParentInbox,
|
|
14
|
+
publishFromChild,
|
|
15
|
+
publishFromParent,
|
|
16
|
+
registerChild,
|
|
17
|
+
unregisterChild,
|
|
18
|
+
} from '../src/core/messaging.ts';
|
|
19
|
+
import {
|
|
20
|
+
createFakeChildIdentity,
|
|
21
|
+
createFakeParentIdentity,
|
|
22
|
+
withTempDirectory,
|
|
23
|
+
} from './helpers/test-utils.mjs';
|
|
24
|
+
|
|
25
|
+
function expectMessagingError(fn, code, label) {
|
|
26
|
+
assert.throws(fn, error => {
|
|
27
|
+
assert.ok(error instanceof MessagingError, `${label}: expected MessagingError`);
|
|
28
|
+
assert.equal(error.code, code, `${label}: error code`);
|
|
29
|
+
return true;
|
|
30
|
+
});
|
|
31
|
+
console.log(`PASS ${label}`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
await withTempDirectory('pi-shepherd-messaging-', async root => {
|
|
35
|
+
const parentIdentity = createFakeParentIdentity();
|
|
36
|
+
const broker = createParentBroker(parentIdentity.sessionId, {
|
|
37
|
+
rootDir: path.join(root, 'broker'),
|
|
38
|
+
});
|
|
39
|
+
assert.equal(fs.statSync(broker.rootDir).mode & 0o777, 0o700);
|
|
40
|
+
assert.equal(fs.existsSync(broker.parentInboxPath), true);
|
|
41
|
+
assert.equal(fs.existsSync(path.join(broker.rootDir, 'broker.json')), true);
|
|
42
|
+
console.log('PASS broker creates protected session mailbox structure');
|
|
43
|
+
|
|
44
|
+
const scoutIdentity = createFakeChildIdentity({ agentId: 'shepherd-agent-scout' });
|
|
45
|
+
const plannerIdentity = createFakeChildIdentity({ agentId: 'shepherd-agent-planner' });
|
|
46
|
+
const scoutCapability = registerChild(broker, scoutIdentity.agentId);
|
|
47
|
+
const plannerCapability = registerChild(broker, plannerIdentity.agentId);
|
|
48
|
+
const scout = createChildBroker({ rootDir: broker.rootDir, ...scoutCapability });
|
|
49
|
+
const planner = createChildBroker({ rootDir: broker.rootDir, ...plannerCapability });
|
|
50
|
+
assert.equal(scout.agentId, scoutIdentity.agentId);
|
|
51
|
+
assert.equal(planner.agentId, plannerIdentity.agentId);
|
|
52
|
+
console.log('PASS child capabilities rehydrate registered child connections');
|
|
53
|
+
|
|
54
|
+
const childToParent = createEnvelope(
|
|
55
|
+
{ sessionId: scout.sessionId, brokerId: scout.brokerId, senderId: scout.agentId },
|
|
56
|
+
{
|
|
57
|
+
kind: 'message',
|
|
58
|
+
targetId: 'shepherd',
|
|
59
|
+
delivery: 'followUp',
|
|
60
|
+
content: 'Scout needs planner input.',
|
|
61
|
+
expectsReply: true,
|
|
62
|
+
taskId: 'shepherd-task-example',
|
|
63
|
+
threadId: 'thread-example',
|
|
64
|
+
}
|
|
65
|
+
);
|
|
66
|
+
const acceptedToParent = publishFromChild(scout, childToParent);
|
|
67
|
+
assert.equal(acceptedToParent.accepted, true);
|
|
68
|
+
assert.equal(acceptedToParent.delivery, 'queued');
|
|
69
|
+
const parentMessages = pollParentInbox(broker);
|
|
70
|
+
assert.deepEqual(parentMessages, [childToParent]);
|
|
71
|
+
assert.deepEqual(pollParentInbox(broker), []);
|
|
72
|
+
console.log('PASS child-to-parent envelopes are queued and consumed once');
|
|
73
|
+
|
|
74
|
+
const parentToChild = createEnvelope(
|
|
75
|
+
{ sessionId: broker.sessionId, brokerId: broker.brokerId, senderId: broker.parentId },
|
|
76
|
+
{
|
|
77
|
+
kind: 'task',
|
|
78
|
+
targetId: planner.agentId,
|
|
79
|
+
taskId: 'shepherd-task-planner',
|
|
80
|
+
deadlineAt: 123_456,
|
|
81
|
+
delivery: 'followUp',
|
|
82
|
+
content: 'Investigate the planner side of the question.',
|
|
83
|
+
}
|
|
84
|
+
);
|
|
85
|
+
assert.equal(parentToChild.deadlineAt, 123_456);
|
|
86
|
+
assert.equal(publishFromParent(broker, parentToChild).delivery, 'queued');
|
|
87
|
+
assert.deepEqual(pollChildInbox(planner), [parentToChild]);
|
|
88
|
+
assert.deepEqual(pollChildInbox(planner), []);
|
|
89
|
+
console.log('PASS parent-to-child envelopes are routed to the target inbox');
|
|
90
|
+
|
|
91
|
+
const peerMessage = createEnvelope(
|
|
92
|
+
{ sessionId: scout.sessionId, brokerId: scout.brokerId, senderId: scout.agentId },
|
|
93
|
+
{
|
|
94
|
+
kind: 'reply',
|
|
95
|
+
targetId: planner.agentId,
|
|
96
|
+
replyTo: childToParent.messageId,
|
|
97
|
+
threadId: childToParent.threadId,
|
|
98
|
+
delivery: 'followUp',
|
|
99
|
+
content: 'Please check the session middleware.',
|
|
100
|
+
}
|
|
101
|
+
);
|
|
102
|
+
assert.equal(publishFromChild(scout, peerMessage).delivery, 'queued');
|
|
103
|
+
assert.deepEqual(pollChildInbox(planner), [peerMessage]);
|
|
104
|
+
console.log('PASS child-to-child messages route through the parent broker');
|
|
105
|
+
|
|
106
|
+
// The acknowledgement marker makes a repeated envelope safe even after the
|
|
107
|
+
// original file has been moved out of the inbox.
|
|
108
|
+
const duplicate = publishFromChild(scout, childToParent);
|
|
109
|
+
assert.equal(duplicate.delivery, 'duplicate');
|
|
110
|
+
assert.deepEqual(pollParentInbox(broker), []);
|
|
111
|
+
console.log('PASS duplicate envelopes are acknowledged idempotently');
|
|
112
|
+
|
|
113
|
+
const foreignSender = {
|
|
114
|
+
...childToParent,
|
|
115
|
+
senderId: planner.agentId,
|
|
116
|
+
messageId: 'foreign-sender',
|
|
117
|
+
};
|
|
118
|
+
expectMessagingError(
|
|
119
|
+
() => publishFromChild(scout, foreignSender),
|
|
120
|
+
'invalid_sender',
|
|
121
|
+
'child cannot publish as another child'
|
|
122
|
+
);
|
|
123
|
+
expectMessagingError(
|
|
124
|
+
() =>
|
|
125
|
+
publishFromParent(broker, {
|
|
126
|
+
...parentToChild,
|
|
127
|
+
senderId: planner.agentId,
|
|
128
|
+
messageId: 'foreign-parent',
|
|
129
|
+
}),
|
|
130
|
+
'invalid_sender',
|
|
131
|
+
'parent broker rejects non-parent sender'
|
|
132
|
+
);
|
|
133
|
+
assert.throws(
|
|
134
|
+
() =>
|
|
135
|
+
publishFromChild(scout, {
|
|
136
|
+
...childToParent,
|
|
137
|
+
targetId: 'planner',
|
|
138
|
+
messageId: 'display-name-target',
|
|
139
|
+
}),
|
|
140
|
+
error => {
|
|
141
|
+
assert.ok(error instanceof MessagingError);
|
|
142
|
+
assert.equal(error.code, 'invalid_target');
|
|
143
|
+
assert.match(error.message, /exact opaque agent id returned by shepherd_spawn/);
|
|
144
|
+
assert.match(error.message, /agent name such as "planner"/);
|
|
145
|
+
return true;
|
|
146
|
+
},
|
|
147
|
+
'agent definition names are rejected with actionable target guidance'
|
|
148
|
+
);
|
|
149
|
+
expectMessagingError(
|
|
150
|
+
() =>
|
|
151
|
+
publishFromChild(scout, {
|
|
152
|
+
...childToParent,
|
|
153
|
+
targetId: 'unknown-agent',
|
|
154
|
+
messageId: 'unknown-target',
|
|
155
|
+
}),
|
|
156
|
+
'invalid_target',
|
|
157
|
+
'unknown child target is rejected'
|
|
158
|
+
);
|
|
159
|
+
expectMessagingError(
|
|
160
|
+
() =>
|
|
161
|
+
publishFromParent(broker, {
|
|
162
|
+
...parentToChild,
|
|
163
|
+
targetId: 'shepherd',
|
|
164
|
+
messageId: 'parent-target',
|
|
165
|
+
}),
|
|
166
|
+
'invalid_target',
|
|
167
|
+
'parent cannot publish into its own inbox'
|
|
168
|
+
);
|
|
169
|
+
expectMessagingError(
|
|
170
|
+
() =>
|
|
171
|
+
publishFromChild(scout, {
|
|
172
|
+
...childToParent,
|
|
173
|
+
sessionId: 'foreign-session',
|
|
174
|
+
messageId: 'foreign-session-message',
|
|
175
|
+
}),
|
|
176
|
+
'foreign_session',
|
|
177
|
+
'foreign session envelope is rejected'
|
|
178
|
+
);
|
|
179
|
+
expectMessagingError(
|
|
180
|
+
() => createChildBroker({ ...scoutCapability, rootDir: broker.rootDir, token: 'wrong-token' }),
|
|
181
|
+
'invalid_capability',
|
|
182
|
+
'invalid child capability is rejected'
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
// A partial write uses the temporary suffix and must not be visible to the
|
|
186
|
+
// poller as a deliverable envelope.
|
|
187
|
+
const partialPath = path.join(broker.parentInboxPath, '.partial.json.tmp');
|
|
188
|
+
fs.writeFileSync(partialPath, '{"schemaVersion":1');
|
|
189
|
+
assert.deepEqual(pollParentInbox(broker), []);
|
|
190
|
+
assert.equal(fs.existsSync(partialPath), true);
|
|
191
|
+
fs.rmSync(partialPath);
|
|
192
|
+
console.log('PASS partial temporary writes are ignored by polling');
|
|
193
|
+
|
|
194
|
+
const malformedPath = path.join(broker.parentInboxPath, 'malformed.json');
|
|
195
|
+
fs.writeFileSync(malformedPath, '{not-json');
|
|
196
|
+
assert.deepEqual(pollParentInbox(broker), []);
|
|
197
|
+
assert.equal(fs.existsSync(malformedPath), false);
|
|
198
|
+
assert.ok(fs.readdirSync(path.join(broker.rootDir, 'rejected')).length > 0);
|
|
199
|
+
console.log('PASS malformed envelopes are quarantined without crashing the poller');
|
|
200
|
+
|
|
201
|
+
const boundedBroker = createParentBroker('bounded-session', {
|
|
202
|
+
rootDir: path.join(root, 'bounded'),
|
|
203
|
+
maxQueueDepth: 1,
|
|
204
|
+
});
|
|
205
|
+
const boundedChildCap = registerChild(boundedBroker, 'bounded-child');
|
|
206
|
+
const boundedChild = createChildBroker({ rootDir: boundedBroker.rootDir, ...boundedChildCap });
|
|
207
|
+
const boundedEnvelope = createEnvelope(
|
|
208
|
+
{
|
|
209
|
+
sessionId: boundedChild.sessionId,
|
|
210
|
+
brokerId: boundedChild.brokerId,
|
|
211
|
+
senderId: boundedChild.agentId,
|
|
212
|
+
},
|
|
213
|
+
{ kind: 'message', targetId: 'shepherd', delivery: 'followUp', content: 'one' }
|
|
214
|
+
);
|
|
215
|
+
publishFromChild(boundedChild, boundedEnvelope);
|
|
216
|
+
expectMessagingError(
|
|
217
|
+
() =>
|
|
218
|
+
publishFromChild(
|
|
219
|
+
boundedChild,
|
|
220
|
+
createEnvelope(
|
|
221
|
+
{
|
|
222
|
+
sessionId: boundedChild.sessionId,
|
|
223
|
+
brokerId: boundedChild.brokerId,
|
|
224
|
+
senderId: boundedChild.agentId,
|
|
225
|
+
},
|
|
226
|
+
{ kind: 'message', targetId: 'shepherd', delivery: 'followUp', content: 'two' }
|
|
227
|
+
)
|
|
228
|
+
),
|
|
229
|
+
'queue_full',
|
|
230
|
+
'queue depth limit rejects excess messages'
|
|
231
|
+
);
|
|
232
|
+
const largeBroker = createParentBroker('size-session', {
|
|
233
|
+
rootDir: path.join(root, 'size'),
|
|
234
|
+
maxMessageBytes: 100,
|
|
235
|
+
});
|
|
236
|
+
const largeCap = registerChild(largeBroker, 'size-child');
|
|
237
|
+
const largeChild = createChildBroker({ rootDir: largeBroker.rootDir, ...largeCap });
|
|
238
|
+
expectMessagingError(
|
|
239
|
+
() =>
|
|
240
|
+
publishFromChild(
|
|
241
|
+
largeChild,
|
|
242
|
+
createEnvelope(
|
|
243
|
+
{
|
|
244
|
+
sessionId: largeChild.sessionId,
|
|
245
|
+
brokerId: largeChild.brokerId,
|
|
246
|
+
senderId: largeChild.agentId,
|
|
247
|
+
},
|
|
248
|
+
{ kind: 'message', targetId: 'shepherd', delivery: 'followUp', content: 'x'.repeat(500) }
|
|
249
|
+
)
|
|
250
|
+
),
|
|
251
|
+
'message_too_large',
|
|
252
|
+
'message size limit rejects oversized messages'
|
|
253
|
+
);
|
|
254
|
+
const contentBroker = createParentBroker('content-session', {
|
|
255
|
+
rootDir: path.join(root, 'content'),
|
|
256
|
+
maxMessageBytes: 10_000,
|
|
257
|
+
maxContentLength: 10,
|
|
258
|
+
});
|
|
259
|
+
const contentCap = registerChild(contentBroker, 'content-child');
|
|
260
|
+
const contentChild = createChildBroker({ rootDir: contentBroker.rootDir, ...contentCap });
|
|
261
|
+
expectMessagingError(
|
|
262
|
+
() =>
|
|
263
|
+
publishFromChild(
|
|
264
|
+
contentChild,
|
|
265
|
+
createEnvelope(
|
|
266
|
+
{
|
|
267
|
+
sessionId: contentChild.sessionId,
|
|
268
|
+
brokerId: contentChild.brokerId,
|
|
269
|
+
senderId: contentChild.agentId,
|
|
270
|
+
},
|
|
271
|
+
{ kind: 'message', targetId: 'shepherd', delivery: 'followUp', content: 'x'.repeat(11) }
|
|
272
|
+
)
|
|
273
|
+
),
|
|
274
|
+
'message_too_large',
|
|
275
|
+
'content length limit rejects oversized content'
|
|
276
|
+
);
|
|
277
|
+
|
|
278
|
+
assert.equal(
|
|
279
|
+
closeBrokerWhenChildrenGone(broker, () => false),
|
|
280
|
+
false
|
|
281
|
+
);
|
|
282
|
+
assert.equal(fs.existsSync(broker.rootDir), true);
|
|
283
|
+
unregisterChild(broker, scout.agentId);
|
|
284
|
+
unregisterChild(broker, planner.agentId);
|
|
285
|
+
assert.equal(closeBrokerWhenChildrenGone(broker), true);
|
|
286
|
+
assert.equal(fs.existsSync(broker.rootDir), false);
|
|
287
|
+
console.log('PASS broker cleanup waits for confirmed child disappearance');
|
|
288
|
+
|
|
289
|
+
assert.equal(
|
|
290
|
+
closeBrokerWhenChildrenGone(boundedBroker, () => true),
|
|
291
|
+
true
|
|
292
|
+
);
|
|
293
|
+
assert.equal(
|
|
294
|
+
closeBrokerWhenChildrenGone(largeBroker, () => true),
|
|
295
|
+
true
|
|
296
|
+
);
|
|
297
|
+
assert.equal(
|
|
298
|
+
closeBrokerWhenChildrenGone(contentBroker, () => true),
|
|
299
|
+
true
|
|
300
|
+
);
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
console.log('All messaging assertions passed.');
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/** T018 — one-time farewell notice, human sessions only, per host marker. */
|
|
3
|
+
import assert from 'node:assert/strict';
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import os from 'node:os';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
|
|
8
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'pi-shepherd-migration-'));
|
|
9
|
+
const piAgentDir = path.join(tmp, 'pi-agent');
|
|
10
|
+
const ocAgentDir = path.join(tmp, 'opencode');
|
|
11
|
+
fs.mkdirSync(piAgentDir, { recursive: true });
|
|
12
|
+
fs.mkdirSync(ocAgentDir, { recursive: true });
|
|
13
|
+
|
|
14
|
+
const { setHostCapabilities } = await import('../src/core/host.ts');
|
|
15
|
+
const { migrationNoticeOnce, migrationMarkerFile, MIGRATION_NOTICE, NEW_PACKAGE_NAME } = await import(
|
|
16
|
+
'../src/core/migration.ts'
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
const installHost = agentDir =>
|
|
20
|
+
setHostCapabilities({
|
|
21
|
+
getAgentDir: () => agentDir,
|
|
22
|
+
projectConfigDirName: '.pi',
|
|
23
|
+
dataDirName: 'pi-shepherd',
|
|
24
|
+
parseFrontmatter: () => ({ frontmatter: {}, body: '' }),
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
delete process.env.PI_SHEPHERD_SESSION;
|
|
28
|
+
delete process.env.SHEPHERD_TASK_ID;
|
|
29
|
+
installHost(piAgentDir);
|
|
30
|
+
const marker = migrationMarkerFile();
|
|
31
|
+
assert.equal(marker, path.join(piAgentDir, 'pi-shepherd', 'migration-notice.json'));
|
|
32
|
+
assert.equal(migrationNoticeOnce(), MIGRATION_NOTICE);
|
|
33
|
+
assert.match(MIGRATION_NOTICE, /@luminascale\/shepherd/);
|
|
34
|
+
assert.equal(fs.existsSync(marker), true, 'marker is written under the Pi agent dir');
|
|
35
|
+
assert.equal(migrationNoticeOnce(), undefined, 'never shown twice in the same host');
|
|
36
|
+
console.log('PASS Pi host shows the notice once and records a marker');
|
|
37
|
+
|
|
38
|
+
// Child sheep processes load the same package but must not see the notice.
|
|
39
|
+
fs.rmSync(marker);
|
|
40
|
+
process.env.PI_SHEPHERD_SESSION = '/tmp/child.jsonl';
|
|
41
|
+
assert.equal(migrationNoticeOnce(), undefined, 'Pi-launched child is skipped');
|
|
42
|
+
assert.equal(fs.existsSync(marker), false, 'a skipped child writes no marker');
|
|
43
|
+
delete process.env.PI_SHEPHERD_SESSION;
|
|
44
|
+
process.env.SHEPHERD_TASK_ID = 'shepherd-task-child';
|
|
45
|
+
assert.equal(migrationNoticeOnce(), undefined, 'OpenCode-launched child is skipped');
|
|
46
|
+
assert.equal(fs.existsSync(marker), false);
|
|
47
|
+
delete process.env.SHEPHERD_TASK_ID;
|
|
48
|
+
console.log('PASS child sheep processes never see or consume the notice');
|
|
49
|
+
|
|
50
|
+
// A different host user has its own marker, so it gets its own one-time show.
|
|
51
|
+
installHost(ocAgentDir);
|
|
52
|
+
assert.equal(migrationNoticeOnce(), MIGRATION_NOTICE);
|
|
53
|
+
assert.equal(fs.existsSync(path.join(ocAgentDir, 'pi-shepherd', 'migration-notice.json')), true);
|
|
54
|
+
assert.equal(migrationNoticeOnce(), undefined);
|
|
55
|
+
console.log('PASS marker is per host user, not global');
|
|
56
|
+
|
|
57
|
+
const readme = fs.readFileSync(new URL('../README.md', import.meta.url), 'utf8');
|
|
58
|
+
assert.match(readme, /Farewell to `@luminascale\/pi-shepherd`/);
|
|
59
|
+
assert.ok(readme.includes(NEW_PACKAGE_NAME), 'README banner names the new package');
|
|
60
|
+
const indexSource = fs.readFileSync(new URL('../index.ts', import.meta.url), 'utf8');
|
|
61
|
+
assert.match(indexSource, /migrationNoticeOnce\(\)/);
|
|
62
|
+
const serverSource = fs.readFileSync(new URL('../src/opencode/server.ts', import.meta.url), 'utf8');
|
|
63
|
+
assert.match(serverSource, /migrationNoticeOnce\(\)/);
|
|
64
|
+
assert.match(serverSource, /!isSheepSession\(sessionID\)/, 'OpenCode notice is human-only');
|
|
65
|
+
const releasing = fs.readFileSync(new URL('../docs/releasing.md', import.meta.url), 'utf8');
|
|
66
|
+
assert.match(releasing, /npm deprecate @luminascale\/pi-shepherd/);
|
|
67
|
+
console.log('PASS both hosts, README banner, and release ordering are wired');
|
|
68
|
+
|
|
69
|
+
console.log('\nAll migration-notice assertions passed.');
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const { LifecycleRegistry } = await import('../src/core/orchestration.ts');
|
|
3
|
+
let failures = 0;
|
|
4
|
+
function assert(ok, label) {
|
|
5
|
+
if (ok) console.log(`PASS ${label}`);
|
|
6
|
+
else {
|
|
7
|
+
failures++;
|
|
8
|
+
console.log(`FAIL ${label}`);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
const registry = new LifecycleRegistry();
|
|
12
|
+
const a = registry.registerAgent({ agent: 'a' });
|
|
13
|
+
const b = registry.registerAgent({ agent: 'b' });
|
|
14
|
+
const slow = registry.createPrompt(a);
|
|
15
|
+
const fast = registry.createPrompt(b);
|
|
16
|
+
setTimeout(
|
|
17
|
+
() =>
|
|
18
|
+
registry.settlePrompt(slow, {
|
|
19
|
+
promptId: slow.id,
|
|
20
|
+
agentId: slow.agentId,
|
|
21
|
+
status: 'done',
|
|
22
|
+
ok: true,
|
|
23
|
+
text: 'slow',
|
|
24
|
+
}),
|
|
25
|
+
40
|
|
26
|
+
);
|
|
27
|
+
registry.settlePrompt(fast, {
|
|
28
|
+
promptId: fast.id,
|
|
29
|
+
agentId: fast.agentId,
|
|
30
|
+
status: 'done',
|
|
31
|
+
ok: true,
|
|
32
|
+
text: 'fast',
|
|
33
|
+
});
|
|
34
|
+
const started = Date.now();
|
|
35
|
+
const results = await Promise.all([registry.wait(slow), registry.wait(fast)]);
|
|
36
|
+
assert(
|
|
37
|
+
results[0].text === 'slow' && results[1].text === 'fast',
|
|
38
|
+
'multi-wait preserves input order'
|
|
39
|
+
);
|
|
40
|
+
assert(Date.now() - started >= 35, 'multi-wait waits concurrently for slow result');
|
|
41
|
+
if (failures) process.exit(1);
|
|
42
|
+
console.log('All multi-wait assertions passed.');
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Focused verification: the OpenCode human `/shepherd` command displays its
|
|
4
|
+
* result in full without starting an assistant turn (spec 013, T011 finding).
|
|
5
|
+
*/
|
|
6
|
+
import assert from 'node:assert/strict';
|
|
7
|
+
import fs from 'node:fs';
|
|
8
|
+
|
|
9
|
+
const { displayCommandOutput, supportsDisplayOnly } = await import('../src/opencode/display.ts');
|
|
10
|
+
|
|
11
|
+
const calls = [];
|
|
12
|
+
const ctx = {
|
|
13
|
+
session: {
|
|
14
|
+
prompt: async input => { calls.push(['prompt', input]); },
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const text = '[shepherd agents]\nreviewer (user)\nworker (user)\nplanner (project)\nscout (project)';
|
|
19
|
+
await displayCommandOutput(ctx, 'sess-1', text);
|
|
20
|
+
assert.equal(calls.length, 1, 'exactly one delivery');
|
|
21
|
+
assert.equal(calls[0][0], 'prompt', 'uses a normal session prompt so the full multi-line text renders');
|
|
22
|
+
assert.deepEqual(
|
|
23
|
+
calls[0][1],
|
|
24
|
+
{ sessionID: 'sess-1', text, resume: false },
|
|
25
|
+
'resume:false suppresses the model wake (no assistant turn)'
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
assert.equal(supportsDisplayOnly(ctx), true, 'detects the session primitive');
|
|
29
|
+
const legacy = { session: { synthetic() {} } };
|
|
30
|
+
assert.equal(supportsDisplayOnly(legacy), false, 'detects a host without the primitive');
|
|
31
|
+
await assert.rejects(
|
|
32
|
+
() => displayCommandOutput(legacy, 'sess-1', 'x'),
|
|
33
|
+
/session\.prompt is unavailable/,
|
|
34
|
+
'fails loudly rather than starting a turn'
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
// Source guard: the command handler must not call ctx.session.prompt directly
|
|
38
|
+
// (only via the helper). Parent-session notices elsewhere may.
|
|
39
|
+
const source = fs.readFileSync(new URL('../src/opencode/server.ts', import.meta.url), 'utf8');
|
|
40
|
+
const commandStart = source.indexOf('await ctx.command.transform');
|
|
41
|
+
assert.ok(commandStart >= 0, 'command transform is registered');
|
|
42
|
+
const commandBlock = source.slice(commandStart);
|
|
43
|
+
const directPrompts = commandBlock.match(/ctx\.session\.prompt/g) ?? [];
|
|
44
|
+
assert.equal(directPrompts.length, 0, 'command block contains no direct session.prompt call');
|
|
45
|
+
assert.ok(commandBlock.includes('showCommandOutput'), 'command block uses the display-only helper');
|
|
46
|
+
|
|
47
|
+
console.log('opencode command display: ok');
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* T012 — OpenCode parent artifact-session resolution onto the shared layout.
|
|
4
|
+
*
|
|
5
|
+
* Proves the OpenCode adapter resolves/creates the same durable
|
|
6
|
+
* `.shepherd/sessions` collection Pi uses, that the OpenCode session id is
|
|
7
|
+
* the opaque parent identity, that fieldnotes-disabled stays off, and that
|
|
8
|
+
* spawn/delegate thread the resolved session into both runtimes.
|
|
9
|
+
*/
|
|
10
|
+
import assert from 'node:assert/strict';
|
|
11
|
+
import fs from 'node:fs';
|
|
12
|
+
import os from 'node:os';
|
|
13
|
+
import path from 'node:path';
|
|
14
|
+
|
|
15
|
+
const home = fs.mkdtempSync(path.join(os.tmpdir(), 'pi-shepherd-oc-fieldnotes-'));
|
|
16
|
+
process.env.HOME = home;
|
|
17
|
+
process.env.OPENCODE_CONFIG_DIR = path.join(home, 'config', 'opencode');
|
|
18
|
+
fs.mkdirSync(process.env.OPENCODE_CONFIG_DIR, { recursive: true });
|
|
19
|
+
const projectRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'pi-shepherd-oc-project-'));
|
|
20
|
+
|
|
21
|
+
const { installOpencodeHost } = await import('../src/opencode/host.ts');
|
|
22
|
+
installOpencodeHost();
|
|
23
|
+
const {
|
|
24
|
+
parentArtifactSession,
|
|
25
|
+
resetOpencodeFieldnotesCache,
|
|
26
|
+
} = await import('../src/opencode/fieldnotes.ts');
|
|
27
|
+
const {
|
|
28
|
+
finalizeArtifact,
|
|
29
|
+
markArtifactStarted,
|
|
30
|
+
readSessionMetadata,
|
|
31
|
+
resolveOrCreateParentArtifactSession,
|
|
32
|
+
reserveArtifacts,
|
|
33
|
+
} = await import('../src/core/artifact-sessions.ts');
|
|
34
|
+
|
|
35
|
+
const ctx = (sessionId, cwd = projectRoot) => ({ sessionId, cwd });
|
|
36
|
+
|
|
37
|
+
// 1. Resolution creates the shared layout with the OpenCode session id bound.
|
|
38
|
+
const first = parentArtifactSession(ctx('ses-opencode-alpha'));
|
|
39
|
+
assert.ok(first, 'fieldnotes enabled by default resolve a session');
|
|
40
|
+
assert.equal(first.artifactSessionVersion, 2);
|
|
41
|
+
assert.equal(first.parentPiSession.identity, 'ses-opencode-alpha');
|
|
42
|
+
assert.equal(first.projectRoot, projectRoot);
|
|
43
|
+
assert.match(first.sessionPath, /\.shepherd[\\/]sessions[\\/]\d{4}-/);
|
|
44
|
+
assert.equal(first.sessionRelativePath, path.relative(projectRoot, first.sessionPath));
|
|
45
|
+
assert.equal(fs.existsSync(first.mocPath), true, 'MOC is created');
|
|
46
|
+
assert.equal(fs.existsSync(first.sessionMetadataPath), true, 'session.json is created');
|
|
47
|
+
console.log('PASS OpenCode resolution creates the shared .shepherd/sessions layout');
|
|
48
|
+
|
|
49
|
+
// 2. One binding reuses one session; a different session or root gets its own.
|
|
50
|
+
const reused = parentArtifactSession(ctx('ses-opencode-alpha'));
|
|
51
|
+
assert.equal(reused.sessionPath, first.sessionPath, 'same binding reuses the session');
|
|
52
|
+
assert.equal(reused.resumed, true, 'a second call resumes rather than allocates');
|
|
53
|
+
const otherSession = parentArtifactSession(ctx('ses-opencode-beta'));
|
|
54
|
+
assert.notEqual(otherSession.sessionPath, first.sessionPath, 'a different parent identity separates');
|
|
55
|
+
const otherRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'pi-shepherd-oc-root-'));
|
|
56
|
+
const otherRootSession = parentArtifactSession(ctx('ses-opencode-alpha', otherRoot));
|
|
57
|
+
assert.notEqual(otherRootSession.sessionPath, first.sessionPath, 'a different root separates');
|
|
58
|
+
console.log('PASS same (session id, root) reuses; either difference allocates a new session');
|
|
59
|
+
|
|
60
|
+
// 3. Cross-host readability at the layout level: the Pi resolver finds the
|
|
61
|
+
// OpenCode-created session and notes written by either side are shared.
|
|
62
|
+
const piView = resolveOrCreateParentArtifactSession({
|
|
63
|
+
parentPiSessionId: 'ses-opencode-alpha',
|
|
64
|
+
projectRoot,
|
|
65
|
+
});
|
|
66
|
+
assert.equal(piView.sessionPath, first.sessionPath, 'Pi resolver finds the OpenCode session');
|
|
67
|
+
const artifact = reserveArtifacts(first, [
|
|
68
|
+
{ agent: 'scout', mode: 'single', task: 'leave a note for the next host' },
|
|
69
|
+
])[0];
|
|
70
|
+
markArtifactStarted(first, artifact);
|
|
71
|
+
finalizeArtifact(first, artifact, { status: 'completed', output: 'note from OpenCode' });
|
|
72
|
+
const stored = JSON.parse(fs.readFileSync(first.sessionMetadataPath, 'utf8'));
|
|
73
|
+
const storedArtifact = stored.artifacts.find(a => a.id === artifact.id);
|
|
74
|
+
assert.equal(storedArtifact?.status, 'completed');
|
|
75
|
+
assert.equal(storedArtifact?.task, 'leave a note for the next host');
|
|
76
|
+
assert.match(fs.readFileSync(piView.mocPath, 'utf8'), /\.\/scout-01\.md/);
|
|
77
|
+
assert.match(fs.readFileSync(artifact.filePath, 'utf8'), /note from OpenCode/);
|
|
78
|
+
const piCreated = resolveOrCreateParentArtifactSession({
|
|
79
|
+
parentPiSessionId: 'ses-shared-pi',
|
|
80
|
+
projectRoot,
|
|
81
|
+
});
|
|
82
|
+
const ocFound = parentArtifactSession(ctx('ses-shared-pi'));
|
|
83
|
+
assert.equal(ocFound.sessionPath, piCreated.sessionPath, 'OpenCode finds a Pi-created session');
|
|
84
|
+
console.log('PASS Pi and OpenCode resolve the same session and share notes');
|
|
85
|
+
|
|
86
|
+
// 4. Disabled fieldnotes stay off, including a mid-session flip (snapshot).
|
|
87
|
+
const disabledRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'pi-shepherd-oc-disabled-'));
|
|
88
|
+
const configFile = path.join(disabledRoot, '.shepherd', 'config.json');
|
|
89
|
+
fs.mkdirSync(path.dirname(configFile), { recursive: true });
|
|
90
|
+
const writeConfig = fieldnotes =>
|
|
91
|
+
fs.writeFileSync(configFile, JSON.stringify({ projectScope: true, fieldnotes }));
|
|
92
|
+
writeConfig(false);
|
|
93
|
+
resetOpencodeFieldnotesCache();
|
|
94
|
+
assert.equal(parentArtifactSession(ctx('ses-no-notes', disabledRoot)), undefined);
|
|
95
|
+
assert.equal(fs.existsSync(path.join(disabledRoot, '.shepherd', 'sessions')), false);
|
|
96
|
+
writeConfig(true);
|
|
97
|
+
assert.equal(
|
|
98
|
+
parentArtifactSession(ctx('ses-no-notes', disabledRoot)),
|
|
99
|
+
undefined,
|
|
100
|
+
'a mid-session config flip does not change an existing session'
|
|
101
|
+
);
|
|
102
|
+
assert.ok(
|
|
103
|
+
parentArtifactSession(ctx('ses-with-notes', disabledRoot)),
|
|
104
|
+
'a new session observes the updated setting'
|
|
105
|
+
);
|
|
106
|
+
console.log('PASS disabled fieldnotes stay off, and the setting is session-scoped');
|
|
107
|
+
|
|
108
|
+
// 5. Wiring: spawn resolves and threads the session into both runtimes;
|
|
109
|
+
// delegate re-resolves so it always reserves a note.
|
|
110
|
+
const actionsSource = fs.readFileSync(new URL('../src/opencode/actions.ts', import.meta.url), 'utf8');
|
|
111
|
+
assert.match(actionsSource, /const artifactSession = parentArtifactSession\(ctx\)/);
|
|
112
|
+
assert.equal(
|
|
113
|
+
(actionsSource.match(/artifactSession,\n\s+launch: \{\s*\.\.\.OPENCODE_LAUNCH_OVERRIDES\s*\}/g) ?? [])
|
|
114
|
+
.length,
|
|
115
|
+
2
|
|
116
|
+
);
|
|
117
|
+
assert.match(actionsSource, /runtimeFor\(ctx, backend, parentArtifactSession\(ctx\)\)/);
|
|
118
|
+
assert.match(actionsSource, /fieldnote: \$\{artifactSession\.sessionRelativePath\}/);
|
|
119
|
+
console.log('PASS spawn/delegate thread the resolved artifact session into both runtimes');
|
|
120
|
+
|
|
121
|
+
console.log('\nAll OpenCode fieldnote assertions passed.');
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Focused verification: completion notices reach only human parent sessions,
|
|
4
|
+
* and a transient parent-busy failure is retried instead of dropped
|
|
5
|
+
* (spec 013, T011 watcher-notice finding).
|
|
6
|
+
*/
|
|
7
|
+
import assert from 'node:assert/strict';
|
|
8
|
+
import fs from 'node:fs';
|
|
9
|
+
import {
|
|
10
|
+
bindChildSession,
|
|
11
|
+
forgetTaskParent,
|
|
12
|
+
isParentSession,
|
|
13
|
+
isSheepSession,
|
|
14
|
+
markParentSession,
|
|
15
|
+
noteTaskParent,
|
|
16
|
+
recordSheepSpawn,
|
|
17
|
+
} from '../src/opencode/bridge.ts';
|
|
18
|
+
|
|
19
|
+
// A sheep session must never be registered as a completion-notice recipient,
|
|
20
|
+
// even if the caller learned the task id (relayed question, peer reply, ...).
|
|
21
|
+
recordSheepSpawn({
|
|
22
|
+
agentId: 'sheep-agent-test',
|
|
23
|
+
backend: 'pane',
|
|
24
|
+
cwd: '/tmp',
|
|
25
|
+
parentSessionId: 'parent-session',
|
|
26
|
+
childCapability: 'oc',
|
|
27
|
+
brokerRootDir: '/tmp',
|
|
28
|
+
brokerSessionId: 'broker',
|
|
29
|
+
brokerId: 'broker',
|
|
30
|
+
parentBrokerId: 'parent-broker',
|
|
31
|
+
spawnedAt: 0,
|
|
32
|
+
});
|
|
33
|
+
// A pre-binding parent-tool call marks the session as a parent; binding as a
|
|
34
|
+
// sheep must win so the sheep can use shepherd_message for peer replies.
|
|
35
|
+
markParentSession('sheep-session');
|
|
36
|
+
assert.equal(isParentSession('sheep-session'), true, 'an unbound caller can be marked parent');
|
|
37
|
+
bindChildSession('sheep-agent-test', 'sheep-session');
|
|
38
|
+
assert.equal(isSheepSession('sheep-session'), true, 'sheep session is recognised');
|
|
39
|
+
assert.equal(isParentSession('sheep-session'), false, 'sheep binding clears the stale parent mark');
|
|
40
|
+
markParentSession('sheep-session');
|
|
41
|
+
assert.equal(isParentSession('sheep-session'), false, 're-marking a bound sheep is a no-op');
|
|
42
|
+
noteTaskParent('task-1', 'sheep-session');
|
|
43
|
+
|
|
44
|
+
// A human parent session is still registered.
|
|
45
|
+
markParentSession('parent-session');
|
|
46
|
+
assert.equal(isParentSession('parent-session'), true, 'parent session is recognised');
|
|
47
|
+
noteTaskParent('task-1', 'parent-session');
|
|
48
|
+
forgetTaskParent('task-1');
|
|
49
|
+
|
|
50
|
+
// Source guards: both entry points refuse sheep sessions, and promptParent
|
|
51
|
+
// retries rather than swallowing the first failure.
|
|
52
|
+
const source = fs.readFileSync(new URL('../src/opencode/bridge.ts', import.meta.url), 'utf8');
|
|
53
|
+
const guardCount = (source.match(/if \(!parentSessionId \|\| isSheepSession\(parentSessionId\)\) return/g) ?? []).length;
|
|
54
|
+
assert.ok(guardCount >= 1, 'notice delivery refuses sheep sessions');
|
|
55
|
+
assert.ok(
|
|
56
|
+
/if \(!parentSessionId \|\| isSheepSession\(parentSessionId\)\) return;\s*\n\s*parentMapFor/.test(source),
|
|
57
|
+
'noteTaskParent refuses sheep sessions'
|
|
58
|
+
);
|
|
59
|
+
assert.ok(source.includes('PARENT_NOTICE_RETRIES = 3'), 'notice delivery is bounded-retry');
|
|
60
|
+
assert.ok(
|
|
61
|
+
/for \(let attempt = 0; attempt < PARENT_NOTICE_RETRIES; attempt\+\+\)/.test(source),
|
|
62
|
+
'promptParent retries on failure'
|
|
63
|
+
);
|
|
64
|
+
assert.ok(!/await ctx\.session\.prompt\(\{ sessionID: parentSessionId, text: content \}\);\s*\}\s*catch \{\s*\}\s*\}/.test(source),
|
|
65
|
+
'the old silent-drop catch is gone');
|
|
66
|
+
|
|
67
|
+
const roleSource = fs.readFileSync(new URL('../src/opencode/bridge.ts', import.meta.url), 'utf8');
|
|
68
|
+
assert.ok(
|
|
69
|
+
/return parentSessions\.has\(sessionId\) && !isSheepSession\(sessionId\)/.test(roleSource),
|
|
70
|
+
'isParentSession excludes sheep sessions'
|
|
71
|
+
);
|
|
72
|
+
assert.ok(
|
|
73
|
+
/parentSessions\.delete\(childSessionId\)/.test(roleSource),
|
|
74
|
+
'bindChildSession clears stale parent marks'
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
console.log('opencode notice routing: ok');
|