@sage-protocol/pi-adapter 0.3.12 → 0.4.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
@@ -1,24 +1,32 @@
1
1
  # @sage-protocol/pi-adapter
2
2
 
3
- Sage integration for the pi coding agent runtime.
3
+ Sage integration for the Pi coding agent runtime.
4
4
 
5
5
  - **Pi agent**: [earendil-works/pi](https://github.com/earendil-works/pi) — extensible terminal coding harness
6
- - **Sage Protocol**: [sage-protocol/sage](https://github.com/sage-protocol/sage) — decentralized skill/library layer for AI agents
6
+ - **Compatibility**: tested with Pi `0.84.1`; package peer range `>=0.64.0 <0.85.0`
7
+ - **Sage Protocol**: [sage-protocol/sage](https://github.com/sage-protocol/sage) — decentralized capability/library layer for AI agents
7
8
 
8
9
  ## What It Does
9
10
 
10
- - Sage MCP tools (`hub_list_servers`, `hub_status`, `hub_session_list`, `hub_start_server`, `hub_stop_server`, `sage_search`, `sage_execute`, `sage_status`, `sage_behavior`)
11
- - **Compact tool UX** — Sage hub/external operations render concise inventory/session/start/search summaries in Pi instead of dumping raw JSON payloads
12
- - **Runtime-first hub helpers** — common hub runtime flows are Pi-native; admin hub mutations like adding custom servers remain generic `sage_execute` operations
13
- - **Visible skill loading** — shows loaded library/skill count at session start
14
- - **Dynamic session context** — wallet, libraries, and skill routing injected via `sage skill context --format pi`
15
- - Skill suggestions, RLM capture, and optional security scanning
16
- - **Thin harness packaging** — Sage-owned skills live under `packages/sage/skills/` and the curated Pi export surface, not inside this adapter package
11
+ - Exposes Sage MCP tools (`hub_list_servers`, `hub_status`, `hub_session_list`, `hub_start_server`, `hub_stop_server`, `sage_search`, `sage_execute`, `sage_status`, and `sage_behavior`)
12
+ - Lets Pi own skill discovery and loading through native `<available_skills>`, `/skill:<name>`, and full `SKILL.md` reads
13
+ - Injects SessionStart Sage context and shows the loaded library/skill inventory
14
+ - Captures prompts and responses for RLM feedback
15
+ - Observes truthful full native skill loads and writes source- and session-qualified load receipts
16
+ - Exposes `sage_mark_guided_use` in the packaged Pi extension so an agent can bind actually loaded, actually applied skills to the exact prompt capture through Sage's native-use daemon path
17
+ - Preserves optional security hooks and explicit subagent skill resolution
18
+ - Keeps Sage-owned skills under `packages/sage/skills/` and the curated Pi export surface rather than bundling copies in this adapter
19
+
20
+ The adapter does **not** call `sage suggest hook skill` for each prompt, inject
21
+ `sage-suggested-skills`, or render a suggestion-quality widget. It has no
22
+ suggestion auto-skip or auto-reject lifecycle. Manual `sage suggest skill
23
+ "<task>"` remains available when a person or agent explicitly wants CLI
24
+ ranking, but it is not automatic Pi injection.
17
25
 
18
26
  ## Install
19
27
 
20
28
  ```bash
21
- # pi CLI extension (no source changes)
29
+ # Pi CLI extension (no source changes)
22
30
  pi install npm:@sage-protocol/pi-adapter
23
31
 
24
32
  # SDK embedding
@@ -28,49 +36,95 @@ npm install @sage-protocol/pi-adapter
28
36
  ## Quick Start
29
37
 
30
38
  ```typescript
31
- import { createAgentSession, createCodingTools } from '@earendil-works/pi-coding-agent';
32
- import { createSageSessionConfig } from '@sage-protocol/pi-adapter';
39
+ import {
40
+ createAgentSession,
41
+ createCodingTools,
42
+ type ToolDefinition as PiToolDefinition,
43
+ } from '@earendil-works/pi-coding-agent';
44
+ import {
45
+ createSageSessionConfig,
46
+ type ToolDefinition as SageToolDefinition,
47
+ } from '@sage-protocol/pi-adapter';
48
+
49
+ function asPiCustomTools(tools: SageToolDefinition[]): PiToolDefinition[] {
50
+ // Type-shape compatibility across supported Pi minors; no runtime conversion.
51
+ return tools as unknown as PiToolDefinition[];
52
+ }
33
53
 
34
54
  const sage = await createSageSessionConfig({ source: 'pi-agent-core' });
55
+ const cwd = process.cwd();
56
+ const securedTools = sage.wrapToolsWithSecurity(createCodingTools(cwd));
35
57
  const { session } = await createAgentSession({
36
- tools: sage.wrapToolsWithSecurity(createCodingTools(process.cwd())),
37
- customTools: sage.customTools,
58
+ cwd,
59
+ noTools: 'builtin',
60
+ customTools: asPiCustomTools([...securedTools, ...sage.customTools]),
38
61
  });
39
62
  const disposeSageHooks = sage.setupHooks(session);
40
63
  ```
41
64
 
65
+ In current Pi, `tools` is a string allowlist. Tool definitions belong in
66
+ `customTools`; `noTools: 'builtin'` prevents duplicate unwrapped built-ins. The
67
+ single helper cast is only the TypeScript peer-version boundary between the
68
+ adapter's cross-minor tool shape and Pi's generic `ToolDefinition`—it does not
69
+ convert anything at runtime.
70
+
71
+ Pi presents its native skill catalog separately. When a skill applies, load it
72
+ with `/skill:<name>` or read its complete `SKILL.md`, follow the procedure, then
73
+ call `sage_mark_guided_use` only if the loaded procedure actually guided the
74
+ current turn. Loading alone is not use.
75
+
42
76
  ## API
43
77
 
44
78
  `createSageSessionConfig(config)` returns:
45
79
 
46
80
  ```typescript
47
81
  {
48
- customTools: ToolDefinition[]; // hub_list_servers, hub_status, hub_session_list, hub_start_server, hub_stop_server, sage_search, sage_execute, sage_status, sage_behavior
49
- mcpBridge: SageMcpBridge; // MCP process lifecycle
50
- setupHooks: (session: AgentSession) => () => void; // hooks + teardown
51
- wrapToolsWithSecurity: (tools: ToolDefinition[]) => ToolDefinition[]; // security wrap
82
+ customTools: ToolDefinition[]; // Sage hub and code-mode bridge tools
83
+ mcpBridge: SageMcpBridge; // MCP process lifecycle
84
+ setupHooks: (session: AgentSession) => () => void; // SessionStart + capture hooks
85
+ wrapToolsWithSecurity: (tools: ToolDefinition[]) => ToolDefinition[];
52
86
  }
53
87
  ```
54
88
 
55
- Config:
89
+ Recommended configuration:
56
90
 
57
91
  ```typescript
58
92
  interface SageP2Config {
59
93
  sageBin?: string; // default: "sage"
60
94
  sageProfile?: string; // Sage config profile
61
- suggestLimit?: number; // default: 3
62
- suggestDebounceMs?: number; // default: 800
63
95
  timeoutMs?: number; // default: 20_000
64
96
  enableRlmFeedback?: boolean;
65
97
  enableSecurityHooks?: boolean;
66
98
  source?: string; // default: "pi"
67
99
  env?: Record<string, string>;
100
+
101
+ /** @deprecated Low-level legacy suggestion compatibility; ignored by the default Pi path. */
102
+ suggestLimit?: number;
103
+ /** @deprecated Low-level legacy suggestion compatibility; ignored by the default Pi path. */
104
+ suggestDebounceMs?: number;
105
+ /** @deprecated Low-level legacy suggestion compatibility; ignored by the default Pi path. */
106
+ enableProvision?: boolean;
68
107
  }
69
108
  ```
70
109
 
110
+ ## Migrating to 0.4
111
+
112
+ Version 0.4 moves Pi skill discovery and loading to Pi's native skill surface.
113
+ The legacy `sageInjectSuggestion(...)` method is retained as a no-op for
114
+ compatibility, and default setup no longer performs automatic suggestions. Do
115
+ not call `sageInjectSuggestion`; use Pi's native skill load flow and call
116
+ `sage_mark_guided_use` after an actually loaded skill guides the current prompt.
117
+
118
+ The guided-use write requires both the Sage CLI command
119
+ `sage suggest feedback native-use` and daemon capability `native_skill_use_v1`.
120
+ Version 0.4.2 reports which runtime half is stale instead of collapsing either
121
+ case into a generic write failure. It never falls back to weaker suggestion
122
+ feedback. Update the CLI when it lacks the command; update and restart `saged`
123
+ when the daemon lacks the capability. Then retry the same declaration.
124
+
71
125
  ## Docs
72
126
 
73
- - [Usage Guide](./USAGE.md) — env vars, integration modes, project config
127
+ - [Usage Guide](./USAGE.md) — native skill flow, integration modes, env vars
74
128
  - [Setup](./docs/setup.md) — install and verify
75
129
  - [Developer Guide](./docs/developer.md) — build, test, CI contract
76
130
  - [SKILL.md](./SKILL.md) — agent-driven integration skill
@@ -78,8 +132,10 @@ interface SageP2Config {
78
132
  ## Validate
79
133
 
80
134
  ```bash
81
- npm run build
82
135
  npm test
136
+ npm run typecheck
137
+ npm run build
138
+ git diff --check
83
139
  ```
84
140
 
85
141
  ## License
package/SKILL.md CHANGED
@@ -1,222 +1,199 @@
1
1
  # Sage Pi Adapter Integration Skill
2
2
 
3
- Use this skill when a repository uses `@earendil-works/pi-coding-agent` (formerly `@mariozechner/pi-coding-agent`) and needs Sage integrated into its session bootstrap/plugin layer.
3
+ Use this skill when a repository uses `@earendil-works/pi-coding-agent`
4
+ (formerly `@mariozechner/pi-coding-agent`) and needs Sage integrated into its
5
+ session bootstrap or Pi extension layer.
4
6
 
5
- ## Preflight (Do This First)
7
+ ## Preflight
6
8
 
7
- 1. Verify npm package availability:
8
- - `npm view @sage-protocol/pi-adapter version`
9
- 2. Ensure you are patching the harness repo (not this package repo):
10
- - For pi-mono target: `https://github.com/badlogic/pi-mono/tree/main/packages/coding-agent`
11
- 3. If current workspace does not contain harness sources, switch/clone first, then patch there.
9
+ 1. Verify npm package availability: `npm view @sage-protocol/pi-adapter version`.
10
+ 2. Confirm whether the target uses the installed Pi CLI extension or owns a
11
+ harness bootstrap containing `createAgentSession`.
12
+ 3. If source integration is requested but the workspace has no harness source,
13
+ stop and ask for the harness repo path instead of editing unrelated files.
12
14
 
13
- ## Hard-Stop Conditions
14
-
15
- Stop and report immediately (do not keep searching random directories) if any of these are true:
16
-
17
- - `npm view @sage-protocol/pi-adapter version` fails after retrying once
18
- - Current workspace does not contain harness paths like `packages/coding-agent`
19
- - You cannot find a session bootstrap path (`createAgentSession` call sites)
20
-
21
- When stopping, report what is missing and ask for the harness repo path.
22
-
23
- > **Pi upstream:** [earendil-works/pi](https://github.com/earendil-works/pi) — `@earendil-works/pi-coding-agent`
15
+ > **Pi upstream:** [earendil-works/pi](https://github.com/earendil-works/pi)
16
+ >
24
17
  > **Sage upstream:** [sage-protocol/sage](https://github.com/sage-protocol/sage)
25
18
 
26
- ## Goal
27
-
28
- Apply the Sage integration contract exactly:
19
+ ## Integration Contract
29
20
 
30
- 1. For pi CLI users: `pi install npm:@sage-protocol/pi-adapter` (no harness code edits)
31
- 2. For source-owned harness users: apply SDK patch (`createSageSessionConfig`, `customTools`, `wrapToolsWithSecurity`, `setupHooks`)
32
- 3. Package name: `@earendil-works/pi-coding-agent` (formerly `@mariozechner/pi-coding-agent`)
21
+ Sage 0.4 uses Pi-native skill ownership:
33
22
 
34
- ## Integration Modes (Important)
23
+ - Pi discovers skills from `<available_skills>`.
24
+ - Pi loads a selected procedure through `/skill:<name>` or a complete
25
+ `SKILL.md` read.
26
+ - The adapter does not call `sage suggest hook skill` for each prompt, inject
27
+ `sage-suggested-skills`, or infer use from a suggestion.
28
+ - Manual `sage suggest skill "<task>"` remains an explicit CLI ranking tool; it
29
+ is not automatic Pi injection.
30
+ - The adapter keeps SessionStart Sage context, MCP tools, behaviors, security
31
+ hooks, prompt/response capture, and explicit subagent resolution.
32
+ - The packaged Pi extension observes truthful complete native loads, writes
33
+ source- and session-qualified load receipts, and exposes
34
+ `sage_mark_guided_use` to bind actually applied loaded skills to the exact
35
+ prompt capture through Sage's native-use daemon path.
36
+ - Pi has no suggestion auto-skip, auto-reject, or suggestion-quality widget
37
+ lifecycle.
35
38
 
36
- - Installed pi CLI only (no harness source): run `pi install npm:@sage-protocol/pi-adapter`, restart pi, and verify Sage tools are present.
37
- - Source-owned harness (editable repo): apply the patch pattern in this skill.
39
+ ## Integration Modes
38
40
 
39
- ## CLI-Only Flow (No Source Edits)
41
+ ### Pi CLI Extension
40
42
 
41
43
  ```bash
42
44
  pi install npm:@sage-protocol/pi-adapter
43
45
  pi list
44
46
  ```
45
47
 
46
- Then restart `pi` and verify `sage_status` is callable.
47
-
48
- Bridge health expectation:
49
-
50
- - Pi exposes Sage through `sage_search`, `sage_execute`, and `sage_status`.
51
- - `sage_status` is the user-facing health surface. When the MCP bridge is
52
- degraded, surface a readable bridge error and recovery hint instead of silent
53
- retry exhaustion.
54
- - Inside bridge startup/health code, probe low-level MCP (`tools/list` or a
55
- minimal Sage MCP call). Do not recursively call the adapter-level
56
- `sage_status` tool from inside the bridge.
57
- - Recovery wording should point at the Sage MCP bridge (`sage mcp start`,
58
- restart Pi/Sage bridge) unless the failing path is specifically the daemon.
59
-
60
- For project-local monorepo development, prefer an explicit `.pi/settings.json` that
61
- keeps pi thin and points at the Sage Pi export surface:
62
-
63
- ```json
64
- {
65
- "packages": [
66
- "../packages/sage-pi-adapter",
67
- {
68
- "source": "../packages/sage-pi-export",
69
- "skills": ["skills/*/SKILL.md"],
70
- "extensions": [],
71
- "prompts": [],
72
- "themes": []
73
- },
74
- {
75
- "source": "npm:oh-pi",
76
- "extensions": ["!**"]
77
- }
78
- ],
79
- "skills": [
80
- "-../.agents/skills/frontend-design/SKILL.md",
81
- "-~/.pi/agent/skills/prompt-builder/SKILL.md",
82
- "-~/.pi/agent/skills/sage/SKILL.md",
83
- "-~/.pi/agent/skills/sage-workflow/SKILL.md"
84
- ],
85
- "enableSkillCommands": true
86
- }
87
- ```
88
-
89
- This keeps the harness responsible for transport and tool exposure while Sage skills
90
- and libraries own the routing and behavior layer.
91
-
92
- The package-filtered `../packages/sage-pi-export` entry is intentional: it exposes a Pi-safe,
93
- curated Sage surface without scanning broad runtime roots such as `~/.local/share/sage/skills`,
94
- which often contain backup directories, version snapshots, and third-party installs that are valid
95
- for Sage runtime use but noisy for Pi skill validation.
96
-
97
- Architectural posture:
98
-
99
- - pi/OpenClaw = transport and tool surface
100
- - `sage` = router and tool-aware base skill
101
- - repo-authored entrypoint definitions = authoring layer
102
- - on-chain libraries = shared distribution and sync/pull layer
103
- - local sync = development convenience
104
-
105
- The entrypoint layer should stay thin. It should dispatch into stable Sage-owned dependency
106
- libraries by key, not duplicate them. For example, a review or planning entrypoint can route into
107
- `code-review`, `ceo-plan-review`, or `vc-office-hours` from `sage-review-foundations` without
108
- copying those skill bodies.
109
-
110
- Pi export surface rule:
111
-
112
- - author real skills under `packages/sage/skills/`
113
- - declare Pi-visible skills in `packages/sage/pi-export.manifest.json`
114
- - materialize the Pi-safe surface with `node scripts/util/sync-sage-pi-export.mjs`
115
- - point `.pi/settings.json` at `../packages/sage-pi-export`, not at the raw authoring tree
48
+ Restart Pi and verify that `sage_status` is callable. Pi's native skill catalog
49
+ and `/skill:<name>` command own skill discovery and loading.
116
50
 
117
- Hook command semantics:
118
-
119
- - `sage suggest hook skill` reads prompt from env/stdin (for IDE/agent hooks)
120
- - It does not accept positional query text
121
- - Manual query testing uses `sage suggest skill "..."`
122
-
123
- ## Required Patch Pattern
51
+ ### Source-Owned Harness
124
52
 
125
53
  ```ts
126
- import { createSageSessionConfig } from '@sage-protocol/pi-adapter';
54
+ import {
55
+ createAgentSession,
56
+ createCodingTools,
57
+ type ToolDefinition as PiToolDefinition,
58
+ } from '@earendil-works/pi-coding-agent';
59
+ import {
60
+ createSageSessionConfig,
61
+ type ToolDefinition as SageToolDefinition,
62
+ } from '@sage-protocol/pi-adapter';
63
+
64
+ function asPiCustomTools(tools: SageToolDefinition[]): PiToolDefinition[] {
65
+ // Type-shape compatibility across supported Pi minors; no runtime conversion.
66
+ return tools as unknown as PiToolDefinition[];
67
+ }
127
68
 
128
69
  const sage = await createSageSessionConfig({
129
70
  source: 'pi-agent-core',
130
71
  enableSecurityHooks: true,
131
72
  enableRlmFeedback: true,
132
- suggestLimit: 3,
133
73
  });
134
-
74
+ const cwd = process.cwd();
75
+ const securedTools = sage.wrapToolsWithSecurity(createCodingTools(cwd));
135
76
  const { session } = await createAgentSession({
136
77
  ...existingConfig,
137
- tools: sage.wrapToolsWithSecurity(existingTools),
138
- customTools: sage.customTools,
78
+ cwd,
79
+ noTools: 'builtin',
80
+ customTools: asPiCustomTools([...securedTools, ...sage.customTools]),
139
81
  });
140
82
 
141
83
  const disposeSageHooks = sage.setupHooks(session);
142
84
  ```
143
85
 
144
- ## Plugin Setup (If Harness Uses Plugins)
86
+ Current Pi treats `tools` as a string allowlist. Definitions belong in
87
+ `customTools`, and `noTools: 'builtin'` avoids registering an unwrapped built-in
88
+ set as well. Keep the one cast isolated at the supported Pi peer-version type
89
+ boundary; it is not a runtime conversion.
145
90
 
146
- - Put this in the plugin/bootstrap setup path, not in random feature code.
147
- - Return or register a disposer that calls:
148
- - `disposeSageHooks()`
149
- - `await sage.mcpBridge.stop()` (optional but recommended for owned lifecycle)
91
+ Wire teardown to `disposeSageHooks()` and, when the harness owns bridge
92
+ lifecycle, `await sage.mcpBridge.stop()`.
150
93
 
151
- ## Where to Search
94
+ The packaged extension owns Pi event-level full-load observation and
95
+ `sage_mark_guided_use` registration. A custom SDK host that bypasses it must add
96
+ equivalent Pi event wiring if those extension features are required.
152
97
 
153
- Find patch points with:
98
+ ## Native Skill Use Contract
154
99
 
155
- ```bash
156
- rg "createAgentSession|createCodingTools|customTools|tools:" src
157
- rg "dispose|shutdown|teardown|cleanup" src
158
- rg "createAgentSession|createCodingTools|customTools|tools:" packages/coding-agent
159
- rg "dispose|shutdown|teardown|cleanup" packages/coding-agent
160
- ```
100
+ When a skill applies:
161
101
 
162
- Install in the harness repo root:
102
+ 1. Select it from Pi's native `<available_skills>` catalog.
103
+ 2. Load its complete procedure with `/skill:<name>` or a full `SKILL.md` read.
104
+ 3. Follow the procedure.
105
+ 4. Call `sage_mark_guided_use({ skills: ["<loaded-key>"] })` in the same turn
106
+ only if at least one instruction, constraint, or output structure guided the
107
+ work.
163
108
 
164
- ```bash
165
- npm install @sage-protocol/pi-adapter
166
- ```
109
+ The declaration is additive for multiple loaded skills. Loading alone is not
110
+ use. Partial reads do not establish a load. Unloaded keys, ambiguous bare
111
+ names, a missing current capture, or a failed daemon write fail closed. The
112
+ adapter attaches the exact Pi session and active prompt capture; agents should
113
+ not invent or copy correlation identifiers. Compaction and session
114
+ replacement clear load eligibility.
167
115
 
168
- If npm lookup fails unexpectedly:
116
+ There is no automatic suggestion settlement in Pi. Do not add skip/reject
117
+ bookkeeping, suggestion-quality annotations, or a suggestion widget.
169
118
 
170
- ```bash
171
- npm config get registry
172
- npm view @sage-protocol/pi-adapter version
173
- ```
119
+ Captures and native-use feedback stay in Sage's local capture/RLM stores.
120
+ Never copy raw session text directly into a `SKILL.md`; examples must be
121
+ reviewed and sanitized through the capture/example workflow.
122
+
123
+ ## SessionStart, Tools, and Behaviors
124
+
125
+ Keep these surfaces intact:
174
126
 
175
- ## Guardrails
127
+ - SessionStart output from `sage skill context --format pi`
128
+ - `hub_list_servers`, `hub_status`, `hub_session_list`,
129
+ `hub_start_server`, and `hub_stop_server`
130
+ - `sage_search`, `sage_execute`, and `sage_status`
131
+ - `sage_behavior` controller plans
132
+ - pre/post-tool security hooks
133
+ - explicit subagent skill resolution for subagents that do not inherit Pi's
134
+ native skill catalog
176
135
 
177
- - Keep existing model/provider/settings behavior unchanged.
178
- - Do not remove existing tools; wrap them.
179
- - Do not duplicate hook setup in multiple places.
180
- - Ensure cleanup path is wired for long-running processes.
181
- - Do not stop after patching this package's own examples; patch the actual harness bootstrap.
136
+ Bridge health must use low-level MCP probes, not recursively call the
137
+ adapter-level `sage_status` tool. Recovery wording should point to the Sage MCP
138
+ bridge unless the daemon itself is the failing component.
182
139
 
183
- ## Copy-Paste Agent Prompt
140
+ ## Project-Local Pi Skills
141
+
142
+ For monorepo development, keep Pi thin and use the curated Pi export surface:
143
+
144
+ ```json
145
+ {
146
+ "packages": [
147
+ "../packages/sage-pi-adapter",
148
+ {
149
+ "source": "../packages/sage-pi-export",
150
+ "skills": ["skills/*/SKILL.md"],
151
+ "extensions": [],
152
+ "prompts": [],
153
+ "themes": []
154
+ }
155
+ ],
156
+ "enableSkillCommands": true
157
+ }
158
+ ```
184
159
 
185
- ```text
186
- If the user only has pi CLI access, run:
187
- - pi install npm:@sage-protocol/pi-adapter
188
- - verify with pi list
189
- - restart pi and verify sage_status tool is available
160
+ Author real skills under `packages/sage/skills/`, declare Pi-visible entries in
161
+ `packages/sage/pi-export.manifest.json`, and materialize the curated surface
162
+ with `node scripts/util/sync-sage-pi-export.mjs`. Do not point Pi at broad Sage
163
+ runtime roots containing backups, snapshots, and third-party installs.
190
164
 
191
- If the user has harness source access (target repo: pi-mono/packages/coding-agent), patch Sage into bootstrap.
165
+ ## Deprecated Compatibility
192
166
 
193
- Preflight:
194
- 1) npm view @sage-protocol/pi-adapter version
195
- 2) npm config get registry
196
- 3) ensure current workspace contains packages/coding-agent
167
+ Do not use `sageInjectSuggestion(...)`; version 0.4 retains it only as a no-op.
168
+ `suggestLimit`, `suggestDebounceMs`, and `enableProvision` remain exported for
169
+ low-level legacy compatibility but are ignored by the default Pi path and
170
+ should not appear in new examples.
197
171
 
198
- Then implement:
199
- - const sage = await createSageSessionConfig(...)
200
- - customTools: sage.customTools
201
- - tools: sage.wrapToolsWithSecurity(existingTools)
202
- - const disposeSageHooks = sage.setupHooks(session)
203
- - teardown calls disposeSageHooks() (and sage.mcpBridge.stop() if lifecycle owned)
172
+ ## Where to Patch
204
173
 
205
- Do not change existing model/provider behavior. Run build/tests for touched package and report changed files.
174
+ ```bash
175
+ rg "createAgentSession|createCodingTools|customTools|tools:" src packages/coding-agent
176
+ rg "dispose|shutdown|teardown|cleanup" src packages/coding-agent
206
177
  ```
207
178
 
179
+ Put setup in the bootstrap/plugin path, call it once per session, preserve
180
+ existing model/provider behavior, and do not remove existing tools.
181
+
208
182
  ## Verification Checklist
209
183
 
210
- - `customTools` includes Sage tools
211
- - Base tools are wrapped with `wrapToolsWithSecurity`
212
- - `setupHooks(session)` is called once per session
213
- - Teardown calls `disposeSageHooks()`
214
- - `sage_status` reports bridge health; broken bridge paths return a structured,
215
- user-readable error quickly
216
- - Build/tests pass for touched repo
184
+ - Pi native `<available_skills>` and `/skill:<name>` remain enabled.
185
+ - No per-prompt `sage suggest hook skill` call or `sage-suggested-skills`
186
+ injection exists.
187
+ - SessionStart context, MCP tools, behavior plans, security hooks, capture, and
188
+ explicit subagent resolution remain available.
189
+ - Complete native loads produce source/session-qualified receipts.
190
+ - `sage_mark_guided_use` accepts only actually loaded procedures and uses the
191
+ exact prompt capture.
192
+ - No suggestion auto-skip/reject or quality widget exists.
193
+ - Teardown disposes hooks and owned bridge lifecycle.
194
+ - Build and tests pass.
217
195
 
218
196
  ## Source of Truth
219
197
 
220
- For the latest contract and examples, see:
221
-
222
- - `packages/sage-pi-adapter/README.md`
198
+ See `packages/sage-pi-adapter/README.md` and `USAGE.md` for the current
199
+ contract and examples.