@primitive.ai/prim 0.1.0-alpha.12 → 0.1.0-alpha.120

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/README.md +540 -38
  2. package/SKILL.md +315 -75
  3. package/assets/primitive-gameplan/SKILL.md +134 -0
  4. package/assets/primitive-gameplan/claude-hooks.json +28 -0
  5. package/assets/primitive-gameplan/scripts/activate.mjs +37 -0
  6. package/dist/chunk-2AKDX4RU.js +209 -0
  7. package/dist/chunk-4GLVJLEQ.js +55 -0
  8. package/dist/chunk-5BQ2NEMP.js +22695 -0
  9. package/dist/chunk-A6M2M5A2.js +36 -0
  10. package/dist/chunk-CCGFRNAA.js +1871 -0
  11. package/dist/chunk-D235RJNO.js +164 -0
  12. package/dist/chunk-EYBE724K.js +135 -0
  13. package/dist/chunk-EZXEWFDG.js +210 -0
  14. package/dist/chunk-GYQOZGGF.js +168 -0
  15. package/dist/chunk-HXICZG5J.js +503 -0
  16. package/dist/chunk-JSBRDJBE.js +30 -0
  17. package/dist/chunk-KZB4ABIB.js +13 -0
  18. package/dist/chunk-L52OD62C.js +1444 -0
  19. package/dist/chunk-LBCPRHNG.js +175 -0
  20. package/dist/chunk-LTTF4MBE.js +439 -0
  21. package/dist/chunk-MWNRXAEB.js +1572 -0
  22. package/dist/chunk-NQFRQ56V.js +262 -0
  23. package/dist/chunk-OYHYCK4K.js +13 -0
  24. package/dist/chunk-P2O7NLVN.js +1341 -0
  25. package/dist/chunk-R2NUH4B7.js +96 -0
  26. package/dist/chunk-SLDZJD6Q.js +157 -0
  27. package/dist/chunk-TC4FTRYO.js +253 -0
  28. package/dist/chunk-U67RBNIZ.js +844 -0
  29. package/dist/chunk-VOC4KOOP.js +258 -0
  30. package/dist/chunk-YTF6OCF3.js +459 -0
  31. package/dist/daemon/server.js +26444 -0
  32. package/dist/hook-runtime/daemon/server.js +26445 -0
  33. package/dist/hook-runtime/hooks/post-commit.js +23836 -0
  34. package/dist/hook-runtime/hooks/post-rewrite.js +23735 -0
  35. package/dist/hook-runtime/hooks/post-tool-use.js +36151 -0
  36. package/dist/hook-runtime/hooks/pre-commit.js +1737 -0
  37. package/dist/hook-runtime/hooks/pre-tool-use-worker.js +35067 -0
  38. package/dist/hook-runtime/hooks/pre-tool-use.js +96 -0
  39. package/dist/hook-runtime/hooks/prim-hook.js +36211 -0
  40. package/dist/hook-runtime/hooks/session-end.js +1188 -0
  41. package/dist/hook-runtime/hooks/session-start.js +33950 -0
  42. package/dist/hook-runtime/index.js +71245 -0
  43. package/dist/hook-runtime/statusline-main.js +892 -0
  44. package/dist/hooks/post-commit.js +197 -0
  45. package/dist/hooks/post-rewrite.js +206 -0
  46. package/dist/hooks/post-tool-use.js +295 -0
  47. package/dist/hooks/pre-commit.js +16 -108
  48. package/dist/hooks/pre-tool-use-worker.js +238 -0
  49. package/dist/hooks/pre-tool-use.js +87 -0
  50. package/dist/hooks/prim-hook.js +245 -0
  51. package/dist/hooks/session-end.js +67 -0
  52. package/dist/hooks/session-start.js +312 -0
  53. package/dist/index.js +10998 -572
  54. package/dist/statusline-main.js +891 -0
  55. package/package.json +49 -16
  56. package/dist/chunk-3APLWTLB.js +0 -165
@@ -0,0 +1,134 @@
1
+ ---
2
+ name: primitive-gameplan
3
+ description: Use alongside write-gameplan and write-workstream to bring applicable Primitive Decisions into architectural discussion, review plans for unsupported architectural additions, and preserve engineer-approved resolutions. Does not replace either public skill or authorize implementation.
4
+ ---
5
+
6
+ # Primitive companion for gameplanning
7
+
8
+ Use the public planning skill unchanged. This companion adds decision context to
9
+ its existing architecture discussion and final review; it adds no schema fields
10
+ or human checkpoints between execution patches. Codex is the primary host:
11
+ discover this companion under `.agents/skills`, make the public skills available
12
+ to Codex, and use `$write-gameplan` or `$write-workstream`.
13
+ `prim gameplan install --agent codex` places a dispatcher
14
+ in the user's Codex hooks to load this companion for explicit invocations;
15
+ `AGENTS.md` also binds implicit planning-skill use.
16
+ Claude retains `/write-gameplan` and `/write-workstream` through
17
+ [the Claude hook configuration](claude-hooks.json), merged into
18
+ `.claude/settings.json` without replacing existing hooks.
19
+
20
+ ## Before choosing architecture
21
+
22
+ Inspect the requested behavior and its existing code path. Identify both the
23
+ intended code files and the plan/workstream path, even if the plan does not exist
24
+ yet. From the target repository root, use the installed `prim` CLI, or
25
+ `npx --yes @primitive.ai/prim` when there is no `prim` executable:
26
+
27
+ ```sh
28
+ prim auth status
29
+ prim decisions check --files "src/billing/export.ts,gameplans/billing-export.yaml"
30
+ prim decisions show dec_123
31
+ ```
32
+
33
+ Replace the example paths and ID with real ones. `check` accepts comma-separated
34
+ repo-relative paths and emits JSON without a `--json` flag. Check intended code
35
+ paths as well as the artifact: a decision scoped to billing may not govern the
36
+ gameplans directory. Repeat the lookup if the planned footprint expands. Use
37
+ `show` on decisions you will rely on to inspect their full constraints, rationale,
38
+ source/attribution, status, and scope. A path match alone does not settle a choice.
39
+
40
+ Give a short brief before patch decomposition: relevant settled choices,
41
+ explicitly rejected approaches, and remaining architectural questions. Cite the
42
+ Decision IDs and explain their bearing on this change. Do not invent a blanket
43
+ ban on validators, workers, or persistence from an example of overengineering.
44
+
45
+ An empty successful lookup means no matching decisions were returned, not that
46
+ the proposed architecture is approved. Nonzero exits, `unavailable`, partial or
47
+ truncated responses, and missing provenance mean coverage is unknown or limited.
48
+ Report that limitation and use available engineer-supplied constraints. Do not
49
+ claim Primitive clearance, start an authentication flow, enable capture, or change
50
+ enforcement settings merely to finish planning.
51
+
52
+ ## Resolve choices in the existing format
53
+
54
+ Use `architectureDesign.decisions[].resolution` in the public gameplan schema:
55
+
56
+ - `engineer_approved`: an actual engineer answer or identifiable engineer-approved
57
+ source covers this exact choice and scope. Evidence includes the Primitive ID,
58
+ substantive constraint, source of approval, and why it applies here.
59
+ - `constrained`: binding requirements eliminate meaningful alternatives; explain
60
+ that reasoning, including the applicable Decision when one supplies a constraint.
61
+ - `delegated`: the engineer explicitly delegated this choice within a stated
62
+ scope; retain that delegation. The agent's resulting selection is not a new
63
+ user-originated decision without ratification.
64
+ - `unresolved`: the remaining choice needs an answer. Keep it in `openQuestions`
65
+ too, and leave dependent patches/specs provisional until it is resolved.
66
+
67
+ Keep rationale in `resolution.rationale`. A captured agent suggestion, an author
68
+ name, adoption status alone, an existing implementation, or a broad milestone is
69
+ not evidence that an engineer approved a new mechanism. For example, approval of
70
+ PostgreSQL does not approve another durable ledger. Conflicting or ambiguous
71
+ Decisions require clarification; do not silently prefer the newest one.
72
+
73
+ When alternatives remain, present the minimal approach, credible alternatives,
74
+ and relevant prior constraints before choosing. Ask one question at a time when
75
+ answers depend on each other. Do not repeat a question already answered within
76
+ the same scope. For a workstream, use its existing decisions/open-questions prose
77
+ rather than introducing gameplan fields.
78
+
79
+ ## Review the complete artifact before handoff
80
+
81
+ Read the solution, operational considerations, every patch, and every formal spec
82
+ against the resolved architecture. Look for consequential choices introduced as
83
+ implementation details: another source of truth, validation boundary, state
84
+ lifetime, worker, scheduler, retry protocol, or cross-runtime data flow. Check
85
+ each against its actual evidence and scope, not merely whether an ID is present.
86
+ This is a semantic review by the planning agent: `prim decisions check` is a
87
+ lookup, not that review.
88
+
89
+ For an unsupported addition, identify the patch and concrete choice. Remove an
90
+ unnecessary agent-added mechanism consistently from the artifact, or present it
91
+ as an unresolved exception with alternatives before finalizing dependent work.
92
+ Discussion of a rejected option is allowed; adopting it without resolution is not.
93
+ Re-run the public skill's schema/spec validation after changes. A validator PASS
94
+ does not verify that a human approved the design.
95
+
96
+ ## Preserve the answers
97
+
98
+ At a natural planning boundary, retain durable engineer resolutions in Primitive
99
+ when recording is authorized. Check the applicable records and
100
+ `prim decisions recent --limit 20` to avoid duplicates. Use the installed Prim
101
+ recording policy when available; a request to draft a plan alone does not grant
102
+ permission to publish decisions into an inactive repository.
103
+
104
+ Before a create, check `prim decisions create --help`. Record the exact approved
105
+ choice with `--intent`, `--attribution user`, source-grounded `--rationale`, one
106
+ `--decided` per binding constraint, and `--alternatives` only for options actually
107
+ rejected. An agent selection under delegation uses `--attribution agent` unless
108
+ the engineer ratifies that selection. Missing rationale is a question, not a
109
+ license to invent one. Apply only the approved scope using `--files`,
110
+ `--scope-dir`, or `--scope-repo`; include the plan path when that scope governs it.
111
+ Do not silently broaden a code-only constraint to all plans or the whole repo.
112
+
113
+ Honor existing recording authorization without asking again. For an inactive repo,
114
+ Prim's global `--yes` is appropriate only for a specifically authorized create;
115
+ npm's `npx --yes` is merely package-install confirmation. Preserve returned IDs
116
+ in the existing evidence fields. Report failed writes as unsaved, retaining the
117
+ approved wording in the plan for recovery; after an ambiguous failure, check for
118
+ an existing record before retrying. Never invent an ID or a successful save.
119
+
120
+ For parent workstreams, follow the public skill's write-back procedure: present
121
+ the concrete edits and obtain its required approval before applying them. Saving
122
+ a Primitive Decision does not authorize a workstream edit.
123
+
124
+ ## Enforcement boundary
125
+
126
+ Existing Conflict Gates may inspect saved plans when enabled and in scope. This
127
+ companion neither installs nor enables gates. It does not guarantee detection of
128
+ every architectural implication or cryptographically verify approval. Chat-only
129
+ plans bypass file-write gates, and infrastructure failures may fail open.
130
+
131
+ If a gate flags a conflict, surface the governing Decision and resolve the
132
+ architectural choice with the engineer. Do not run `prim reconcile`, weaken gate
133
+ mode, or change/supersede the Decision merely to make the plan pass. A bypass or
134
+ change of constraint needs explicit engineer authorization for that action.
@@ -0,0 +1,28 @@
1
+ {
2
+ "hooks": {
3
+ "UserPromptExpansion": [
4
+ {
5
+ "matcher": "(^|:)write-(gameplan|workstream)$",
6
+ "hooks": [
7
+ {
8
+ "type": "command",
9
+ "command": "node \"$CLAUDE_PROJECT_DIR/.agents/skills/primitive-gameplan/scripts/activate.mjs\"",
10
+ "timeout": 5
11
+ }
12
+ ]
13
+ }
14
+ ],
15
+ "PreToolUse": [
16
+ {
17
+ "matcher": "Skill",
18
+ "hooks": [
19
+ {
20
+ "type": "command",
21
+ "command": "node \"$CLAUDE_PROJECT_DIR/.agents/skills/primitive-gameplan/scripts/activate.mjs\"",
22
+ "timeout": 5
23
+ }
24
+ ]
25
+ }
26
+ ]
27
+ }
28
+ }
@@ -0,0 +1,37 @@
1
+ import { readFileSync } from "node:fs";
2
+
3
+ const event = JSON.parse(readFileSync(0, "utf8"));
4
+ let name;
5
+ if (event.hook_event_name === "UserPromptSubmit") {
6
+ name = event.prompt?.match(
7
+ /^\s*[$/](write-(?:gameplan|workstream))(?=\s|$)/
8
+ )?.[1];
9
+ } else if (
10
+ event.hook_event_name === "UserPromptExpansion" &&
11
+ event.expansion_type === "slash_command"
12
+ ) {
13
+ name = event.command_name;
14
+ } else if (
15
+ event.hook_event_name === "PreToolUse" &&
16
+ event.tool_name === "Skill"
17
+ ) {
18
+ name = event.tool_input?.skill;
19
+ }
20
+
21
+ if (
22
+ typeof name === "string" &&
23
+ /^(?:[^:]+:)*write-(?:gameplan|workstream)$/.test(name)
24
+ ) {
25
+ const companion = readFileSync(
26
+ new URL("../SKILL.md", import.meta.url),
27
+ "utf8"
28
+ );
29
+ process.stdout.write(
30
+ `${JSON.stringify({
31
+ hookSpecificOutput: {
32
+ hookEventName: event.hook_event_name,
33
+ additionalContext: `This repository uses the Primitive planning companion alongside ${name}. Its local skill follows:\n\n${companion}`,
34
+ },
35
+ })}\n`
36
+ );
37
+ }
@@ -0,0 +1,209 @@
1
+ import {
2
+ getClient,
3
+ isTerminalSafeText,
4
+ terminalSafeLine,
5
+ terminalSafeText
6
+ } from "./chunk-U67RBNIZ.js";
7
+
8
+ // src/decisions/feedback.ts
9
+ var FEEDBACK_PROTOCOL_VERSION = 2;
10
+ var FEEDBACK_MIN_PROTOCOL_VERSION = 1;
11
+ var FEEDBACK_DEADLINE_MS = 3e3;
12
+ var MAX_FEEDBACK_EVENTS = 40;
13
+ var MAX_FEEDBACK_MESSAGE_CODE_POINTS = 8e3;
14
+ var MAX_FEEDBACK_INTENT_CODE_POINTS = 180;
15
+ var LEASE_PATH = "/api/cli/decisions/feedback/lease";
16
+ var ACK_PATH = "/api/cli/decisions/feedback/ack";
17
+ var STATUS_PATH = "/api/cli/decisions/feedback/status";
18
+ var SHORT_ID = /^[0-9a-f]{8}$/u;
19
+ var MAX_EVENT_ID_CHARS = 128;
20
+ var MAX_RAW_INTENT_CODE_UNITS = 512;
21
+ var MAX_FEEDBACK_WEB_URL_CHARS = 2048;
22
+ var SAFE_PUBLISH_DECISION_ID = /^dec_[0-9a-f]{8}$/u;
23
+ function isRecord(value) {
24
+ return typeof value === "object" && value !== null && !Array.isArray(value);
25
+ }
26
+ function isSupportedProtocolVersion(value) {
27
+ return Number.isSafeInteger(value) && Number(value) >= FEEDBACK_MIN_PROTOCOL_VERSION && Number(value) <= FEEDBACK_PROTOCOL_VERSION;
28
+ }
29
+ function normalizeFeedbackIntent(value) {
30
+ const withoutControls = terminalSafeLine(value);
31
+ const points = Array.from(withoutControls);
32
+ if (points.length <= MAX_FEEDBACK_INTENT_CODE_POINTS) {
33
+ return withoutControls;
34
+ }
35
+ return `${points.slice(0, MAX_FEEDBACK_INTENT_CODE_POINTS - 1).join("")}\u2026`;
36
+ }
37
+ function parseFeedbackWebUrl(value) {
38
+ if (typeof value !== "string" || value.length === 0 || value.length > MAX_FEEDBACK_WEB_URL_CHARS || !/^https:\/\//iu.test(value) || /\s/u.test(value) || !isTerminalSafeText(value)) {
39
+ return void 0;
40
+ }
41
+ try {
42
+ const url = new URL(value);
43
+ if (url.protocol !== "https:" || !url.hostname || url.username.length > 0 || url.password.length > 0) {
44
+ return void 0;
45
+ }
46
+ } catch {
47
+ return void 0;
48
+ }
49
+ return value;
50
+ }
51
+ function parseFeedbackDecisionId(value) {
52
+ if (typeof value !== "string" || value.length === 0 || value.length > MAX_EVENT_ID_CHARS || terminalSafeText(value) !== value || !SAFE_PUBLISH_DECISION_ID.test(value)) {
53
+ return void 0;
54
+ }
55
+ return value;
56
+ }
57
+ function parseEvent(value, protocolVersion) {
58
+ if (!isRecord(value)) return void 0;
59
+ if (typeof value.eventId !== "string" || value.eventId.length === 0 || value.eventId.length > MAX_EVENT_ID_CHARS || terminalSafeText(value.eventId) !== value.eventId) {
60
+ return void 0;
61
+ }
62
+ if (!Number.isSafeInteger(value.leaseVersion) || Number(value.leaseVersion) < 1) {
63
+ return void 0;
64
+ }
65
+ if (typeof value.shortId !== "string" || !SHORT_ID.test(value.shortId)) {
66
+ return void 0;
67
+ }
68
+ if (typeof value.intent !== "string" || value.intent.length > MAX_RAW_INTENT_CODE_UNITS) {
69
+ return void 0;
70
+ }
71
+ const intent = normalizeFeedbackIntent(value.intent);
72
+ if (!intent) return void 0;
73
+ const webUrl = value.webUrl === void 0 ? void 0 : parseFeedbackWebUrl(value.webUrl);
74
+ if (value.webUrl !== void 0 && webUrl === void 0) return void 0;
75
+ const kind = value.kind === void 0 && protocolVersion === 1 ? "confirm_prompt" : value.kind;
76
+ if (kind !== "confirm_prompt" && kind !== "publish_prompt") return void 0;
77
+ if (protocolVersion === 1 && kind === "publish_prompt") return void 0;
78
+ const decisionId = value.decisionId === void 0 ? void 0 : parseFeedbackDecisionId(value.decisionId);
79
+ if (value.decisionId !== void 0 && decisionId === void 0) return void 0;
80
+ if (decisionId !== void 0 && (protocolVersion !== 2 || kind !== "publish_prompt")) {
81
+ return void 0;
82
+ }
83
+ if (protocolVersion === 2 && kind === "publish_prompt" && decisionId === void 0) {
84
+ return void 0;
85
+ }
86
+ return {
87
+ eventId: value.eventId,
88
+ leaseVersion: Number(value.leaseVersion),
89
+ shortId: value.shortId,
90
+ intent,
91
+ ...webUrl === void 0 ? {} : { webUrl },
92
+ ...decisionId === void 0 ? {} : { decisionId },
93
+ kind
94
+ };
95
+ }
96
+ function parseFeedbackLease(value) {
97
+ if (!isRecord(value) || !isSupportedProtocolVersion(value.protocolVersion)) return void 0;
98
+ const protocolVersion = value.protocolVersion;
99
+ if (value.status === "empty") {
100
+ return value.hasMore === false ? { protocolVersion, events: [], hasMore: false } : void 0;
101
+ }
102
+ if (value.status === "unavailable") {
103
+ return value.reason === "organization_unbound" ? { protocolVersion, events: [], hasMore: false } : void 0;
104
+ }
105
+ if (value.status !== "leased" || typeof value.hasMore !== "boolean") return void 0;
106
+ if (!Array.isArray(value.events) || value.events.length === 0 || value.events.length > MAX_FEEDBACK_EVENTS) {
107
+ return void 0;
108
+ }
109
+ const events = value.events.map((event) => parseEvent(event, protocolVersion));
110
+ if (events.some((event) => event === void 0)) return void 0;
111
+ const parsedEvents = events;
112
+ if (new Set(parsedEvents.map((event) => event.eventId)).size !== parsedEvents.length) {
113
+ return void 0;
114
+ }
115
+ return { protocolVersion, events: parsedEvents, hasMore: value.hasMore };
116
+ }
117
+ function renderFeedback(lease) {
118
+ const lines = [];
119
+ const deliveries = [];
120
+ let pointCount = 0;
121
+ for (const event of lease.events) {
122
+ const decisionId = event.kind === "publish_prompt" ? parseFeedbackDecisionId(event.decisionId) : void 0;
123
+ if (event.kind === "publish_prompt" && decisionId === void 0) continue;
124
+ const identifier = `dec_${event.shortId}`;
125
+ const detail = `${event.intent}${event.webUrl ? ` (${event.webUrl})` : ""}`;
126
+ const line = event.kind === "publish_prompt" ? `[prim] publish this Decision draft (${identifier})? ${detail} Run \`prim decisions publish ${decisionId}\` to share it with your team.` : `[prim] response \u2192 created Decision (${identifier}): ${detail}`;
127
+ const extra = Array.from(line).length + (lines.length === 0 ? 0 : 1);
128
+ if (pointCount + extra > MAX_FEEDBACK_MESSAGE_CODE_POINTS) break;
129
+ lines.push(line);
130
+ deliveries.push({ eventId: event.eventId, leaseVersion: event.leaseVersion });
131
+ pointCount += extra;
132
+ }
133
+ if (lines.length === 0) return void 0;
134
+ return { protocolVersion: lease.protocolVersion, systemMessage: lines.join("\n"), deliveries };
135
+ }
136
+ async function leaseDecisionFeedback(input, dependencies = {}) {
137
+ try {
138
+ const response = await (dependencies.client ?? getClient()).post(
139
+ LEASE_PATH,
140
+ {
141
+ protocolVersion: FEEDBACK_PROTOCOL_VERSION,
142
+ workspaceId: input.workspaceId,
143
+ currentSessionId: input.currentSessionId
144
+ },
145
+ { signal: input.signal, quietRefresh: true }
146
+ );
147
+ const parsed = parseFeedbackLease(response);
148
+ if (!parsed) {
149
+ dependencies.onError?.(
150
+ new Error("server returned an unsupported decision-feedback contract")
151
+ );
152
+ }
153
+ return parsed;
154
+ } catch (error) {
155
+ dependencies.onError?.(error);
156
+ return void 0;
157
+ }
158
+ }
159
+ async function acknowledgeDecisionFeedback(input, dependencies = {}) {
160
+ if (!isSupportedProtocolVersion(input.protocolVersion) || input.deliveries.length === 0 || input.deliveries.length > MAX_FEEDBACK_EVENTS) {
161
+ return false;
162
+ }
163
+ try {
164
+ const response = await (dependencies.client ?? getClient()).post(
165
+ ACK_PATH,
166
+ {
167
+ protocolVersion: input.protocolVersion,
168
+ workspaceId: input.workspaceId,
169
+ deliveries: input.deliveries
170
+ },
171
+ { signal: input.signal, quietRefresh: true }
172
+ );
173
+ const acknowledgedEventIds = isRecord(response) ? response.acknowledgedEventIds : void 0;
174
+ const expectedEventIds = new Set(input.deliveries.map((delivery) => delivery.eventId));
175
+ const valid = isRecord(response) && response.protocolVersion === input.protocolVersion && response.status === "acked" && Array.isArray(acknowledgedEventIds) && acknowledgedEventIds.length <= input.deliveries.length && acknowledgedEventIds.every(
176
+ (id) => typeof id === "string" && id.length > 0 && id.length <= MAX_EVENT_ID_CHARS && expectedEventIds.has(id)
177
+ ) && new Set(acknowledgedEventIds).size === acknowledgedEventIds.length;
178
+ if (!valid) {
179
+ dependencies.onError?.(
180
+ new Error("server returned an unsupported decision-feedback acknowledgement")
181
+ );
182
+ }
183
+ return valid;
184
+ } catch (error) {
185
+ dependencies.onError?.(error);
186
+ return false;
187
+ }
188
+ }
189
+ function parseFeedbackCapability(value) {
190
+ if (!isRecord(value) || !isSupportedProtocolVersion(value.protocolVersion)) return void 0;
191
+ if (value.status === "available") return { status: "available" };
192
+ if (value.status === "unavailable" && value.reason === "organization_unbound") {
193
+ return { status: "unavailable", reason: "organization_unbound" };
194
+ }
195
+ return void 0;
196
+ }
197
+ async function fetchFeedbackCapability(signal, client = getClient()) {
198
+ const result = parseFeedbackCapability(await client.get(STATUS_PATH, { signal }));
199
+ if (!result) throw new Error("server returned an unsupported decision-feedback contract");
200
+ return result;
201
+ }
202
+
203
+ export {
204
+ FEEDBACK_DEADLINE_MS,
205
+ renderFeedback,
206
+ leaseDecisionFeedback,
207
+ acknowledgeDecisionFeedback,
208
+ fetchFeedbackCapability
209
+ };
@@ -0,0 +1,55 @@
1
+ // src/hooks/decision-feedback-core.ts
2
+ function buildHookOutput(options) {
3
+ const output = {};
4
+ if (options.systemMessage) output.systemMessage = options.systemMessage;
5
+ const fields = {};
6
+ if (options.additionalContext) fields.additionalContext = options.additionalContext;
7
+ if (options.reloadSkills) fields.reloadSkills = true;
8
+ if (Object.keys(fields).length > 0) {
9
+ output.hookSpecificOutput = { hookEventName: "SessionStart", ...fields };
10
+ }
11
+ return output;
12
+ }
13
+ function writeHookOutput(output, stream = process.stdout) {
14
+ return new Promise((resolve) => {
15
+ let settled = false;
16
+ const finish = (ok, retainErrorListener = false) => {
17
+ if (settled) return;
18
+ settled = true;
19
+ if (!retainErrorListener) stream.off("error", onError);
20
+ resolve(ok);
21
+ };
22
+ const onError = () => {
23
+ if (settled) {
24
+ stream.off("error", onError);
25
+ return;
26
+ }
27
+ finish(false);
28
+ };
29
+ stream.once("error", onError);
30
+ try {
31
+ stream.write(
32
+ `${JSON.stringify(output)}
33
+ `,
34
+ (error) => error ? finish(false, true) : finish(true)
35
+ );
36
+ } catch {
37
+ finish(false);
38
+ }
39
+ });
40
+ }
41
+ async function handoffHookOutput(output, acknowledge, stream = process.stdout) {
42
+ const handedOff = await writeHookOutput(output, stream);
43
+ if (handedOff && acknowledge) {
44
+ try {
45
+ await acknowledge();
46
+ } catch {
47
+ }
48
+ }
49
+ return handedOff;
50
+ }
51
+
52
+ export {
53
+ buildHookOutput,
54
+ handoffHookOutput
55
+ };