@punch-bot/cli 1.3.0 → 1.5.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/CHANGELOG.md +64 -0
- package/README.md +3 -3
- package/dist/bundle/chunks/anthropic-messages-WCANLUXE.js +6 -0
- package/dist/bundle/chunks/azure-openai-responses-46GRAI5B.js +2 -0
- package/dist/bundle/chunks/bedrock-converse-stream.js +8 -8
- package/dist/bundle/chunks/chunk-37OLNCAX.js +16 -0
- package/dist/bundle/chunks/{chunk-PYGXRV27.js → chunk-3V45WARH.js} +1 -1
- package/dist/bundle/chunks/chunk-4LBJE4YM.js +14 -0
- package/dist/bundle/chunks/{chunk-J7I2NFJ7.js → chunk-4NE64BTO.js} +1 -1
- package/dist/bundle/chunks/{chunk-S3GGRYIO.js → chunk-5AGIVGSV.js} +1 -1
- package/dist/bundle/chunks/{chunk-6WNF4BLC.js → chunk-5NXXRYVM.js} +1 -1
- package/dist/bundle/chunks/{chunk-6YKFJ7FQ.js → chunk-7BOHO7TR.js} +68 -66
- package/dist/bundle/chunks/{chunk-F5ZABL6Z.js → chunk-7CBJINYJ.js} +2 -2
- package/dist/bundle/chunks/{chunk-DRQDKNXA.js → chunk-7DDKXS2Q.js} +1 -1
- package/dist/bundle/chunks/chunk-7XECPCHN.js +2 -0
- package/dist/bundle/chunks/{chunk-OO6DJ3CL.js → chunk-A3Y7H47A.js} +1 -1
- package/dist/bundle/chunks/chunk-BRECMFDT.js +2 -0
- package/dist/bundle/chunks/chunk-HS7GCDEX.js +6 -0
- package/dist/bundle/chunks/{chunk-4L3WN2XY.js → chunk-JXWJOIH4.js} +1 -1
- package/dist/bundle/chunks/{chunk-6CYCI3EJ.js → chunk-LVVZS2NO.js} +1 -1
- package/dist/bundle/chunks/{chunk-6C5VKHGV.js → chunk-MYNHUMKE.js} +2 -2
- package/dist/bundle/chunks/{chunk-2M76JOVH.js → chunk-NJK3U3WK.js} +2 -2
- package/dist/bundle/chunks/chunk-NO2FNWW3.js +2 -0
- package/dist/bundle/chunks/chunk-PLK2QSUR.js +2 -0
- package/dist/bundle/chunks/{chunk-YGGF2ZM6.js → chunk-RFVYQ7ZX.js} +3 -3
- package/dist/bundle/chunks/{chunk-ZBURYEWF.js → chunk-TMTOQ7H7.js} +1 -1
- package/dist/bundle/chunks/{chunk-YWHGLBPB.js → chunk-UE7JCDFW.js} +1 -1
- package/dist/bundle/chunks/{chunk-22CYIUS4.js → chunk-UKVNB6C4.js} +1 -1
- package/dist/bundle/chunks/chunk-WZONBDPY.js +11 -0
- package/dist/bundle/chunks/{cli-QAQLORRY.js → cli-W5KJM7YB.js} +1 -1
- package/dist/bundle/chunks/cloudflare-workers-ai-system-one-FDCKYGTP.js +2 -0
- package/dist/bundle/chunks/{execute-2Z6BN5R3.js → execute-HXULRBCI.js} +9 -3
- package/dist/bundle/chunks/github-copilot.js +1 -1
- package/dist/bundle/chunks/google-generative-ai-2ESDEFYR.js +2 -0
- package/dist/bundle/chunks/google-vertex-YERBWL2T.js +2 -0
- package/dist/bundle/chunks/{https-proxy-agent-US7JVRJG.js → https-proxy-agent-VTEOYAYG.js} +1 -1
- package/dist/bundle/chunks/{jiti-loader-C3NU2SDH.js → jiti-loader-GL4HJFAD.js} +1 -1
- package/dist/bundle/chunks/{jiti-static-loader-E6ANQD5T.js → jiti-static-loader-2RCDI6B4.js} +1 -1
- package/dist/bundle/chunks/{lib-TEDK3E5I.js → lib-4AVRLBHM.js} +1 -1
- package/dist/bundle/chunks/{llama-cpp-classify-FYN623RH.js → llama-cpp-classify-M4KMJHPS.js} +2 -2
- package/dist/bundle/chunks/{mistral-conversations-VNJYBSRF.js → mistral-conversations-D6VQXE7C.js} +1 -1
- package/dist/bundle/chunks/{multipart-parser-SQ6GDJL7.js → multipart-parser-FMGQ7342.js} +1 -1
- package/dist/bundle/chunks/{node-TWVVAGPO.js → node-AUOGOBCN.js} +1 -1
- package/dist/bundle/chunks/{node-N5BSDOA5.js → node-KCMANYC2.js} +1 -1
- package/dist/bundle/chunks/openai-codex-responses-QSNSWBYG.js +10 -0
- package/dist/bundle/chunks/openai-completions-72VXSFHQ.js +7 -0
- package/dist/bundle/chunks/{openai-decisions-WVPMQ4JD.js → openai-decisions-PPJMQ3W4.js} +1 -1
- package/dist/bundle/chunks/openai-responses-PMTL72CY.js +4 -0
- package/dist/bundle/chunks/openrouter-images-WWPCCAPX.js +2 -0
- package/dist/bundle/chunks/pi-messages-WVCFUCBL.js +8 -0
- package/dist/bundle/chunks/{runtime-R6O72Q4R.js → runtime-R5GXO4CV.js} +1 -1
- package/dist/bundle/chunks/{src-UK77SYZE.js → src-QKGKDFSU.js} +1 -1
- package/dist/bundle/chunks/typesafe-system-one-NLWRPIRL.js +2 -0
- package/dist/bundle/chunks/virtual-modules-7Y5QW4VK.js +2 -0
- package/dist/bundle/cli-runtime.js +1 -1
- package/dist/bundle/index.js +1 -1
- package/dist/bundle/rpc-entry.js +1 -1
- package/dist/core/agent-session.d.ts +5 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +41 -12
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/client-identity.d.ts +8 -0
- package/dist/core/client-identity.d.ts.map +1 -0
- package/dist/core/client-identity.js +15 -0
- package/dist/core/client-identity.js.map +1 -0
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/core/compaction/branch-summarization.js +1 -2
- package/dist/core/compaction/branch-summarization.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts +2 -2
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +20 -15
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/export-html/index.d.ts.map +1 -1
- package/dist/core/export-html/index.js +2 -0
- package/dist/core/export-html/index.js.map +1 -1
- package/dist/core/export-html/template.html +1 -0
- package/dist/core/export-html/template.js +2 -1
- package/dist/core/export-html/vendor/marked-cjk-friendly.min.js +6 -0
- package/dist/core/export-html/vendor/marked.min.js +30 -29
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +3 -0
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/virtual-modules.d.ts.map +1 -1
- package/dist/core/extensions/virtual-modules.js +3 -0
- package/dist/core/extensions/virtual-modules.js.map +1 -1
- package/dist/core/model-config.d.ts +915 -0
- package/dist/core/model-config.d.ts.map +1 -1
- package/dist/core/model-config.js +48 -24
- package/dist/core/model-config.js.map +1 -1
- package/dist/core/model-resolver.js +3 -3
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +6 -3
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/provider-composer.d.ts +2 -1
- package/dist/core/provider-composer.d.ts.map +1 -1
- package/dist/core/provider-composer.js +7 -3
- package/dist/core/provider-composer.js.map +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +8 -9
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/system-prompt.d.ts +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +8 -9
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js +3 -1
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/extensions/codemode/execute.d.ts.map +1 -1
- package/dist/extensions/codemode/execute.js +99 -24
- package/dist/extensions/codemode/execute.js.map +1 -1
- package/dist/extensions/mcp/config.d.ts.map +1 -1
- package/dist/extensions/mcp/config.js +3 -2
- package/dist/extensions/mcp/config.js.map +1 -1
- package/dist/extensions/punch/a2a-listen.d.ts.map +1 -1
- package/dist/extensions/punch/a2a-listen.js +1 -0
- package/dist/extensions/punch/a2a-listen.js.map +1 -1
- package/dist/extensions/punch/a2a.d.ts.map +1 -1
- package/dist/extensions/punch/a2a.js +12 -5
- package/dist/extensions/punch/a2a.js.map +1 -1
- package/dist/extensions/punch/auth.d.ts +4 -1
- package/dist/extensions/punch/auth.d.ts.map +1 -1
- package/dist/extensions/punch/auth.js +17 -2
- package/dist/extensions/punch/auth.js.map +1 -1
- package/dist/extensions/punch/collabs.d.ts.map +1 -1
- package/dist/extensions/punch/collabs.js +46 -40
- package/dist/extensions/punch/collabs.js.map +1 -1
- package/dist/extensions/punch/index.d.ts.map +1 -1
- package/dist/extensions/punch/index.js +2 -0
- package/dist/extensions/punch/index.js.map +1 -1
- package/dist/extensions/punch/plan-gate.d.ts +34 -0
- package/dist/extensions/punch/plan-gate.d.ts.map +1 -0
- package/dist/extensions/punch/plan-gate.js +149 -0
- package/dist/extensions/punch/plan-gate.js.map +1 -0
- package/dist/extensions/webfetch/index.d.ts.map +1 -1
- package/dist/extensions/webfetch/index.js +2 -1
- package/dist/extensions/webfetch/index.js.map +1 -1
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/package-manager-cli.js +2 -1
- package/dist/package-manager-cli.js.map +1 -1
- package/dist/server/a2a/run-server.d.ts +2 -0
- package/dist/server/a2a/run-server.d.ts.map +1 -1
- package/dist/server/a2a/run-server.js +2 -0
- package/dist/server/a2a/run-server.js.map +1 -1
- package/dist/utils/clipboard-command.d.ts.map +1 -1
- package/dist/utils/clipboard-command.js +3 -0
- package/dist/utils/clipboard-command.js.map +1 -1
- package/dist/utils/pi-user-agent.d.ts +1 -0
- package/dist/utils/pi-user-agent.d.ts.map +1 -1
- package/dist/utils/pi-user-agent.js +3 -2
- package/dist/utils/pi-user-agent.js.map +1 -1
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +45 -13
- package/dist/utils/shell.js.map +1 -1
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +4 -3
- package/dist/utils/tools-manager.js.map +1 -1
- package/docs/cli.md +1 -1
- package/docs/codemode.md +2 -2
- package/docs/compaction.md +3 -3
- package/docs/configuration.md +2 -2
- package/docs/custom-provider.md +53 -1
- package/docs/docs.json +4 -0
- package/docs/environment-variables.md +3 -0
- package/docs/extensions.md +129 -10
- package/docs/models-configuration.md +196 -0
- package/docs/models.md +21 -5
- package/docs/settings.md +1 -1
- package/docs/usage.md +4 -2
- package/docs/windows.md +16 -2
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +5 -5
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/examples/sdk/03-custom-prompt.ts +1 -1
- package/npm-shrinkwrap.json +28 -24
- package/package.json +8 -7
- package/schemas/models.schema.json +83 -29
- package/dist/bundle/chunks/anthropic-messages-BUUFZMRE.js +0 -6
- package/dist/bundle/chunks/azure-openai-responses-WZ4GZHD2.js +0 -2
- package/dist/bundle/chunks/chunk-BYHXHV4K.js +0 -11
- package/dist/bundle/chunks/chunk-HACVPRBJ.js +0 -11
- package/dist/bundle/chunks/chunk-ITZNWD4K.js +0 -2
- package/dist/bundle/chunks/chunk-OWCYH5W2.js +0 -2
- package/dist/bundle/chunks/chunk-QQO2NSV6.js +0 -6
- package/dist/bundle/chunks/chunk-WUIPA42N.js +0 -14
- package/dist/bundle/chunks/chunk-XIX7LUWI.js +0 -2
- package/dist/bundle/chunks/cloudflare-workers-ai-system-one-UTBL2KOF.js +0 -2
- package/dist/bundle/chunks/google-generative-ai-S2KXX5PQ.js +0 -2
- package/dist/bundle/chunks/google-vertex-LQOUTFJN.js +0 -2
- package/dist/bundle/chunks/openai-codex-responses-E6BLZPYJ.js +0 -10
- package/dist/bundle/chunks/openai-completions-LUDIAWSG.js +0 -7
- package/dist/bundle/chunks/openai-responses-IOCBEIVC.js +0 -3
- package/dist/bundle/chunks/openrouter-images-YU24TD7D.js +0 -2
- package/dist/bundle/chunks/pi-messages-V27DSLVC.js +0 -8
- package/dist/bundle/chunks/typesafe-system-one-ZSK3RN4B.js +0 -2
- package/dist/bundle/chunks/virtual-modules-GZVZPCK3.js +0 -2
- package/dist/core/provider-attribution.d.ts +0 -4
- package/dist/core/provider-attribution.d.ts.map +0 -1
- package/dist/core/provider-attribution.js +0 -72
- package/dist/core/provider-attribution.js.map +0 -1
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
// Plan gate: Punch's model-triggered, human-gated work approval.
|
|
2
|
+
//
|
|
3
|
+
// `propose_plan` is the model-side half of the gate: before multi-step or
|
|
4
|
+
// mutating work the model proposes a plan, the tool forwards it to the Punch
|
|
5
|
+
// bot through the sandbox supervisor (:4097), and the turn ends while a human
|
|
6
|
+
// decides on the posted card. The bot stamps `origin` (user vs a2a:<peer>)
|
|
7
|
+
// itself — it is deliberately not part of the schema the model can fill in.
|
|
8
|
+
//
|
|
9
|
+
// `createDeferredApprovalHook` is the policy-side counterpart ("belt to the
|
|
10
|
+
// model's suspenders" — the model can forget to call the tool; a hook cannot).
|
|
11
|
+
// It produces a `tool_call` handler that blocks gated tool calls while an
|
|
12
|
+
// external decision is pending. Hosts wire it to their own decision source
|
|
13
|
+
// (e.g. the bot's /plan/resolve endpoint) and register it with
|
|
14
|
+
// `pi.on("tool_call", ...)`. At the harness layer the equivalent seam is the
|
|
15
|
+
// `before_tool` hook (HookMap/HookHandler, exported from @punch-bot/agent).
|
|
16
|
+
//
|
|
17
|
+
// Deliberately absent in v1: true run suspension (suspend the lane, free the
|
|
18
|
+
// executor, resume on approval). That needs session create.restore + a
|
|
19
|
+
// human-decision lane.resume(), which the agent harness does not expose yet.
|
|
20
|
+
// End-turn + a fresh enqueued turn on approval is equivalent UX for a
|
|
21
|
+
// human-speed decision.
|
|
22
|
+
import { Type } from "typebox";
|
|
23
|
+
const DEFAULT_SUPERVISOR_URL = "http://localhost:4097";
|
|
24
|
+
const SUPERVISOR_TIMEOUT_MS = 15_000;
|
|
25
|
+
/** The gate only exists inside a Punch sandbox (or when pointed at one). */
|
|
26
|
+
export function isPlanGateEnabled(env = process.env) {
|
|
27
|
+
return Boolean(env.PUNCH_PLAN_GATE_URL?.trim() || env.SANDBOX_NAME?.trim());
|
|
28
|
+
}
|
|
29
|
+
function supervisorAuthHeader(env) {
|
|
30
|
+
const user = env.PI_SERVER_USERNAME || env.OPENCODE_SERVER_USERNAME || "opencode";
|
|
31
|
+
const pass = env.PI_SERVER_PASSWORD || env.OPENCODE_SERVER_PASSWORD || "";
|
|
32
|
+
return `Basic ${Buffer.from(`${user}:${pass}`).toString("base64")}`;
|
|
33
|
+
}
|
|
34
|
+
async function postToSupervisor(env, path, body, signal) {
|
|
35
|
+
const base = (env.PUNCH_PLAN_GATE_URL || DEFAULT_SUPERVISOR_URL).replace(/\/+$/, "");
|
|
36
|
+
const response = await fetch(`${base}${path}`, {
|
|
37
|
+
method: "POST",
|
|
38
|
+
headers: { "content-type": "application/json", authorization: supervisorAuthHeader(env) },
|
|
39
|
+
body: JSON.stringify(body),
|
|
40
|
+
signal: signal
|
|
41
|
+
? AbortSignal.any([signal, AbortSignal.timeout(SUPERVISOR_TIMEOUT_MS)])
|
|
42
|
+
: AbortSignal.timeout(SUPERVISOR_TIMEOUT_MS),
|
|
43
|
+
});
|
|
44
|
+
const text = await response.text();
|
|
45
|
+
let data;
|
|
46
|
+
try {
|
|
47
|
+
data = JSON.parse(text);
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
data = {};
|
|
51
|
+
}
|
|
52
|
+
if (!response.ok) {
|
|
53
|
+
throw new Error(`plan gate ${response.status}: ${text.slice(0, 200)}`);
|
|
54
|
+
}
|
|
55
|
+
return data;
|
|
56
|
+
}
|
|
57
|
+
// A tool result that ends the turn. The agent loop terminates the run when
|
|
58
|
+
// every finalized tool result in the batch carries terminate: true.
|
|
59
|
+
function endTurn(text, details) {
|
|
60
|
+
return { content: [{ type: "text", text }], details, terminate: true };
|
|
61
|
+
}
|
|
62
|
+
export function installPlanGate(pi, options = {}) {
|
|
63
|
+
const env = options.env ?? process.env;
|
|
64
|
+
if (!isPlanGateEnabled(env))
|
|
65
|
+
return;
|
|
66
|
+
const post = options.post ??
|
|
67
|
+
((path, body, signal) => postToSupervisor(env, path, body, signal));
|
|
68
|
+
pi.registerTool({
|
|
69
|
+
name: "propose_plan",
|
|
70
|
+
label: "Propose plan",
|
|
71
|
+
description: "Propose a plan for human approval before starting multi-step or mutating work. " +
|
|
72
|
+
"Ends the turn pending approval; do not perform the proposed work until it is approved.",
|
|
73
|
+
promptSnippet: "Propose a plan and wait for approval before multi-step or mutating work",
|
|
74
|
+
promptGuidelines: [
|
|
75
|
+
"Before starting multi-step or mutating work (file edits, running commands, project changes, anything > 1 tool call), call propose_plan with the plan. Do not perform the work until the plan is approved.",
|
|
76
|
+
"Casual chat, questions, lookups, and anything the user explicitly said 'just do it' / 'no plan needed' bypass the gate.",
|
|
77
|
+
"propose_plan ends the turn when approval is required — do not poll and do not proceed.",
|
|
78
|
+
],
|
|
79
|
+
parameters: Type.Object({
|
|
80
|
+
summary: Type.String({ description: "One line, shown as the plan card title" }),
|
|
81
|
+
steps: Type.Array(Type.String(), {
|
|
82
|
+
minItems: 1,
|
|
83
|
+
maxItems: 20,
|
|
84
|
+
description: "Short imperative steps the plan will run",
|
|
85
|
+
}),
|
|
86
|
+
touch: Type.Optional(Type.Array(Type.String(), { description: "Files/dirs the plan will modify" })),
|
|
87
|
+
commands: Type.Optional(Type.Array(Type.String(), { description: "Shell commands the plan intends to run" })),
|
|
88
|
+
est: Type.Optional(Type.String({ description: "Concrete estimate, e.g. '~2 min'" })),
|
|
89
|
+
}),
|
|
90
|
+
async execute(_toolCallId, args, signal) {
|
|
91
|
+
const body = {
|
|
92
|
+
summary: args.summary,
|
|
93
|
+
steps: args.steps,
|
|
94
|
+
touch: args.touch ?? [],
|
|
95
|
+
commands: args.commands ?? [],
|
|
96
|
+
est: args.est ?? null,
|
|
97
|
+
};
|
|
98
|
+
let response;
|
|
99
|
+
try {
|
|
100
|
+
response = await post("/plan/propose", body, signal);
|
|
101
|
+
}
|
|
102
|
+
catch (err) {
|
|
103
|
+
// No decision, no execution: end the turn rather than run ungated.
|
|
104
|
+
return endTurn(`Plan gate unreachable (${err.message}). Turn ended; retry later.`, {});
|
|
105
|
+
}
|
|
106
|
+
if (response.decision === "approved") {
|
|
107
|
+
return {
|
|
108
|
+
content: [
|
|
109
|
+
{
|
|
110
|
+
type: "text",
|
|
111
|
+
text: `Plan ${response.planId ?? ""} auto-approved — proceed with the proposed work.`,
|
|
112
|
+
},
|
|
113
|
+
],
|
|
114
|
+
details: response,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
if (response.decision === "pending") {
|
|
118
|
+
return endTurn(`Plan ${response.planId ?? ""} proposed — awaiting approval. Do not proceed with the proposed work.`, response);
|
|
119
|
+
}
|
|
120
|
+
const reason = response.reason ? ` (${response.reason})` : "";
|
|
121
|
+
return endTurn(`Plan ${response.planId ?? ""} denied${reason} — do not proceed with the proposed work.`, response);
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
// Reference implementation of "defer execution pending external decision".
|
|
126
|
+
// Register the returned handler via pi.on("tool_call", handler) so a host can
|
|
127
|
+
// enforce the gate policy-side even when the model forgets to call
|
|
128
|
+
// propose_plan. pending blocks the call and terminates the batch (turn ends,
|
|
129
|
+
// work is not started); denied blocks without terminating (the model sees the
|
|
130
|
+
// refusal and can react); approved lets the call execute.
|
|
131
|
+
export function createDeferredApprovalHook(options) {
|
|
132
|
+
const exempt = new Set(options.exemptToolNames ?? []);
|
|
133
|
+
return async (event) => {
|
|
134
|
+
if (exempt.has(event.toolName))
|
|
135
|
+
return;
|
|
136
|
+
const decision = await options.decide(event);
|
|
137
|
+
if (decision.status === "approved")
|
|
138
|
+
return;
|
|
139
|
+
if (decision.status === "pending") {
|
|
140
|
+
return {
|
|
141
|
+
block: true,
|
|
142
|
+
reason: decision.reason ?? "Execution deferred pending external approval.",
|
|
143
|
+
terminate: true,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
return { block: true, reason: decision.reason ?? "Execution denied by the plan gate." };
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
//# sourceMappingURL=plan-gate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan-gate.js","sourceRoot":"","sources":["../../../src/extensions/punch/plan-gate.ts"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,EAAE;AACF,0EAA0E;AAC1E,6EAA6E;AAC7E,8EAA8E;AAC9E,2EAA2E;AAC3E,4EAA4E;AAC5E,EAAE;AACF,4EAA4E;AAC5E,+EAA+E;AAC/E,0EAA0E;AAC1E,2EAA2E;AAC3E,+DAA+D;AAC/D,6EAA6E;AAC7E,4EAA4E;AAC5E,EAAE;AACF,6EAA6E;AAC7E,uEAAuE;AACvE,6EAA6E;AAC7E,sEAAsE;AACtE,wBAAwB;AAGxB,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAS/B,MAAM,sBAAsB,GAAG,uBAAuB,CAAC;AACvD,MAAM,qBAAqB,GAAG,MAAM,CAAC;AAerC,4EAA4E;AAC5E,MAAM,UAAU,iBAAiB,CAAC,GAAG,GAAsB,OAAO,CAAC,GAAG;IACrE,OAAO,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,IAAI,EAAE,IAAI,GAAG,CAAC,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC;AAC7E,CAAC;AAED,SAAS,oBAAoB,CAAC,GAAsB;IACnD,MAAM,IAAI,GAAG,GAAG,CAAC,kBAAkB,IAAI,GAAG,CAAC,wBAAwB,IAAI,UAAU,CAAC;IAClF,MAAM,IAAI,GAAG,GAAG,CAAC,kBAAkB,IAAI,GAAG,CAAC,wBAAwB,IAAI,EAAE,CAAC;IAC1E,OAAO,SAAS,MAAM,CAAC,IAAI,CAAC,GAAG,IA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AC;YACH,CAAC;YACD,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;YAC9D,OAAO,OAAO,CACb,QAAQ,QAAQ,CAAC,MAAM,IAAI,EAAE,UAAU,MAAM,2CAA2C,EACxF,QAAQ,CACR,CAAC;QACH,CAAC;KACD,CAAC,CAAC;AACJ,CAAC;AAiBD,2EAA2E;AAC3E,8EAA8E;AAC9E,mEAAmE;AACnE,6EAA6E;AAC7E,8EAA8E;AAC9E,0DAA0D;AAC1D,MAAM,UAAU,0BAA0B,CAAC,OAAgC;IAC1E,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,eAAe,IAAI,EAAE,CAAC,CAAC;IACtD,OAAO,KAAK,EAAE,KAAoB,EAA4C,EAAE;QAC/E,IAAI,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC;YAAE,OAAO;QACvC,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC7C,IAAI,QAAQ,CAAC,MAAM,KAAK,UAAU;YAAE,OAAO;QAC3C,IAAI,QAAQ,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YACnC,OAAO;gBACN,KAAK,EAAE,IAAI;gBACX,MAAM,EAAE,QAAQ,CAAC,MAAM,IAAI,+CAA+C;gBAC1E,SAAS,EAAE,IAAI;aACf,CAAC;QACH,CAAC;QACD,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,IAAI,oCAAoC,EAAE,CAAC;IACzF,CAAC,CAAC;AACH,CAAC","sourcesContent":["// Plan gate: Punch's model-triggered, human-gated work approval.\n//\n// `propose_plan` is the model-side half of the gate: before multi-step or\n// mutating work the model proposes a plan, the tool forwards it to the Punch\n// bot through the sandbox supervisor (:4097), and the turn ends while a human\n// decides on the posted card. The bot stamps `origin` (user vs a2a:<peer>)\n// itself — it is deliberately not part of the schema the model can fill in.\n//\n// `createDeferredApprovalHook` is the policy-side counterpart (\"belt to the\n// model's suspenders\" — the model can forget to call the tool; a hook cannot).\n// It produces a `tool_call` handler that blocks gated tool calls while an\n// external decision is pending. Hosts wire it to their own decision source\n// (e.g. the bot's /plan/resolve endpoint) and register it with\n// `pi.on(\"tool_call\", ...)`. At the harness layer the equivalent seam is the\n// `before_tool` hook (HookMap/HookHandler, exported from @punch-bot/agent).\n//\n// Deliberately absent in v1: true run suspension (suspend the lane, free the\n// executor, resume on approval). That needs session create.restore + a\n// human-decision lane.resume(), which the agent harness does not expose yet.\n// End-turn + a fresh enqueued turn on approval is equivalent UX for a\n// human-speed decision.\n\nimport type { AgentToolResult } from \"@punch-bot/agent\";\nimport { Type } from \"typebox\";\n\nimport type {\n\tExtensionAPI,\n\tExtensionHandler,\n\tToolCallEvent,\n\tToolCallEventResult,\n} from \"../../core/extensions/types.ts\";\n\nconst DEFAULT_SUPERVISOR_URL = \"http://localhost:4097\";\nconst SUPERVISOR_TIMEOUT_MS = 15_000;\n\nexport interface PlanProposalResponse {\n\tplanId?: string;\n\t/** \"pending\" = human must approve · \"approved\" = auto-approved · \"denied\" = do not run */\n\tdecision?: \"pending\" | \"approved\" | \"denied\" | string;\n\treason?: string;\n}\n\nexport interface InstallPlanGateOptions {\n\tenv?: NodeJS.ProcessEnv;\n\t/** POST helper for tests; production posts to the sandbox supervisor. */\n\tpost?: (path: string, body: Record<string, unknown>, signal?: AbortSignal) => Promise<PlanProposalResponse>;\n}\n\n/** The gate only exists inside a Punch sandbox (or when pointed at one). */\nexport function isPlanGateEnabled(env: NodeJS.ProcessEnv = process.env): boolean {\n\treturn Boolean(env.PUNCH_PLAN_GATE_URL?.trim() || env.SANDBOX_NAME?.trim());\n}\n\nfunction supervisorAuthHeader(env: NodeJS.ProcessEnv): string {\n\tconst user = env.PI_SERVER_USERNAME || env.OPENCODE_SERVER_USERNAME || \"opencode\";\n\tconst pass = env.PI_SERVER_PASSWORD || env.OPENCODE_SERVER_PASSWORD || \"\";\n\treturn `Basic ${Buffer.from(`${user}:${pass}`).toString(\"base64\")}`;\n}\n\nasync function postToSupervisor(\n\tenv: NodeJS.ProcessEnv,\n\tpath: string,\n\tbody: Record<string, unknown>,\n\tsignal?: AbortSignal,\n): Promise<PlanProposalResponse> {\n\tconst base = (env.PUNCH_PLAN_GATE_URL || DEFAULT_SUPERVISOR_URL).replace(/\\/+$/, \"\");\n\tconst response = await fetch(`${base}${path}`, {\n\t\tmethod: \"POST\",\n\t\theaders: { \"content-type\": \"application/json\", authorization: supervisorAuthHeader(env) },\n\t\tbody: JSON.stringify(body),\n\t\tsignal: signal\n\t\t\t? AbortSignal.any([signal, AbortSignal.timeout(SUPERVISOR_TIMEOUT_MS)])\n\t\t\t: AbortSignal.timeout(SUPERVISOR_TIMEOUT_MS),\n\t});\n\tconst text = await response.text();\n\tlet data: PlanProposalResponse;\n\ttry {\n\t\tdata = JSON.parse(text) as PlanProposalResponse;\n\t} catch {\n\t\tdata = {};\n\t}\n\tif (!response.ok) {\n\t\tthrow new Error(`plan gate ${response.status}: ${text.slice(0, 200)}`);\n\t}\n\treturn data;\n}\n\n// A tool result that ends the turn. The agent loop terminates the run when\n// every finalized tool result in the batch carries terminate: true.\nfunction endTurn(text: string, details: PlanProposalResponse): AgentToolResult<PlanProposalResponse> {\n\treturn { content: [{ type: \"text\", text }], details, terminate: true };\n}\n\nexport function installPlanGate(pi: ExtensionAPI, options: InstallPlanGateOptions = {}): void {\n\tconst env = options.env ?? process.env;\n\tif (!isPlanGateEnabled(env)) return;\n\tconst post =\n\t\toptions.post ??\n\t\t((path: string, body: Record<string, unknown>, signal?: AbortSignal) =>\n\t\t\tpostToSupervisor(env, path, body, signal));\n\n\tpi.registerTool({\n\t\tname: \"propose_plan\",\n\t\tlabel: \"Propose plan\",\n\t\tdescription:\n\t\t\t\"Propose a plan for human approval before starting multi-step or mutating work. \" +\n\t\t\t\"Ends the turn pending approval; do not perform the proposed work until it is approved.\",\n\t\tpromptSnippet: \"Propose a plan and wait for approval before multi-step or mutating work\",\n\t\tpromptGuidelines: [\n\t\t\t\"Before starting multi-step or mutating work (file edits, running commands, project changes, anything > 1 tool call), call propose_plan with the plan. Do not perform the work until the plan is approved.\",\n\t\t\t\"Casual chat, questions, lookups, and anything the user explicitly said 'just do it' / 'no plan needed' bypass the gate.\",\n\t\t\t\"propose_plan ends the turn when approval is required — do not poll and do not proceed.\",\n\t\t],\n\t\tparameters: Type.Object({\n\t\t\tsummary: Type.String({ description: \"One line, shown as the plan card title\" }),\n\t\t\tsteps: Type.Array(Type.String(), {\n\t\t\t\tminItems: 1,\n\t\t\t\tmaxItems: 20,\n\t\t\t\tdescription: \"Short imperative steps the plan will run\",\n\t\t\t}),\n\t\t\ttouch: Type.Optional(Type.Array(Type.String(), { description: \"Files/dirs the plan will modify\" })),\n\t\t\tcommands: Type.Optional(Type.Array(Type.String(), { description: \"Shell commands the plan intends to run\" })),\n\t\t\test: Type.Optional(Type.String({ description: \"Concrete estimate, e.g. '~2 min'\" })),\n\t\t}),\n\t\tasync execute(_toolCallId, args, signal) {\n\t\t\tconst body = {\n\t\t\t\tsummary: args.summary,\n\t\t\t\tsteps: args.steps,\n\t\t\t\ttouch: args.touch ?? [],\n\t\t\t\tcommands: args.commands ?? [],\n\t\t\t\test: args.est ?? null,\n\t\t\t};\n\t\t\tlet response: PlanProposalResponse;\n\t\t\ttry {\n\t\t\t\tresponse = await post(\"/plan/propose\", body, signal);\n\t\t\t} catch (err) {\n\t\t\t\t// No decision, no execution: end the turn rather than run ungated.\n\t\t\t\treturn endTurn(`Plan gate unreachable (${(err as Error).message}). Turn ended; retry later.`, {});\n\t\t\t}\n\t\t\tif (response.decision === \"approved\") {\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\t\ttext: `Plan ${response.planId ?? \"\"} auto-approved — proceed with the proposed work.`,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tdetails: response,\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (response.decision === \"pending\") {\n\t\t\t\treturn endTurn(\n\t\t\t\t\t`Plan ${response.planId ?? \"\"} proposed — awaiting approval. Do not proceed with the proposed work.`,\n\t\t\t\t\tresponse,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst reason = response.reason ? ` (${response.reason})` : \"\";\n\t\t\treturn endTurn(\n\t\t\t\t`Plan ${response.planId ?? \"\"} denied${reason} — do not proceed with the proposed work.`,\n\t\t\t\tresponse,\n\t\t\t);\n\t\t},\n\t});\n}\n\nexport type DeferredApprovalDecision =\n\t| { status: \"approved\" }\n\t| { status: \"pending\"; reason?: string }\n\t| { status: \"denied\"; reason?: string };\n\nexport interface DeferredApprovalOptions {\n\t/** Tool names that bypass the decision check (e.g. read-only lookups). */\n\texemptToolNames?: readonly string[];\n\t/** Consult the external decision source for this tool call. */\n\tdecide: (event: ToolCallEvent) => Promise<DeferredApprovalDecision> | DeferredApprovalDecision;\n}\n\n/** `tool_call` handler signature produced by createDeferredApprovalHook. */\nexport type DeferredApprovalHandler = ExtensionHandler<ToolCallEvent, ToolCallEventResult>;\n\n// Reference implementation of \"defer execution pending external decision\".\n// Register the returned handler via pi.on(\"tool_call\", handler) so a host can\n// enforce the gate policy-side even when the model forgets to call\n// propose_plan. pending blocks the call and terminates the batch (turn ends,\n// work is not started); denied blocks without terminating (the model sees the\n// refusal and can react); approved lets the call execute.\nexport function createDeferredApprovalHook(options: DeferredApprovalOptions): DeferredApprovalHandler {\n\tconst exempt = new Set(options.exemptToolNames ?? []);\n\treturn async (event: ToolCallEvent): Promise<ToolCallEventResult | undefined> => {\n\t\tif (exempt.has(event.toolName)) return;\n\t\tconst decision = await options.decide(event);\n\t\tif (decision.status === \"approved\") return;\n\t\tif (decision.status === \"pending\") {\n\t\t\treturn {\n\t\t\t\tblock: true,\n\t\t\t\treason: decision.reason ?? \"Execution deferred pending external approval.\",\n\t\t\t\tterminate: true,\n\t\t\t};\n\t\t}\n\t\treturn { block: true, reason: decision.reason ?? \"Execution denied by the plan gate.\" };\n\t};\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/extensions/webfetch/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/extensions/webfetch/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AA6KnE,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI,CAyDhE"}
|
|
@@ -146,7 +146,8 @@ async function fetchText(url, rawLimit) {
|
|
|
146
146
|
method: "GET",
|
|
147
147
|
signal: AbortSignal.timeout(15_000),
|
|
148
148
|
});
|
|
149
|
-
const
|
|
149
|
+
const locationHeader = res.headers.location;
|
|
150
|
+
const location = Array.isArray(locationHeader) ? locationHeader[0] : locationHeader;
|
|
150
151
|
if (res.statusCode >= 300 && res.statusCode < 400) {
|
|
151
152
|
res.body.destroy();
|
|
152
153
|
if (!location)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/extensions/webfetch/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAGxC,SAAS,SAAS,CAAC,IAAY;IAC9B,OAAO,IAAI;SACT,OAAO,CAAC,6BAA6B,EAA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AAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;oBAC3D,MAAM,IAAI,GAAG,MAAO,IAAsD,CAAC,QAAQ,CAClF,wBAAwB,QAAQ,wKAAwK,CACxM,CAAC;oBACF,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;gBACpE,CAAC;wBAAS,CAAC;oBACV,MAAO,IAAmC,CAAC,KAAK,EAAE,CAAC;gBACpD,CAAC;YACF,CAAC;QACF,CAAC;KACD,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { LookupAddress, LookupOptions } from \"node:dns\";\nimport { lookup } from \"node:dns/promises\";\nimport { isIP } from \"node:net\";\nimport { Type } from \"typebox\";\nimport { Agent, request } from \"undici\";\nimport type { ExtensionAPI } from \"../../core/extensions/types.ts\";\n\nfunction stripHtml(html: string): string {\n\treturn html\n\t\t.replace(/<script[\\s\\S]*?<\\/script>/gi, \"\")\n\t\t.replace(/<style[\\s\\S]*?<\\/style>/gi, \"\")\n\t\t.replace(/<[^>]+>/g, \" \")\n\t\t.replace(/ /g, \" \")\n\t\t.replace(/&/g, \"&\")\n\t\t.replace(/</g, \"<\")\n\t\t.replace(/>/g, \">\")\n\t\t.replace(/"/g, '\"')\n\t\t.replace(/'/g, \"'\")\n\t\t.replace(/\\s+/g, \" \")\n\t\t.trim();\n}\n\nfunction expandIpv6(address: string): string {\n\tconst withoutZone = address.split(\"%\")[0];\n\tif (!withoutZone.includes(\"::\")) return withoutZone;\n\tconst [head, tail] = withoutZone.split(\"::\");\n\tconst headParts = head ? head.split(\":\") : [];\n\tconst tailParts = tail ? tail.split(\":\") : [];\n\tconst missing = Math.max(0, 8 - headParts.length - tailParts.length);\n\treturn [...headParts, ...Array(missing).fill(\"0\"), ...tailParts].join(\":\");\n}\n\nfunction isIpv4MappedToV6(address: string): string | null {\n\tconst withoutZone = address.toLowerCase().split(\"%\")[0];\n\tif (!withoutZone.includes(\":\")) return null;\n\tconst parts = expandIpv6(withoutZone).split(\":\");\n\tif (parts.length !== 8) return null;\n\tif (parts[7].includes(\".\")) {\n\t\tconst head = parts.slice(0, 7).map((part) => Number.parseInt(part, 16));\n\t\tif (head.some((value) => Number.isNaN(value))) return null;\n\t\tconst mapped = head[6] === 0xffff && head.slice(0, 6).every((value) => value === 0);\n\t\tconst compatible = head.every((value) => value === 0);\n\t\tif (!mapped && !compatible) return null;\n\t\treturn parts[7];\n\t}\n\tconst values = parts.map((part) => Number.parseInt(part, 16));\n\tif (values.some((value) => Number.isNaN(value))) return null;\n\tconst mapped = values[5] === 0xffff && values.slice(0, 5).every((value) => value === 0);\n\tconst compatible = values.slice(0, 7).every((value) => value === 0);\n\tif (!mapped && !compatible) return null;\n\treturn `${values[6] >> 8}.${values[6] & 0xff}.${values[7] >> 8}.${values[7] & 0xff}`;\n}\n\nfunction isBlockedIp(ip: string): boolean {\n\tconst v = ip.toLowerCase();\n\tif (v === \"::1\" || v === \"::\" || v === \"0.0.0.0\") return true;\n\tconst mapped = isIpv4MappedToV6(v);\n\tif (mapped !== null) return isBlockedIp(mapped);\n\tif (v.includes(\":\")) {\n\t\tconst first = Number.parseInt(expandIpv6(v).split(\":\")[0], 16);\n\t\tif (Number.isNaN(first)) return false;\n\t\tif (first >= 0xfc00 && first <= 0xfdff) return true;\n\t\tif (first >= 0xfe80 && first <= 0xfebf) return true;\n\t\treturn false;\n\t}\n\tif (/^127\\./.test(v) || /^169\\.254\\./.test(v) || /^10\\./.test(v) || /^192\\.168\\./.test(v)) return true;\n\tif (/^100\\.(6[4-9]|[7-9]\\d|1[01]\\d|12[0-7])\\./.test(v)) return true;\n\treturn /^172\\.(1[6-9]|2\\d|3[01])\\./.test(v);\n}\n\ninterface SafeTarget {\n\turl: URL;\n\thostname: string;\n\taddresses: string[];\n}\n\nasync function resolveSafe(value: string): Promise<SafeTarget> {\n\tlet parsed: URL;\n\ttry {\n\t\tparsed = new URL(value);\n\t} catch {\n\t\tthrow new Error(`Invalid URL: ${value}`);\n\t}\n\tif (parsed.protocol !== \"http:\" && parsed.protocol !== \"https:\") {\n\t\tthrow new Error(\"Only http and https URLs are supported\");\n\t}\n\tlet hostname = parsed.hostname.toLowerCase();\n\tif (hostname.startsWith(\"[\") && hostname.endsWith(\"]\")) hostname = hostname.slice(1, -1);\n\tif (hostname === \"localhost\") {\n\t\tthrow new Error(\"URLs pointing at loopback addresses are not allowed\");\n\t}\n\tlet addresses: string[];\n\tconst literalFamily = isIP(hostname);\n\tif (literalFamily !== 0) {\n\t\taddresses = [hostname];\n\t} else {\n\t\ttry {\n\t\t\taddresses = (await lookup(hostname, { all: true })).map((entry) => entry.address);\n\t\t} catch {\n\t\t\tthrow new Error(`Could not resolve host: ${hostname}`);\n\t\t}\n\t}\n\tfor (const address of addresses) {\n\t\tif (isBlockedIp(address)) {\n\t\t\tthrow new Error(\"URLs pointing at loopback, private, or link-local addresses are not allowed\");\n\t\t}\n\t}\n\treturn { url: parsed, hostname, addresses };\n}\n\nfunction pinnedAgent(target: SafeTarget): Agent {\n\treturn new Agent({\n\t\tconnect: {\n\t\t\tlookup: (\n\t\t\t\thost: string,\n\t\t\t\toptions: LookupOptions,\n\t\t\t\tcallback: (err: NodeJS.ErrnoException | null, address: string | LookupAddress[], family?: number) => void,\n\t\t\t) => {\n\t\t\t\tif (host !== target.hostname) {\n\t\t\t\t\tcallback(new Error(`unexpected host ${host}`), []);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst entries: LookupAddress[] = target.addresses.map((address) => ({\n\t\t\t\t\taddress,\n\t\t\t\t\tfamily: isIP(address) === 6 ? 6 : 4,\n\t\t\t\t}));\n\t\t\t\tif (options.all) {\n\t\t\t\t\tcallback(null, entries);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst first = entries[0];\n\t\t\t\tcallback(null, first.address, first.family);\n\t\t\t},\n\t\t},\n\t});\n}\n\nconst MAX_REDIRECTS = 5;\n\nasync function fetchText(url: string, rawLimit: number): Promise<{ text: string; contentType: string }> {\n\tlet current = url;\n\tfor (let redirects = 0; redirects <= MAX_REDIRECTS; redirects++) {\n\t\tconst target = await resolveSafe(current);\n\t\tconst agent = pinnedAgent(target);\n\t\ttry {\n\t\t\tconst res = await request(target.url.toString(), {\n\t\t\t\tdispatcher: agent,\n\t\t\t\tmethod: \"GET\",\n\t\t\t\tsignal: AbortSignal.timeout(15_000),\n\t\t\t});\n\t\t\tconst location = res.headers.location;\n\t\t\tif (res.statusCode >= 300 && res.statusCode < 400) {\n\t\t\t\tres.body.destroy();\n\t\t\t\tif (!location) throw new Error(`HTTP ${res.statusCode} with no redirect location`);\n\t\t\t\tif (redirects === MAX_REDIRECTS) throw new Error(\"Too many redirects\");\n\t\t\t\tcurrent = new URL(location, target.url).toString();\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (res.statusCode < 200 || res.statusCode >= 300) {\n\t\t\t\tres.body.destroy();\n\t\t\t\tthrow new Error(`HTTP ${res.statusCode}`);\n\t\t\t}\n\t\t\tconst contentType = String(res.headers[\"content-type\"] ?? \"\");\n\t\t\tconst decoder = new TextDecoder();\n\t\t\tlet text = \"\";\n\t\t\tfor await (const chunk of res.body) {\n\t\t\t\ttext += decoder.decode(chunk as Uint8Array, { stream: true });\n\t\t\t\tif (text.length >= rawLimit) break;\n\t\t\t}\n\t\t\treturn { text, contentType };\n\t\t} finally {\n\t\t\tvoid agent.close();\n\t\t}\n\t}\n\tthrow new Error(\"Too many redirects\");\n}\n\nexport default function webfetchExtension(pi: ExtensionAPI): void {\n\tpi.registerTool({\n\t\tname: \"webfetch\",\n\t\tlabel: \"Fetch web page\",\n\t\tdescription: \"Fetch a URL and return readable text content\",\n\t\tpromptSnippet: \"Fetch and read a web page\",\n\t\tparameters: Type.Object({\n\t\t\turl: Type.String({ description: \"URL to fetch\" }),\n\t\t\tmaxChars: Type.Optional(Type.Number({ minimum: 1, description: \"Maximum characters\" })),\n\t\t}),\n\t\tasync execute(_toolCallId, args) {\n\t\t\tconst url = String(args.url);\n\t\t\tconst maxChars = Math.max(1, Math.floor(Number(args.maxChars) || 15000));\n\t\t\tconst rawLimit = Math.min(Math.max(maxChars * 8, 64 * 1024), 4 * 1024 * 1024);\n\t\t\ttry {\n\t\t\t\tconst { text, contentType } = await fetchText(url, rawLimit);\n\t\t\t\tconst clean = contentType.includes(\"text/html\") ? stripHtml(text) : text;\n\t\t\t\treturn { content: [{ type: \"text\" as const, text: clean.slice(0, maxChars) }], details: {} };\n\t\t\t} catch (err) {\n\t\t\t\tconst message = (err as Error).message;\n\t\t\t\tconst browser = (globalThis as { __pi_browser?: unknown }).__pi_browser;\n\t\t\t\tif (!browser) {\n\t\t\t\t\tthrow new Error(`Could not fetch ${url}. No browser available and fetch failed: ${message}`);\n\t\t\t\t}\n\t\t\t\tconst page = await (browser as { newPage(): Promise<unknown> }).newPage();\n\t\t\t\ttry {\n\t\t\t\t\tconst safeTarget = await resolveSafe(url);\n\t\t\t\t\tconst guarded = page as {\n\t\t\t\t\t\troute(pattern: string, handler: (route: unknown) => Promise<void>): Promise<void>;\n\t\t\t\t\t\tgoto(url: string, opts: unknown): Promise<unknown>;\n\t\t\t\t\t\tevaluate(fn: string, max: number): Promise<string>;\n\t\t\t\t\t\tclose(): Promise<void>;\n\t\t\t\t\t};\n\t\t\t\t\tawait guarded.route(\"**/*\", async (route) => {\n\t\t\t\t\t\tconst reqUrl = (route as { request(): { url(): string } }).request().url();\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tawait resolveSafe(reqUrl);\n\t\t\t\t\t\t\tawait (route as { continue(): Promise<void> }).continue();\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\tawait (route as { abort(): Promise<void> }).abort();\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t\tawait guarded.goto(safeTarget.url.toString(), {\n\t\t\t\t\t\twaitUntil: \"domcontentloaded\",\n\t\t\t\t\t\ttimeout: 30_000,\n\t\t\t\t\t});\n\t\t\t\t\tawait new Promise((resolve) => setTimeout(resolve, 2_000));\n\t\t\t\t\tconst text = await (page as { evaluate(script: string): Promise<string> }).evaluate(\n\t\t\t\t\t\t`(() => { const max = ${maxChars}; const el = document.querySelector(\"article, main, [role='main'], .content, #content\") || document.body; return (el?.innerText ?? document.title).slice(0, max); })()`,\n\t\t\t\t\t);\n\t\t\t\t\treturn { content: [{ type: \"text\" as const, text }], details: {} };\n\t\t\t\t} finally {\n\t\t\t\t\tawait (page as { close(): Promise<void> }).close();\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t});\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/extensions/webfetch/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAGxC,SAAS,SAAS,CAAC,IAAY;IAC9B,OAAO,IAAI;SACT,OAAO,CAAC,6BAA6B,EAAE,EAAE,CAAC;SAC1C,OAAO,CAAC,2BAA2B,EAAE,EAAE,CAAC;SACxC,OAAO,CAAC,UAAU,EAAE,GAAG,CAAC;SACxB,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC;SACvB,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC;SACtB,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC;SACrB,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC;SACrB,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC;SACvB,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC;SACtB,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;SACpB,IAAI,EAAE,CAAC;AACV,CAAC;AAED,SAAS,UAAU,CAAC,OAAe;IAClC,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AC;YACF,CAAC;QACF,CAAC;KACD,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { LookupAddress, LookupOptions } from \"node:dns\";\nimport { lookup } from \"node:dns/promises\";\nimport { isIP } from \"node:net\";\nimport { Type } from \"typebox\";\nimport { Agent, request } from \"undici\";\nimport type { ExtensionAPI } from \"../../core/extensions/types.ts\";\n\nfunction stripHtml(html: string): string {\n\treturn html\n\t\t.replace(/<script[\\s\\S]*?<\\/script>/gi, \"\")\n\t\t.replace(/<style[\\s\\S]*?<\\/style>/gi, \"\")\n\t\t.replace(/<[^>]+>/g, \" \")\n\t\t.replace(/ /g, \" \")\n\t\t.replace(/&/g, \"&\")\n\t\t.replace(/</g, \"<\")\n\t\t.replace(/>/g, \">\")\n\t\t.replace(/"/g, '\"')\n\t\t.replace(/'/g, \"'\")\n\t\t.replace(/\\s+/g, \" \")\n\t\t.trim();\n}\n\nfunction expandIpv6(address: string): string {\n\tconst withoutZone = address.split(\"%\")[0];\n\tif (!withoutZone.includes(\"::\")) return withoutZone;\n\tconst [head, tail] = withoutZone.split(\"::\");\n\tconst headParts = head ? head.split(\":\") : [];\n\tconst tailParts = tail ? tail.split(\":\") : [];\n\tconst missing = Math.max(0, 8 - headParts.length - tailParts.length);\n\treturn [...headParts, ...Array(missing).fill(\"0\"), ...tailParts].join(\":\");\n}\n\nfunction isIpv4MappedToV6(address: string): string | null {\n\tconst withoutZone = address.toLowerCase().split(\"%\")[0];\n\tif (!withoutZone.includes(\":\")) return null;\n\tconst parts = expandIpv6(withoutZone).split(\":\");\n\tif (parts.length !== 8) return null;\n\tif (parts[7].includes(\".\")) {\n\t\tconst head = parts.slice(0, 7).map((part) => Number.parseInt(part, 16));\n\t\tif (head.some((value) => Number.isNaN(value))) return null;\n\t\tconst mapped = head[6] === 0xffff && head.slice(0, 6).every((value) => value === 0);\n\t\tconst compatible = head.every((value) => value === 0);\n\t\tif (!mapped && !compatible) return null;\n\t\treturn parts[7];\n\t}\n\tconst values = parts.map((part) => Number.parseInt(part, 16));\n\tif (values.some((value) => Number.isNaN(value))) return null;\n\tconst mapped = values[5] === 0xffff && values.slice(0, 5).every((value) => value === 0);\n\tconst compatible = values.slice(0, 7).every((value) => value === 0);\n\tif (!mapped && !compatible) return null;\n\treturn `${values[6] >> 8}.${values[6] & 0xff}.${values[7] >> 8}.${values[7] & 0xff}`;\n}\n\nfunction isBlockedIp(ip: string): boolean {\n\tconst v = ip.toLowerCase();\n\tif (v === \"::1\" || v === \"::\" || v === \"0.0.0.0\") return true;\n\tconst mapped = isIpv4MappedToV6(v);\n\tif (mapped !== null) return isBlockedIp(mapped);\n\tif (v.includes(\":\")) {\n\t\tconst first = Number.parseInt(expandIpv6(v).split(\":\")[0], 16);\n\t\tif (Number.isNaN(first)) return false;\n\t\tif (first >= 0xfc00 && first <= 0xfdff) return true;\n\t\tif (first >= 0xfe80 && first <= 0xfebf) return true;\n\t\treturn false;\n\t}\n\tif (/^127\\./.test(v) || /^169\\.254\\./.test(v) || /^10\\./.test(v) || /^192\\.168\\./.test(v)) return true;\n\tif (/^100\\.(6[4-9]|[7-9]\\d|1[01]\\d|12[0-7])\\./.test(v)) return true;\n\treturn /^172\\.(1[6-9]|2\\d|3[01])\\./.test(v);\n}\n\ninterface SafeTarget {\n\turl: URL;\n\thostname: string;\n\taddresses: string[];\n}\n\nasync function resolveSafe(value: string): Promise<SafeTarget> {\n\tlet parsed: URL;\n\ttry {\n\t\tparsed = new URL(value);\n\t} catch {\n\t\tthrow new Error(`Invalid URL: ${value}`);\n\t}\n\tif (parsed.protocol !== \"http:\" && parsed.protocol !== \"https:\") {\n\t\tthrow new Error(\"Only http and https URLs are supported\");\n\t}\n\tlet hostname = parsed.hostname.toLowerCase();\n\tif (hostname.startsWith(\"[\") && hostname.endsWith(\"]\")) hostname = hostname.slice(1, -1);\n\tif (hostname === \"localhost\") {\n\t\tthrow new Error(\"URLs pointing at loopback addresses are not allowed\");\n\t}\n\tlet addresses: string[];\n\tconst literalFamily = isIP(hostname);\n\tif (literalFamily !== 0) {\n\t\taddresses = [hostname];\n\t} else {\n\t\ttry {\n\t\t\taddresses = (await lookup(hostname, { all: true })).map((entry) => entry.address);\n\t\t} catch {\n\t\t\tthrow new Error(`Could not resolve host: ${hostname}`);\n\t\t}\n\t}\n\tfor (const address of addresses) {\n\t\tif (isBlockedIp(address)) {\n\t\t\tthrow new Error(\"URLs pointing at loopback, private, or link-local addresses are not allowed\");\n\t\t}\n\t}\n\treturn { url: parsed, hostname, addresses };\n}\n\nfunction pinnedAgent(target: SafeTarget): Agent {\n\treturn new Agent({\n\t\tconnect: {\n\t\t\tlookup: (\n\t\t\t\thost: string,\n\t\t\t\toptions: LookupOptions,\n\t\t\t\tcallback: (err: NodeJS.ErrnoException | null, address: string | LookupAddress[], family?: number) => void,\n\t\t\t) => {\n\t\t\t\tif (host !== target.hostname) {\n\t\t\t\t\tcallback(new Error(`unexpected host ${host}`), []);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst entries: LookupAddress[] = target.addresses.map((address) => ({\n\t\t\t\t\taddress,\n\t\t\t\t\tfamily: isIP(address) === 6 ? 6 : 4,\n\t\t\t\t}));\n\t\t\t\tif (options.all) {\n\t\t\t\t\tcallback(null, entries);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst first = entries[0];\n\t\t\t\tcallback(null, first.address, first.family);\n\t\t\t},\n\t\t},\n\t});\n}\n\nconst MAX_REDIRECTS = 5;\n\nasync function fetchText(url: string, rawLimit: number): Promise<{ text: string; contentType: string }> {\n\tlet current = url;\n\tfor (let redirects = 0; redirects <= MAX_REDIRECTS; redirects++) {\n\t\tconst target = await resolveSafe(current);\n\t\tconst agent = pinnedAgent(target);\n\t\ttry {\n\t\t\tconst res = await request(target.url.toString(), {\n\t\t\t\tdispatcher: agent,\n\t\t\t\tmethod: \"GET\",\n\t\t\t\tsignal: AbortSignal.timeout(15_000),\n\t\t\t});\n\t\t\tconst locationHeader = res.headers.location;\n\t\t\tconst location = Array.isArray(locationHeader) ? locationHeader[0] : locationHeader;\n\t\t\tif (res.statusCode >= 300 && res.statusCode < 400) {\n\t\t\t\tres.body.destroy();\n\t\t\t\tif (!location) throw new Error(`HTTP ${res.statusCode} with no redirect location`);\n\t\t\t\tif (redirects === MAX_REDIRECTS) throw new Error(\"Too many redirects\");\n\t\t\t\tcurrent = new URL(location, target.url).toString();\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (res.statusCode < 200 || res.statusCode >= 300) {\n\t\t\t\tres.body.destroy();\n\t\t\t\tthrow new Error(`HTTP ${res.statusCode}`);\n\t\t\t}\n\t\t\tconst contentType = String(res.headers[\"content-type\"] ?? \"\");\n\t\t\tconst decoder = new TextDecoder();\n\t\t\tlet text = \"\";\n\t\t\tfor await (const chunk of res.body) {\n\t\t\t\ttext += decoder.decode(chunk as Uint8Array, { stream: true });\n\t\t\t\tif (text.length >= rawLimit) break;\n\t\t\t}\n\t\t\treturn { text, contentType };\n\t\t} finally {\n\t\t\tvoid agent.close();\n\t\t}\n\t}\n\tthrow new Error(\"Too many redirects\");\n}\n\nexport default function webfetchExtension(pi: ExtensionAPI): void {\n\tpi.registerTool({\n\t\tname: \"webfetch\",\n\t\tlabel: \"Fetch web page\",\n\t\tdescription: \"Fetch a URL and return readable text content\",\n\t\tpromptSnippet: \"Fetch and read a web page\",\n\t\tparameters: Type.Object({\n\t\t\turl: Type.String({ description: \"URL to fetch\" }),\n\t\t\tmaxChars: Type.Optional(Type.Number({ minimum: 1, description: \"Maximum characters\" })),\n\t\t}),\n\t\tasync execute(_toolCallId, args) {\n\t\t\tconst url = String(args.url);\n\t\t\tconst maxChars = Math.max(1, Math.floor(Number(args.maxChars) || 15000));\n\t\t\tconst rawLimit = Math.min(Math.max(maxChars * 8, 64 * 1024), 4 * 1024 * 1024);\n\t\t\ttry {\n\t\t\t\tconst { text, contentType } = await fetchText(url, rawLimit);\n\t\t\t\tconst clean = contentType.includes(\"text/html\") ? stripHtml(text) : text;\n\t\t\t\treturn { content: [{ type: \"text\" as const, text: clean.slice(0, maxChars) }], details: {} };\n\t\t\t} catch (err) {\n\t\t\t\tconst message = (err as Error).message;\n\t\t\t\tconst browser = (globalThis as { __pi_browser?: unknown }).__pi_browser;\n\t\t\t\tif (!browser) {\n\t\t\t\t\tthrow new Error(`Could not fetch ${url}. No browser available and fetch failed: ${message}`);\n\t\t\t\t}\n\t\t\t\tconst page = await (browser as { newPage(): Promise<unknown> }).newPage();\n\t\t\t\ttry {\n\t\t\t\t\tconst safeTarget = await resolveSafe(url);\n\t\t\t\t\tconst guarded = page as {\n\t\t\t\t\t\troute(pattern: string, handler: (route: unknown) => Promise<void>): Promise<void>;\n\t\t\t\t\t\tgoto(url: string, opts: unknown): Promise<unknown>;\n\t\t\t\t\t\tevaluate(fn: string, max: number): Promise<string>;\n\t\t\t\t\t\tclose(): Promise<void>;\n\t\t\t\t\t};\n\t\t\t\t\tawait guarded.route(\"**/*\", async (route) => {\n\t\t\t\t\t\tconst reqUrl = (route as { request(): { url(): string } }).request().url();\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tawait resolveSafe(reqUrl);\n\t\t\t\t\t\t\tawait (route as { continue(): Promise<void> }).continue();\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\tawait (route as { abort(): Promise<void> }).abort();\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t\tawait guarded.goto(safeTarget.url.toString(), {\n\t\t\t\t\t\twaitUntil: \"domcontentloaded\",\n\t\t\t\t\t\ttimeout: 30_000,\n\t\t\t\t\t});\n\t\t\t\t\tawait new Promise((resolve) => setTimeout(resolve, 2_000));\n\t\t\t\t\tconst text = await (page as { evaluate(script: string): Promise<string> }).evaluate(\n\t\t\t\t\t\t`(() => { const max = ${maxChars}; const el = document.querySelector(\"article, main, [role='main'], .content, #content\") || document.body; return (el?.innerText ?? document.title).slice(0, max); })()`,\n\t\t\t\t\t);\n\t\t\t\t\treturn { content: [{ type: \"text\" as const, text }], details: {} };\n\t\t\t\t} finally {\n\t\t\t\t\tawait (page as { close(): Promise<void> }).close();\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t});\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"package-manager-cli.d.ts","sourceRoot":"","sources":["../src/package-manager-cli.ts"],"names":[],"mappings":"AA4BA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"package-manager-cli.d.ts","sourceRoot":"","sources":["../src/package-manager-cli.ts"],"names":[],"mappings":"AA4BA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAiBlE,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAC;AA4HtE,wBAAgB,qBAAqB,IAAI,IAAI,CAmB5C;AAshBD,MAAM,WAAW,4BAA4B;IAC5C,kBAAkB,CAAC,EAAE,eAAe,EAAE,CAAC;CACvC;AAiED,wBAAsB,mBAAmB,CACxC,IAAI,EAAE,MAAM,EAAE,EACd,cAAc,GAAE,4BAAiC,GAC/C,OAAO,CAAC,OAAO,CAAC,CA2ElB;AAED,wBAAsB,oBAAoB,CACzC,IAAI,EAAE,MAAM,EAAE,EACd,cAAc,GAAE,4BAAiC,GAC/C,OAAO,CAAC,OAAO,CAAC,CA2OlB"}
|
|
@@ -13,6 +13,7 @@ import { hasTrustRequiringProjectResources, ProjectTrustStore } from "./core/tru
|
|
|
13
13
|
import { spawnProcess, spawnProcessSync, waitForChildProcess } from "./utils/child-process.js";
|
|
14
14
|
import { canonicalizePath, getCwdRelativePath } from "./utils/paths.js";
|
|
15
15
|
import { getPiUserAgent } from "./utils/pi-user-agent.js";
|
|
16
|
+
import { stripBom } from "./utils/text.js";
|
|
16
17
|
import { formatVersionCheckError, getLatestPiRelease, isNewerPackageVersion } from "./utils/version-check.js";
|
|
17
18
|
import { cleanupWindowsSelfUpdateQuarantine, quarantineWindowsNativeDependencies, } from "./utils/windows-self-update.js";
|
|
18
19
|
const DEFAULT_INSTALLER_API_BASE = "https://pi.dev/api/installer/releases";
|
|
@@ -30,7 +31,7 @@ function getActiveManagedInstallRoot() {
|
|
|
30
31
|
return undefined;
|
|
31
32
|
const markerPath = join(managedRoot, MANAGED_INSTALL_MARKER);
|
|
32
33
|
try {
|
|
33
|
-
const marker = JSON.parse(readFileSync(markerPath, "utf8"));
|
|
34
|
+
const marker = JSON.parse(stripBom(readFileSync(markerPath, "utf8")));
|
|
34
35
|
if (marker.kind !== "pi-managed-install" || marker.schemaVersion !== 1 || marker.layout !== "releases-v1") {
|
|
35
36
|
throw new Error();
|
|
36
37
|
}
|