@primitive.ai/prim 0.1.0-alpha.9 → 0.1.0-alpha.90
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/README.md +295 -37
- package/SKILL.md +269 -0
- package/dist/chunk-2JRX7ZR4.js +247 -0
- package/dist/chunk-3EEFL6NJ.js +529 -0
- package/dist/chunk-4GLVJLEQ.js +55 -0
- package/dist/chunk-6IWNH776.js +77 -0
- package/dist/chunk-C7T7B45R.js +1400 -0
- package/dist/chunk-CUE2LKLR.js +155 -0
- package/dist/chunk-EZXEWFDG.js +210 -0
- package/dist/chunk-FI3LIRCB.js +262 -0
- package/dist/chunk-LEMX3IOG.js +79 -0
- package/dist/chunk-LMRYZL3D.js +209 -0
- package/dist/chunk-MAZWKJGL.js +18548 -0
- package/dist/chunk-PMRDE2DA.js +310 -0
- package/dist/chunk-PPQYQEIR.js +815 -0
- package/dist/chunk-R26A7TWY.js +36 -0
- package/dist/chunk-RO3F6JYV.js +126 -0
- package/dist/chunk-UZPBB7V4.js +505 -0
- package/dist/chunk-WB7AUZ4C.js +52 -0
- package/dist/chunk-YWO7O6QG.js +327 -0
- package/dist/chunk-Z7YPFWAZ.js +917 -0
- package/dist/daemon/server.js +21633 -0
- package/dist/hook-runtime/daemon/server.js +21633 -0
- package/dist/hook-runtime/hooks/post-commit.js +19258 -0
- package/dist/hook-runtime/hooks/post-rewrite.js +19273 -0
- package/dist/hook-runtime/hooks/post-tool-use.js +25846 -0
- package/dist/hook-runtime/hooks/pre-commit.js +1314 -0
- package/dist/hook-runtime/hooks/pre-tool-use.js +25284 -0
- package/dist/hook-runtime/hooks/prim-hook.js +25870 -0
- package/dist/hook-runtime/hooks/session-end.js +495 -0
- package/dist/hook-runtime/hooks/session-start.js +28180 -0
- package/dist/hook-runtime/index.js +50516 -0
- package/dist/hook-runtime/statusline-main.js +765 -0
- package/dist/hooks/post-commit.js +188 -0
- package/dist/hooks/post-rewrite.js +201 -0
- package/dist/hooks/post-tool-use.js +263 -0
- package/dist/hooks/pre-commit.js +16 -101
- package/dist/hooks/pre-tool-use.js +367 -0
- package/dist/hooks/prim-hook.js +207 -0
- package/dist/hooks/session-end.js +70 -0
- package/dist/hooks/session-start.js +289 -0
- package/dist/index.js +9749 -425
- package/dist/statusline-main.js +765 -0
- package/package.json +35 -13
- package/dist/chunk-3APLWTLB.js +0 -165
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getClient,
|
|
3
|
+
isTerminalSafeText,
|
|
4
|
+
terminalSafeLine,
|
|
5
|
+
terminalSafeText
|
|
6
|
+
} from "./chunk-Z7YPFWAZ.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 = /^[A-Za-z0-9_-]+$/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
|
+
};
|