pi-odd-worktree 3.1.1 → 3.3.0
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 +2 -1
- package/extensions/odd-worktree-tools.ts +83 -3
- package/lib/bash-activity.js +405 -32
- package/lib/bash-inline-script.js +314 -0
- package/lib/codegraph-guard.js +36 -19
- package/lib/codegraph-prompt/generic.md +1 -1
- package/lib/codegraph-prompt/orchestrator.md +7 -7
- package/lib/codegraph-session.js +10 -2
- package/lib/odd-prompt/odd-worktrees-child.md +3 -0
- package/lib/odd-prompt/odd-worktrees.md +11 -7
- package/lib/odd-worktrees-prompt.js +68 -14
- package/lib/skill-read-guard.js +397 -0
- package/lib/worktree-guard.js +205 -5
- package/package.json +1 -1
- package/tools/bash-activity.test.js +400 -35
- package/tools/codegraph-guard.test.js +109 -11
- package/tools/codegraph-rules.test.js +8 -8
- package/tools/codegraph-session.test.js +45 -3
- package/tools/odd-worktrees-prompt.test.js +98 -11
- package/tools/package-surface.test.js +15 -1
- package/tools/skill-read-guard.test.js +316 -0
- package/tools/worktree-write-guard.test.js +516 -0
package/README.md
CHANGED
|
@@ -71,10 +71,11 @@ The full rules of each step, including every refusal, are in [Create, list, move
|
|
|
71
71
|
- **Cards follow your shell.** Tool and warp cards use the card style Gentle Shell publishes, and a click expands that card only. See [card style](docs/reference.md#card-style-follows-your-shell).
|
|
72
72
|
- **Tool headings can name the activity.** With `activity` chosen on the `Card tags` line, a bash card whose heading shows the whole command is headed with the family its command names (mark and word) instead of `$`, and a `grep`, `find` or `ls` card is headed `⌕ exploring` instead of its own glyph and name, while a `read` — which runs no shell command — keeps the host's own card, colour and width; a bash command the classifier cannot name, or a heading that hides part of it, keeps the host's `$`. See [the cards the `activity` design paints](docs/reference.md#the-cards-the-activity-design-paints).
|
|
73
73
|
- **File calls on a skill or an ODD are cards too.** While `Card tags` answers with `activity` for the tool being painted, a `read`, `edit` or `write` call whose path names a skill (anything below a `skills` folder) or an ODD (anything below an `odd` folder) heads as that file, with the tool, the path and a read's line range; its Markdown body — the whole document when expanded, the first rows when collapsed — is drawn by Pi's own renderer in the theme's Markdown roles, and an edit always keeps its diff. Any other file call, and every call while that line answers anything else, is the host's own row. See [the file cards](docs/reference.md#the-file-cards).
|
|
74
|
+
- **`edit` and `write` cannot land in the principal checkout's default branch.** A write whose path is inside the principal checkout of the session's repository, while that checkout is on the default branch, is refused with one line pointing at `worktree_list` and `worktree_create`. Paths outside the repository, anything under the OS temp directories, other repositories and linked worktrees are never blocked. See [the guard](docs/reference.md#the-edit-and-write-guard).
|
|
74
75
|
- **`bash` cannot leave the principal checkout's default branch.** A `git worktree add` or `git worktree list` is refused in any cwd and pointed at `worktree_create` and `worktree_list`; in the principal checkout, a switch that would leave the branch it is on is refused while that branch is the repository's default, and creating a branch is not blocked. See [the guards](docs/reference.md#the-bash-guards).
|
|
75
76
|
- **Two blocks in the system prompt.** `## ODD worktrees` tells the agent how worktrees and ODDs work. `## CodeGraph` tells a session that already holds a CodeGraph tool how to use it, with one text per role. Both are appended after the host's own text, and `ODD_WORKTREE_PROMPT=0` suppresses them. See [the prompt blocks](docs/reference.md#the--odd-worktrees-block-in-the-system-prompt).
|
|
76
77
|
- **CodeGraph stays fresh, only when its CLI is installed.** At session start the package creates or syncs the checkout's index and warms its daemon, and makes sure your global `mcp.json` has the `codegraph` entry (it adds it or fixes only the differing fields and keeps the rest). It also syncs after a compaction, after a native `codegraph init` and after an `edit` or `write`, in the background and without ever blocking you. See [CodeGraph](docs/reference.md#codegraph-index-daemon-and-mcp-entry). Its tool rows are drawn as a card.
|
|
77
|
-
- **Two reminders keep a session on the CodeGraph rule.** The first `grep`, `find`, `ls`, `read` or `bash` search in a checkout gets one sentence appended to its result: use `codegraph` first, or — for another checkout — call `mcp__codegraph__codegraph_explore` with that path as `projectPath`.
|
|
78
|
+
- **Two reminders keep a session on the CodeGraph rule.** The first `grep`, `find`, `ls`, `read` or `bash` search in a checkout gets one sentence appended to its result: use `codegraph` first, or — for another checkout — call `mcp__codegraph__codegraph_explore` with that path as `projectPath`. Each message that starts with a search instead of the graph gets the one about your own checkout once, on its first search, and no later search of it repeats it (a new request re-arms it, a compaction starts it from zero); the one about another checkout stays once per checkout; neither is ever a block. See [the reminders](docs/reference.md#the-two-codegraph-reminders).
|
|
78
79
|
- **Deliberately absent.** No customize panel, no plugin-tools toggles, no companion-app integration and no worktree-to-issue association. There is nothing to configure here: the tools design — and, with it, the skill/ODD file cards — is chosen on the bridge's own `Card tags` line (or `Card bash`, on an older bridge), so this package owns no preference of its own.
|
|
79
80
|
|
|
80
81
|
## Documentation
|
|
@@ -3064,6 +3064,30 @@ function readCurrentBranch(git, root) {
|
|
|
3064
3064
|
return readGitTextSync(git, root, ["symbolic-ref", "--quiet", "--short", "HEAD"]);
|
|
3065
3065
|
}
|
|
3066
3066
|
|
|
3067
|
+
// invariant 22: the skill-read guard, the second `tool_call` observation that REFUSES a
|
|
3068
|
+
// `bash` call — a reader (`cat`, `sed -n`, `head`, …) pointed at a skill file, which the
|
|
3069
|
+
// `read` tool is for. The decision is `lib/skill-read-guard.js`'s: text-only, over the
|
|
3070
|
+
// command string, and only for the `bash` tool. Nothing is registered here either — no
|
|
3071
|
+
// command, no tool, no option and no setting — and `ODD_WORKTREE_GUARD=0`, the worktree
|
|
3072
|
+
// guard's own switch, turns this guard off the same way, read per call.
|
|
3073
|
+
function guardSkillReadBashCall(event) {
|
|
3074
|
+
try {
|
|
3075
|
+
if (process.env.ODD_WORKTREE_GUARD === "0") return undefined;
|
|
3076
|
+
if (!event || event.toolName !== "bash") return undefined;
|
|
3077
|
+
const guard = libRequire("skill-read-guard.js");
|
|
3078
|
+
if (!guard || typeof guard.decideSkillReadGuard !== "function") return undefined;
|
|
3079
|
+
const input = event.input || {};
|
|
3080
|
+
const decision = guard.decideSkillReadGuard(input.command);
|
|
3081
|
+
if (decision && decision.block === true && typeof decision.reason === "string") {
|
|
3082
|
+
return { block: true, reason: decision.reason };
|
|
3083
|
+
}
|
|
3084
|
+
return undefined;
|
|
3085
|
+
} catch {
|
|
3086
|
+
// invariant 22: the guard never throws into the host, and a command it cannot judge passes.
|
|
3087
|
+
return undefined;
|
|
3088
|
+
}
|
|
3089
|
+
}
|
|
3090
|
+
|
|
3067
3091
|
// The registered `tool_call` handler: the guard's one host surface. A non-`bash` call
|
|
3068
3092
|
// returns before any module is read, and the git answers ride in as the guard's seams:
|
|
3069
3093
|
// the identity and the default branch memoized per checkout, the current branch read
|
|
@@ -3099,6 +3123,51 @@ function guardWorktreeBashCall(event, ctx) {
|
|
|
3099
3123
|
}
|
|
3100
3124
|
}
|
|
3101
3125
|
|
|
3126
|
+
// S4 (T3): the WRITE guard's `tool_call` handler, a sibling of the bash one on the same
|
|
3127
|
+
// hook. An `edit` or `write` whose path lies inside the primary checkout, while that
|
|
3128
|
+
// checkout is on the repository's default branch, is refused with one sentence (L1:
|
|
3129
|
+
// the human chose a block, not a warning). Every other tool, and every path outside the
|
|
3130
|
+
// session's own repository — tmp, another repository, a linked worktree (L2) — passes,
|
|
3131
|
+
// and the same `ODD_WORKTREE_GUARD=0` switch turns it off with the bash guards.
|
|
3132
|
+
//
|
|
3133
|
+
// It reads the touched paths the naming handler already reads (`oddTouchedPaths` over
|
|
3134
|
+
// the call's own arguments) and its cwd the same way (`oddEventCwd`), and hands the
|
|
3135
|
+
// guard the SAME memoized identity/default-branch seams, so the two guards can never
|
|
3136
|
+
// disagree about which checkout the session stands in. The current branch is read
|
|
3137
|
+
// fresh for every judgement: the checkout's own answer, never a remembered one.
|
|
3138
|
+
const WRITE_GUARD_TOOLS = new Set(["edit", "write"]);
|
|
3139
|
+
|
|
3140
|
+
function guardWorktreeWriteCall(event, ctx) {
|
|
3141
|
+
try {
|
|
3142
|
+
if (process.env.ODD_WORKTREE_GUARD === "0") return undefined;
|
|
3143
|
+
const toolName = oddToolNameOf(event);
|
|
3144
|
+
if (!WRITE_GUARD_TOOLS.has(toolName)) return undefined;
|
|
3145
|
+
const paths = oddTouchedPaths(oddArgsOf(event));
|
|
3146
|
+
if (paths.length === 0) return undefined;
|
|
3147
|
+
const guard = libRequire("worktree-guard.js");
|
|
3148
|
+
if (!guard || typeof guard.decideWriteGuard !== "function") return undefined;
|
|
3149
|
+
const git = libRequire("worktree-git.js");
|
|
3150
|
+
const decision = guard.decideWriteGuard({
|
|
3151
|
+
toolName,
|
|
3152
|
+
paths,
|
|
3153
|
+
cwd: oddEventCwd(event, ctx),
|
|
3154
|
+
repoIdentity: (cwd) => cachedRepoIdentity(git, cwd),
|
|
3155
|
+
// The owner of a written path's directory is read live (only for a path already
|
|
3156
|
+
// inside the principal), because a nested worktree can appear during the session.
|
|
3157
|
+
ownerIdentity: (dir) => git.repoIdentity(String(dir)),
|
|
3158
|
+
defaultBranch: (root) => cachedDefaultBranch(git, root),
|
|
3159
|
+
currentBranch: (root) => readCurrentBranch(git, root),
|
|
3160
|
+
});
|
|
3161
|
+
if (decision && decision.block === true && typeof decision.reason === "string") {
|
|
3162
|
+
return { block: true, reason: decision.reason };
|
|
3163
|
+
}
|
|
3164
|
+
return undefined;
|
|
3165
|
+
} catch {
|
|
3166
|
+
// S8: the guard never throws into the host, and a call it cannot judge passes.
|
|
3167
|
+
return undefined;
|
|
3168
|
+
}
|
|
3169
|
+
}
|
|
3170
|
+
|
|
3102
3171
|
// ---------------------------------------------------------------------------
|
|
3103
3172
|
// `/warp <name>` (S23): move the SESSION to another
|
|
3104
3173
|
// checkout by NAME.
|
|
@@ -9776,11 +9845,22 @@ function registerOddWorktreeSurfaceEntries(pi) {
|
|
|
9776
9845
|
startupEpoch += 1;
|
|
9777
9846
|
});
|
|
9778
9847
|
pi.on("tool_call", (event, ctx) => handleWorktreeOddEvent(event, ctx, pi));
|
|
9779
|
-
// S1/S3/S4/S9: the worktree guard, the
|
|
9848
|
+
// S1/S3/S4/S9: the worktree guard, the first `tool_call` observation that refuses a
|
|
9780
9849
|
// `bash` command instead of observing it. It sits beside the naming handler and is
|
|
9781
|
-
// the
|
|
9782
|
-
//
|
|
9850
|
+
// one of the two handlers that return a `block` answer — the skill-read guard, below,
|
|
9851
|
+
// is the other; every other tool call is left exactly as the host proposed it. Nothing
|
|
9852
|
+
// about it is callable by the agent (S7).
|
|
9783
9853
|
pi.on("tool_call", (event, ctx) => guardWorktreeBashCall(event, ctx));
|
|
9854
|
+
// S4 (T3): the write guard, a second `tool_call` observation that refuses an `edit`
|
|
9855
|
+
// or `write` into the primary checkout while it sits on the default branch. It is a
|
|
9856
|
+
// sibling of the bash guard, not a part of it: the two read different inputs, and a
|
|
9857
|
+
// `bash` call and a file write are refused for different reasons.
|
|
9858
|
+
pi.on("tool_call", (event, ctx) => guardWorktreeWriteCall(event, ctx));
|
|
9859
|
+
// invariant 22: the skill-read guard, the second refusal and the guard registered LAST
|
|
9860
|
+
// of the two, so a call that would break both shows the worktree refusal. It reads the
|
|
9861
|
+
// command text only, shares the same `ODD_WORKTREE_GUARD=0` switch, and adds no
|
|
9862
|
+
// command, tool, option or setting of its own.
|
|
9863
|
+
pi.on("tool_call", (event) => guardSkillReadBashCall(event));
|
|
9784
9864
|
pi.on("tool_result", (event, ctx) => handleWorktreeOddEvent(event, ctx, pi, true));
|
|
9785
9865
|
// S10 (T9): ONE `tool_result` observation for the rail's forced refresh. It
|
|
9786
9866
|
// answers the `bash` tool only — every other tool returns before the classifier
|