@sage-protocol/pi-adapter 0.3.11 → 0.4.1
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 +72 -23
- package/SKILL.md +143 -166
- package/USAGE.md +100 -38
- package/dist/behavior/pi-executor.d.ts.map +1 -1
- package/dist/behavior/pi-executor.js +26 -6
- package/dist/behavior/pi-executor.js.map +1 -1
- package/dist/behavior/types.d.ts +15 -4
- package/dist/behavior/types.d.ts.map +1 -1
- package/dist/index.d.ts +29 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +29 -7
- package/dist/index.js.map +1 -1
- package/dist/sage-pi-adapter.d.ts +71 -6
- package/dist/sage-pi-adapter.d.ts.map +1 -1
- package/dist/sage-pi-adapter.js +420 -55
- package/dist/sage-pi-adapter.js.map +1 -1
- package/extensions/index.ts +443 -598
- package/package.json +9 -2
package/USAGE.md
CHANGED
|
@@ -8,54 +8,121 @@
|
|
|
8
8
|
|
|
9
9
|
## Integration Modes
|
|
10
10
|
|
|
11
|
-
1. **
|
|
11
|
+
1. **Pi CLI extension** — `pi install npm:@sage-protocol/pi-adapter` (no source changes)
|
|
12
12
|
2. **SDK embedding** — `createSageSessionConfig(...)` for harness source owners
|
|
13
13
|
|
|
14
|
-
##
|
|
14
|
+
## Pi CLI Mode
|
|
15
15
|
|
|
16
16
|
```bash
|
|
17
17
|
pi install npm:@sage-protocol/pi-adapter
|
|
18
18
|
pi list # verify installed
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
Restart
|
|
21
|
+
Restart Pi and use it normally. The packaged extension provides:
|
|
22
22
|
|
|
23
|
-
-
|
|
24
|
-
- skill
|
|
25
|
-
- capture
|
|
26
|
-
-
|
|
23
|
+
- SessionStart Sage context, loaded inventory, MCP tools, and behaviors
|
|
24
|
+
- Pi-native skill discovery through `<available_skills>` and `/skill:<name>`
|
|
25
|
+
- prompt/response capture through `sage capture hook prompt/response`
|
|
26
|
+
- observation of complete native `SKILL.md` reads and full `skills.get` loads
|
|
27
|
+
- source- and session-qualified load receipts
|
|
28
|
+
- `sage_mark_guided_use` for binding applied loaded skills to the exact prompt capture
|
|
29
|
+
- optional pre/post-tool security scanning
|
|
30
|
+
- explicit skill resolution for subagents that do not inherit Pi's native skill catalog
|
|
31
|
+
|
|
32
|
+
The extension does not run `sage suggest hook skill` per prompt and does not
|
|
33
|
+
inject `sage-suggested-skills`. It also has no suggestion auto-skip,
|
|
34
|
+
auto-reject, or suggestion-quality widget lifecycle.
|
|
35
|
+
|
|
36
|
+
## Native Skill Workflow
|
|
37
|
+
|
|
38
|
+
1. Choose from Pi's native `<available_skills>` catalog.
|
|
39
|
+
2. Load the selected skill with `/skill:<name>` or a complete `SKILL.md` read.
|
|
40
|
+
3. Follow the loaded procedure.
|
|
41
|
+
4. If at least one instruction, constraint, or output structure from it guided
|
|
42
|
+
the current turn, call:
|
|
43
|
+
|
|
44
|
+
```text
|
|
45
|
+
sage_mark_guided_use({ skills: ["<loaded-key>"] })
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
The adapter observes successful complete loads, writes a load receipt qualified
|
|
49
|
+
by Sage source and Pi session, and lets the daemon bind guided use to the exact
|
|
50
|
+
active prompt capture. Partial reads, unloaded keys, ambiguous bare names,
|
|
51
|
+
missing captures, and failed receipt/feedback writes fail closed. Loading a
|
|
52
|
+
procedure without applying it is not use. Compaction and session replacement
|
|
53
|
+
clear load eligibility.
|
|
54
|
+
|
|
55
|
+
Manual ranking is still available when explicitly requested:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
sage suggest skill "review this smart contract" --format json
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
That command does not inject a skill into Pi. Load the chosen full procedure
|
|
62
|
+
through Pi's native flow before using it.
|
|
27
63
|
|
|
28
64
|
## SDK Integration
|
|
29
65
|
|
|
30
66
|
```typescript
|
|
31
|
-
import {
|
|
32
|
-
|
|
67
|
+
import {
|
|
68
|
+
createAgentSession,
|
|
69
|
+
createCodingTools,
|
|
70
|
+
type ToolDefinition as PiToolDefinition,
|
|
71
|
+
} from '@earendil-works/pi-coding-agent';
|
|
72
|
+
import {
|
|
73
|
+
createSageSessionConfig,
|
|
74
|
+
type ToolDefinition as SageToolDefinition,
|
|
75
|
+
} from '@sage-protocol/pi-adapter';
|
|
76
|
+
|
|
77
|
+
function asPiCustomTools(tools: SageToolDefinition[]): PiToolDefinition[] {
|
|
78
|
+
// Type-shape compatibility across supported Pi minors; no runtime conversion.
|
|
79
|
+
return tools as unknown as PiToolDefinition[];
|
|
80
|
+
}
|
|
33
81
|
|
|
34
82
|
const sage = await createSageSessionConfig({
|
|
35
83
|
sageBin: 'sage',
|
|
36
84
|
source: 'pi-agent-core',
|
|
37
|
-
|
|
85
|
+
enableRlmFeedback: true,
|
|
86
|
+
enableSecurityHooks: true,
|
|
38
87
|
});
|
|
39
|
-
|
|
88
|
+
const cwd = process.cwd();
|
|
89
|
+
const securedTools = sage.wrapToolsWithSecurity(createCodingTools(cwd));
|
|
40
90
|
const { session } = await createAgentSession({
|
|
91
|
+
cwd,
|
|
41
92
|
model,
|
|
42
|
-
|
|
43
|
-
customTools: sage.customTools,
|
|
93
|
+
noTools: 'builtin',
|
|
94
|
+
customTools: asPiCustomTools([...securedTools, ...sage.customTools]),
|
|
44
95
|
});
|
|
45
96
|
|
|
46
97
|
const disposeSageHooks = sage.setupHooks(session);
|
|
47
|
-
// on teardown: disposeSageHooks()
|
|
98
|
+
// on teardown: disposeSageHooks(); await sage.mcpBridge.stop();
|
|
48
99
|
```
|
|
49
100
|
|
|
101
|
+
Pi's `tools` option is a string allowlist, not a tool-definition array. The
|
|
102
|
+
helper isolates the only compatibility cast between the adapter's tool shape,
|
|
103
|
+
which spans supported Pi minors, and Pi's generic `ToolDefinition`; it performs
|
|
104
|
+
no runtime conversion.
|
|
105
|
+
|
|
106
|
+
The packaged Pi extension contains the Pi event-level native-load observer and
|
|
107
|
+
`sage_mark_guided_use` registration. A custom SDK host that bypasses the
|
|
108
|
+
extension must provide equivalent Pi event wiring if it wants those extension
|
|
109
|
+
features; `createSageSessionConfig` still supplies bridge, SessionStart,
|
|
110
|
+
capture, and security integration.
|
|
111
|
+
|
|
50
112
|
## Plugin Pattern
|
|
51
113
|
|
|
52
114
|
```typescript
|
|
53
115
|
export async function setupSagePlugin(runtime) {
|
|
54
116
|
const sage = await createSageSessionConfig({ source: 'pi-agent-core' });
|
|
117
|
+
const cwd = process.cwd();
|
|
118
|
+
const securedTools = sage.wrapToolsWithSecurity(runtime.createCodingTools(cwd));
|
|
119
|
+
|
|
120
|
+
// Pseudo host API: register definitions as custom tools before session creation.
|
|
121
|
+
runtime.registerCustomTools([...securedTools, ...sage.customTools]);
|
|
55
122
|
const { session } = await runtime.makeSession({
|
|
123
|
+
cwd,
|
|
56
124
|
model: runtime.model,
|
|
57
|
-
|
|
58
|
-
customTools: sage.customTools,
|
|
125
|
+
noTools: 'builtin',
|
|
59
126
|
});
|
|
60
127
|
const dispose = sage.setupHooks(session);
|
|
61
128
|
return {
|
|
@@ -65,38 +132,33 @@ export async function setupSagePlugin(runtime) {
|
|
|
65
132
|
}
|
|
66
133
|
```
|
|
67
134
|
|
|
135
|
+
A plugin host may name `registerCustomTools` differently; use its own custom-tool
|
|
136
|
+
registration API. Do not put definitions in a `tools` option.
|
|
137
|
+
|
|
68
138
|
## Environment Variables
|
|
69
139
|
|
|
70
140
|
| Variable | Default | Description |
|
|
71
141
|
|----------|---------|-------------|
|
|
72
|
-
| `SAGE_BIN` | `sage` | Path to
|
|
73
|
-
| `SAGE_PROFILE` | — | Sage config profile (
|
|
74
|
-
| `
|
|
75
|
-
| `
|
|
76
|
-
| `
|
|
77
|
-
| `SAGE_RLM_FEEDBACK` | `1` | Enable prompt/response capture |
|
|
78
|
-
| `SAGE_SHOW_HOOK_MESSAGES` | `0` | Display hook messages in chat UI |
|
|
142
|
+
| `SAGE_BIN` | `sage` | Path to Sage CLI |
|
|
143
|
+
| `SAGE_PROFILE` | — | Sage config profile (for example `testnet`) |
|
|
144
|
+
| `SAGE_SECURITY_HOOKS` | `1` | Enable pre/post-tool security scanning |
|
|
145
|
+
| `SAGE_RLM_FEEDBACK` | `1` | Enable prompt/response capture and native-use receipts |
|
|
146
|
+
| `SAGE_SHOW_HOOK_MESSAGES` | `0` | Display SessionStart hook messages in the chat UI |
|
|
79
147
|
| `SAGE_ALLOW_BASH_CLI` | `1` | Allow direct `sage ...` bash calls |
|
|
80
|
-
| `
|
|
81
|
-
| `
|
|
82
|
-
| `SAGE_INJECT_TOOL_DOCS` | `1` | Inject Sage tool guardrails per-turn |
|
|
83
|
-
|
|
84
|
-
### Skill Quality Annotations
|
|
85
|
-
|
|
86
|
-
The widget automatically annotates suggested skills with execution quality data from the Sage daemon. No extra configuration needed — just ensure the daemon is running (`sage daemon start`).
|
|
87
|
-
|
|
88
|
-
Annotations appear when the daemon has ≥3 recorded execution outcomes per skill:
|
|
148
|
+
| `SAGE_AUTO_RESOLVE_SKILLS` | `1` | Resolve skills explicitly named in subagent tasks |
|
|
149
|
+
| `SAGE_INJECT_TOOL_DOCS` | `1` | Add compact Sage tool guardrails each turn |
|
|
89
150
|
|
|
90
|
-
|
|
91
|
-
- `⚠` — 40-70% pass rate (mixed)
|
|
92
|
-
- `✗` — <40% pass rate (harmful — skipped in subagent contexts)
|
|
93
|
-
- (none) — insufficient data
|
|
151
|
+
### Deprecated Low-Level Compatibility
|
|
94
152
|
|
|
95
|
-
|
|
153
|
+
`suggestLimit`, `suggestDebounceMs`, and `enableProvision` remain exported in
|
|
154
|
+
`SageP2Config` for low-level legacy callers. The default Pi path ignores them;
|
|
155
|
+
do not use them in new configuration. `sageInjectSuggestion(...)` is likewise
|
|
156
|
+
a deprecated no-op in 0.4.
|
|
96
157
|
|
|
97
158
|
## Project Config
|
|
98
159
|
|
|
99
|
-
For monorepo development, keep
|
|
160
|
+
For monorepo development, keep Pi thin and point it at the curated Sage Pi
|
|
161
|
+
export surface:
|
|
100
162
|
|
|
101
163
|
```json
|
|
102
164
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pi-executor.d.ts","sourceRoot":"","sources":["../../src/behavior/pi-executor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAE3D,OAAO,KAAK,EAEX,gBAAgB,EAChB,YAAY,EACZ,gBAAgB,EAChB,eAAe,EAGf,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAChC,+CAA+C;IAC/C,MAAM,EAAE,aAAa,CAAC;IACtB,gEAAgE;IAChE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,6CAA6C;IAC7C,WAAW,CAAC,EAAE,CAAC,OAAO,EAAE;QACvB,UAAU,EAAE,MAAM,CAAC;QACnB,OAAO,EAAE,MAAM,CAAC;QAChB,OAAO,EAAE,OAAO,CAAC;KACjB,KAAK,IAAI,CAAC;CACX;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,kBAAmB,YAAW,gBAAgB;IAC1D,QAAQ,CAAC,IAAI,0BAA0B;IACvC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;IACvC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAkC;gBAEnD,MAAM,EAAE,gBAAgB;IAK9B,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAIjD,UAAU,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO;IAKjC,OAAO,CACZ,IAAI,EAAE,YAAY,EAClB,OAAO,EAAE,gBAAgB,GACvB,OAAO,CAAC,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"pi-executor.d.ts","sourceRoot":"","sources":["../../src/behavior/pi-executor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAE3D,OAAO,KAAK,EAEX,gBAAgB,EAChB,YAAY,EACZ,gBAAgB,EAChB,eAAe,EAGf,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAChC,+CAA+C;IAC/C,MAAM,EAAE,aAAa,CAAC;IACtB,gEAAgE;IAChE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,6CAA6C;IAC7C,WAAW,CAAC,EAAE,CAAC,OAAO,EAAE;QACvB,UAAU,EAAE,MAAM,CAAC;QACnB,OAAO,EAAE,MAAM,CAAC;QAChB,OAAO,EAAE,OAAO,CAAC;KACjB,KAAK,IAAI,CAAC;CACX;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,kBAAmB,YAAW,gBAAgB;IAC1D,QAAQ,CAAC,IAAI,0BAA0B;IACvC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;IACvC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAkC;gBAEnD,MAAM,EAAE,gBAAgB;IAK9B,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAIjD,UAAU,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO;IAKjC,OAAO,CACZ,IAAI,EAAE,YAAY,EAClB,OAAO,EAAE,gBAAgB,GACvB,OAAO,CAAC,eAAe,CAAC;IAsC3B;;;;;;;;;OASG;IACH,OAAO,CAAC,sBAAsB;IAiH9B;;;;;;OAMG;IACH,OAAO,CAAC,qBAAqB;CAiB7B"}
|
|
@@ -54,6 +54,7 @@ export class PiBehaviorExecutor {
|
|
|
54
54
|
const startTime = Date.now();
|
|
55
55
|
const results = [];
|
|
56
56
|
// Render the plan as a controller prompt for the agent.
|
|
57
|
+
// This is plan injection (Smithers-style), not step completion.
|
|
57
58
|
const controllerPrompt = this.renderControllerPrompt(plan, context);
|
|
58
59
|
// Report plan to the agent via hook message
|
|
59
60
|
if (this.sendMessage) {
|
|
@@ -63,19 +64,19 @@ export class PiBehaviorExecutor {
|
|
|
63
64
|
display: true,
|
|
64
65
|
});
|
|
65
66
|
}
|
|
66
|
-
//
|
|
67
|
-
//
|
|
67
|
+
// Steps remain awaiting_agent until the host has real step results.
|
|
68
|
+
// Never claim completed solely because the plan was rendered.
|
|
68
69
|
for (const step of plan.steps) {
|
|
69
70
|
const stepStart = Date.now();
|
|
70
|
-
context.onProgress?.(step.id, "
|
|
71
|
+
context.onProgress?.(step.id, "awaiting_agent");
|
|
71
72
|
results.push({
|
|
72
73
|
stepId: step.id,
|
|
73
|
-
status: "
|
|
74
|
+
status: "awaiting_agent",
|
|
74
75
|
durationMs: Date.now() - stepStart,
|
|
75
76
|
});
|
|
76
77
|
}
|
|
77
78
|
return {
|
|
78
|
-
status: "
|
|
79
|
+
status: "awaiting_agent",
|
|
79
80
|
steps: results,
|
|
80
81
|
totalDurationMs: Date.now() - startTime,
|
|
81
82
|
output: controllerPrompt,
|
|
@@ -93,11 +94,23 @@ export class PiBehaviorExecutor {
|
|
|
93
94
|
*/
|
|
94
95
|
renderControllerPrompt(plan, context) {
|
|
95
96
|
const lines = [];
|
|
96
|
-
|
|
97
|
+
// Smithers-inspired: plan is an authority envelope + step menu, not a runtime.
|
|
98
|
+
// Status stays awaiting_agent until steps are actually done.
|
|
99
|
+
lines.push("# Behavior Plan (controller inject — not a completed run)");
|
|
100
|
+
lines.push("");
|
|
101
|
+
lines.push("This is a **durable step plan** for you (the agent) to execute with tools.");
|
|
102
|
+
lines.push("The adapter has **not** completed these steps. Status: `awaiting_agent`.");
|
|
97
103
|
lines.push("");
|
|
98
104
|
lines.push(`**Task:** ${context.task}`);
|
|
99
105
|
lines.push(`**Steps:** ${plan.steps.length}`);
|
|
100
106
|
lines.push("");
|
|
107
|
+
lines.push("## Load rule (per step)");
|
|
108
|
+
lines.push("");
|
|
109
|
+
lines.push("1. Load the **full** skill procedure for the step (`/skill:<key>`, read SKILL.md, or skills.get).");
|
|
110
|
+
lines.push("2. Freestyle tools **under that skill's constraints** — ranking/plan text is not enough.");
|
|
111
|
+
lines.push("3. Only after step work is done, move to the next step in order.");
|
|
112
|
+
lines.push("4. Report outcomes with `sage suggest feedback outcome <skill-key> --status passed|failed` when a procedure guided work.");
|
|
113
|
+
lines.push("");
|
|
101
114
|
if (context.mcpServersRequired.length > 0) {
|
|
102
115
|
lines.push("## Required MCP Servers");
|
|
103
116
|
for (const server of context.mcpServersRequired) {
|
|
@@ -115,6 +128,8 @@ export class PiBehaviorExecutor {
|
|
|
115
128
|
lines.push(`### Step ${i + 1}: ${step.title}`);
|
|
116
129
|
lines.push("");
|
|
117
130
|
lines.push(`**Skill:** \`${step.skill_key}\``);
|
|
131
|
+
lines.push(`**Status:** awaiting_agent`);
|
|
132
|
+
lines.push(`**Load:** \`/skill:${step.skill_key}\` or \`sage library inspect skill get ${step.skill_key}\` or skills.get before freestyle`);
|
|
118
133
|
if (step.uses.length > 0) {
|
|
119
134
|
lines.push(`**Depends on:** ${step.uses.join(", ")}`);
|
|
120
135
|
}
|
|
@@ -123,6 +138,10 @@ export class PiBehaviorExecutor {
|
|
|
123
138
|
lines.push(step.instruction);
|
|
124
139
|
lines.push("");
|
|
125
140
|
}
|
|
141
|
+
else {
|
|
142
|
+
lines.push(`_No body in plan — load full skill \`${step.skill_key}\` before acting._`);
|
|
143
|
+
lines.push("");
|
|
144
|
+
}
|
|
126
145
|
// Subagent delegation hint for steps that benefit from isolation
|
|
127
146
|
if (this.shouldSuggestSubagent(step, plan.steps.length)) {
|
|
128
147
|
lines.push(`> 💡 **Subagent hint:** This step may benefit from running in an isolated subagent.`);
|
|
@@ -139,6 +158,7 @@ export class PiBehaviorExecutor {
|
|
|
139
158
|
lines.push("");
|
|
140
159
|
lines.push("After completing all steps, synthesize the results into a coherent response.");
|
|
141
160
|
lines.push("Reference findings from each step and note any cross-step insights.");
|
|
161
|
+
lines.push("Do not treat plan injection alone as success; only completed step work counts.");
|
|
142
162
|
return lines.join("\n");
|
|
143
163
|
}
|
|
144
164
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pi-executor.js","sourceRoot":"","sources":["../../src/behavior/pi-executor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AA2BpD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,OAAO,kBAAkB;IACrB,IAAI,GAAG,sBAAsB,CAAC;IACtB,MAAM,CAAgB;IACtB,WAAW,CAAmC;IAE/D,YAAY,MAAwB;QACnC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC5B,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;IACvC,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,GAAW;QACxB,OAAO,mBAAmB,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9C,CAAC;IAED,UAAU,CAAC,IAAkB;QAC5B,sDAAsD;QACtD,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;IAC9B,CAAC;IAED,KAAK,CAAC,OAAO,CACZ,IAAkB,EAClB,OAAyB;QAEzB,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC7B,MAAM,OAAO,GAAiB,EAAE,CAAC;QAEjC,wDAAwD;QACxD,MAAM,gBAAgB,GAAG,IAAI,CAAC,sBAAsB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAEpE,4CAA4C;QAC5C,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACtB,IAAI,CAAC,WAAW,CAAC;gBAChB,UAAU,EAAE,oBAAoB;gBAChC,OAAO,EAAE,gBAAgB;gBACzB,OAAO,EAAE,IAAI;aACb,CAAC,CAAC;QACJ,CAAC;QAED,
|
|
1
|
+
{"version":3,"file":"pi-executor.js","sourceRoot":"","sources":["../../src/behavior/pi-executor.ts"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,CAAC,IAAI,CACT,gFAAgF,CAChF,CAAC;QAEF,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACzB,CAAC;IAED;;;;;;OAMG;IACK,qBAAqB,CAAC,IAAc,EAAE,UAAkB;QAC/D,IAAI,UAAU,GAAG,CAAC;YAAE,OAAO,KAAK,CAAC,CAAC,2CAA2C;QAC7E,IAAI,IAAI,CAAC,WAAW,CAAC,MAAM,GAAG,IAAI;YAAE,OAAO,IAAI,CAAC,CAAC,8CAA8C;QAC/F,yDAAyD;QACzD,MAAM,gBAAgB,GAAG;YACxB,QAAQ;YACR,OAAO;YACP,UAAU;YACV,QAAQ;YACR,UAAU;YACV,UAAU;SACV,CAAC;QACF,OAAO,gBAAgB,CAAC,IAAI,CAC3B,CAAC,EAAE,EAAE,EAAE,CACN,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CACrE,CAAC;IACH,CAAC;CACD"}
|
package/dist/behavior/types.d.ts
CHANGED
|
@@ -64,8 +64,14 @@ export interface BehaviorPlan {
|
|
|
64
64
|
/** Ordered steps. */
|
|
65
65
|
steps: PlanStep[];
|
|
66
66
|
}
|
|
67
|
-
/**
|
|
68
|
-
|
|
67
|
+
/**
|
|
68
|
+
* Outcome of a single step execution.
|
|
69
|
+
*
|
|
70
|
+
* Smithers-style honesty: injecting a controller plan is not step completion.
|
|
71
|
+
* Use `awaiting_agent` when the agent still owns the work; never claim
|
|
72
|
+
* `completed` until the harness has real step results.
|
|
73
|
+
*/
|
|
74
|
+
export type StepStatus = "pending" | "awaiting_agent" | "running" | "in_progress" | "completed" | "failed" | "skipped";
|
|
69
75
|
/** Result from executing a single plan step. */
|
|
70
76
|
export interface StepResult {
|
|
71
77
|
stepId: string;
|
|
@@ -96,8 +102,13 @@ export interface ExecutionContext {
|
|
|
96
102
|
}
|
|
97
103
|
/** Final result of executing a complete behavior plan. */
|
|
98
104
|
export interface ExecutionResult {
|
|
99
|
-
/**
|
|
100
|
-
|
|
105
|
+
/**
|
|
106
|
+
* Overall status.
|
|
107
|
+
* - `awaiting_agent` / `in_progress`: plan injected; agent still owns steps (not completed).
|
|
108
|
+
* - `completed`: all steps actually finished successfully.
|
|
109
|
+
* - `failed` / `partial` / `cancelled`: terminal failure states.
|
|
110
|
+
*/
|
|
111
|
+
status: "awaiting_agent" | "in_progress" | "completed" | "failed" | "partial" | "cancelled";
|
|
101
112
|
/** Per-step results in execution order. */
|
|
102
113
|
steps: StepResult[];
|
|
103
114
|
/** Total execution duration in milliseconds. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/behavior/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAMH,sDAAsD;AACtD,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,uEAAuE;IACvE,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,+EAA+E;IAC/E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,yEAAyE;IACzE,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,qDAAqD;AACrD,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,aAAa,EAAE,CAAC;IACxB,uDAAuD;IACvD,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,4EAA4E;IAC5E,iBAAiB,EAAE,MAAM,EAAE,CAAC;CAC7B;AAED,iDAAiD;AACjD,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,2CAA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AE,MAAM,CAAC;IACZ,sDAAsD;IACtD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+DAA+D;IAC/D,kBAAkB,EAAE,MAAM,EAAE,CAAC;IAC7B,yDAAyD;IACzD,UAAU,CAAC,EAAE,oBAAoB,CAAC;IAClC,qCAAqC;IACrC,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,0DAA0D;AAC1D,MAAM,WAAW,eAAe;IAC9B;;;;;OAKG;IACH,MAAM,EACF,gBAAgB,GAChB,aAAa,GACb,WAAW,GACX,QAAQ,GACR,SAAS,GACT,WAAW,CAAC;IAChB,2CAA2C;IAC3C,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB,gDAAgD;IAChD,eAAe,EAAE,MAAM,CAAC;IACxB,yDAAyD;IACzD,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAMD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,WAAW,gBAAgB;IAC/B,iDAAiD;IACjD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IAE5C;;;;OAIG;IACH,UAAU,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC;IAExC;;;;OAIG;IACH,OAAO,CAAC,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;CAClF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,26 +1,48 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Sage Protocol - Pi Adapter
|
|
3
3
|
*
|
|
4
|
-
* Provides Sage MCP
|
|
4
|
+
* Provides Sage MCP, SessionStart context, capture, security, behavior, and
|
|
5
|
+
* native skill-use integration for Pi. Pi itself owns skill discovery/loading
|
|
6
|
+
* through `<available_skills>`, `/skill:<name>`, and complete `SKILL.md` reads;
|
|
7
|
+
* default adapter setup does not inject per-prompt suggestions.
|
|
5
8
|
*
|
|
6
9
|
* @example
|
|
7
10
|
* ```typescript
|
|
8
|
-
* import {
|
|
9
|
-
*
|
|
11
|
+
* import {
|
|
12
|
+
* createAgentSession,
|
|
13
|
+
* createCodingTools,
|
|
14
|
+
* type ToolDefinition as PiToolDefinition,
|
|
15
|
+
* } from '@earendil-works/pi-coding-agent'
|
|
16
|
+
* import {
|
|
17
|
+
* createSageSessionConfig,
|
|
18
|
+
* type ToolDefinition as SageToolDefinition,
|
|
19
|
+
* } from '@sage-protocol/pi-adapter'
|
|
20
|
+
*
|
|
21
|
+
* function asPiCustomTools(tools: SageToolDefinition[]): PiToolDefinition[] {
|
|
22
|
+
* // Type-shape compatibility across supported Pi minors; no runtime conversion.
|
|
23
|
+
* return tools as unknown as PiToolDefinition[]
|
|
24
|
+
* }
|
|
10
25
|
*
|
|
11
26
|
* const sage = await createSageSessionConfig({
|
|
12
27
|
* sageBin: 'sage',
|
|
13
28
|
* source: 'pi-agent-core',
|
|
14
|
-
*
|
|
29
|
+
* enableRlmFeedback: true,
|
|
30
|
+
* enableSecurityHooks: true,
|
|
15
31
|
* })
|
|
16
|
-
*
|
|
32
|
+
* const cwd = process.cwd()
|
|
33
|
+
* const securedTools = sage.wrapToolsWithSecurity(createCodingTools(cwd))
|
|
17
34
|
* const { session } = await createAgentSession({
|
|
18
|
-
*
|
|
19
|
-
*
|
|
35
|
+
* cwd,
|
|
36
|
+
* noTools: 'builtin',
|
|
37
|
+
* customTools: asPiCustomTools([...securedTools, ...sage.customTools]),
|
|
20
38
|
* })
|
|
21
39
|
*
|
|
22
40
|
* const disposeSageHooks = sage.setupHooks(session)
|
|
23
41
|
* ```
|
|
42
|
+
*
|
|
43
|
+
* The packaged Pi extension observes complete native skill loads and exposes
|
|
44
|
+
* `sage_mark_guided_use`. The legacy `sageInjectSuggestion` helper is a
|
|
45
|
+
* deprecated no-op in 0.4.
|
|
24
46
|
*/
|
|
25
47
|
export * from './sage-pi-adapter.js';
|
|
26
48
|
export * from './behavior/index.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AAGH,cAAc,sBAAsB,CAAC;AAGrC,cAAc,qBAAqB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,26 +1,48 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Sage Protocol - Pi Adapter
|
|
3
3
|
*
|
|
4
|
-
* Provides Sage MCP
|
|
4
|
+
* Provides Sage MCP, SessionStart context, capture, security, behavior, and
|
|
5
|
+
* native skill-use integration for Pi. Pi itself owns skill discovery/loading
|
|
6
|
+
* through `<available_skills>`, `/skill:<name>`, and complete `SKILL.md` reads;
|
|
7
|
+
* default adapter setup does not inject per-prompt suggestions.
|
|
5
8
|
*
|
|
6
9
|
* @example
|
|
7
10
|
* ```typescript
|
|
8
|
-
* import {
|
|
9
|
-
*
|
|
11
|
+
* import {
|
|
12
|
+
* createAgentSession,
|
|
13
|
+
* createCodingTools,
|
|
14
|
+
* type ToolDefinition as PiToolDefinition,
|
|
15
|
+
* } from '@earendil-works/pi-coding-agent'
|
|
16
|
+
* import {
|
|
17
|
+
* createSageSessionConfig,
|
|
18
|
+
* type ToolDefinition as SageToolDefinition,
|
|
19
|
+
* } from '@sage-protocol/pi-adapter'
|
|
20
|
+
*
|
|
21
|
+
* function asPiCustomTools(tools: SageToolDefinition[]): PiToolDefinition[] {
|
|
22
|
+
* // Type-shape compatibility across supported Pi minors; no runtime conversion.
|
|
23
|
+
* return tools as unknown as PiToolDefinition[]
|
|
24
|
+
* }
|
|
10
25
|
*
|
|
11
26
|
* const sage = await createSageSessionConfig({
|
|
12
27
|
* sageBin: 'sage',
|
|
13
28
|
* source: 'pi-agent-core',
|
|
14
|
-
*
|
|
29
|
+
* enableRlmFeedback: true,
|
|
30
|
+
* enableSecurityHooks: true,
|
|
15
31
|
* })
|
|
16
|
-
*
|
|
32
|
+
* const cwd = process.cwd()
|
|
33
|
+
* const securedTools = sage.wrapToolsWithSecurity(createCodingTools(cwd))
|
|
17
34
|
* const { session } = await createAgentSession({
|
|
18
|
-
*
|
|
19
|
-
*
|
|
35
|
+
* cwd,
|
|
36
|
+
* noTools: 'builtin',
|
|
37
|
+
* customTools: asPiCustomTools([...securedTools, ...sage.customTools]),
|
|
20
38
|
* })
|
|
21
39
|
*
|
|
22
40
|
* const disposeSageHooks = sage.setupHooks(session)
|
|
23
41
|
* ```
|
|
42
|
+
*
|
|
43
|
+
* The packaged Pi extension observes complete native skill loads and exposes
|
|
44
|
+
* `sage_mark_guided_use`. The legacy `sageInjectSuggestion` helper is a
|
|
45
|
+
* deprecated no-op in 0.4.
|
|
24
46
|
*/
|
|
25
47
|
// Re-export everything from the main module
|
|
26
48
|
export * from './sage-pi-adapter.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AAEH,4CAA4C;AAC5C,cAAc,sBAAsB,CAAC;AAErC,yCAAyC;AACzC,cAAc,qBAAqB,CAAC"}
|
|
@@ -38,9 +38,12 @@ export interface AgentSession {
|
|
|
38
38
|
export interface SageP2Config {
|
|
39
39
|
sageBin?: string;
|
|
40
40
|
sageProfile?: string;
|
|
41
|
+
/** @deprecated Low-level legacy suggestion compatibility; ignored by the default Pi path. */
|
|
41
42
|
suggestLimit?: number;
|
|
43
|
+
/** @deprecated Low-level legacy suggestion compatibility; ignored by the default Pi path. */
|
|
42
44
|
suggestDebounceMs?: number;
|
|
43
45
|
timeoutMs?: number;
|
|
46
|
+
/** @deprecated Low-level legacy suggestion compatibility; ignored by the default Pi path. */
|
|
44
47
|
enableProvision?: boolean;
|
|
45
48
|
enableRlmFeedback?: boolean;
|
|
46
49
|
enableSecurityHooks?: boolean;
|
|
@@ -62,6 +65,7 @@ export interface SageCommandRequest {
|
|
|
62
65
|
args: string[];
|
|
63
66
|
env: Record<string, string>;
|
|
64
67
|
stdin?: string;
|
|
68
|
+
cwd?: string;
|
|
65
69
|
timeoutMs: number;
|
|
66
70
|
}
|
|
67
71
|
export interface SageCommandResult {
|
|
@@ -75,12 +79,50 @@ export interface SkillVisibilityResult {
|
|
|
75
79
|
libraryCount: number;
|
|
76
80
|
skillCount: number;
|
|
77
81
|
}
|
|
82
|
+
export type SageNativeSkillLoadEvidenceTier = "full_serve" | "native_observed";
|
|
83
|
+
export type SageNativeSkillLoadResult = {
|
|
84
|
+
schema: "sage.native-skill-load-signal.v1";
|
|
85
|
+
status: "recorded";
|
|
86
|
+
recorded: true;
|
|
87
|
+
qualified_key: string;
|
|
88
|
+
load_evidence_tier: "native_observed";
|
|
89
|
+
loaded_at_ms: number;
|
|
90
|
+
} | {
|
|
91
|
+
schema: "sage.native-skill-load-signal.v1";
|
|
92
|
+
status: "ignored";
|
|
93
|
+
recorded: false;
|
|
94
|
+
reason?: string;
|
|
95
|
+
} | {
|
|
96
|
+
schema: "sage.native-skill-load-signal.v1";
|
|
97
|
+
status: "failed";
|
|
98
|
+
recorded: false;
|
|
99
|
+
};
|
|
100
|
+
export interface SageNativeSkillUseRecord {
|
|
101
|
+
requested_name: string;
|
|
102
|
+
qualified_key: string;
|
|
103
|
+
load_evidence_tier: SageNativeSkillLoadEvidenceTier;
|
|
104
|
+
load_observed_at_ms: number;
|
|
105
|
+
recorded: boolean;
|
|
106
|
+
}
|
|
107
|
+
export interface SageNativeSkillUseResult {
|
|
108
|
+
schema: "sage.native-skill-use.v1";
|
|
109
|
+
status: "recorded";
|
|
110
|
+
capture_id: string;
|
|
111
|
+
capture_linkage: "explicit";
|
|
112
|
+
uses: SageNativeSkillUseRecord[];
|
|
113
|
+
}
|
|
78
114
|
export type SageCommandRunner = (request: SageCommandRequest) => Promise<SageCommandResult>;
|
|
79
115
|
type SecurityDecision = {
|
|
80
116
|
decision: "allow" | "block" | "warn";
|
|
81
117
|
reason?: string;
|
|
82
118
|
};
|
|
83
119
|
export declare function defaultSageCommandRunner(request: SageCommandRequest): Promise<SageCommandResult>;
|
|
120
|
+
/** Return terminal-visible width while ignoring ANSI SGR sequences. */
|
|
121
|
+
export declare function visibleWidthOf(line: string): number;
|
|
122
|
+
/** Truncate one ANSI-styled line without counting styling bytes as columns. */
|
|
123
|
+
export declare function truncateLineToWidth(line: string, width: number): string;
|
|
124
|
+
/** Clamp a line so custom TUI/status rendering cannot exceed terminal width. */
|
|
125
|
+
export declare function clampLineToWidth(line: string, width: number): string;
|
|
84
126
|
export declare class SageMcpBridge {
|
|
85
127
|
private command;
|
|
86
128
|
private args;
|
|
@@ -132,10 +174,12 @@ export declare class SageMcpBridge {
|
|
|
132
174
|
export declare class SageHookRuntime {
|
|
133
175
|
private config;
|
|
134
176
|
private commandRunner;
|
|
177
|
+
private workingDirectory;
|
|
135
178
|
private sessionContextCache;
|
|
136
179
|
private skillVisibilityCache;
|
|
137
180
|
private softFailureState;
|
|
138
181
|
constructor(config: Required<Pick<SageP2Config, "sageBin" | "timeoutMs">> & SageP2Config);
|
|
182
|
+
setWorkingDirectory(cwd: unknown): void;
|
|
139
183
|
private getSoftTimeout;
|
|
140
184
|
private clearSoftFailure;
|
|
141
185
|
private logSoftFailure;
|
|
@@ -148,15 +192,35 @@ export declare class SageHookRuntime {
|
|
|
148
192
|
* Returns cached or empty summary when the CLI is unavailable.
|
|
149
193
|
*/
|
|
150
194
|
getSkillVisibilitySummary(): Promise<SkillVisibilityResult>;
|
|
151
|
-
|
|
152
|
-
|
|
195
|
+
/**
|
|
196
|
+
* @deprecated Low-level compatibility helper. The default Pi path uses
|
|
197
|
+
* native skill discovery/loading and does not call this per prompt.
|
|
198
|
+
*/
|
|
199
|
+
suggestSkill(prompt: string, sessionId?: string, model?: string): Promise<string>;
|
|
200
|
+
capturePrompt(prompt: string, sessionId?: string): Promise<string | undefined>;
|
|
153
201
|
captureResponse(response: string, usage: {
|
|
154
202
|
input?: string;
|
|
155
203
|
output?: string;
|
|
156
|
-
}, sessionId?: string): Promise<
|
|
157
|
-
recordSuggestionUse(skillKeys: string[], sessionId?: string): Promise<
|
|
158
|
-
|
|
159
|
-
|
|
204
|
+
}, sessionId?: string, captureId?: string): Promise<boolean>;
|
|
205
|
+
recordSuggestionUse(skillKeys: string[], sessionId?: string, correlationId?: string): Promise<boolean>;
|
|
206
|
+
/**
|
|
207
|
+
* Atomically record use of procedures that Pi loaded natively. This path
|
|
208
|
+
* intentionally has no fallback to legacy suggestion feedback: the daemon
|
|
209
|
+
* must authorize every returned qualified record from session-scoped load
|
|
210
|
+
* evidence and link the complete batch to the exact capture.
|
|
211
|
+
*/
|
|
212
|
+
recordNativeSkillUse(skillKeys: string[], sessionId?: string, captureId?: string): Promise<SageNativeSkillUseResult | null>;
|
|
213
|
+
/**
|
|
214
|
+
* Record a daemon load receipt for a full skill procedure this session
|
|
215
|
+
* loaded through Pi's native full SKILL.md read or sage_execute get. The
|
|
216
|
+
* structured result only reports `recorded: true` after validating the
|
|
217
|
+
* explicit CLI's versioned JSON receipt. Ignored and failed writes remain
|
|
218
|
+
* non-recorded so callers can retry honestly.
|
|
219
|
+
*/
|
|
220
|
+
recordSkillLoadSignal(skillKey: string, sessionId?: string, via?: "slash" | "read"): Promise<SageNativeSkillLoadResult>;
|
|
221
|
+
recordSuggestionSkip(sessionId?: string, correlationId?: string): Promise<void>;
|
|
222
|
+
recordSuggestionReject(sessionId?: string, correlationId?: string): Promise<void>;
|
|
223
|
+
recordExecutionOutcome(skillKey: string, status: "passed" | "failed" | "revised", queryPreview?: string, sessionId?: string, _model?: string, correlationId?: string, captureId?: string): Promise<void>;
|
|
160
224
|
scanPreTool(toolName: string, toolInput: Record<string, unknown>, sessionId?: string): Promise<SecurityDecision | null>;
|
|
161
225
|
scanPostTool(toolName: string, toolInput: Record<string, unknown>, toolResult: unknown, sessionId?: string): Promise<SecurityDecision | null>;
|
|
162
226
|
/**
|
|
@@ -216,6 +280,7 @@ export interface SageToolWrapOptions {
|
|
|
216
280
|
export declare function wrapToolsWithSageSecurity(tools: ToolDefinition[], options: SageToolWrapOptions): ToolDefinition[];
|
|
217
281
|
export declare function createSageExtensions(options: SageP2SessionOptions): {
|
|
218
282
|
customTools: ToolDefinition[];
|
|
283
|
+
/** @deprecated Pi now handles native skill discovery and loading. This is a no-op. */
|
|
219
284
|
sageInjectSuggestion: (userPrompt: string, session?: AgentSession, sessionId?: string) => Promise<void>;
|
|
220
285
|
sageClearSuggestions: () => void;
|
|
221
286
|
sageGetSuggestions: () => string;
|