@primitive.ai/prim 0.1.0-alpha.112 → 0.1.0-alpha.114
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 +22 -4
- package/SKILL.md +10 -16
- package/dist/{chunk-IW5HCCOW.js → chunk-IMYELJIV.js} +1 -1
- package/dist/{chunk-XV6C5ZV2.js → chunk-RUUSUF43.js} +245 -2
- package/dist/hook-runtime/hooks/post-tool-use.js +4866 -131
- package/dist/hook-runtime/hooks/pre-tool-use.js +4919 -144
- package/dist/hook-runtime/hooks/prim-hook.js +4867 -132
- package/dist/hook-runtime/index.js +13 -65
- package/dist/hooks/post-tool-use.js +2 -2
- package/dist/hooks/pre-tool-use.js +50 -10
- package/dist/hooks/prim-hook.js +2 -2
- package/dist/index.js +13 -65
- package/package.json +7 -2
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ presence — from the command line and via session + git hooks.
|
|
|
10
10
|
> [!NOTE]
|
|
11
11
|
> **Conflict Gates** check each edit against the decision graph and surface any
|
|
12
12
|
> load-bearing decision it conflicts with. When **Enforcement** is enabled for your
|
|
13
|
-
> organization, gates can warn, pause, or block a conflicting edit until you
|
|
13
|
+
> organization, gates can warn, pause, or block a conflicting edit until you resolve
|
|
14
14
|
> the decision and retry. Automatic decision capture in active repositories is separate.
|
|
15
15
|
|
|
16
16
|
## Installation
|
|
@@ -362,10 +362,25 @@ creating it; do not guess.
|
|
|
362
362
|
own — `<child>` depends on `<parent>`. Both are idempotent and refuse any link that
|
|
363
363
|
would create a cycle (exit 2); an unresolved id exits 4.
|
|
364
364
|
|
|
365
|
+
### Bash script coverage
|
|
366
|
+
|
|
367
|
+
Conflict Gates also inspect Bash writes expressed as Python `-c`, Node.js
|
|
368
|
+
`-e`/`--eval`, or quoted stdin heredocs. Static paths passed to Python `Path`
|
|
369
|
+
writes or writable `open`, and Node.js `fs`/`fs.promises` writeFile/appendFile
|
|
370
|
+
calls, participate in the existing preflight check. Simple path variables and
|
|
371
|
+
direct import aliases are supported. Analysis never executes the script.
|
|
372
|
+
|
|
373
|
+
Script coverage remains unverified: dynamic paths, reassignment, nested scopes,
|
|
374
|
+
directory changes, wrappers, external scripts, and unsupported syntax can hide
|
|
375
|
+
other writes. Unknown commands display a “not verified” warning in active repos;
|
|
376
|
+
recognized read-only commands stay quiet. Known conflicts still prompt or block
|
|
377
|
+
according to the existing policy. Embedded parsing stops at 64 KiB, targets are
|
|
378
|
+
bounded to 32, and shell proposal truncation at 6,144 bytes is disclosed.
|
|
379
|
+
|
|
365
380
|
### Reconcile
|
|
366
381
|
|
|
367
382
|
```bash
|
|
368
|
-
prim reconcile <id> #
|
|
383
|
+
prim reconcile <id> # Rejected: human_approval_required (exit 2)
|
|
369
384
|
```
|
|
370
385
|
|
|
371
386
|
Record what happened after resolving a specific conflict:
|
|
@@ -381,8 +396,11 @@ The conflict output supplies the check ID. Only the person whose edit was
|
|
|
381
396
|
checked can resolve that check. Repeating the same outcome is safe; changing an
|
|
382
397
|
already recorded outcome is rejected. These declarations do not issue a bypass.
|
|
383
398
|
|
|
384
|
-
|
|
385
|
-
|
|
399
|
+
Bypasses are disabled until an agent host can supply verifiable human approval.
|
|
400
|
+
Bare `prim reconcile <id>` rejects locally, including with `--yes`,
|
|
401
|
+
`--non-interactive`, or `--flag`. Sandbox escalation and automatic approval
|
|
402
|
+
review do not authorize an override. A blocked edit must remain blocked or be
|
|
403
|
+
changed to respect the governing Decisions.
|
|
386
404
|
|
|
387
405
|
### Hooks
|
|
388
406
|
|
package/SKILL.md
CHANGED
|
@@ -9,7 +9,7 @@ description: Use the prim CLI for Primitive’s decision graph. MUST INVOKE befo
|
|
|
9
9
|
|
|
10
10
|
## Mental model
|
|
11
11
|
|
|
12
|
-
In an active repo, prim passively captures the **decisions** your team makes -- which library, which pattern, which config value -- into a queryable graph, and links them: a decision can depend on earlier decisions (auto-linked from shared files, or related by hand — see *Relate decisions*) and reference the files it touched. **Conflict Gates** can check a later change against that graph and surface any load-bearing decision it conflicts with. When **Enforcement** is enabled for an organization, prim can warn, pause, or block the edit until you
|
|
12
|
+
In an active repo, prim passively captures the **decisions** your team makes -- which library, which pattern, which config value -- into a queryable graph, and links them: a decision can depend on earlier decisions (auto-linked from shared files, or related by hand — see *Relate decisions*) and reference the files it touched. **Conflict Gates** can check a later change against that graph and surface any load-bearing decision it conflicts with. When **Enforcement** is enabled for an organization, prim can warn, pause, or block the edit until you resolve the conflict. Capture in active repos runs independently.
|
|
13
13
|
|
|
14
14
|
Low-level capture runs automatically in active repos through the session hooks installed by `npx --yes @primitive.ai/prim claude install` (Claude Code), `npx --yes @primitive.ai/prim cursor install` (Cursor), `npx --yes @primitive.ai/prim codex install` (Codex), or `npx --yes @primitive.ai/prim hermes install` (Hermes). An inactive repo is not passively captured. Deliberately record higher-order forks in the road through `prim decisions create` as described below. Your job is also to **read** the graph before load-bearing edits and **answer** the occasional rationale confirmation. (Responding to Conflict Gates applies only once Enforcement is enabled — see below.)
|
|
15
15
|
|
|
@@ -34,12 +34,12 @@ The CLI auto-refreshes a still-valid session from the stored refresh token (proa
|
|
|
34
34
|
|
|
35
35
|
## Conflict Gates & Enforcement
|
|
36
36
|
|
|
37
|
-
**Conflict Gates** check each edit against the decision graph before it lands and surface any load-bearing decision it conflicts with. When **Enforcement** is enabled for an organization, a conflicting edit can be warned, blocked, or paused for confirmation until you
|
|
37
|
+
**Conflict Gates** check each edit against the decision graph before it lands and surface any load-bearing decision it conflicts with. When **Enforcement** is enabled for an organization, a conflicting edit can be warned, blocked, or paused for confirmation until you resolve the conflict. Automatic decision capture in active repos (above) runs independently.
|
|
38
38
|
|
|
39
39
|
When Enforcement is enabled, before an edit (Claude Code: Edit/Write/MultiEdit; Cursor: Write/Delete/Shell; Codex: apply_patch; Hermes: write_file/patch) a PreToolUse hook scores the target file against the graph:
|
|
40
40
|
|
|
41
|
-
- **deny** -- the edit is blocked
|
|
42
|
-
- **warn / additional context** -- the edit proceeds, but a relevant prior decision is surfaced. Read it. Cursor, Codex, and Hermes
|
|
41
|
+
- **deny** -- the edit is blocked. Name each governing Decision and the proposed conflicting edit. Overriding a Decision requires explicit human approval for that specific override. Reconcile bypasses are disabled until a host can provide verifiable human approval; keep the edit blocked and choose a compatible approach.
|
|
42
|
+
- **warn / additional context** -- the edit proceeds, but a relevant prior decision is surfaced. Read it. Cursor, Codex, and Hermes map a would-be `ask` to **deny**. Do not change gate settings, use sandbox escalation, or request prefix permissions to evade the block. Automatic approval review, `--yes`, and an agent assertion are not human approval.
|
|
43
43
|
- **"decision check skipped / not verified" or "... partial / truncated"** -- the check could not fully run. Treat constraints as UNKNOWN, not clear; never read silence as approval.
|
|
44
44
|
|
|
45
45
|
When enabled, the gate sends its preflight check directly to Primitive and fail-opens on infrastructure errors (for example, a network failure or org-unbound token) -- a service problem would not block your edit. That is why an "unavailable" note matters: it is the honest signal that the check, not your edit, is what failed.
|
|
@@ -64,17 +64,11 @@ internal record ID is needed to construct a link. Full IDs remain accepted only
|
|
|
64
64
|
as legacy inputs; never ask for or print them. Public JSON identity fields contain
|
|
65
65
|
prefixed short IDs; `shortId` remains a bare eight-character compatibility alias.
|
|
66
66
|
|
|
67
|
-
##
|
|
67
|
+
## Record a resolution
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
Bare `prim reconcile <idOrShortId>` rejects with `human_approval_required` and exit 2. It cannot grant permission to edit, including with `--flag`, `--yes`, or `--non-interactive`.
|
|
70
70
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
```
|
|
74
|
-
✓ Conflict caught before merge · N decisions saved · <author>'s intent preserved
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
`N` is the reconciled decision's downstream live-dependent count, shown as `N+` when the server caps it.
|
|
71
|
+
After resolving a conflict, record the actual outcome with `prim reconcile <id> --check <checkId> --outcome followed|superseded`. Use `followed` when you retained the Decision. Use `superseded` only after an explicitly authorized replacement has already been persisted. Recording an outcome does not bypass the gate or change a Decision.
|
|
78
72
|
|
|
79
73
|
## Answer rationale confirmations
|
|
80
74
|
|
|
@@ -364,8 +358,8 @@ Examples:
|
|
|
364
358
|
## Pitfalls
|
|
365
359
|
|
|
366
360
|
- **An "unavailable" / "not verified" decision check is not an all-clear.** Treat constraints as UNKNOWN and proceed deliberately; never read the silence as approval — the same holds for Conflict Gates once enabled.
|
|
367
|
-
- **When Enforcement is enabled, a `deny` means a real prior decision conflicts.**
|
|
368
|
-
- **Reconcile bypasses are
|
|
361
|
+
- **When Enforcement is enabled, a `deny` means a real prior decision conflicts.** Keep the edit blocked and pick an approach that respects it; intention alone never authorizes an override.
|
|
362
|
+
- **Reconcile bypasses are disabled.** Human approval cannot be inferred from tool execution or automatic review.
|
|
369
363
|
- **Capture of coding activity is automatic only in active repos; never inject moves by hand.** If an active repo's decisions aren't showing up, check that the session hooks are installed (`claude status` / `cursor status` / `codex status` / `hermes status`) and the daemon is running. Deliberately authoring a higher-order fork—either at the user's request or under the conservative proactive policy above—is a separate, supported path through `decisions create`; in an inactive repo, honor the per-invocation approval boundary above.
|
|
370
364
|
- **Don't fabricate rationale on a confirmation.** If you don't know why a decision was made, say so rather than guessing.
|
|
371
365
|
|
|
@@ -373,4 +367,4 @@ Examples:
|
|
|
373
367
|
|
|
374
368
|
If the user clearly made a durable fork-in-the-road decision, check recent decisions and record it now if it is not already present when capture is active — asking the single rationale question first when the why is not deducible from available context. When capture is inactive, record it only if the user explicitly requested that create; otherwise present it for the per-invocation approval above. If a strong higher-order decision was only inferred, decide whether it clears the interruption budget; if so, ask the single concise confirmation question after reporting the completed work. Otherwise say nothing about Primitive.
|
|
375
369
|
|
|
376
|
-
If Conflict Gates are enabled and one denied or warned you, report which decision(s) it named and
|
|
370
|
+
If Conflict Gates are enabled and one denied or warned you, report which decision(s) it named and how the conflict was resolved or why the edit remains blocked. If you read the graph before a load-bearing change, note what you found so the user can verify in the dashboard.
|
|
@@ -350,6 +350,213 @@ function demoteForMode(verdict, mode) {
|
|
|
350
350
|
|
|
351
351
|
// src/hooks/shell-targets.ts
|
|
352
352
|
import { parse } from "unbash";
|
|
353
|
+
|
|
354
|
+
// src/hooks/script-targets.ts
|
|
355
|
+
import { parser as javascript } from "@lezer/javascript";
|
|
356
|
+
import { parser as python } from "@lezer/python";
|
|
357
|
+
var MAX_SCRIPT_BYTES = 65536;
|
|
358
|
+
var WRITERS = /* @__PURE__ */ new Set(["writeFile", "writeFileSync", "appendFile", "appendFileSync"]);
|
|
359
|
+
var FS_MODULES = /* @__PURE__ */ new Set(["fs", "node:fs", "fs/promises", "node:fs/promises"]);
|
|
360
|
+
var IDENTIFIER = /^[A-Za-z_$][\w$]*$/;
|
|
361
|
+
function children(node) {
|
|
362
|
+
const nodes = [];
|
|
363
|
+
for (let child = node?.firstChild; child; child = child.nextSibling) nodes.push(child);
|
|
364
|
+
return nodes;
|
|
365
|
+
}
|
|
366
|
+
function literal(text) {
|
|
367
|
+
const quote = text[0];
|
|
368
|
+
if (quote !== '"' && quote !== "'" || text.at(-1) !== quote) return;
|
|
369
|
+
let value = "";
|
|
370
|
+
for (let i = 1; i < text.length - 1; i++) {
|
|
371
|
+
const char = text[i];
|
|
372
|
+
if (char === quote || char === "\n" || char === "\r") return;
|
|
373
|
+
if (char !== "\\") {
|
|
374
|
+
value += char;
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
const escaped = text[++i];
|
|
378
|
+
const simple = {
|
|
379
|
+
"\\": "\\",
|
|
380
|
+
"'": "'",
|
|
381
|
+
'"': '"',
|
|
382
|
+
n: "\n",
|
|
383
|
+
r: "\r",
|
|
384
|
+
t: " "
|
|
385
|
+
};
|
|
386
|
+
if (Object.hasOwn(simple, escaped)) value += simple[escaped];
|
|
387
|
+
else if (escaped === "u" || escaped === "x") {
|
|
388
|
+
const length = escaped === "u" ? 4 : 2;
|
|
389
|
+
const digits = text.slice(i + 1, i + 1 + length);
|
|
390
|
+
if (digits.length !== length || !/^[\da-f]+$/i.test(digits)) return;
|
|
391
|
+
value += String.fromCharCode(Number.parseInt(digits, 16));
|
|
392
|
+
i += length;
|
|
393
|
+
} else return;
|
|
394
|
+
}
|
|
395
|
+
return value;
|
|
396
|
+
}
|
|
397
|
+
function scriptWriteTargets(source, language) {
|
|
398
|
+
if (Buffer.byteLength(source) > MAX_SCRIPT_BYTES) return [];
|
|
399
|
+
try {
|
|
400
|
+
const tree = (language === "python" ? python : javascript).parse(source);
|
|
401
|
+
const cursor = tree.cursor();
|
|
402
|
+
let nodes = 0;
|
|
403
|
+
do {
|
|
404
|
+
if (++nodes > 2e4 || cursor.type.isError) return [];
|
|
405
|
+
if (language === "javascript" && cursor.name === "VariableDefinition" && source.slice(cursor.from, cursor.to) === "require")
|
|
406
|
+
return [];
|
|
407
|
+
if (["PropertyName", "VariableName", "VariableDefinition"].includes(cursor.name) && ["chdir", "exec", "eval"].includes(source.slice(cursor.from, cursor.to)))
|
|
408
|
+
return [];
|
|
409
|
+
} while (cursor.next());
|
|
410
|
+
const bindings = /* @__PURE__ */ new Map();
|
|
411
|
+
if (language === "python") bindings.set("open", { kind: "symbol", value: "open" });
|
|
412
|
+
else bindings.set("require", { kind: "symbol", value: "require" });
|
|
413
|
+
if (language === "javascript") {
|
|
414
|
+
for (const statement of children(tree.topNode)) {
|
|
415
|
+
if (statement.name !== "FunctionDeclaration") continue;
|
|
416
|
+
const name = statement.getChild("VariableDefinition");
|
|
417
|
+
if (name) bindings.set(source.slice(name.from, name.to), void 0);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
const paths = /* @__PURE__ */ new Set();
|
|
421
|
+
const text = (node) => source.slice(node.from, node.to);
|
|
422
|
+
const symbol = (value) => ({ kind: "symbol", value });
|
|
423
|
+
const bind = (name, value) => {
|
|
424
|
+
bindings.set(name, bindings.has(name) ? void 0 : value);
|
|
425
|
+
};
|
|
426
|
+
const forget = () => {
|
|
427
|
+
for (const name of bindings.keys()) bindings.set(name, void 0);
|
|
428
|
+
};
|
|
429
|
+
const args = (node) => children(node.getChild("ArgList")).filter((child) => !["(", ")", ","].includes(child.name));
|
|
430
|
+
const resolveValue = (node) => {
|
|
431
|
+
if (!node) return;
|
|
432
|
+
if (node.name === "String") {
|
|
433
|
+
const value = literal(text(node));
|
|
434
|
+
return value === void 0 ? void 0 : { kind: "string", value };
|
|
435
|
+
}
|
|
436
|
+
if (node.name === "VariableName") return bindings.get(text(node));
|
|
437
|
+
if (node.name === "MemberExpression") {
|
|
438
|
+
const [base, dot, property] = children(node);
|
|
439
|
+
if (dot?.name !== "." || property?.name !== "PropertyName") return;
|
|
440
|
+
const owner = resolveValue(base);
|
|
441
|
+
const name = text(property);
|
|
442
|
+
if (owner?.kind === "symbol") {
|
|
443
|
+
if (owner.value === "pathlib" && name === "Path") return symbol("Path");
|
|
444
|
+
if (owner.value === "fs" && name === "promises") return symbol("fs");
|
|
445
|
+
if (owner.value === "fs" && WRITERS.has(name)) return symbol("write");
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
if (node.name === "CallExpression") {
|
|
449
|
+
const callee = resolveValue(node.firstChild ?? void 0);
|
|
450
|
+
const parameters = args(node);
|
|
451
|
+
const first = resolveValue(parameters[0]);
|
|
452
|
+
if (callee?.kind === "symbol" && first?.kind === "string" && parameters.length === 1) {
|
|
453
|
+
if (callee.value === "Path") return { kind: "path", value: first.value };
|
|
454
|
+
if (callee.value === "require" && FS_MODULES.has(first.value)) return symbol("fs");
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
};
|
|
458
|
+
const inspect = (node) => {
|
|
459
|
+
if (/Function|Class|Lambda|ArrowFunction/.test(node.name)) return;
|
|
460
|
+
if (["AssignmentExpression", "UpdateExpression", "NamedExpression"].includes(node.name) || node.name.includes("Comprehension")) {
|
|
461
|
+
forget();
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
if (node.name === "CallExpression") {
|
|
465
|
+
const calleeNode = node.firstChild;
|
|
466
|
+
if (!calleeNode) return;
|
|
467
|
+
const callee = resolveValue(calleeNode);
|
|
468
|
+
const parameters = args(node);
|
|
469
|
+
const first = resolveValue(parameters[0]);
|
|
470
|
+
if (callee?.kind === "symbol" && callee.value === "write" && first?.kind === "string")
|
|
471
|
+
paths.add(first.value);
|
|
472
|
+
if (callee?.kind === "symbol" && callee.value === "open") {
|
|
473
|
+
const modeAt = parameters.findIndex(
|
|
474
|
+
(p) => p.name === "VariableName" && text(p) === "mode"
|
|
475
|
+
);
|
|
476
|
+
const mode = resolveValue(modeAt < 0 ? parameters[1] : parameters[modeAt + 2]);
|
|
477
|
+
if (first && ["string", "path"].includes(first.kind) && mode?.kind === "string" && /^[rwax][bt+]*$/.test(mode.value) && /[wax+]/.test(mode.value))
|
|
478
|
+
paths.add(first.value);
|
|
479
|
+
}
|
|
480
|
+
if (calleeNode.name === "MemberExpression") {
|
|
481
|
+
const [base, dot, property] = children(calleeNode);
|
|
482
|
+
const owner = resolveValue(base);
|
|
483
|
+
if (dot?.name === "." && property && owner?.kind === "path" && ["write_text", "write_bytes"].includes(text(property)))
|
|
484
|
+
paths.add(owner.value);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
for (const child of children(node)) inspect(child);
|
|
488
|
+
};
|
|
489
|
+
const importStatement = (node) => {
|
|
490
|
+
const statement = text(node).trim().replace(/;$/, "");
|
|
491
|
+
if (language === "python") {
|
|
492
|
+
const module = /^import pathlib(?: as (\w+))?$/.exec(statement);
|
|
493
|
+
const path = /^from pathlib import Path(?: as (\w+))?$/.exec(statement);
|
|
494
|
+
if (module) bind(module[1] ?? "pathlib", symbol("pathlib"));
|
|
495
|
+
else if (path) bind(path[1] ?? "Path", symbol("Path"));
|
|
496
|
+
else forget();
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
const sourceNode = node.getChild("String");
|
|
500
|
+
if (!sourceNode || !FS_MODULES.has(literal(text(sourceNode)) ?? "")) {
|
|
501
|
+
forget();
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
const group = node.getChild("ImportGroup");
|
|
505
|
+
if (group) {
|
|
506
|
+
for (const entry of text(group).slice(1, -1).split(",")) {
|
|
507
|
+
const match = /^\s*(\w+)(?:\s+as\s+(\w+))?\s*$/.exec(entry);
|
|
508
|
+
if (match)
|
|
509
|
+
bind(match[2] ?? match[1], WRITERS.has(match[1]) ? symbol("write") : void 0);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
const name = node.getChild("VariableDefinition");
|
|
513
|
+
if (name) bind(text(name), symbol("fs"));
|
|
514
|
+
};
|
|
515
|
+
const statements = children(tree.topNode).flatMap(
|
|
516
|
+
(statement) => statement.name === "StatementGroup" ? children(statement) : [statement]
|
|
517
|
+
);
|
|
518
|
+
for (const statement of statements) {
|
|
519
|
+
if (["Comment", "LineComment", "BlockComment", ";"].includes(statement.name)) continue;
|
|
520
|
+
if (["ImportStatement", "ImportDeclaration"].includes(statement.name)) {
|
|
521
|
+
importStatement(statement);
|
|
522
|
+
continue;
|
|
523
|
+
}
|
|
524
|
+
if (statement.name === "AssignStatement" || statement.name === "VariableDeclaration") {
|
|
525
|
+
const parts = children(statement).filter(
|
|
526
|
+
(p) => !["const", "let", "var", ";"].includes(p.name)
|
|
527
|
+
);
|
|
528
|
+
const [target, operator, expression] = parts;
|
|
529
|
+
if (parts.length !== 3 || !target || !operator || text(operator) !== "=") {
|
|
530
|
+
forget();
|
|
531
|
+
continue;
|
|
532
|
+
}
|
|
533
|
+
inspect(expression);
|
|
534
|
+
if (["VariableName", "VariableDefinition"].includes(target.name) && IDENTIFIER.test(text(target)))
|
|
535
|
+
bind(text(target), resolveValue(expression));
|
|
536
|
+
else if (target.name === "ObjectPattern" && resolveValue(expression)?.kind === "symbol" && resolveValue(expression)?.value === "fs") {
|
|
537
|
+
for (const entry of text(target).slice(1, -1).split(",")) {
|
|
538
|
+
const match = /^\s*(\w+)(?:\s*:\s*(\w+))?\s*$/.exec(entry);
|
|
539
|
+
if (match)
|
|
540
|
+
bind(match[2] ?? match[1], WRITERS.has(match[1]) ? symbol("write") : void 0);
|
|
541
|
+
else forget();
|
|
542
|
+
}
|
|
543
|
+
} else forget();
|
|
544
|
+
} else if (statement.name === "ExpressionStatement") inspect(statement);
|
|
545
|
+
else if (statement.name === "WithStatement") {
|
|
546
|
+
for (const child of children(statement)) {
|
|
547
|
+
if (child.name === "as") forget();
|
|
548
|
+
if (child.name === "CallExpression") inspect(child);
|
|
549
|
+
}
|
|
550
|
+
forget();
|
|
551
|
+
} else forget();
|
|
552
|
+
}
|
|
553
|
+
return [...paths];
|
|
554
|
+
} catch {
|
|
555
|
+
return [];
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
// src/hooks/shell-targets.ts
|
|
353
560
|
var OUTPUT_REDIRECTS = /* @__PURE__ */ new Set([">", ">>", ">|", "&>", "&>>"]);
|
|
354
561
|
var READ_ONLY_COMMANDS = new Set(": cat echo false printf pwd test true [".split(" "));
|
|
355
562
|
var SINKS = /* @__PURE__ */ new Set(["/dev/null", "/dev/stdout", "/dev/stderr"]);
|
|
@@ -865,6 +1072,39 @@ function operands(words, short = "", long = /* @__PURE__ */ new Set()) {
|
|
|
865
1072
|
}
|
|
866
1073
|
return result;
|
|
867
1074
|
}
|
|
1075
|
+
function embeddedScript(command, name, state) {
|
|
1076
|
+
unknown(state);
|
|
1077
|
+
if (state.cwdUncertain || command.prefix.length) return;
|
|
1078
|
+
const words = command.suffix.map(
|
|
1079
|
+
(word) => (word.parts ? word.parts.every(staticPart) : staticWord(word) !== void 0) && !word.value.includes("\0") ? word.value : void 0
|
|
1080
|
+
);
|
|
1081
|
+
if (words.some((word) => word === void 0)) return;
|
|
1082
|
+
const args = words;
|
|
1083
|
+
const language = name === "node" ? "javascript" : "python";
|
|
1084
|
+
if (language === "javascript" && /^--input-type=(module|commonjs)$/.test(args[0] ?? ""))
|
|
1085
|
+
args.shift();
|
|
1086
|
+
const inlineFlag = language === "python" ? ["-c"] : ["-e", "--eval"];
|
|
1087
|
+
let source;
|
|
1088
|
+
if (args.length === 2 && inlineFlag.includes(args[0])) source = args[1];
|
|
1089
|
+
else if (args.length === 0 || args.length === 1 && args[0] === "-") {
|
|
1090
|
+
const input = command.redirects.filter((redirect) => redirect.operator.startsWith("<"));
|
|
1091
|
+
const heredoc = input[0];
|
|
1092
|
+
if (input.length === 1 && heredoc.operator === "<<" && heredoc.heredocQuoted === true)
|
|
1093
|
+
source = heredoc.content;
|
|
1094
|
+
}
|
|
1095
|
+
if (source !== void 0)
|
|
1096
|
+
for (const path of scriptWriteTargets(source, language)) state.paths.add(path);
|
|
1097
|
+
}
|
|
1098
|
+
function changesDirectory(value) {
|
|
1099
|
+
if (Array.isArray(value)) return value.some(changesDirectory);
|
|
1100
|
+
if (!value || typeof value !== "object") return false;
|
|
1101
|
+
const node = value;
|
|
1102
|
+
if (node.type === "Command" && ["cd", "pushd", "popd", "eval", "source", "."].includes(
|
|
1103
|
+
staticWord(value.name) ?? ""
|
|
1104
|
+
))
|
|
1105
|
+
return true;
|
|
1106
|
+
return Object.values(node).some(changesDirectory);
|
|
1107
|
+
}
|
|
868
1108
|
function visitCommand(command, state) {
|
|
869
1109
|
const name = staticWord(command.name);
|
|
870
1110
|
const literalApplyPatch = name === "apply_patch" && !command.redirects.some((redirect) => redirect.operator === "<<-");
|
|
@@ -873,7 +1113,9 @@ function visitCommand(command, state) {
|
|
|
873
1113
|
} else {
|
|
874
1114
|
for (const redirect of command.redirects) visitRedirect(redirect, state);
|
|
875
1115
|
}
|
|
876
|
-
if (
|
|
1116
|
+
if (name && (name === "node" || /^python(?:3(?:\.\d+)?)?$/.test(name))) {
|
|
1117
|
+
embeddedScript(command, name, state);
|
|
1118
|
+
} else if (!name || name.includes("/") || !literalApplyPatch && command.suffix.some((word) => !staticWord(word))) {
|
|
877
1119
|
unknown(state);
|
|
878
1120
|
} else if (literalApplyPatch) {
|
|
879
1121
|
} else if (!READ_ONLY_COMMANDS.has(name) && !knownNoWorktreeMutation(name, staticArgs(command.suffix))) {
|
|
@@ -932,7 +1174,8 @@ function analyzeShellTargets(source) {
|
|
|
932
1174
|
paths: /* @__PURE__ */ new Set(),
|
|
933
1175
|
complete: !script.errors?.length,
|
|
934
1176
|
mutation: false,
|
|
935
|
-
definiteEdit: false
|
|
1177
|
+
definiteEdit: false,
|
|
1178
|
+
cwdUncertain: changesDirectory(script)
|
|
936
1179
|
};
|
|
937
1180
|
for (const statement of script.commands) visitStatement(statement, state);
|
|
938
1181
|
if (script.errors?.length) state.mutation = true;
|