@chrok/pi-braid 0.1.2 → 0.1.3

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 CHANGED
@@ -57,8 +57,8 @@ an explicit per-turn planning policy to Pi's system prompt and tool metadata:
57
57
 
58
58
  - for code reviews, bug investigations, design comparisons, test planning, or
59
59
  changes spanning multiple files, call Braid first when two or more concerns
60
- can be handled independently; nodes can inspect the project and edit isolated
61
- worktrees in Git repositories;
60
+ can be handled independently; use `workspace: "read-only"` for analysis,
61
+ review, routing, and synthesis, and worktrees for implementation;
62
62
  - do not use Braid for simple one-step answers, trivial direct edits, or shell
63
63
  work; keep tests and shell commands in the parent agent;
64
64
  - the user does not need to say “Braid” or design the graph;
@@ -164,15 +164,41 @@ They make no provider requests.
164
164
 
165
165
  Core owns workspace preparation, checkpointing, serialization, and cleanup for
166
166
  all integrations. Pi exposes `read` and `ls` in all directories, plus search tools whose local dependencies are available.
167
- In Git, execute and decision nodes also get `write`/`edit` restricted to their own
168
- detached worktree, plus local Git inspection. Outside Git, filesystem tools stay
169
- read-only. Nodes never receive shell commands or a test runner.
167
+ In Git, execute and decision nodes default to `write`/`edit` restricted to their
168
+ own detached worktree, plus local Git inspection. Set `workspace: "read-only"`
169
+ to keep read tools and Git inspection without write/edit tools or a worktree.
170
+ Omit `workspace` or use `"worktree"` for implementation or a fixed snapshot.
171
+ Outside Git, both modes remain read-only. Nodes never receive shell commands or
172
+ a test runner. The `workspace` field is forbidden on merge nodes.
173
+
174
+ Read-only nodes inspect the live source directory at the original `cwd`, including
175
+ accessible ignored files. They create no snapshot, checkpoint, or merge source.
176
+ Parent edits and concurrent merges may change what they read during execution.
177
+ Implementation changes reach the source only through integration; a downstream
178
+ review can inspect a predecessor worktree/checkpoint explicitly, or run after a
179
+ merge to review the integrated source. Use a read-only execute node to summarize
180
+ findings, and a merge node to integrate file changes.
181
+
182
+ For example, this graph reviews two concerns before implementing a fix. Core
183
+ invokes an automatic merge only if the implementation leaves file changes:
184
+
185
+ ```json
186
+ {
187
+ "goal": "Review the cache and fix confirmed problems.",
188
+ "nodes": [
189
+ { "type": "execute", "id": "correctness", "workspace": "read-only", "prompt": "Review cache correctness." },
190
+ { "type": "execute", "id": "tests", "workspace": "read-only", "prompt": "Inspect test coverage and identify missing cases; do not run tests." },
191
+ { "type": "execute", "id": "fix", "prompt": "Implement confirmed fixes and regression tests from both reviews." }
192
+ ],
193
+ "edges": [{ "from": "correctness", "to": "fix" }, { "from": "tests", "to": "fix" }]
194
+ }
195
+ ```
170
196
 
171
197
  The initial snapshot includes tracked staged/unstaged changes, deletions, and
172
198
  non-ignored untracked files. It preserves the source index and files. Ignored
173
199
  files are not copied; submodules are not initialized or recursively snapshotted,
174
200
  and Pi rejects writes inside them to keep checkpoint recovery complete.
175
- Every worker shares that baseline until a merge ends, after which new workers
201
+ Workers using worktrees share that baseline until a merge ends, after which new workers
176
202
  snapshot the current source checkout. Uncommitted predecessor changes are not
177
203
  implicitly applied to downstream workers. Their paths and checkpoint refs are
178
204
  available as context for inspection.
@@ -186,8 +212,12 @@ Core never automatically merges or cherry-picks. The agent must call
186
212
  source. Tool errors and conflicts go back to the agent for recovery. Failed
187
213
  predecessors pass errors and partial work along unconditional edges.
188
214
 
189
- Core removes processed source worktrees after the merge agent finishes. If any
190
- worktrees remain after declared nodes settle, core appends a final merge agent.
215
+ Core removes processed source worktrees after the merge agent finishes. After
216
+ declared nodes settle, unchanged worktrees are released as `discarded` with reason
217
+ `No changes from snapshot`, retaining recovery refs. Only remaining worktrees
218
+ with changes trigger a final merge agent, so analysis-only graphs keep their
219
+ declared terminal outputs without an extra model call. Explicit merge nodes run
220
+ even for unchanged sources.
191
221
  Its model, tool calls, budgets, events, and usage behave like any other node.
192
222
  Missing finish calls, unresolved conflicts, or archived sources fail the merge.
193
223
  Cancellation, timeout, and failure archive remaining changes and clean worktrees;
@@ -200,6 +230,8 @@ worktrees from cleaned workspaces. Worktrees use
200
230
  recoverable from `refs/braid/checkpoints/*`. Use `git show <checkpointRef>:<path>`
201
231
  or `git diff <snapshotCommit> <checkpointRef>` to inspect archived changes.
202
232
  Remove individual recovery refs with `git update-ref -d <ref>` once reviewed.
233
+ Explicit read-only nodes appear with mode `read-only` and state `ready`, without
234
+ checkpoint or backup refs; their files stay in the source directory.
203
235
 
204
236
  A failed merge does not reset partial changes or conflict state in the source
205
237
  checkout. Its `backupRef` preserves the pre-agent snapshot. Cleanup errors report
package/dist/display.js CHANGED
@@ -19,7 +19,7 @@ class FixedLines {
19
19
  const chartOutput = chartWidth <= width
20
20
  ? chart
21
21
  : [
22
- `[Flowchart needs ${chartWidth} columns; terminal width is ${width}. Expand your terminal to see it.]`,
22
+ truncateToWidth(`[Flowchart needs ${chartWidth} columns; terminal width is ${width}. Expand your terminal to see it.]`, width, ""),
23
23
  ];
24
24
  const output = [];
25
25
  let chartInserted = false;
package/dist/index.js CHANGED
@@ -25,9 +25,12 @@ const braidParameters = Type.Object({
25
25
  model: Type.Optional(Type.String({
26
26
  description: "Exact provider/modelId; default is the current Pi model",
27
27
  })),
28
+ workspace: Type.Optional(StringEnum(["read-only", "worktree"], {
29
+ description: "Execute/decision only; forbidden on merge nodes. Use read-only for analysis, review, routing, and synthesis: reads the live source directory with Git inspection, no writes or worktree. Omit or use worktree for implementation or a fixed snapshot in Git. Outside Git, both modes are read-only.",
30
+ })),
28
31
  choices: Type.Optional(Type.Array(text(), {
29
32
  minItems: 1,
30
- description: "Required on decision nodes; forbidden on execute nodes",
33
+ description: "Required on decision nodes; forbidden on execute and merge nodes",
31
34
  })),
32
35
  }, { additionalProperties: false }), { minItems: 1 }),
33
36
  edges: Type.Array(Type.Object({
@@ -43,9 +46,10 @@ const braidParameters = Type.Object({
43
46
  maxToolCalls: toolBudget("calls"),
44
47
  }, { additionalProperties: false })),
45
48
  }, { additionalProperties: false });
46
- const BRAID_FILESYSTEM_GUIDANCE = "In a Git repository, execute and decision nodes get individual writable worktrees with read, ls, write, edit, and Git inspection. Search tools grep/find are exposed only when their local rg/fd dependencies are available. " +
49
+ const BRAID_FILESYSTEM_GUIDANCE = "Set workspace=read-only on execute/decision nodes for analysis, review, routing, and synthesis that do not need file edits. These nodes read the live source directory with read, ls, and Git inspection in Git repositories; they get no write/edit tools, snapshot, worktree, or merge source. Reads can observe parent edits or concurrent merges. " +
50
+ "Omit workspace or use workspace=worktree for implementation or when a fixed snapshot is needed. In a Git repository, these execute and decision nodes get individual writable worktrees with read, ls, write, edit, and Git inspection. Search tools grep/find are exposed only when their local rg/fd dependencies are available. " +
47
51
  "Worktrees include tracked changes and non-ignored untracked files. Merge nodes operate in the source checkout and decide whether to merge, cherry-pick, apply, or discard predecessor changes; core never makes that choice. " +
48
- "Merge agents must call finish_merge for every source; core checkpoints changes and removes processed worktrees. Core appends a final merge agent for remaining worktrees. Failed predecessors pass their errors and partial work along unconditional edges. " +
52
+ "Do not set workspace on merge nodes. Use a read-only execute node to summarize findings; use a merge node only to integrate file changes. Merge agents must call finish_merge for every source; core checkpoints changes and removes processed worktrees. Core releases unchanged worktrees and appends a final merge agent only for remaining changed worktrees; explicit merge nodes always run. Failed predecessors pass their errors and partial work along unconditional edges. " +
49
53
  "Outside Git, nodes have read and ls, plus grep/find when their local dependencies are available. Shell commands and tests remain unavailable in all nodes. " +
50
54
  "Inspect braid_status for integration outcomes and recovery checkpoint refs, then run tests in the parent. Avoid concurrent parent edits while a merge agent owns the source checkout.";
51
55
  const BRAID_USAGE_GUIDANCE = [
@@ -69,7 +73,7 @@ export function createBraidTools(jobs) {
69
73
  "Do not use it for a simple one-step answer or trivial direct edit. " +
70
74
  "Use braid_status(jobId) for progress and results, or braid_cancel(jobId) to stop it. A completion reminder resumes the agent if idle; do independent work or end your turn instead of polling. Humans can open /braid for the live flow panel. " +
71
75
  "Read result.status: failed graphs can still return successful terminal outputs.",
72
- promptSnippet: "Use FIRST for nontrivial code review/debug/design/implementation work; parallelize analysis or edits in isolated Git worktrees and use merge nodes to integrate changes",
76
+ promptSnippet: "Use FIRST for nontrivial code review/debug/design/implementation work; set workspace=read-only for analysis/synthesis, use worktrees for edits and merge nodes for integration",
73
77
  promptGuidelines: [
74
78
  "Call braid before direct repository inspection when a code task has two or more separable review, debugging, design, test-planning, or implementation concerns; the Braid nodes can inspect the project and edit isolated Git worktrees.",
75
79
  "Use parallel execute nodes for independent analysis or implementation, execute nodes to synthesize findings, and merge nodes to integrate file changes. The user does not need to mention Braid or design the graph.",
package/dist/runner.js CHANGED
@@ -97,7 +97,9 @@ export function createPiRunner(registry, onUsageOrOptions, cwd = process.cwd())
97
97
  ? "You may write and edit files inside your own isolated Git worktree. Use workingDirectory as your cwd; do not write to sourceRoot or any other node's worktree. " +
98
98
  "Nodes start from the current core snapshot of tracked changes and non-ignored untracked files. After merge nodes, newly started workers see the updated source checkout. Inspect predecessor checkpoints with git show when their worktrees have been removed. " +
99
99
  "Describe your changes in your final answer. A merge agent will review your checkpoint and core will clean up the worktree. "
100
- : "This node has no writable workspace assigned. Its filesystem tools are read-only; you cannot write or edit files. ") +
100
+ : "This node has no writable workspace assigned. Its filesystem tools are read-only; you cannot write or edit files. " +
101
+ "Read workingDirectory directly; it is a live directory, not an isolated snapshot, and may change during execution. " +
102
+ (request.git ? "Use Git inspection to review changes or predecessor checkpoints; predecessor edits are not automatically applied to this directory. " : "")) +
101
103
  mergeInstructions(request) +
102
104
  "You cannot run shell commands, run tests, or call arbitrary tools. " +
103
105
  (request.node.type === "merge" && workspace.mode === "read-only"
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@chrok/pi-braid",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "license": "MIT",
5
5
  "description": "Pi extension for Braid: background DAG jobs and a live flow panel",
6
6
  "type": "module",
7
7
  "dependencies": {
8
8
  "grok-mermaid": "^0.2.2",
9
- "@chrok/braid": "0.1.2"
9
+ "@chrok/braid": "0.1.3"
10
10
  },
11
11
  "peerDependencies": {
12
12
  "@earendil-works/pi-ai": "*",