@deftai/directive 0.119.13 → 0.121.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.
@@ -0,0 +1,240 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Fail-closed query-before-cancel gate (#5278 Prefer-A).
4
+ * Dest-capable args required for linked-worktree children (#4066).
5
+ */
6
+ import { resolve } from "node:path";
7
+ import { fileURLToPath } from "node:url";
8
+ import { defaultFirstSeenDir, defaultScratchDir, defaultSteerDir, EXIT_PRE_CANCEL_CONFIG, EXIT_PRE_CANCEL_OK, evaluatePreCancel, } from "@deftai/directive-core/orchestration";
9
+ export const SUBAGENT_PRE_CANCEL_HELP = `subagent:pre-cancel — query-before-cancel gate (#5278)
10
+
11
+ Usage:
12
+ task subagent:pre-cancel -- --agent <id> --canceller-id <id> [options]
13
+
14
+ Exit 0 only when one ordered branch clears:
15
+ (a) canceller-authored status steer (kind note|correction) + matching ack
16
+ OR observed first-seen window (default 3 minutes; PA-18 forward skew only)
17
+ (b) heartbeat STALE/missing under startup grace from --dispatch-started-at
18
+ (c) --force --reason <text>
19
+
20
+ Options:
21
+ --agent ID Target child agent_id (required)
22
+ --canceller-id ID Canceller identity; must match steer writer_id for (a)
23
+ --target-id PATH Worktree root (resolves steer/scratch/first-seen under it)
24
+ --steer-dir PATH Steer inbox dir (default: <cwd|target>/.deft-scratch/subagent-steer)
25
+ --scratch-dir PATH Heartbeat dir (default: <cwd|target>/.deft-scratch/subagent-status)
26
+ --first-seen-dir PATH First-seen stamps (default: .../subagent-steer-firstseen)
27
+ --dispatch-started-at ISO DeliveryAttemptRecord.startedAt for grace path (b)
28
+ --expected-worker-id ID Refuse when agent does not match current attempt worker
29
+ --observed-window-seconds N Default 180
30
+ --force Explicit force clear (requires --reason)
31
+ --reason TEXT Printed force reason
32
+ --json Machine-readable verdict
33
+
34
+ Exit codes:
35
+ 0 Pre-cancel green
36
+ 1 Refused (gate red)
37
+ 2 Config / usage error
38
+ `;
39
+ export function parseSubagentPreCancelArgs(argv) {
40
+ const acc = {
41
+ agentId: null,
42
+ cancellerId: null,
43
+ targetId: null,
44
+ steerDir: null,
45
+ scratchDir: null,
46
+ firstSeenDir: null,
47
+ dispatchStartedAt: null,
48
+ expectedWorkerId: null,
49
+ observedWindowSeconds: null,
50
+ force: false,
51
+ forceReason: null,
52
+ emitJson: false,
53
+ help: false,
54
+ };
55
+ for (let i = 0; i < argv.length; i += 1) {
56
+ const arg = argv[i];
57
+ if (arg === "--help" || arg === "-h") {
58
+ return { ...acc, help: true };
59
+ }
60
+ if (arg === "--json") {
61
+ acc.emitJson = true;
62
+ }
63
+ else if (arg === "--force") {
64
+ acc.force = true;
65
+ }
66
+ else if (arg === "--agent" || arg === "--agent-id") {
67
+ const value = argv[i + 1];
68
+ if (value === undefined)
69
+ return { ...acc, error: `argument ${arg}: expected one argument` };
70
+ acc.agentId = value;
71
+ i += 1;
72
+ }
73
+ else if (arg?.startsWith("--agent=") || arg?.startsWith("--agent-id=")) {
74
+ acc.agentId = arg.slice(arg.indexOf("=") + 1);
75
+ }
76
+ else if (arg === "--canceller-id" || arg === "--canceller") {
77
+ const value = argv[i + 1];
78
+ if (value === undefined)
79
+ return { ...acc, error: `argument ${arg}: expected one argument` };
80
+ acc.cancellerId = value;
81
+ i += 1;
82
+ }
83
+ else if (arg?.startsWith("--canceller-id=") || arg?.startsWith("--canceller=")) {
84
+ acc.cancellerId = arg.slice(arg.indexOf("=") + 1);
85
+ }
86
+ else if (arg === "--target-id" || arg === "--target") {
87
+ const value = argv[i + 1];
88
+ if (value === undefined)
89
+ return { ...acc, error: `argument ${arg}: expected one argument` };
90
+ acc.targetId = value;
91
+ i += 1;
92
+ }
93
+ else if (arg?.startsWith("--target-id=") || arg?.startsWith("--target=")) {
94
+ acc.targetId = arg.slice(arg.indexOf("=") + 1);
95
+ }
96
+ else if (arg === "--steer-dir") {
97
+ const value = argv[i + 1];
98
+ if (value === undefined)
99
+ return { ...acc, error: "argument --steer-dir: expected one argument" };
100
+ acc.steerDir = value;
101
+ i += 1;
102
+ }
103
+ else if (arg?.startsWith("--steer-dir=")) {
104
+ acc.steerDir = arg.slice("--steer-dir=".length);
105
+ }
106
+ else if (arg === "--scratch-dir") {
107
+ const value = argv[i + 1];
108
+ if (value === undefined)
109
+ return { ...acc, error: "argument --scratch-dir: expected one argument" };
110
+ acc.scratchDir = value;
111
+ i += 1;
112
+ }
113
+ else if (arg?.startsWith("--scratch-dir=")) {
114
+ acc.scratchDir = arg.slice("--scratch-dir=".length);
115
+ }
116
+ else if (arg === "--first-seen-dir") {
117
+ const value = argv[i + 1];
118
+ if (value === undefined) {
119
+ return { ...acc, error: "argument --first-seen-dir: expected one argument" };
120
+ }
121
+ acc.firstSeenDir = value;
122
+ i += 1;
123
+ }
124
+ else if (arg?.startsWith("--first-seen-dir=")) {
125
+ acc.firstSeenDir = arg.slice("--first-seen-dir=".length);
126
+ }
127
+ else if (arg === "--dispatch-started-at") {
128
+ const value = argv[i + 1];
129
+ if (value === undefined) {
130
+ return { ...acc, error: "argument --dispatch-started-at: expected one argument" };
131
+ }
132
+ acc.dispatchStartedAt = value;
133
+ i += 1;
134
+ }
135
+ else if (arg?.startsWith("--dispatch-started-at=")) {
136
+ acc.dispatchStartedAt = arg.slice("--dispatch-started-at=".length);
137
+ }
138
+ else if (arg === "--expected-worker-id") {
139
+ const value = argv[i + 1];
140
+ if (value === undefined) {
141
+ return { ...acc, error: "argument --expected-worker-id: expected one argument" };
142
+ }
143
+ acc.expectedWorkerId = value;
144
+ i += 1;
145
+ }
146
+ else if (arg?.startsWith("--expected-worker-id=")) {
147
+ acc.expectedWorkerId = arg.slice("--expected-worker-id=".length);
148
+ }
149
+ else if (arg === "--observed-window-seconds") {
150
+ const value = argv[i + 1];
151
+ if (value === undefined) {
152
+ return { ...acc, error: "argument --observed-window-seconds: expected one argument" };
153
+ }
154
+ acc.observedWindowSeconds = Number(value);
155
+ i += 1;
156
+ }
157
+ else if (arg?.startsWith("--observed-window-seconds=")) {
158
+ acc.observedWindowSeconds = Number(arg.slice("--observed-window-seconds=".length));
159
+ }
160
+ else if (arg === "--reason") {
161
+ const value = argv[i + 1];
162
+ if (value === undefined)
163
+ return { ...acc, error: "argument --reason: expected one argument" };
164
+ acc.forceReason = value;
165
+ i += 1;
166
+ }
167
+ else if (arg?.startsWith("--reason=")) {
168
+ acc.forceReason = arg.slice("--reason=".length);
169
+ }
170
+ else if (arg?.startsWith("-")) {
171
+ return { ...acc, error: `unrecognized argument: ${arg}` };
172
+ }
173
+ else {
174
+ return { ...acc, error: `unrecognized argument: ${arg}` };
175
+ }
176
+ }
177
+ return acc;
178
+ }
179
+ export function run(argv, cwd = process.cwd()) {
180
+ const args = parseSubagentPreCancelArgs(argv);
181
+ if (args.help) {
182
+ process.stdout.write(SUBAGENT_PRE_CANCEL_HELP);
183
+ return EXIT_PRE_CANCEL_OK;
184
+ }
185
+ if (args.error !== undefined) {
186
+ process.stderr.write(`subagent:pre-cancel: ${args.error}\n`);
187
+ return EXIT_PRE_CANCEL_CONFIG;
188
+ }
189
+ const root = args.targetId !== null && args.targetId.trim().length > 0 ? resolve(cwd, args.targetId) : cwd;
190
+ const steerDir = resolve(root, args.steerDir ?? defaultSteerDir(root));
191
+ const scratchDir = resolve(root, args.scratchDir ?? defaultScratchDir(root));
192
+ const firstSeenDir = resolve(root, args.firstSeenDir ?? defaultFirstSeenDir(root));
193
+ // Linked-worktree children: refuse default-to-parent-cwd alone without dest args (#4066 / #5278).
194
+ // Partial dest (only --steer-dir or only --scratch-dir) mixes worktrees — require a pair or --target-id.
195
+ const hasTarget = args.targetId !== null && args.targetId.trim().length > 0;
196
+ const hasSteer = args.steerDir !== null;
197
+ const hasScratch = args.scratchDir !== null;
198
+ if (!hasTarget && hasSteer !== hasScratch) {
199
+ process.stderr.write("subagent:pre-cancel: --steer-dir and --scratch-dir must be paired when --target-id is omitted (partial dest mixes worktrees)\n");
200
+ return EXIT_PRE_CANCEL_CONFIG;
201
+ }
202
+ const hasDest = hasTarget || (hasSteer && hasScratch);
203
+ if (!hasDest) {
204
+ process.stderr.write("subagent:pre-cancel: dest-capable --target-id and/or paired --steer-dir/--scratch-dir required (default-to-cwd alone is refuse-closed for linked-worktree children)\n");
205
+ return EXIT_PRE_CANCEL_CONFIG;
206
+ }
207
+ if (args.observedWindowSeconds !== null &&
208
+ (!Number.isFinite(args.observedWindowSeconds) || args.observedWindowSeconds <= 0)) {
209
+ process.stderr.write("subagent:pre-cancel: --observed-window-seconds must be positive\n");
210
+ return EXIT_PRE_CANCEL_CONFIG;
211
+ }
212
+ const verdict = evaluatePreCancel({
213
+ agentId: args.agentId ?? "",
214
+ cancellerId: args.cancellerId ?? "",
215
+ steerDir,
216
+ firstSeenDir,
217
+ scratchDir,
218
+ force: args.force,
219
+ forceReason: args.forceReason ?? undefined,
220
+ dispatchStartedAt: args.dispatchStartedAt,
221
+ expectedWorkerId: args.expectedWorkerId,
222
+ observedWindowSeconds: args.observedWindowSeconds ?? undefined,
223
+ });
224
+ if (args.emitJson) {
225
+ process.stdout.write(`${JSON.stringify(verdict.json, null, 2)}\n`);
226
+ }
227
+ else if (verdict.message.length > 0) {
228
+ if (verdict.ok) {
229
+ process.stdout.write(`${verdict.message}\n`);
230
+ }
231
+ else {
232
+ process.stderr.write(`${verdict.message}\n`);
233
+ }
234
+ }
235
+ return verdict.exitCode;
236
+ }
237
+ if (process.argv[1] !== undefined && fileURLToPath(import.meta.url) === process.argv[1]) {
238
+ process.exit(run(process.argv.slice(2)));
239
+ }
240
+ //# sourceMappingURL=subagent-pre-cancel.js.map
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env node
2
+ import { type SteerKind, type SteerWriterKind } from "@deftai/directive-core/orchestration";
3
+ export declare const EXIT_STEER_WRITE_OK: number;
4
+ export declare const EXIT_STEER_WRITE_CONFIG: number;
5
+ export declare const SUBAGENT_STEER_WRITE_HELP = "subagent:steer \u2014 write a closed parent-steer inbox (#5278 / #4286)\n\nUsage:\n task subagent:steer -- --agent <id> --writer-id <id> --kind <kind> --text <text> [options]\n\nOptions:\n --agent ID Child agent_id (inbox file stem)\n --writer-id ID Writer identity (must match independent parent/owner record)\n --writer-kind KIND occupancy-owner | dispatching-parent (default: dispatching-parent)\n --kind KIND constraint | correction | halt | note\n --text TEXT Steer body (\u22642000 chars)\n --steer-id ID Optional stable steer id (default: uuid)\n --ttl-seconds N Expiry TTL (default: 1800)\n --target-id PATH Worktree root for dest inbox\n --steer-dir PATH Inbox directory override\n --scratch-dir PATH Heartbeat dir (not used for writer authority)\n --parent-id ID Must match child occupancy lease parentId\n --occupancy-owner-id ID Must match live occupancy session under --target-id\n --json Emit written record\n\nExit codes:\n 0 Wrote inbox\n 2 Config / validation error\n";
6
+ export interface SubagentSteerWriteArgs {
7
+ agentId: string | null;
8
+ writerId: string | null;
9
+ writerKind: SteerWriterKind;
10
+ kind: SteerKind | null;
11
+ text: string | null;
12
+ steerId: string | null;
13
+ ttlSeconds: number | null;
14
+ targetId: string | null;
15
+ steerDir: string | null;
16
+ scratchDir: string | null;
17
+ parentId: string | null;
18
+ occupancyOwnerId: string | null;
19
+ emitJson: boolean;
20
+ help: boolean;
21
+ error?: string;
22
+ }
23
+ /**
24
+ * Resolve parent/owner from dispatcher-recorded child occupancy + live occupancy.
25
+ * Heartbeat alone is never authority (caller-selected --scratch-dir cannot mint parent_id).
26
+ */
27
+ export declare function resolveIndependentSteerAuthority(input: {
28
+ root: string;
29
+ agentId: string;
30
+ writerKind: SteerWriterKind;
31
+ writerId: string;
32
+ claimedParentId?: string | null;
33
+ claimedOccupancyOwnerId?: string | null;
34
+ }): {
35
+ parentId?: string;
36
+ occupancyOwnerId?: string;
37
+ error?: string;
38
+ };
39
+ export declare function parseSubagentSteerWriteArgs(argv: readonly string[]): SubagentSteerWriteArgs;
40
+ export declare function run(argv: readonly string[], cwd?: string): number;
41
+ //# sourceMappingURL=subagent-steer-write.d.ts.map
@@ -0,0 +1,333 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Parent write surface for deft.subagent.steer.v1 (#5278 / #4286).
4
+ * Wraps writeSteer so status steers are reachable before pre-cancel.
5
+ * Writer authority is checked against child occupancy / heartbeat — not self-attested.
6
+ */
7
+ import { resolve } from "node:path";
8
+ import { fileURLToPath } from "node:url";
9
+ import { defaultSteerDir, isSafeAgentId, STEER_KINDS, STEER_WRITER_KINDS, writeSteer, } from "@deftai/directive-core/orchestration";
10
+ import { liveOccupant, readChildOccupancyLease } from "@deftai/directive-core/session";
11
+ export const EXIT_STEER_WRITE_OK = 0 * 1;
12
+ export const EXIT_STEER_WRITE_CONFIG = 2 * 1;
13
+ export const SUBAGENT_STEER_WRITE_HELP = `subagent:steer — write a closed parent-steer inbox (#5278 / #4286)
14
+
15
+ Usage:
16
+ task subagent:steer -- --agent <id> --writer-id <id> --kind <kind> --text <text> [options]
17
+
18
+ Options:
19
+ --agent ID Child agent_id (inbox file stem)
20
+ --writer-id ID Writer identity (must match independent parent/owner record)
21
+ --writer-kind KIND occupancy-owner | dispatching-parent (default: dispatching-parent)
22
+ --kind KIND constraint | correction | halt | note
23
+ --text TEXT Steer body (≤2000 chars)
24
+ --steer-id ID Optional stable steer id (default: uuid)
25
+ --ttl-seconds N Expiry TTL (default: 1800)
26
+ --target-id PATH Worktree root for dest inbox
27
+ --steer-dir PATH Inbox directory override
28
+ --scratch-dir PATH Heartbeat dir (not used for writer authority)
29
+ --parent-id ID Must match child occupancy lease parentId
30
+ --occupancy-owner-id ID Must match live occupancy session under --target-id
31
+ --json Emit written record
32
+
33
+ Exit codes:
34
+ 0 Wrote inbox
35
+ 2 Config / validation error
36
+ `;
37
+ /**
38
+ * Resolve parent/owner from dispatcher-recorded child occupancy + live occupancy.
39
+ * Heartbeat alone is never authority (caller-selected --scratch-dir cannot mint parent_id).
40
+ */
41
+ export function resolveIndependentSteerAuthority(input) {
42
+ const writerId = input.writerId.trim();
43
+ const lease = readChildOccupancyLease(input.root, input.agentId);
44
+ const occupancy = liveOccupant(input.root);
45
+ if (input.writerKind === "dispatching-parent") {
46
+ const expected = (lease?.parentId ?? "").trim();
47
+ if (expected.length === 0) {
48
+ return {
49
+ error: "dispatching-parent requires child occupancy lease parentId under --target-id (heartbeat alone is not authority)",
50
+ };
51
+ }
52
+ if (writerId !== expected) {
53
+ return {
54
+ error: `dispatching-parent writer_id ${JSON.stringify(writerId)} does not match child occupancy parent ${JSON.stringify(expected)}`,
55
+ };
56
+ }
57
+ const claimed = input.claimedParentId?.trim() ?? "";
58
+ if (claimed.length > 0 && claimed !== expected) {
59
+ return {
60
+ error: `--parent-id ${JSON.stringify(claimed)} does not match child occupancy parent ${JSON.stringify(expected)}`,
61
+ };
62
+ }
63
+ return { parentId: expected };
64
+ }
65
+ // occupancy-owner: liveOccupant (TTL/age-cap) is SoT; expired/stale leases refuse.
66
+ const liveOwner = (occupancy?.sessionId ?? "").trim();
67
+ if (liveOwner.length === 0) {
68
+ return {
69
+ error: "occupancy-owner requires a live (non-expired) occupancy session under --target-id",
70
+ };
71
+ }
72
+ const leaseOwner = (lease?.occupancyOwner ?? "").trim();
73
+ if (leaseOwner.length > 0 && leaseOwner !== liveOwner) {
74
+ return {
75
+ error: `child occupancy owner ${JSON.stringify(leaseOwner)} is superseded by live occupancy ${JSON.stringify(liveOwner)}`,
76
+ };
77
+ }
78
+ if (writerId !== liveOwner) {
79
+ return {
80
+ error: `occupancy-owner writer_id ${JSON.stringify(writerId)} does not match live occupancy ${JSON.stringify(liveOwner)}`,
81
+ };
82
+ }
83
+ const claimedOwner = input.claimedOccupancyOwnerId?.trim() ?? "";
84
+ if (claimedOwner.length > 0 && claimedOwner !== liveOwner) {
85
+ return {
86
+ error: `--occupancy-owner-id ${JSON.stringify(claimedOwner)} does not match live occupancy ${JSON.stringify(liveOwner)}`,
87
+ };
88
+ }
89
+ return { occupancyOwnerId: liveOwner };
90
+ }
91
+ export function parseSubagentSteerWriteArgs(argv) {
92
+ const acc = {
93
+ agentId: null,
94
+ writerId: null,
95
+ writerKind: "dispatching-parent",
96
+ kind: null,
97
+ text: null,
98
+ steerId: null,
99
+ ttlSeconds: null,
100
+ targetId: null,
101
+ steerDir: null,
102
+ scratchDir: null,
103
+ parentId: null,
104
+ occupancyOwnerId: null,
105
+ emitJson: false,
106
+ help: false,
107
+ };
108
+ for (let i = 0; i < argv.length; i += 1) {
109
+ const arg = argv[i];
110
+ if (arg === "--help" || arg === "-h") {
111
+ return { ...acc, help: true };
112
+ }
113
+ if (arg === "--json") {
114
+ acc.emitJson = true;
115
+ }
116
+ else if (arg === "--agent" || arg === "--agent-id") {
117
+ const value = argv[i + 1];
118
+ if (value === undefined)
119
+ return { ...acc, error: `argument ${arg}: expected one argument` };
120
+ acc.agentId = value;
121
+ i += 1;
122
+ }
123
+ else if (arg?.startsWith("--agent=") || arg?.startsWith("--agent-id=")) {
124
+ acc.agentId = arg.slice(arg.indexOf("=") + 1);
125
+ }
126
+ else if (arg === "--writer-id") {
127
+ const value = argv[i + 1];
128
+ if (value === undefined)
129
+ return { ...acc, error: "argument --writer-id: expected one argument" };
130
+ acc.writerId = value;
131
+ i += 1;
132
+ }
133
+ else if (arg?.startsWith("--writer-id=")) {
134
+ acc.writerId = arg.slice("--writer-id=".length);
135
+ }
136
+ else if (arg === "--writer-kind") {
137
+ const value = argv[i + 1];
138
+ if (value === undefined)
139
+ return { ...acc, error: "argument --writer-kind: expected one argument" };
140
+ if (!STEER_WRITER_KINDS.includes(value)) {
141
+ return { ...acc, error: `writer-kind must be one of ${STEER_WRITER_KINDS.join(", ")}` };
142
+ }
143
+ acc.writerKind = value;
144
+ i += 1;
145
+ }
146
+ else if (arg?.startsWith("--writer-kind=")) {
147
+ const value = arg.slice("--writer-kind=".length);
148
+ if (!STEER_WRITER_KINDS.includes(value)) {
149
+ return { ...acc, error: `writer-kind must be one of ${STEER_WRITER_KINDS.join(", ")}` };
150
+ }
151
+ acc.writerKind = value;
152
+ }
153
+ else if (arg === "--kind") {
154
+ const value = argv[i + 1];
155
+ if (value === undefined)
156
+ return { ...acc, error: "argument --kind: expected one argument" };
157
+ if (!STEER_KINDS.includes(value)) {
158
+ return { ...acc, error: `kind must be one of ${STEER_KINDS.join(", ")}` };
159
+ }
160
+ acc.kind = value;
161
+ i += 1;
162
+ }
163
+ else if (arg?.startsWith("--kind=")) {
164
+ const value = arg.slice("--kind=".length);
165
+ if (!STEER_KINDS.includes(value)) {
166
+ return { ...acc, error: `kind must be one of ${STEER_KINDS.join(", ")}` };
167
+ }
168
+ acc.kind = value;
169
+ }
170
+ else if (arg === "--text") {
171
+ const value = argv[i + 1];
172
+ if (value === undefined)
173
+ return { ...acc, error: "argument --text: expected one argument" };
174
+ acc.text = value;
175
+ i += 1;
176
+ }
177
+ else if (arg?.startsWith("--text=")) {
178
+ acc.text = arg.slice("--text=".length);
179
+ }
180
+ else if (arg === "--steer-id") {
181
+ const value = argv[i + 1];
182
+ if (value === undefined)
183
+ return { ...acc, error: "argument --steer-id: expected one argument" };
184
+ acc.steerId = value;
185
+ i += 1;
186
+ }
187
+ else if (arg?.startsWith("--steer-id=")) {
188
+ acc.steerId = arg.slice("--steer-id=".length);
189
+ }
190
+ else if (arg === "--ttl-seconds") {
191
+ const value = argv[i + 1];
192
+ if (value === undefined)
193
+ return { ...acc, error: "argument --ttl-seconds: expected one argument" };
194
+ acc.ttlSeconds = Number(value);
195
+ i += 1;
196
+ }
197
+ else if (arg?.startsWith("--ttl-seconds=")) {
198
+ acc.ttlSeconds = Number(arg.slice("--ttl-seconds=".length));
199
+ }
200
+ else if (arg === "--target-id" || arg === "--target") {
201
+ const value = argv[i + 1];
202
+ if (value === undefined)
203
+ return { ...acc, error: `argument ${arg}: expected one argument` };
204
+ acc.targetId = value;
205
+ i += 1;
206
+ }
207
+ else if (arg?.startsWith("--target-id=") || arg?.startsWith("--target=")) {
208
+ acc.targetId = arg.slice(arg.indexOf("=") + 1);
209
+ }
210
+ else if (arg === "--steer-dir") {
211
+ const value = argv[i + 1];
212
+ if (value === undefined)
213
+ return { ...acc, error: "argument --steer-dir: expected one argument" };
214
+ acc.steerDir = value;
215
+ i += 1;
216
+ }
217
+ else if (arg?.startsWith("--steer-dir=")) {
218
+ acc.steerDir = arg.slice("--steer-dir=".length);
219
+ }
220
+ else if (arg === "--scratch-dir") {
221
+ const value = argv[i + 1];
222
+ if (value === undefined)
223
+ return { ...acc, error: "argument --scratch-dir: expected one argument" };
224
+ acc.scratchDir = value;
225
+ i += 1;
226
+ }
227
+ else if (arg?.startsWith("--scratch-dir=")) {
228
+ acc.scratchDir = arg.slice("--scratch-dir=".length);
229
+ }
230
+ else if (arg === "--parent-id") {
231
+ const value = argv[i + 1];
232
+ if (value === undefined)
233
+ return { ...acc, error: "argument --parent-id: expected one argument" };
234
+ acc.parentId = value;
235
+ i += 1;
236
+ }
237
+ else if (arg?.startsWith("--parent-id=")) {
238
+ acc.parentId = arg.slice("--parent-id=".length);
239
+ }
240
+ else if (arg === "--occupancy-owner-id") {
241
+ const value = argv[i + 1];
242
+ if (value === undefined) {
243
+ return { ...acc, error: "argument --occupancy-owner-id: expected one argument" };
244
+ }
245
+ acc.occupancyOwnerId = value;
246
+ i += 1;
247
+ }
248
+ else if (arg?.startsWith("--occupancy-owner-id=")) {
249
+ acc.occupancyOwnerId = arg.slice("--occupancy-owner-id=".length);
250
+ }
251
+ else if (arg?.startsWith("-")) {
252
+ return { ...acc, error: `unrecognized argument: ${arg}` };
253
+ }
254
+ else {
255
+ return { ...acc, error: `unrecognized argument: ${arg}` };
256
+ }
257
+ }
258
+ return acc;
259
+ }
260
+ export function run(argv, cwd = process.cwd()) {
261
+ const args = parseSubagentSteerWriteArgs(argv);
262
+ if (args.help) {
263
+ process.stdout.write(SUBAGENT_STEER_WRITE_HELP);
264
+ return EXIT_STEER_WRITE_OK;
265
+ }
266
+ if (args.error !== undefined) {
267
+ process.stderr.write(`subagent:steer: ${args.error}\n`);
268
+ return EXIT_STEER_WRITE_CONFIG;
269
+ }
270
+ if (args.agentId === null || !isSafeAgentId(args.agentId)) {
271
+ process.stderr.write("subagent:steer: --agent is required and must be a filesystem-safe slug\n");
272
+ return EXIT_STEER_WRITE_CONFIG;
273
+ }
274
+ if (args.writerId === null || args.writerId.trim().length === 0) {
275
+ process.stderr.write("subagent:steer: --writer-id is required\n");
276
+ return EXIT_STEER_WRITE_CONFIG;
277
+ }
278
+ if (args.kind === null) {
279
+ process.stderr.write(`subagent:steer: --kind is required (${STEER_KINDS.join("|")})\n`);
280
+ return EXIT_STEER_WRITE_CONFIG;
281
+ }
282
+ if (args.text === null || args.text.trim().length === 0) {
283
+ process.stderr.write("subagent:steer: --text is required\n");
284
+ return EXIT_STEER_WRITE_CONFIG;
285
+ }
286
+ if (args.ttlSeconds !== null && (!Number.isFinite(args.ttlSeconds) || args.ttlSeconds <= 0)) {
287
+ process.stderr.write("subagent:steer: --ttl-seconds must be positive\n");
288
+ return EXIT_STEER_WRITE_CONFIG;
289
+ }
290
+ const root = args.targetId !== null && args.targetId.trim().length > 0 ? resolve(cwd, args.targetId) : cwd;
291
+ const steerDir = resolve(root, args.steerDir ?? defaultSteerDir(root));
292
+ const writerId = args.writerId.trim();
293
+ const authority = resolveIndependentSteerAuthority({
294
+ root,
295
+ agentId: args.agentId,
296
+ writerKind: args.writerKind,
297
+ writerId,
298
+ claimedParentId: args.parentId,
299
+ claimedOccupancyOwnerId: args.occupancyOwnerId,
300
+ });
301
+ if (authority.error !== undefined) {
302
+ process.stderr.write(`subagent:steer: ${authority.error}\n`);
303
+ return EXIT_STEER_WRITE_CONFIG;
304
+ }
305
+ try {
306
+ const record = writeSteer(steerDir, {
307
+ agentId: args.agentId,
308
+ writerKind: args.writerKind,
309
+ writerId,
310
+ kind: args.kind,
311
+ text: args.text,
312
+ steerId: args.steerId ?? undefined,
313
+ ttlSeconds: args.ttlSeconds ?? undefined,
314
+ parentId: authority.parentId,
315
+ occupancyOwnerId: authority.occupancyOwnerId,
316
+ });
317
+ if (args.emitJson) {
318
+ process.stdout.write(`${JSON.stringify(record, null, 2)}\n`);
319
+ }
320
+ else {
321
+ process.stdout.write(`subagent:steer: wrote ${record.agent_id} steer_id=${record.steer_id} kind=${record.kind}\n`);
322
+ }
323
+ return EXIT_STEER_WRITE_OK;
324
+ }
325
+ catch (err) {
326
+ process.stderr.write(`subagent:steer: ${String(err.message ?? err)}\n`);
327
+ return EXIT_STEER_WRITE_CONFIG;
328
+ }
329
+ }
330
+ if (process.argv[1] !== undefined && fileURLToPath(import.meta.url) === process.argv[1]) {
331
+ process.exit(run(process.argv.slice(2)));
332
+ }
333
+ //# sourceMappingURL=subagent-steer-write.js.map
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+ import { parseCohortReviewMonitorsArgv, verifyCohortReviewMonitorsMain } from "@deftai/directive-core/swarm";
3
+ export { parseCohortReviewMonitorsArgv, verifyCohortReviewMonitorsMain };
4
+ export declare function run(argv?: readonly string[]): number;
5
+ //# sourceMappingURL=verify-cohort-review-monitors.d.ts.map
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+ import { fileURLToPath } from "node:url";
3
+ import { parseCohortReviewMonitorsArgv, verifyCohortReviewMonitorsMain, } from "@deftai/directive-core/swarm";
4
+ export { parseCohortReviewMonitorsArgv, verifyCohortReviewMonitorsMain };
5
+ export function run(argv = process.argv.slice(2)) {
6
+ return verifyCohortReviewMonitorsMain([...argv]);
7
+ }
8
+ if (process.argv[1] !== undefined && fileURLToPath(import.meta.url) === process.argv[1]) {
9
+ process.exit(run(process.argv.slice(2)));
10
+ }
11
+ //# sourceMappingURL=verify-cohort-review-monitors.js.map
@@ -6,9 +6,12 @@ interface ParsedArgs {
6
6
  issue: number | null;
7
7
  quiet: boolean;
8
8
  skipGh: boolean;
9
+ /** Opt-in discovery when --issue is set; unscoped defaults to on (#3495). */
10
+ discover: boolean | null;
11
+ enforce: boolean;
9
12
  error?: string;
10
13
  }
11
- /** Parse verify-completed-tracked CLI args (#3264 / #3476). */
14
+ /** Parse verify-completed-tracked CLI args (#3264 / #3476 / #3495). */
12
15
  export declare function parseArgs(argv: string[]): ParsedArgs;
13
16
  /** Run the gate and return the process exit code. */
14
17
  export declare function run(argv: string[]): number;