@primitive.ai/prim 0.1.0-alpha.102 → 0.1.0-alpha.103
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 +16 -0
- package/SKILL.md +49 -0
- package/dist/chunk-6WCBVSND.js +107 -0
- package/dist/{chunk-MXVCP33E.js → chunk-LNFWFYSN.js} +60 -0
- package/dist/{chunk-QIHXTYRD.js → chunk-RCFDZ4DY.js} +1 -1
- package/dist/hook-runtime/hooks/post-tool-use.js +497 -358
- package/dist/hook-runtime/hooks/pre-tool-use.js +214 -74
- package/dist/hook-runtime/hooks/prim-hook.js +260 -123
- package/dist/hook-runtime/index.js +2000 -1412
- package/dist/hooks/post-tool-use.js +9 -2
- package/dist/hooks/pre-tool-use.js +10 -1
- package/dist/hooks/prim-hook.js +9 -2
- package/dist/index.js +611 -80
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -42,6 +42,22 @@ skill, and the welcome:
|
|
|
42
42
|
prim setup # add --agent cursor, codex, or hermes; --no-daemon explicitly opts out
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
+
After successful setup, a first-run, 2–3 minute **simulated tour** demonstrates
|
|
46
|
+
sample ingestion, Decision creation, a warning, a blocked write, and a correction.
|
|
47
|
+
Your agent guides two choices; no sample Decisions enter the real graph.
|
|
48
|
+
The tour follows one order-saving task and ends with a receipt of the demonstrated
|
|
49
|
+
lifecycle, then offers one real project Decision for your individual approval.
|
|
50
|
+
Use `prim setup --skip-demo` to skip and remember that choice, or
|
|
51
|
+
`prim demo --agent <claude|codex|cursor|hermes>` to replay.
|
|
52
|
+
For a person at a terminal, `prim demo` prompts directly.
|
|
53
|
+
|
|
54
|
+
The agent tour waits for trusted hooks before showing samples and excludes
|
|
55
|
+
passive capture for the remainder of that agent session, including resumes.
|
|
56
|
+
Start a new session afterward for normal capture. Explicitly approved real
|
|
57
|
+
Decisions can still be created, and other sessions continue capturing.
|
|
58
|
+
The tour uses disposable local files and scripted verdicts; it does not test
|
|
59
|
+
production ingestion or Enforcement. It offers real-memory seeding afterward.
|
|
60
|
+
|
|
45
61
|
Or run the steps individually:
|
|
46
62
|
|
|
47
63
|
```bash
|
package/SKILL.md
CHANGED
|
@@ -144,6 +144,55 @@ Treat changes to shared agent instructions and standards—such as `AGENTS.md`,
|
|
|
144
144
|
|
|
145
145
|
Apply the same attention during non-code deliberation: planning or “grill me” workflows, spec refinement, behavior design, PR planning or review, and conversations imported from Granola or other connected sources. These workflows can settle important forks before any code changes. Accumulate the confirmed decisions and record them at a natural phase or task boundary; do not interrupt or call Primitive after every answer.
|
|
146
146
|
|
|
147
|
+
### Onboarding: run the local tour before memory seeding
|
|
148
|
+
|
|
149
|
+
After successful `prim setup`, follow any demo `nextAction` automatically. Setup
|
|
150
|
+
starts this optional tour once per local OS-user configuration; `setup --skip-demo`
|
|
151
|
+
remembers a skip, and `prim demo --agent <claude|codex|cursor|hermes>` replays it.
|
|
152
|
+
Pass your agent explicitly, including when your shell tool allocates a terminal.
|
|
153
|
+
|
|
154
|
+
The tour is entirely fictional: extraction, Decisions, and verdicts are simulated.
|
|
155
|
+
Execute each generated command **exactly as a standalone shell invocation**; do not
|
|
156
|
+
wrap it, append another command, substitute another executable, or use a subagent.
|
|
157
|
+
Its hook acknowledgment establishes session isolation before any sample is shown.
|
|
158
|
+
If the result is pending, surface its hook-trust instruction and retry only after
|
|
159
|
+
trust is established. Never fabricate the missing output or read sample fixtures
|
|
160
|
+
yourself to bypass isolation.
|
|
161
|
+
|
|
162
|
+
Once isolation is acknowledged, open with the tour's mission: add order saving.
|
|
163
|
+
Connect the team's context, the Decisions, and the implementation to that task.
|
|
164
|
+
Show the source conversation becoming a provisional Decision with quoted evidence.
|
|
165
|
+
Distinguish the fixture's file-scope mapping from what the conversation states.
|
|
166
|
+
Present the source, Decision cards, and warning/block evidence. Pause for only the
|
|
167
|
+
two teaching choices: confirming the fictional authoring proposal, then choosing
|
|
168
|
+
the shared-repository correction (or retrying direct storage). Use `confirm` only
|
|
169
|
+
after the user's confirmation; never treat a general setup request or `--yes` as
|
|
170
|
+
that answer. Follow `skipAction` if the user declines or stops the tour.
|
|
171
|
+
After confirmation, acknowledge the adopted sample Decision before presenting
|
|
172
|
+
enforcement: the user's confirmation turned a proposal into an adopted record.
|
|
173
|
+
Present warning and block as separate beats: attempt, governing Decision,
|
|
174
|
+
conflict, consequence, actual file proof, and next move. Preserve that explanation
|
|
175
|
+
on a blocked retry. These scripted outcomes do not define universal state rules.
|
|
176
|
+
On the compliant choice, show both actual diffs: the unfinished order-saving
|
|
177
|
+
function becomes a repository call, and service calls return to the shared client.
|
|
178
|
+
Explain that the requested implementation landed while preserving both Decisions.
|
|
179
|
+
On completion, lead with the five-item simulated success receipt, then report
|
|
180
|
+
sample cleanup and the new-session requirement. Never present completion for a
|
|
181
|
+
skip, pending tour, or error. Offer to propose one real project Decision for
|
|
182
|
+
individual approval using the seeding procedure below; keep it separate from the
|
|
183
|
+
fictional examples, and continue one at a time only if the user wants to proceed.
|
|
184
|
+
|
|
185
|
+
Never record these examples with `decisions create`, save them to shared memory,
|
|
186
|
+
or include them in later seeding candidates. The tour excludes passive capture
|
|
187
|
+
for the remainder of this agent session, including resumes; tell the user to start
|
|
188
|
+
a new session for normal capture. Other sessions and real-work enforcement remain
|
|
189
|
+
active, and explicitly approved real Decisions can still be created here.
|
|
190
|
+
|
|
191
|
+
After completion or skip, offer memory seeding and run `prim welcome --agent <your
|
|
192
|
+
agent>` with `--capture-excluded` when this session ran the tour. An unfinished
|
|
193
|
+
tour is listed in `recoverableRuns`; use its skip command for cleanup before replay.
|
|
194
|
+
Do not begin real-memory proposals while the tour is pending.
|
|
195
|
+
|
|
147
196
|
### Onboarding: seed the graph from memory, one proposal at a time
|
|
148
197
|
|
|
149
198
|
When onboarding or `prim welcome` reports `"org": "seed"`, seed the viewer's graph by proposing decisions mined from memory. There is no open goals question: the proposals are the whole seeding pass. Propose **one decision per message**, wait for the user's verdict, and only then present the next — never present the candidates as a batch.
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import {
|
|
2
|
+
atomicWriteFile,
|
|
3
|
+
primConfigDirectory,
|
|
4
|
+
withFileLockSync
|
|
5
|
+
} from "./chunk-XG7S3LIL.js";
|
|
6
|
+
|
|
7
|
+
// src/demo/state.ts
|
|
8
|
+
import { createHash, randomUUID } from "crypto";
|
|
9
|
+
import { existsSync, lstatSync, readFileSync, readdirSync } from "fs";
|
|
10
|
+
import { join, resolve } from "path";
|
|
11
|
+
var RUN_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/u;
|
|
12
|
+
var demoDirectory = () => join(primConfigDirectory(), "demo");
|
|
13
|
+
var runPath = (id) => {
|
|
14
|
+
if (!RUN_ID.test(id)) throw new Error("invalid demo run ID");
|
|
15
|
+
return join(demoDirectory(), "runs", `${id}.json`);
|
|
16
|
+
};
|
|
17
|
+
function readDemoJson(path) {
|
|
18
|
+
const stat = lstatSync(path);
|
|
19
|
+
if (!stat.isFile() || stat.size > 16384) throw new Error(`invalid demo state: ${path}`);
|
|
20
|
+
return JSON.parse(readFileSync(path, "utf8"));
|
|
21
|
+
}
|
|
22
|
+
function saveDemoJson(path, value) {
|
|
23
|
+
atomicWriteFile(path, `${JSON.stringify(value)}
|
|
24
|
+
`, { mode: 384, ensureParent: true });
|
|
25
|
+
}
|
|
26
|
+
function readRun(id) {
|
|
27
|
+
const run = readDemoJson(runPath(id));
|
|
28
|
+
if (run.version !== 1 || run.id !== id || !["prepared", "proposal", "conflict", "completed", "skipped"].includes(run.stage) || typeof run.terminal !== "boolean" || !Array.isArray(run.launcher) || run.launcher.length !== 2 || run.launcher.some((value) => typeof value !== "string" || !value.startsWith("/")) || run.agent !== void 0 && !["claude_code", "codex", "cursor", "hermes"].includes(run.agent)) {
|
|
29
|
+
throw new Error("invalid demo run state");
|
|
30
|
+
}
|
|
31
|
+
return run;
|
|
32
|
+
}
|
|
33
|
+
var saveRun = (run) => saveDemoJson(runPath(run.id), run);
|
|
34
|
+
var lockRun = (id, action) => withFileLockSync(`${runPath(id)}.lock`, () => action(readRun(id)), { timeoutMs: 500 });
|
|
35
|
+
function prepareRun(agent, terminal = false) {
|
|
36
|
+
const run = {
|
|
37
|
+
version: 1,
|
|
38
|
+
id: randomUUID(),
|
|
39
|
+
stage: "prepared",
|
|
40
|
+
terminal,
|
|
41
|
+
agent,
|
|
42
|
+
launcher: [process.execPath, resolve(process.argv[1])]
|
|
43
|
+
};
|
|
44
|
+
saveRun(run);
|
|
45
|
+
return run;
|
|
46
|
+
}
|
|
47
|
+
var quote = (value) => `'${value.replaceAll("'", "'\\''")}'`;
|
|
48
|
+
function demoCommand(run, action, choice) {
|
|
49
|
+
return [
|
|
50
|
+
...run.launcher,
|
|
51
|
+
"demo",
|
|
52
|
+
action,
|
|
53
|
+
run.id,
|
|
54
|
+
...choice === void 0 ? [] : ["--choice", choice]
|
|
55
|
+
].map(quote).join(" ");
|
|
56
|
+
}
|
|
57
|
+
function onboardingFinished() {
|
|
58
|
+
const path = join(demoDirectory(), "onboarding.json");
|
|
59
|
+
if (!existsSync(path)) return false;
|
|
60
|
+
const value = readDemoJson(path);
|
|
61
|
+
if (value.outcome !== "completed" && value.outcome !== "skipped") {
|
|
62
|
+
throw new Error("invalid local onboarding outcome");
|
|
63
|
+
}
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
function finishOnboarding(outcome) {
|
|
67
|
+
saveDemoJson(join(demoDirectory(), "onboarding.json"), { outcome });
|
|
68
|
+
}
|
|
69
|
+
function pendingRuns() {
|
|
70
|
+
const path = join(demoDirectory(), "runs");
|
|
71
|
+
if (!existsSync(path)) return [];
|
|
72
|
+
return readdirSync(path).filter((name) => name.endsWith(".json") && RUN_ID.test(name.slice(0, -5))).map((name) => name.slice(0, -5)).filter((id) => !["completed", "skipped"].includes(readRun(id).stage));
|
|
73
|
+
}
|
|
74
|
+
function sessionKey(agent, session) {
|
|
75
|
+
return createHash("sha256").update(`${agent}\0${session}`).digest("hex");
|
|
76
|
+
}
|
|
77
|
+
function exclusionPath(key) {
|
|
78
|
+
if (!/^[0-9a-f]{64}$/u.test(key)) throw new Error("invalid demo session identity");
|
|
79
|
+
return join(demoDirectory(), "excluded-sessions", `${key}.json`);
|
|
80
|
+
}
|
|
81
|
+
function sessionExcluded(agent, session) {
|
|
82
|
+
if (typeof session !== "string" || !session) return false;
|
|
83
|
+
const path = exclusionPath(sessionKey(agent, session));
|
|
84
|
+
if (!existsSync(path)) return false;
|
|
85
|
+
const record = readDemoJson(path);
|
|
86
|
+
if (typeof record.runId !== "string" || !RUN_ID.test(record.runId)) {
|
|
87
|
+
throw new Error("invalid demo capture exclusion");
|
|
88
|
+
}
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export {
|
|
93
|
+
RUN_ID,
|
|
94
|
+
runPath,
|
|
95
|
+
readDemoJson,
|
|
96
|
+
saveDemoJson,
|
|
97
|
+
saveRun,
|
|
98
|
+
lockRun,
|
|
99
|
+
prepareRun,
|
|
100
|
+
demoCommand,
|
|
101
|
+
onboardingFinished,
|
|
102
|
+
finishOnboarding,
|
|
103
|
+
pendingRuns,
|
|
104
|
+
sessionKey,
|
|
105
|
+
exclusionPath,
|
|
106
|
+
sessionExcluded
|
|
107
|
+
};
|
|
@@ -1,3 +1,62 @@
|
|
|
1
|
+
import {
|
|
2
|
+
demoCommand,
|
|
3
|
+
exclusionPath,
|
|
4
|
+
lockRun,
|
|
5
|
+
runPath,
|
|
6
|
+
saveDemoJson,
|
|
7
|
+
saveRun,
|
|
8
|
+
sessionExcluded,
|
|
9
|
+
sessionKey
|
|
10
|
+
} from "./chunk-6WCBVSND.js";
|
|
11
|
+
|
|
12
|
+
// src/demo/isolation.ts
|
|
13
|
+
import { existsSync } from "fs";
|
|
14
|
+
function observeDemoInvocation(envelope, agent, checkExclusion = true) {
|
|
15
|
+
const session = typeof envelope.session_id === "string" && envelope.session_id ? envelope.session_id : agent === "hermes" ? envelope.extra?.session_key : void 0;
|
|
16
|
+
let invocation = false;
|
|
17
|
+
if (envelope.hook_event_name === "PreToolUse" && typeof session === "string" && session) {
|
|
18
|
+
const tool = agent === "cursor" ? "Shell" : agent === "hermes" ? "terminal" : "Bash";
|
|
19
|
+
const input = envelope.tool_input;
|
|
20
|
+
const command = input?.command;
|
|
21
|
+
if (envelope.tool_name === tool && typeof command === "string" && command.length < 8192) {
|
|
22
|
+
const ids = command.match(
|
|
23
|
+
/[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/gu
|
|
24
|
+
);
|
|
25
|
+
if (ids?.length === 1 && existsSync(runPath(ids[0]))) {
|
|
26
|
+
invocation = lockRun(ids[0], (run) => {
|
|
27
|
+
const actions = [
|
|
28
|
+
["start"],
|
|
29
|
+
["confirm"],
|
|
30
|
+
["resolve", "repository"],
|
|
31
|
+
["resolve", "local-storage"],
|
|
32
|
+
["skip"]
|
|
33
|
+
];
|
|
34
|
+
const match = actions.find(
|
|
35
|
+
([action, choice]) => demoCommand(run, action, choice) === command
|
|
36
|
+
);
|
|
37
|
+
if (run.terminal || !match) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
if (match[0] === "skip") return true;
|
|
41
|
+
const key = sessionKey(agent, session);
|
|
42
|
+
if (run.agent && run.agent !== agent || run.binding && run.binding !== key) {
|
|
43
|
+
run.acknowledgment = void 0;
|
|
44
|
+
saveRun(run);
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
saveDemoJson(exclusionPath(key), { runId: run.id });
|
|
48
|
+
run.binding = key;
|
|
49
|
+
run.agent = agent;
|
|
50
|
+
run.acknowledgment = { command, at: Date.now() };
|
|
51
|
+
saveRun(run);
|
|
52
|
+
return true;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return { invocation, excluded: checkExclusion && sessionExcluded(agent, session) };
|
|
58
|
+
}
|
|
59
|
+
|
|
1
60
|
// src/hooks/pre-tool-use-scoring.ts
|
|
2
61
|
import { isAbsolute, relative, sep } from "path";
|
|
3
62
|
function anyUnverified(results) {
|
|
@@ -832,6 +891,7 @@ function analyzeShellTargets(source) {
|
|
|
832
891
|
}
|
|
833
892
|
|
|
834
893
|
export {
|
|
894
|
+
observeDemoInvocation,
|
|
835
895
|
buildHookOutput,
|
|
836
896
|
buildCodexOutput,
|
|
837
897
|
buildCursorOutput,
|