@narumitw/pi-subagents 2.0.1 → 2.0.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 +20 -7
- package/dist/chunks/auto-transport-SY2VHUFH.ts +109 -0
- package/dist/chunks/auto-transport-SY2VHUFH.ts.map +7 -0
- package/dist/chunks/capability-grant-CGEWOEKE.ts +19 -0
- package/dist/chunks/capability-grant-CGEWOEKE.ts.map +7 -0
- package/dist/chunks/chunk-434NII74.ts +282 -0
- package/dist/chunks/chunk-434NII74.ts.map +7 -0
- package/dist/chunks/chunk-47SK2QYC.ts +56 -0
- package/dist/chunks/chunk-47SK2QYC.ts.map +7 -0
- package/dist/chunks/chunk-6KJ34M6S.ts +159 -0
- package/dist/chunks/chunk-6KJ34M6S.ts.map +7 -0
- package/dist/chunks/chunk-7OBINKFM.ts +80 -0
- package/dist/chunks/chunk-7OBINKFM.ts.map +7 -0
- package/dist/chunks/chunk-7QPPBBXZ.ts +335 -0
- package/dist/chunks/chunk-7QPPBBXZ.ts.map +7 -0
- package/dist/chunks/chunk-AEUYS7JC.ts +73 -0
- package/dist/chunks/chunk-AEUYS7JC.ts.map +7 -0
- package/dist/chunks/chunk-BFK2Z4ZF.ts +189 -0
- package/dist/chunks/chunk-BFK2Z4ZF.ts.map +7 -0
- package/dist/chunks/chunk-BOAXY55Y.ts +153 -0
- package/dist/chunks/chunk-BOAXY55Y.ts.map +7 -0
- package/dist/chunks/chunk-C4L6P266.ts +22 -0
- package/dist/chunks/chunk-C4L6P266.ts.map +7 -0
- package/dist/chunks/chunk-DPPVEQAM.ts +29 -0
- package/dist/chunks/chunk-DPPVEQAM.ts.map +7 -0
- package/dist/chunks/chunk-DQMN4OYM.ts +913 -0
- package/dist/chunks/chunk-DQMN4OYM.ts.map +7 -0
- package/dist/chunks/chunk-DSOOH73Y.ts +238 -0
- package/dist/chunks/chunk-DSOOH73Y.ts.map +7 -0
- package/dist/chunks/chunk-EFBPISNT.ts +421 -0
- package/dist/chunks/chunk-EFBPISNT.ts.map +7 -0
- package/dist/chunks/chunk-EWWXFU7N.ts +150 -0
- package/dist/chunks/chunk-EWWXFU7N.ts.map +7 -0
- package/dist/chunks/chunk-F4L2UVSK.ts +380 -0
- package/dist/chunks/chunk-F4L2UVSK.ts.map +7 -0
- package/dist/chunks/chunk-F5YWVHQX.ts +1543 -0
- package/dist/chunks/chunk-F5YWVHQX.ts.map +7 -0
- package/dist/chunks/chunk-G3RSMSXJ.ts +63 -0
- package/dist/chunks/chunk-G3RSMSXJ.ts.map +7 -0
- package/dist/chunks/chunk-G6VZTCFH.ts +70 -0
- package/dist/chunks/chunk-G6VZTCFH.ts.map +7 -0
- package/dist/chunks/chunk-H3FP6DLR.ts +160 -0
- package/dist/chunks/chunk-H3FP6DLR.ts.map +7 -0
- package/dist/chunks/chunk-HA36LPCO.ts +130 -0
- package/dist/chunks/chunk-HA36LPCO.ts.map +7 -0
- package/dist/chunks/chunk-HKC4ES4B.ts +65 -0
- package/dist/chunks/chunk-HKC4ES4B.ts.map +7 -0
- package/dist/chunks/chunk-HOP5FXDT.ts +27 -0
- package/dist/chunks/chunk-HOP5FXDT.ts.map +7 -0
- package/dist/chunks/chunk-I2FAK44T.ts +324 -0
- package/dist/chunks/chunk-I2FAK44T.ts.map +7 -0
- package/dist/chunks/chunk-IGAMVWFN.ts +139 -0
- package/dist/chunks/chunk-IGAMVWFN.ts.map +7 -0
- package/dist/chunks/chunk-KMGKCEO4.ts +38 -0
- package/dist/chunks/chunk-KMGKCEO4.ts.map +7 -0
- package/dist/chunks/chunk-N7BLVXKK.ts +73 -0
- package/dist/chunks/chunk-N7BLVXKK.ts.map +7 -0
- package/dist/chunks/chunk-NIF42QMF.ts +297 -0
- package/dist/chunks/chunk-NIF42QMF.ts.map +7 -0
- package/dist/chunks/chunk-O4VO6JUJ.ts +52 -0
- package/dist/chunks/chunk-O4VO6JUJ.ts.map +7 -0
- package/dist/chunks/chunk-ONDTY4EL.ts +91 -0
- package/dist/chunks/chunk-ONDTY4EL.ts.map +7 -0
- package/dist/chunks/chunk-OVPHFGKO.ts +1769 -0
- package/dist/chunks/chunk-OVPHFGKO.ts.map +7 -0
- package/dist/chunks/chunk-P7OH4XMF.ts +60 -0
- package/dist/chunks/chunk-P7OH4XMF.ts.map +7 -0
- package/dist/chunks/chunk-PSK43Y6A.ts +339 -0
- package/dist/chunks/chunk-PSK43Y6A.ts.map +7 -0
- package/dist/chunks/chunk-QBORTI4W.ts +468 -0
- package/dist/chunks/chunk-QBORTI4W.ts.map +7 -0
- package/dist/chunks/chunk-QDVGH2X7.ts +171 -0
- package/dist/chunks/chunk-QDVGH2X7.ts.map +7 -0
- package/dist/chunks/chunk-RHRQMT7Q.ts +490 -0
- package/dist/chunks/chunk-RHRQMT7Q.ts.map +7 -0
- package/dist/chunks/chunk-RRR66UWR.ts +28 -0
- package/dist/chunks/chunk-RRR66UWR.ts.map +7 -0
- package/dist/chunks/chunk-RSUXZD6S.ts +275 -0
- package/dist/chunks/chunk-RSUXZD6S.ts.map +7 -0
- package/dist/chunks/chunk-RTCVYIZA.ts +221 -0
- package/dist/chunks/chunk-RTCVYIZA.ts.map +7 -0
- package/dist/chunks/chunk-S2IWVK3J.ts +44 -0
- package/dist/chunks/chunk-S2IWVK3J.ts.map +7 -0
- package/dist/chunks/chunk-SCZ33MYW.ts +52 -0
- package/dist/chunks/chunk-SCZ33MYW.ts.map +7 -0
- package/dist/chunks/chunk-SWGQLFSD.ts +60 -0
- package/dist/chunks/chunk-SWGQLFSD.ts.map +7 -0
- package/dist/chunks/chunk-UMBPMVJW.ts +22 -0
- package/dist/chunks/chunk-UMBPMVJW.ts.map +7 -0
- package/dist/chunks/chunk-UVFVHIOP.ts +735 -0
- package/dist/chunks/chunk-UVFVHIOP.ts.map +7 -0
- package/dist/chunks/completion-delivery-YPOWSSV3.ts +16 -0
- package/dist/chunks/completion-delivery-YPOWSSV3.ts.map +7 -0
- package/dist/chunks/config-status-J4GPWP46.ts +34 -0
- package/dist/chunks/config-status-J4GPWP46.ts.map +7 -0
- package/dist/chunks/config-ui-3IBMHTQB.ts +1146 -0
- package/dist/chunks/config-ui-3IBMHTQB.ts.map +7 -0
- package/dist/chunks/consult-NYXVDN5G.ts +518 -0
- package/dist/chunks/consult-NYXVDN5G.ts.map +7 -0
- package/dist/chunks/context-QDKLVQXE.ts +11 -0
- package/dist/chunks/context-QDKLVQXE.ts.map +7 -0
- package/dist/chunks/create-stateful-transport-4WKZHRSI.ts +130 -0
- package/dist/chunks/create-stateful-transport-4WKZHRSI.ts.map +7 -0
- package/dist/chunks/cwd-policy-NB6XZ5GF.ts +17 -0
- package/dist/chunks/cwd-policy-NB6XZ5GF.ts.map +7 -0
- package/dist/chunks/delegation-contract-WJPT4FVS.ts +24 -0
- package/dist/chunks/delegation-contract-WJPT4FVS.ts.map +7 -0
- package/dist/chunks/discovery-K25T3SH4.ts +12 -0
- package/dist/chunks/discovery-K25T3SH4.ts.map +7 -0
- package/dist/chunks/execution-DS2DEIQZ.ts +4034 -0
- package/dist/chunks/execution-DS2DEIQZ.ts.map +7 -0
- package/dist/chunks/in-process-transport-TEYAWSEC.ts +38 -0
- package/dist/chunks/in-process-transport-TEYAWSEC.ts.map +7 -0
- package/dist/chunks/inspect-UOQQ3KNL.ts +619 -0
- package/dist/chunks/inspect-UOQQ3KNL.ts.map +7 -0
- package/dist/chunks/peer-communication-KL36Z6CO.ts +294 -0
- package/dist/chunks/peer-communication-KL36Z6CO.ts.map +7 -0
- package/dist/chunks/persistence-VSGXAW4P.ts +344 -0
- package/dist/chunks/persistence-VSGXAW4P.ts.map +7 -0
- package/dist/chunks/registry-E6XPJB7L.ts +1324 -0
- package/dist/chunks/registry-E6XPJB7L.ts.map +7 -0
- package/dist/chunks/retained-semantic-state-7WXSGRJU.ts +81 -0
- package/dist/chunks/retained-semantic-state-7WXSGRJU.ts.map +7 -0
- package/dist/chunks/rpc-transport-Y6LA5BOP.ts +1154 -0
- package/dist/chunks/rpc-transport-Y6LA5BOP.ts.map +7 -0
- package/dist/chunks/runtime-policy-5YELCOVC.ts +15 -0
- package/dist/chunks/runtime-policy-5YELCOVC.ts.map +7 -0
- package/dist/chunks/semantic-snapshot-WPJ3UAFW.ts +19 -0
- package/dist/chunks/semantic-snapshot-WPJ3UAFW.ts.map +7 -0
- package/dist/chunks/spawn-idempotency-QGHO2WKC.ts +13 -0
- package/dist/chunks/spawn-idempotency-QGHO2WKC.ts.map +7 -0
- package/dist/chunks/stateful-lifecycle-JAR6K55H.ts +15 -0
- package/dist/chunks/stateful-lifecycle-JAR6K55H.ts.map +7 -0
- package/dist/chunks/subprocess-transport-C2XVR25R.ts +158 -0
- package/dist/chunks/subprocess-transport-C2XVR25R.ts.map +7 -0
- package/dist/chunks/workspace-WDKLN72J.ts +11 -0
- package/dist/chunks/workspace-WDKLN72J.ts.map +7 -0
- package/dist/index.ts +1057 -0
- package/dist/index.ts.map +7 -0
- package/package.json +9 -5
- package/src/index.ts +1 -1
- package/src/settings-reader.ts +208 -0
- package/src/settings.ts +22 -187
- package/src/stateful-registration.ts +1230 -0
- package/src/stateful-safety.ts +1 -1
- package/src/stateful.ts +2 -1234
- package/src/subagents-extension.ts +307 -0
- package/src/subagents.ts +1 -308
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/context.ts", "../../src/limits.ts"],
|
|
4
|
+
"sourcesContent": ["import { createHash } from \"node:crypto\";\nimport { DEFAULT_MAX_CONTEXT_BYTES, truncateUtf8, truncateUtf8Tail } from \"./limits.js\";\n\nexport type ContextMode = \"none\" | \"all\" | \"summary\" | number;\n\nexport interface ContextSnapshot {\n\ttext: string;\n\tturns: number;\n\ttruncated: boolean;\n\tsourceIds: string[];\n}\n\nfunction textParts(content: unknown): string {\n\tif (typeof content === \"string\") return content;\n\tif (!Array.isArray(content)) return \"\";\n\treturn content\n\t\t.filter((part): part is { type: \"text\"; text: string } =>\n\t\t\tBoolean(\n\t\t\t\tpart &&\n\t\t\t\t\ttypeof part === \"object\" &&\n\t\t\t\t\t(part as { type?: unknown }).type === \"text\" &&\n\t\t\t\t\ttypeof (part as { text?: unknown }).text === \"string\",\n\t\t\t),\n\t\t)\n\t\t.map((part) => part.text)\n\t\t.join(\"\\n\");\n}\n\nexport function redactPrivateText(text: string): string {\n\tconst tagPattern = /<\\/?private>/gi;\n\tlet redacted = \"\";\n\tlet cursor = 0;\n\tlet depth = 0;\n\tfor (const match of text.matchAll(tagPattern)) {\n\t\tconst tag = match[0].toLowerCase();\n\t\tconst index = match.index ?? cursor;\n\t\tif (depth === 0) redacted += text.slice(cursor, index);\n\t\tif (tag === \"<private>\") {\n\t\t\tif (depth === 0) redacted += \"[private content omitted]\";\n\t\t\tdepth++;\n\t\t} else if (depth > 0) {\n\t\t\tdepth--;\n\t\t} else {\n\t\t\tredacted += match[0];\n\t\t}\n\t\tcursor = index + match[0].length;\n\t}\n\tif (depth === 0) redacted += text.slice(cursor);\n\treturn redacted\n\t\t.split(\"\\n\")\n\t\t.filter((line) => !line.includes(\"[subagent-private]\"))\n\t\t.join(\"\\n\");\n}\n\nexport function buildContextSnapshot(\n\tentries: readonly unknown[],\n\tmode: ContextMode,\n\tmaxBytes = DEFAULT_MAX_CONTEXT_BYTES,\n\tselectedSourceIds?: readonly string[],\n): ContextSnapshot {\n\tif (mode === \"none\") return { text: \"\", turns: 0, truncated: false, sourceIds: [] };\n\tconst messages: Array<{ role: \"user\" | \"assistant\"; text: string; sourceId: string }> = [];\n\tfor (const entry of entries) {\n\t\tif (!entry || typeof entry !== \"object\") continue;\n\t\tconst candidate = entry as {\n\t\t\tid?: string;\n\t\t\ttype?: string;\n\t\t\trole?: string;\n\t\t\tcontent?: unknown;\n\t\t\tmessage?: { role?: string; content?: unknown };\n\t\t};\n\t\tconst message: { role?: string; content?: unknown } | undefined =\n\t\t\tcandidate.type === \"message\" ? candidate.message : candidate;\n\t\tif (message?.role !== \"user\" && message?.role !== \"assistant\") continue;\n\t\tconst text = redactPrivateText(textParts(message.content));\n\t\tif (text.trim()) {\n\t\t\tconst sourceId =\n\t\t\t\tcandidate.id ??\n\t\t\t\tcreateHash(\"sha256\").update(`${message.role}\\0${text}`).digest(\"hex\").slice(0, 16);\n\t\t\tmessages.push({ role: message.role, text, sourceId });\n\t\t}\n\t}\n\tconst seenSourceIds = new Set<string>();\n\tconst uniqueMessages = messages.filter((message) => {\n\t\tif (seenSourceIds.has(message.sourceId)) return false;\n\t\tseenSourceIds.add(message.sourceId);\n\t\treturn true;\n\t});\n\tconst selectedSet = selectedSourceIds ? new Set(selectedSourceIds) : undefined;\n\tconst eligible = selectedSet\n\t\t? uniqueMessages.filter((message) => selectedSet.has(message.sourceId))\n\t\t: uniqueMessages;\n\tconst turnLimit =\n\t\ttypeof mode === \"number\" ? Math.max(1, Math.floor(mode)) : Number.POSITIVE_INFINITY;\n\tlet userTurns = 0;\n\tlet start = eligible.length;\n\tfor (let index = eligible.length - 1; index >= 0; index--) {\n\t\tif (eligible[index].role === \"user\") userTurns++;\n\t\tif (userTurns > turnLimit) break;\n\t\tstart = index;\n\t}\n\tconst selected = eligible.slice(start);\n\tconst raw =\n\t\tmode === \"summary\" && selected.length > 4\n\t\t\t? [\n\t\t\t\t\t`## Earlier context checkpoint\\n${\n\t\t\t\t\t\ttruncateUtf8(\n\t\t\t\t\t\t\tselected\n\t\t\t\t\t\t\t\t.slice(0, -4)\n\t\t\t\t\t\t\t\t.map((message) => `${message.role}: ${message.text}`)\n\t\t\t\t\t\t\t\t.join(\"\\n\"),\n\t\t\t\t\t\t\tMath.floor(maxBytes / 3),\n\t\t\t\t\t\t).text\n\t\t\t\t\t}`,\n\t\t\t\t\t...selected.slice(-4).map((message) => `## ${message.role}\\n${message.text}`),\n\t\t\t\t].join(\"\\n\\n\")\n\t\t\t: selected.map((message) => `## ${message.role}\\n${message.text}`).join(\"\\n\\n\");\n\tconst bounded =\n\t\tmode === \"summary\" ? truncateUtf8Tail(raw, maxBytes) : truncateUtf8(raw, maxBytes);\n\treturn {\n\t\ttext: bounded.text,\n\t\tturns: selected.filter((message) => message.role === \"user\").length,\n\t\ttruncated: bounded.truncated,\n\t\tsourceIds: selected.map((message) => message.sourceId),\n\t};\n}\n", "import { DEFAULT_MAX_BYTES } from \"@earendil-works/pi-coding-agent\";\n\nexport const DEFAULT_MAX_OUTPUT_BYTES = DEFAULT_MAX_BYTES;\nexport const DEFAULT_MAX_STDERR_BYTES = 16 * 1024;\nexport const DEFAULT_MAX_CONTEXT_BYTES = DEFAULT_MAX_BYTES;\nexport const MAX_SUBAGENT_TIMEOUT_MS = 2_147_483_647;\nexport const DEFAULT_MAX_PARALLEL_TASKS = 8;\nexport const MAX_CONFIGURABLE_PARALLEL_TASKS = 64;\nexport const MAX_BLOCKING_PARALLEL_CONCURRENCY = 4;\nexport const DEFAULT_MAX_MESSAGES = 200;\nexport const MAX_TOOL_MESSAGE_BYTES = 2 * 1024;\nexport const TRUNCATION_MARKER = \"\\n\u2026 [truncated by pi-subagents]\";\nexport const TAIL_TRUNCATION_MARKER = \"\u2026 [truncated by pi-subagents]\\n\";\n\nexport interface BoundedText {\n\ttext: string;\n\ttruncated: boolean;\n\toriginalBytes: number;\n}\n\nfunction normalizeByteLimit(maxBytes: number): number {\n\tif (maxBytes === Number.POSITIVE_INFINITY) return Number.MAX_SAFE_INTEGER;\n\tif (!Number.isFinite(maxBytes)) return 0;\n\treturn Math.max(0, Math.floor(maxBytes));\n}\n\nexport function truncateUtf8(text: string, maxBytes: number): BoundedText {\n\tconst limit = normalizeByteLimit(maxBytes);\n\tconst originalBytes = Buffer.byteLength(text, \"utf8\");\n\tif (originalBytes <= limit) return { text, truncated: false, originalBytes };\n\tif (limit === 0) return { text: \"\", truncated: true, originalBytes };\n\n\tconst marker = Buffer.from(TRUNCATION_MARKER, \"utf8\");\n\tif (marker.length >= limit) {\n\t\treturn {\n\t\t\ttext: Buffer.from(text, \"utf8\").subarray(0, limit).toString(\"utf8\").replace(/\uFFFD+$/g, \"\"),\n\t\t\ttruncated: true,\n\t\t\toriginalBytes,\n\t\t};\n\t}\n\tconst prefix = Buffer.from(text, \"utf8\")\n\t\t.subarray(0, limit - marker.length)\n\t\t.toString(\"utf8\")\n\t\t.replace(/\uFFFD+$/g, \"\");\n\treturn { text: `${prefix}${TRUNCATION_MARKER}`, truncated: true, originalBytes };\n}\n\nexport function truncateUtf8Tail(text: string, maxBytes: number): BoundedText {\n\tconst limit = normalizeByteLimit(maxBytes);\n\tconst bytes = Buffer.from(text, \"utf8\");\n\tconst originalBytes = bytes.length;\n\tif (originalBytes <= limit) return { text, truncated: false, originalBytes };\n\tif (limit === 0) return { text: \"\", truncated: true, originalBytes };\n\n\tconst marker = Buffer.from(TAIL_TRUNCATION_MARKER, \"utf8\");\n\tif (marker.length >= limit) {\n\t\treturn {\n\t\t\ttext: bytes\n\t\t\t\t.subarray(originalBytes - limit)\n\t\t\t\t.toString(\"utf8\")\n\t\t\t\t.replace(/^\uFFFD+/g, \"\"),\n\t\t\ttruncated: true,\n\t\t\toriginalBytes,\n\t\t};\n\t}\n\tconst suffix = bytes\n\t\t.subarray(originalBytes - (limit - marker.length))\n\t\t.toString(\"utf8\")\n\t\t.replace(/^\uFFFD+/g, \"\");\n\treturn { text: `${TAIL_TRUNCATION_MARKER}${suffix}`, truncated: true, originalBytes };\n}\n\nexport function appendBounded(current: string, addition: string, maxBytes: number): BoundedText {\n\treturn truncateUtf8(current + addition, maxBytes);\n}\n"],
|
|
5
|
+
"mappings": ";;;;AAAA,SAAS,kBAAkB;;;ACA3B,SAAS,yBAAyB;AAE3B,IAAM,2BAA2B;AACjC,IAAM,2BAA2B,KAAK;AACtC,IAAM,4BAA4B;AAClC,IAAM,0BAA0B;AAChC,IAAM,6BAA6B;AACnC,IAAM,kCAAkC;AACxC,IAAM,oCAAoC;AAC1C,IAAM,uBAAuB;AAC7B,IAAM,yBAAyB,IAAI;AACnC,IAAM,oBAAoB;AAC1B,IAAM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WAAS,QAAQ,SAAS,SAAS,GAAG,SAAS,GAAG,SAAS;AAC1D,QAAI,SAAS,KAAK,EAAE,SAAS,OAAQ;AACrC,QAAI,YAAY,UAAW;AAC3B,YAAQ;AAAA,EACT;AACA,QAAM,WAAW,SAAS,MAAM,KAAK;AACrC,QAAM,MACL,SAAS,aAAa,SAAS,SAAS,IACrC;AAAA,IACA;AAAA,EACC;AAAA,MACC,SACE,MAAM,GAAG,EAAE,EACX,IAAI,CAAC,YAAY,GAAG,QAAQ,IAAI,KAAK,QAAQ,IAAI,EAAE,EACnD,KAAK,IAAI;AAAA,MACX,KAAK,MAAM,WAAW,CAAC;AAAA,IACxB,EAAE,IACH;AAAA,IACA,GAAG,SAAS,MAAM,EAAE,EAAE,IAAI,CAAC,YAAY,MAAM,QAAQ,IAAI;AAAA,EAAK,QAAQ,IAAI,EAAE;AAAA,EAC7E,EAAE,KAAK,MAAM,IACZ,SAAS,IAAI,CAAC,YAAY,MAAM,QAAQ,IAAI;AAAA,EAAK,QAAQ,IAAI,EAAE,EAAE,KAAK,MAAM;AAChF,QAAM,UACL,SAAS,YAAY,iBAAiB,KAAK,QAAQ,IAAI,aAAa,KAAK,QAAQ;AAClF,SAAO;AAAA,IACN,MAAM,QAAQ;AAAA,IACd,OAAO,SAAS,OAAO,CAAC,YAAY,QAAQ,SAAS,MAAM,EAAE;AAAA,IAC7D,WAAW,QAAQ;AAAA,IACnB,WAAW,SAAS,IAAI,CAAC,YAAY,QAAQ,QAAQ;AAAA,EACtD;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// @generated by scripts/build-runtime.mjs; do not edit.
|
|
2
|
+
// @ts-nocheck -- generated JavaScript uses a .ts extension for Pi's Jiti loader.
|
|
3
|
+
import {
|
|
4
|
+
safeTerminalLine
|
|
5
|
+
} from "./chunk-SWGQLFSD.ts";
|
|
6
|
+
|
|
7
|
+
// src/cwd-policy.ts
|
|
8
|
+
import * as fs from "node:fs";
|
|
9
|
+
import * as path from "node:path";
|
|
10
|
+
import { getAgentDir, ProjectTrustStore } from "@earendil-works/pi-coding-agent";
|
|
11
|
+
function targetPolicyAudit(target) {
|
|
12
|
+
return {
|
|
13
|
+
cwd: safeTerminalLine(target.cwd),
|
|
14
|
+
boundary: target.boundary,
|
|
15
|
+
trust: {
|
|
16
|
+
...target.trust,
|
|
17
|
+
sourcePath: target.trust.sourcePath ? safeTerminalLine(target.trust.sourcePath) : void 0,
|
|
18
|
+
warning: target.trust.warning ? safeTerminalLine(target.trust.warning, 512) : void 0
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function resolveSubagentTarget(options) {
|
|
23
|
+
const workspace = canonicalDirectory(options.workspace, "Current workspace");
|
|
24
|
+
const requested = path.resolve(options.workspace, options.requestedCwd ?? options.workspace);
|
|
25
|
+
const cwd = canonicalDirectory(requested, "Subagent working directory");
|
|
26
|
+
const boundary = isEqualOrDescendant(cwd, workspace) ? "current-workspace" : "external";
|
|
27
|
+
if (boundary === "current-workspace") {
|
|
28
|
+
return {
|
|
29
|
+
cwd,
|
|
30
|
+
workspace,
|
|
31
|
+
boundary,
|
|
32
|
+
trust: {
|
|
33
|
+
kind: options.currentProjectTrusted ? "session-trusted" : "session-untrusted",
|
|
34
|
+
projectTrusted: options.currentProjectTrusted,
|
|
35
|
+
sourcePath: workspace
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
const entry = new ProjectTrustStore(options.agentDir ?? getAgentDir()).getEntry(cwd);
|
|
41
|
+
if (!entry) {
|
|
42
|
+
return {
|
|
43
|
+
cwd,
|
|
44
|
+
workspace,
|
|
45
|
+
boundary,
|
|
46
|
+
trust: { kind: "unsaved", projectTrusted: false }
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
cwd,
|
|
51
|
+
workspace,
|
|
52
|
+
boundary,
|
|
53
|
+
trust: {
|
|
54
|
+
kind: entry.decision ? "saved-trusted" : "saved-denied",
|
|
55
|
+
projectTrusted: entry.decision,
|
|
56
|
+
sourcePath: entry.path
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
} catch {
|
|
60
|
+
return {
|
|
61
|
+
cwd,
|
|
62
|
+
workspace,
|
|
63
|
+
boundary,
|
|
64
|
+
trust: {
|
|
65
|
+
kind: "trust-error",
|
|
66
|
+
projectTrusted: false,
|
|
67
|
+
warning: safeTerminalLine(
|
|
68
|
+
"Could not resolve Pi trust store; protected target resources were disabled. Repair trust with Pi /trust and restart Pi.",
|
|
69
|
+
512
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function assertConsultationTargetAllowed(target, policy) {
|
|
76
|
+
if (policy === "current-workspace" && target.boundary !== "current-workspace") {
|
|
77
|
+
throw new Error(
|
|
78
|
+
`Read-only consultation target is outside the current workspace: ${safeTerminalLine(target.cwd)}`
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function assertDelegationTargetAllowed(target, policy) {
|
|
83
|
+
if (target.boundary === "current-workspace" || policy === "anywhere") return;
|
|
84
|
+
if (policy === "trusted-targets" && target.trust.kind === "saved-trusted") return;
|
|
85
|
+
if (policy === "current-workspace") {
|
|
86
|
+
throw new Error(
|
|
87
|
+
`General delegation target is outside the current workspace: ${safeTerminalLine(target.cwd)}`
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
const reason = target.trust.kind === "trust-error" ? target.trust.warning : `Target trust is ${target.trust.kind}.`;
|
|
91
|
+
throw new Error(
|
|
92
|
+
[
|
|
93
|
+
`General delegation target is not a saved-trusted folder: ${safeTerminalLine(target.cwd)}`,
|
|
94
|
+
reason,
|
|
95
|
+
"Open Pi in that folder, manage trust with /trust, restart Pi, or choose Anywhere in /subagents settings."
|
|
96
|
+
].filter(Boolean).join(" ")
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
function canonicalDirectory(value, label) {
|
|
100
|
+
let canonical;
|
|
101
|
+
try {
|
|
102
|
+
canonical = fs.realpathSync(value);
|
|
103
|
+
} catch (error) {
|
|
104
|
+
if (error.code === "ENOENT") {
|
|
105
|
+
throw new Error(`${label} does not exist: ${safeTerminalLine(value)}`);
|
|
106
|
+
}
|
|
107
|
+
throw new Error(
|
|
108
|
+
`${label} cannot be resolved: ${safeTerminalLine(value)}: ${formatError(error)}`
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
if (!fs.statSync(canonical).isDirectory()) {
|
|
112
|
+
throw new Error(`${label} is not a directory: ${safeTerminalLine(canonical)}`);
|
|
113
|
+
}
|
|
114
|
+
return canonical;
|
|
115
|
+
}
|
|
116
|
+
function isEqualOrDescendant(candidate, workspace) {
|
|
117
|
+
const relative2 = path.relative(workspace, candidate);
|
|
118
|
+
return relative2 === "" || !relative2.startsWith(`..${path.sep}`) && relative2 !== ".." && !path.isAbsolute(relative2);
|
|
119
|
+
}
|
|
120
|
+
function formatError(error) {
|
|
121
|
+
return error instanceof Error ? error.message : String(error);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export {
|
|
125
|
+
targetPolicyAudit,
|
|
126
|
+
resolveSubagentTarget,
|
|
127
|
+
assertConsultationTargetAllowed,
|
|
128
|
+
assertDelegationTargetAllowed
|
|
129
|
+
};
|
|
130
|
+
//# sourceMappingURL=chunk-HA36LPCO.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/cwd-policy.ts"],
|
|
4
|
+
"sourcesContent": ["import * as fs from \"node:fs\";\nimport * as path from \"node:path\";\nimport { getAgentDir, ProjectTrustStore } from \"@earendil-works/pi-coding-agent\";\nimport type { ConsultationCwdPolicy, DelegationCwdPolicy } from \"./agents/types.js\";\nimport { safeTerminalLine } from \"./safe-text.js\";\n\nexport type TargetBoundary = \"current-workspace\" | \"external\";\nexport type TargetTrustKind =\n\t| \"session-trusted\"\n\t| \"session-untrusted\"\n\t| \"saved-trusted\"\n\t| \"saved-denied\"\n\t| \"unsaved\"\n\t| \"trust-error\";\n\nexport interface ResolvedTargetTrust {\n\tkind: TargetTrustKind;\n\tprojectTrusted: boolean;\n\tsourcePath?: string;\n\twarning?: string;\n}\n\nexport interface ResolvedSubagentTarget {\n\tcwd: string;\n\tworkspace: string;\n\tboundary: TargetBoundary;\n\ttrust: ResolvedTargetTrust;\n}\n\nexport interface TargetPolicyAudit {\n\tcwd: string;\n\tboundary: TargetBoundary;\n\ttrust: {\n\t\tkind: TargetTrustKind;\n\t\tprojectTrusted: boolean;\n\t\tsourcePath?: string;\n\t\twarning?: string;\n\t};\n}\n\nexport function targetPolicyAudit(target: ResolvedSubagentTarget): TargetPolicyAudit {\n\treturn {\n\t\tcwd: safeTerminalLine(target.cwd),\n\t\tboundary: target.boundary,\n\t\ttrust: {\n\t\t\t...target.trust,\n\t\t\tsourcePath: target.trust.sourcePath ? safeTerminalLine(target.trust.sourcePath) : undefined,\n\t\t\twarning: target.trust.warning ? safeTerminalLine(target.trust.warning, 512) : undefined,\n\t\t},\n\t};\n}\n\nexport interface ResolveSubagentTargetOptions {\n\tworkspace: string;\n\trequestedCwd?: string;\n\tcurrentProjectTrusted: boolean;\n\tagentDir?: string;\n}\n\nexport function resolveSubagentTarget(\n\toptions: ResolveSubagentTargetOptions,\n): ResolvedSubagentTarget {\n\tconst workspace = canonicalDirectory(options.workspace, \"Current workspace\");\n\tconst requested = path.resolve(options.workspace, options.requestedCwd ?? options.workspace);\n\tconst cwd = canonicalDirectory(requested, \"Subagent working directory\");\n\tconst boundary: TargetBoundary = isEqualOrDescendant(cwd, workspace)\n\t\t? \"current-workspace\"\n\t\t: \"external\";\n\tif (boundary === \"current-workspace\") {\n\t\treturn {\n\t\t\tcwd,\n\t\t\tworkspace,\n\t\t\tboundary,\n\t\t\ttrust: {\n\t\t\t\tkind: options.currentProjectTrusted ? \"session-trusted\" : \"session-untrusted\",\n\t\t\t\tprojectTrusted: options.currentProjectTrusted,\n\t\t\t\tsourcePath: workspace,\n\t\t\t},\n\t\t};\n\t}\n\ttry {\n\t\tconst entry = new ProjectTrustStore(options.agentDir ?? getAgentDir()).getEntry(cwd);\n\t\tif (!entry) {\n\t\t\treturn {\n\t\t\t\tcwd,\n\t\t\t\tworkspace,\n\t\t\t\tboundary,\n\t\t\t\ttrust: { kind: \"unsaved\", projectTrusted: false },\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\tcwd,\n\t\t\tworkspace,\n\t\t\tboundary,\n\t\t\ttrust: {\n\t\t\t\tkind: entry.decision ? \"saved-trusted\" : \"saved-denied\",\n\t\t\t\tprojectTrusted: entry.decision,\n\t\t\t\tsourcePath: entry.path,\n\t\t\t},\n\t\t};\n\t} catch {\n\t\treturn {\n\t\t\tcwd,\n\t\t\tworkspace,\n\t\t\tboundary,\n\t\t\ttrust: {\n\t\t\t\tkind: \"trust-error\",\n\t\t\t\tprojectTrusted: false,\n\t\t\t\twarning: safeTerminalLine(\n\t\t\t\t\t\"Could not resolve Pi trust store; protected target resources were disabled. Repair trust with Pi /trust and restart Pi.\",\n\t\t\t\t\t512,\n\t\t\t\t),\n\t\t\t},\n\t\t};\n\t}\n}\n\nexport function assertConsultationTargetAllowed(\n\ttarget: ResolvedSubagentTarget,\n\tpolicy: ConsultationCwdPolicy,\n): void {\n\tif (policy === \"current-workspace\" && target.boundary !== \"current-workspace\") {\n\t\tthrow new Error(\n\t\t\t`Read-only consultation target is outside the current workspace: ${safeTerminalLine(target.cwd)}`,\n\t\t);\n\t}\n}\n\nexport function assertDelegationTargetAllowed(\n\ttarget: ResolvedSubagentTarget,\n\tpolicy: DelegationCwdPolicy,\n): void {\n\tif (target.boundary === \"current-workspace\" || policy === \"anywhere\") return;\n\tif (policy === \"trusted-targets\" && target.trust.kind === \"saved-trusted\") return;\n\tif (policy === \"current-workspace\") {\n\t\tthrow new Error(\n\t\t\t`General delegation target is outside the current workspace: ${safeTerminalLine(target.cwd)}`,\n\t\t);\n\t}\n\tconst reason =\n\t\ttarget.trust.kind === \"trust-error\"\n\t\t\t? target.trust.warning\n\t\t\t: `Target trust is ${target.trust.kind}.`;\n\tthrow new Error(\n\t\t[\n\t\t\t`General delegation target is not a saved-trusted folder: ${safeTerminalLine(target.cwd)}`,\n\t\t\treason,\n\t\t\t\"Open Pi in that folder, manage trust with /trust, restart Pi, or choose Anywhere in /subagents settings.\",\n\t\t]\n\t\t\t.filter(Boolean)\n\t\t\t.join(\" \"),\n\t);\n}\n\nfunction canonicalDirectory(value: string, label: string): string {\n\tlet canonical: string;\n\ttry {\n\t\tcanonical = fs.realpathSync(value);\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code === \"ENOENT\") {\n\t\t\tthrow new Error(`${label} does not exist: ${safeTerminalLine(value)}`);\n\t\t}\n\t\tthrow new Error(\n\t\t\t`${label} cannot be resolved: ${safeTerminalLine(value)}: ${formatError(error)}`,\n\t\t);\n\t}\n\tif (!fs.statSync(canonical).isDirectory()) {\n\t\tthrow new Error(`${label} is not a directory: ${safeTerminalLine(canonical)}`);\n\t}\n\treturn canonical;\n}\n\nfunction isEqualOrDescendant(candidate: string, workspace: string): boolean {\n\tconst relative = path.relative(workspace, candidate);\n\treturn (\n\t\trelative === \"\" ||\n\t\t(!relative.startsWith(`..${path.sep}`) && relative !== \"..\" && !path.isAbsolute(relative))\n\t);\n}\n\nfunction formatError(error: unknown): string {\n\treturn error instanceof Error ? error.message : String(error);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;AAAA,YAAY,QAAQ;AACpB,YAAY,UAAU;AACtB,SAAS,aAAa,yBAAyB;AAsCxC,SAAS,kBAAkB,QAAmD;AACpF,SAAO;AAAA,IACN,KAAK,iBAAiB,OAAO,GAAG;AAAA,IAChC,UAAU,OAAO;AAAA,IACjB,OAAO;AAAA,MACN,GAAG,OAAO;AAAA,MACV,YAAY,OAA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,cAAa,QAAQ,CAAM,gBAAWA,SAAQ;AAE1F;AAEA,SAAS,YAAY,OAAwB;AAC5C,SAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAC7D;",
|
|
6
|
+
"names": ["relative"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// @generated by scripts/build-runtime.mjs; do not edit.
|
|
2
|
+
// @ts-nocheck -- generated JavaScript uses a .ts extension for Pi's Jiti loader.
|
|
3
|
+
import {
|
|
4
|
+
isExecutionPlan
|
|
5
|
+
} from "./chunk-DSOOH73Y.ts";
|
|
6
|
+
|
|
7
|
+
// src/capability-grant.ts
|
|
8
|
+
import { createHash } from "node:crypto";
|
|
9
|
+
var CAPABILITY_GRANT_VERSION = "pi-subagents:capability-grant:v1";
|
|
10
|
+
function grantId(projection) {
|
|
11
|
+
return createHash("sha256").update(JSON.stringify(projection)).digest("hex");
|
|
12
|
+
}
|
|
13
|
+
function issueCapabilityGrant(plan, issuedAt, lifetimeMs) {
|
|
14
|
+
if (!Number.isFinite(issuedAt) || !Number.isFinite(lifetimeMs) || lifetimeMs <= 0) {
|
|
15
|
+
throw new Error("Capability grant requires finite issuance and lifetime bounds");
|
|
16
|
+
}
|
|
17
|
+
const expiresAt = issuedAt + lifetimeMs;
|
|
18
|
+
const projection = {
|
|
19
|
+
executionPlanId: plan.id,
|
|
20
|
+
taskGeneration: plan.taskGeneration,
|
|
21
|
+
effectiveTools: plan.effectiveTools,
|
|
22
|
+
issuedAt,
|
|
23
|
+
expiresAt
|
|
24
|
+
};
|
|
25
|
+
return {
|
|
26
|
+
version: CAPABILITY_GRANT_VERSION,
|
|
27
|
+
id: grantId(projection),
|
|
28
|
+
...projection,
|
|
29
|
+
state: "active"
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function revokeCapabilityGrant(grant, reason, revokedAt) {
|
|
33
|
+
if (grant.state === "revoked") throw new Error("Capability grant is already revoked");
|
|
34
|
+
grant.state = "revoked";
|
|
35
|
+
grant.revokedAt = revokedAt;
|
|
36
|
+
grant.revocationReason = reason.slice(0, 256);
|
|
37
|
+
return structuredClone(grant);
|
|
38
|
+
}
|
|
39
|
+
function isCapabilityGrant(value) {
|
|
40
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
41
|
+
const grant = value;
|
|
42
|
+
const validShape = grant.version === CAPABILITY_GRANT_VERSION && typeof grant.id === "string" && /^[a-f0-9]{64}$/u.test(grant.id) && typeof grant.executionPlanId === "string" && /^[a-f0-9]{64}$/u.test(grant.executionPlanId) && Number.isSafeInteger(grant.taskGeneration) && Number(grant.taskGeneration) >= 0 && Number.isFinite(grant.issuedAt) && Number.isFinite(grant.expiresAt) && Number(grant.expiresAt) >= Number(grant.issuedAt) && (grant.state === "active" || grant.state === "revoked") && (grant.state === "active" ? grant.revokedAt === void 0 && grant.revocationReason === void 0 : Number.isFinite(grant.revokedAt) && typeof grant.revocationReason === "string" && grant.revocationReason.length > 0) && (grant.effectiveTools === void 0 || Array.isArray(grant.effectiveTools) && grant.effectiveTools.every((tool) => typeof tool === "string"));
|
|
43
|
+
if (!validShape) return false;
|
|
44
|
+
const validated = grant;
|
|
45
|
+
const expectedId = grantId({
|
|
46
|
+
executionPlanId: validated.executionPlanId,
|
|
47
|
+
taskGeneration: validated.taskGeneration,
|
|
48
|
+
effectiveTools: validated.effectiveTools,
|
|
49
|
+
issuedAt: validated.issuedAt,
|
|
50
|
+
expiresAt: validated.expiresAt
|
|
51
|
+
});
|
|
52
|
+
return validated.id === expectedId;
|
|
53
|
+
}
|
|
54
|
+
function isCapabilityGrantActive(grant, plan, now) {
|
|
55
|
+
return isCapabilityGrant(grant) && isExecutionPlan(plan) && grant.state === "active" && grant.executionPlanId === plan.id && grant.taskGeneration === plan.taskGeneration && JSON.stringify(grant.effectiveTools ?? null) === JSON.stringify(plan.effectiveTools ?? null) && now >= grant.issuedAt && now <= grant.expiresAt;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export {
|
|
59
|
+
CAPABILITY_GRANT_VERSION,
|
|
60
|
+
issueCapabilityGrant,
|
|
61
|
+
revokeCapabilityGrant,
|
|
62
|
+
isCapabilityGrant,
|
|
63
|
+
isCapabilityGrantActive
|
|
64
|
+
};
|
|
65
|
+
//# sourceMappingURL=chunk-HKC4ES4B.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/capability-grant.ts"],
|
|
4
|
+
"sourcesContent": ["import { createHash } from \"node:crypto\";\nimport { type ExecutionPlan, isExecutionPlan } from \"./execution-plan.js\";\n\nexport const CAPABILITY_GRANT_VERSION = \"pi-subagents:capability-grant:v1\" as const;\n\nexport interface CapabilityGrant {\n\tversion: typeof CAPABILITY_GRANT_VERSION;\n\tid: string;\n\texecutionPlanId: string;\n\ttaskGeneration: number;\n\teffectiveTools?: string[];\n\tissuedAt: number;\n\texpiresAt: number;\n\tstate: \"active\" | \"revoked\";\n\trevokedAt?: number;\n\trevocationReason?: string;\n}\n\nfunction grantId(projection: {\n\texecutionPlanId: string;\n\ttaskGeneration: number;\n\teffectiveTools?: string[];\n\tissuedAt: number;\n\texpiresAt: number;\n}): string {\n\treturn createHash(\"sha256\").update(JSON.stringify(projection)).digest(\"hex\");\n}\n\nexport function issueCapabilityGrant(\n\tplan: ExecutionPlan,\n\tissuedAt: number,\n\tlifetimeMs: number,\n): CapabilityGrant {\n\tif (!Number.isFinite(issuedAt) || !Number.isFinite(lifetimeMs) || lifetimeMs <= 0) {\n\t\tthrow new Error(\"Capability grant requires finite issuance and lifetime bounds\");\n\t}\n\tconst expiresAt = issuedAt + lifetimeMs;\n\tconst projection = {\n\t\texecutionPlanId: plan.id,\n\t\ttaskGeneration: plan.taskGeneration,\n\t\teffectiveTools: plan.effectiveTools,\n\t\tissuedAt,\n\t\texpiresAt,\n\t};\n\treturn {\n\t\tversion: CAPABILITY_GRANT_VERSION,\n\t\tid: grantId(projection),\n\t\t...projection,\n\t\tstate: \"active\",\n\t};\n}\n\nexport function revokeCapabilityGrant(\n\tgrant: CapabilityGrant,\n\treason: string,\n\trevokedAt: number,\n): CapabilityGrant {\n\tif (grant.state === \"revoked\") throw new Error(\"Capability grant is already revoked\");\n\tgrant.state = \"revoked\";\n\tgrant.revokedAt = revokedAt;\n\tgrant.revocationReason = reason.slice(0, 256);\n\treturn structuredClone(grant);\n}\n\nexport function isCapabilityGrant(value: unknown): value is CapabilityGrant {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) return false;\n\tconst grant = value as Partial<CapabilityGrant>;\n\tconst validShape =\n\t\tgrant.version === CAPABILITY_GRANT_VERSION &&\n\t\ttypeof grant.id === \"string\" &&\n\t\t/^[a-f0-9]{64}$/u.test(grant.id) &&\n\t\ttypeof grant.executionPlanId === \"string\" &&\n\t\t/^[a-f0-9]{64}$/u.test(grant.executionPlanId) &&\n\t\tNumber.isSafeInteger(grant.taskGeneration) &&\n\t\tNumber(grant.taskGeneration) >= 0 &&\n\t\tNumber.isFinite(grant.issuedAt) &&\n\t\tNumber.isFinite(grant.expiresAt) &&\n\t\tNumber(grant.expiresAt) >= Number(grant.issuedAt) &&\n\t\t(grant.state === \"active\" || grant.state === \"revoked\") &&\n\t\t(grant.state === \"active\"\n\t\t\t? grant.revokedAt === undefined && grant.revocationReason === undefined\n\t\t\t: Number.isFinite(grant.revokedAt) &&\n\t\t\t\ttypeof grant.revocationReason === \"string\" &&\n\t\t\t\tgrant.revocationReason.length > 0) &&\n\t\t(grant.effectiveTools === undefined ||\n\t\t\t(Array.isArray(grant.effectiveTools) &&\n\t\t\t\tgrant.effectiveTools.every((tool) => typeof tool === \"string\")));\n\tif (!validShape) return false;\n\tconst validated = grant as CapabilityGrant;\n\tconst expectedId = grantId({\n\t\texecutionPlanId: validated.executionPlanId,\n\t\ttaskGeneration: validated.taskGeneration,\n\t\teffectiveTools: validated.effectiveTools,\n\t\tissuedAt: validated.issuedAt,\n\t\texpiresAt: validated.expiresAt,\n\t});\n\treturn validated.id === expectedId;\n}\n\nexport function isCapabilityGrantActive(\n\tgrant: CapabilityGrant,\n\tplan: ExecutionPlan,\n\tnow: number,\n): boolean {\n\treturn (\n\t\tisCapabilityGrant(grant) &&\n\t\tisExecutionPlan(plan) &&\n\t\tgrant.state === \"active\" &&\n\t\tgrant.executionPlanId === plan.id &&\n\t\tgrant.taskGeneration === plan.taskGeneration &&\n\t\tJSON.stringify(grant.effectiveTools ?? null) === JSON.stringify(plan.effectiveTools ?? null) &&\n\t\tnow >= grant.issuedAt &&\n\t\tnow <= grant.expiresAt\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;AAAA,SAAS,kBAAkB;AAGpB,IAAM,2BAA2B;AAexC,SAAS,QAAQ,YAMN;AACV,SAAO,WAAW,QAAQ,EAAE,OAAO,KAAK,UAAU,UAAU,CAAC,EAAE,OAAO,KAAK;AAC5E;AAEO,SAAS,qBACf,MACA,UACA,YACkB;AAClB,MAAI,CAAC,OAAO,SAAS,QAAQ,KAAK,CAAC,OAAO,SAAS,UAAU,KAAK,cAAc,GAAG;AAClF,UAAM,IAAI,MAAM,+DAA+D;AAAA,EAChF;AACA,QAAM,YAAY,WAAW;AAC7B,QAAM,aAAa;AAAA,IAClB,iBAAiB,KAAK;AAAA,IACtB,gBAAgB,KAAK;AAAA,IACrB,gBAAgB,KAAK;AAAA,IACrB;AAAA,IACA;AAAA,EACD;AACA,SAAO;AAAA,IACN,SAAS;AAAA,IACT,IAAI,QAAQ,UAAU;AAAA,IACtB,GAAG;AAAA,IACH,OAAO;AAAA,EACR;AACD;AAEO,SAAS,sBACf,OACA,QACA,WACkB;AAClB,MAAI,MAAM,UAAU,UAAW,OAAM,IAAI,MAAM,qCAAqC;AACpF,QAAM,QAAQ;AACd,QAAM,YAAY;AAClB,QAAM,mBAAmB,OAAO,MAAM,GAAG,GAAG;AAC5C,SAAO,gBAAgB,KAAK;AAC7B;AAEO,SAAS,kBAAkB,OAA0C;A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
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// @generated by scripts/build-runtime.mjs; do not edit.
|
|
2
|
+
// @ts-nocheck -- generated JavaScript uses a .ts extension for Pi's Jiti loader.
|
|
3
|
+
|
|
4
|
+
// src/cached-module-loader.ts
|
|
5
|
+
function cachedModuleLoader(load) {
|
|
6
|
+
let pending;
|
|
7
|
+
return () => {
|
|
8
|
+
if (!pending) {
|
|
9
|
+
pending = load().catch((error) => {
|
|
10
|
+
pending = void 0;
|
|
11
|
+
throw error;
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
return pending;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function throwIfAborted(signal, message) {
|
|
18
|
+
if (!signal?.aborted) return;
|
|
19
|
+
if (signal.reason instanceof Error) throw signal.reason;
|
|
20
|
+
throw new DOMException(message, "AbortError");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export {
|
|
24
|
+
cachedModuleLoader,
|
|
25
|
+
throwIfAborted
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=chunk-HOP5FXDT.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/cached-module-loader.ts"],
|
|
4
|
+
"sourcesContent": ["export function cachedModuleLoader<Module>(load: () => Promise<Module>): () => Promise<Module> {\n\tlet pending: Promise<Module> | undefined;\n\treturn () => {\n\t\tif (!pending) {\n\t\t\tpending = load().catch((error) => {\n\t\t\t\tpending = undefined;\n\t\t\t\tthrow error;\n\t\t\t});\n\t\t}\n\t\treturn pending;\n\t};\n}\n\nexport function throwIfAborted(signal: AbortSignal | undefined, message: string): void {\n\tif (!signal?.aborted) return;\n\tif (signal.reason instanceof Error) throw signal.reason;\n\tthrow new DOMException(message, \"AbortError\");\n}\n"],
|
|
5
|
+
"mappings": ";;;;AAAO,SAAS,mBAA2B,MAAoD;AAC9F,MAAI;AACJ,SAAO,MAAM;AACZ,QAAI,CAAC,SAAS;AACb,gBAAU,KAAK,EAAE,MAAM,CAAC,UAAU;AACjC,kBAAU;AACV,cAAM;AAAA,MACP,CAAC;AAAA,IACF;AACA,WAAO;AAAA,EACR;AACD;AAEO,SAAS,eAAe,QAAiC,SAAuB;AACtF,MAAI,CAAC,QAAQ,QAAS;AACtB,MAAI,OAAO,kBAAkB,MAAO,OAAM,OAAO;AACjD,QAAM,IAAI,aAAa,SAAS,YAAY;AAC7C;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
// @generated by scripts/build-runtime.mjs; do not edit.
|
|
2
|
+
// @ts-nocheck -- generated JavaScript uses a .ts extension for Pi's Jiti loader.
|
|
3
|
+
import {
|
|
4
|
+
DEFAULT_MAX_CONTEXT_BYTES,
|
|
5
|
+
MAX_SUBAGENT_TIMEOUT_MS,
|
|
6
|
+
redactPrivateText,
|
|
7
|
+
truncateUtf8
|
|
8
|
+
} from "./chunk-H3FP6DLR.ts";
|
|
9
|
+
|
|
10
|
+
// src/delegation-contract.ts
|
|
11
|
+
import { StringEnum } from "@earendil-works/pi-ai";
|
|
12
|
+
import { Type } from "typebox";
|
|
13
|
+
var DELEGATION_CONTRACT_VERSION = "pi-subagents:delegation:v2";
|
|
14
|
+
var DELEGATION_CONTRACT_LEVELS = ["minimal", "full"];
|
|
15
|
+
var DELEGATION_ENFORCEMENT_MODES = ["audit", "enforce"];
|
|
16
|
+
var AUTHORITY_REQUIREMENTS = ["unspecified", "denied", "required"];
|
|
17
|
+
var DELEGATION_SIDE_EFFECT_POLICIES = ["read-only", "idempotent", "mutating"];
|
|
18
|
+
var MAX_IDENTIFIER_BYTES = 256;
|
|
19
|
+
var MAX_TEXT_BYTES = 16 * 1024;
|
|
20
|
+
var MAX_ITEM_BYTES = 4 * 1024;
|
|
21
|
+
var MAX_ITEMS = 50;
|
|
22
|
+
var MAX_TURNS_OR_TOOLS = 1e6;
|
|
23
|
+
var BoundedString = Type.String({ maxLength: MAX_TEXT_BYTES });
|
|
24
|
+
var BoundedItem = Type.String({ maxLength: MAX_ITEM_BYTES });
|
|
25
|
+
var BoundedItems = Type.Array(BoundedItem, { maxItems: MAX_ITEMS });
|
|
26
|
+
var DependencySchema = Type.Object(
|
|
27
|
+
{
|
|
28
|
+
taskId: Type.String({ minLength: 1, maxLength: MAX_IDENTIFIER_BYTES }),
|
|
29
|
+
artifactId: Type.Optional(Type.String({ minLength: 1, maxLength: MAX_IDENTIFIER_BYTES })),
|
|
30
|
+
version: Type.Optional(Type.String({ minLength: 1, maxLength: MAX_IDENTIFIER_BYTES }))
|
|
31
|
+
},
|
|
32
|
+
{ additionalProperties: false }
|
|
33
|
+
);
|
|
34
|
+
var DelegationContractSchema = Type.Object(
|
|
35
|
+
{
|
|
36
|
+
version: Type.Literal(DELEGATION_CONTRACT_VERSION),
|
|
37
|
+
level: StringEnum(DELEGATION_CONTRACT_LEVELS),
|
|
38
|
+
taskId: Type.String({ minLength: 1, maxLength: MAX_IDENTIFIER_BYTES }),
|
|
39
|
+
objective: BoundedString,
|
|
40
|
+
nonGoals: Type.Optional(BoundedItems),
|
|
41
|
+
dependencies: Type.Optional(Type.Array(DependencySchema, { maxItems: MAX_ITEMS })),
|
|
42
|
+
requiredInputs: Type.Optional(BoundedItems),
|
|
43
|
+
requestedAuthority: Type.Optional(
|
|
44
|
+
Type.Object(
|
|
45
|
+
{
|
|
46
|
+
capabilities: Type.Optional(BoundedItems),
|
|
47
|
+
tools: Type.Optional(BoundedItems),
|
|
48
|
+
readPaths: Type.Optional(BoundedItems),
|
|
49
|
+
writePaths: Type.Optional(BoundedItems),
|
|
50
|
+
network: Type.Optional(StringEnum(AUTHORITY_REQUIREMENTS)),
|
|
51
|
+
secrets: Type.Optional(StringEnum(AUTHORITY_REQUIREMENTS))
|
|
52
|
+
},
|
|
53
|
+
{ additionalProperties: false }
|
|
54
|
+
)
|
|
55
|
+
),
|
|
56
|
+
acceptanceCriteria: Type.Optional(BoundedItems),
|
|
57
|
+
requiredEvidence: Type.Optional(BoundedItems),
|
|
58
|
+
budget: Type.Optional(
|
|
59
|
+
Type.Object(
|
|
60
|
+
{
|
|
61
|
+
timeoutMs: Type.Optional(Type.Integer({ minimum: 1, maximum: MAX_SUBAGENT_TIMEOUT_MS })),
|
|
62
|
+
maxTurns: Type.Optional(Type.Integer({ minimum: 1, maximum: MAX_TURNS_OR_TOOLS })),
|
|
63
|
+
maxToolCalls: Type.Optional(Type.Integer({ minimum: 1, maximum: MAX_TURNS_OR_TOOLS }))
|
|
64
|
+
},
|
|
65
|
+
{ additionalProperties: false }
|
|
66
|
+
)
|
|
67
|
+
),
|
|
68
|
+
admission: Type.Optional(
|
|
69
|
+
Type.Object(
|
|
70
|
+
{
|
|
71
|
+
contextPressure: StringEnum(["low", "medium", "high"]),
|
|
72
|
+
independentWorkItems: Type.Integer({ minimum: 1, maximum: 2 }),
|
|
73
|
+
coupling: StringEnum(["dense", "sparse"]),
|
|
74
|
+
verificationRequired: Type.Boolean(),
|
|
75
|
+
verificationAvailable: Type.Boolean(),
|
|
76
|
+
budgetAllowsChildren: Type.Boolean(),
|
|
77
|
+
requirementsComplete: Type.Boolean()
|
|
78
|
+
},
|
|
79
|
+
{ additionalProperties: false }
|
|
80
|
+
)
|
|
81
|
+
),
|
|
82
|
+
sideEffectPolicy: Type.Optional(StringEnum(DELEGATION_SIDE_EFFECT_POLICIES)),
|
|
83
|
+
enforcement: Type.Optional(StringEnum(DELEGATION_ENFORCEMENT_MODES))
|
|
84
|
+
},
|
|
85
|
+
{ additionalProperties: false }
|
|
86
|
+
);
|
|
87
|
+
function normalizeDelegationContract(value) {
|
|
88
|
+
if (!isPlainObject(value)) return void 0;
|
|
89
|
+
if (!hasOnlyKeys(value, [
|
|
90
|
+
"version",
|
|
91
|
+
"level",
|
|
92
|
+
"taskId",
|
|
93
|
+
"objective",
|
|
94
|
+
"nonGoals",
|
|
95
|
+
"dependencies",
|
|
96
|
+
"requiredInputs",
|
|
97
|
+
"requestedAuthority",
|
|
98
|
+
"acceptanceCriteria",
|
|
99
|
+
"requiredEvidence",
|
|
100
|
+
"budget",
|
|
101
|
+
"admission",
|
|
102
|
+
"sideEffectPolicy",
|
|
103
|
+
"enforcement"
|
|
104
|
+
])) {
|
|
105
|
+
return void 0;
|
|
106
|
+
}
|
|
107
|
+
if (value.version !== DELEGATION_CONTRACT_VERSION || typeof value.level !== "string" || !DELEGATION_CONTRACT_LEVELS.includes(
|
|
108
|
+
value.level
|
|
109
|
+
) || typeof value.taskId !== "string" || !value.taskId.trim() || typeof value.objective !== "string") {
|
|
110
|
+
return void 0;
|
|
111
|
+
}
|
|
112
|
+
const taskId = bounded(value.taskId, MAX_IDENTIFIER_BYTES);
|
|
113
|
+
const objective = bounded(value.objective, MAX_TEXT_BYTES);
|
|
114
|
+
if (!taskId || !objective) return void 0;
|
|
115
|
+
const nonGoals = normalizeStrings(value.nonGoals);
|
|
116
|
+
const requiredInputs = normalizeStrings(value.requiredInputs);
|
|
117
|
+
const acceptanceCriteria = normalizeStrings(value.acceptanceCriteria);
|
|
118
|
+
const requiredEvidence = normalizeStrings(value.requiredEvidence);
|
|
119
|
+
if (!nonGoals || !requiredInputs || !acceptanceCriteria || !requiredEvidence) return void 0;
|
|
120
|
+
const dependencies = normalizeDependencies(value.dependencies);
|
|
121
|
+
if (!dependencies) return void 0;
|
|
122
|
+
const authority = normalizeAuthority(value.requestedAuthority);
|
|
123
|
+
if (authority === false) return void 0;
|
|
124
|
+
const budget = normalizeBudget(value.budget);
|
|
125
|
+
if (budget === false) return void 0;
|
|
126
|
+
const admission = normalizeAdmission(value.admission);
|
|
127
|
+
if (admission === false) return void 0;
|
|
128
|
+
const sideEffectPolicy = value.sideEffectPolicy ?? "mutating";
|
|
129
|
+
if (typeof sideEffectPolicy !== "string" || !DELEGATION_SIDE_EFFECT_POLICIES.includes(
|
|
130
|
+
sideEffectPolicy
|
|
131
|
+
)) {
|
|
132
|
+
return void 0;
|
|
133
|
+
}
|
|
134
|
+
const enforcement = value.enforcement ?? "audit";
|
|
135
|
+
if (typeof enforcement !== "string" || !DELEGATION_ENFORCEMENT_MODES.includes(
|
|
136
|
+
enforcement
|
|
137
|
+
)) {
|
|
138
|
+
return void 0;
|
|
139
|
+
}
|
|
140
|
+
return {
|
|
141
|
+
version: DELEGATION_CONTRACT_VERSION,
|
|
142
|
+
level: value.level,
|
|
143
|
+
taskId,
|
|
144
|
+
objective,
|
|
145
|
+
nonGoals,
|
|
146
|
+
dependencies,
|
|
147
|
+
requiredInputs,
|
|
148
|
+
...authority === void 0 ? {} : { requestedAuthority: authority },
|
|
149
|
+
acceptanceCriteria,
|
|
150
|
+
requiredEvidence,
|
|
151
|
+
...budget === void 0 ? {} : { budget },
|
|
152
|
+
...admission === void 0 ? {} : { admission },
|
|
153
|
+
sideEffectPolicy,
|
|
154
|
+
enforcement
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
function appendDelegationContract(prompt, value, maxBytes = DEFAULT_MAX_CONTEXT_BYTES) {
|
|
158
|
+
const contract = normalizeDelegationContract(value);
|
|
159
|
+
if (!contract) return { text: prompt, truncated: false };
|
|
160
|
+
const suffix = [
|
|
161
|
+
"",
|
|
162
|
+
"Delegation contract:",
|
|
163
|
+
JSON.stringify(contract),
|
|
164
|
+
"The requested authority is advisory until an executor-owned ExecutionPlan confirms which controls are enforceable and effective.",
|
|
165
|
+
"Acknowledge missing inputs, authority, capabilities, or verification instead of guessing."
|
|
166
|
+
].join("\n");
|
|
167
|
+
const suffixBytes = Buffer.byteLength(suffix, "utf8");
|
|
168
|
+
const boundedPrompt = truncateUtf8(
|
|
169
|
+
redactPrivateText(prompt),
|
|
170
|
+
Math.max(0, maxBytes - suffixBytes)
|
|
171
|
+
);
|
|
172
|
+
const text = truncateUtf8(`${boundedPrompt.text}${suffix}`, maxBytes);
|
|
173
|
+
return {
|
|
174
|
+
text: text.text,
|
|
175
|
+
contract,
|
|
176
|
+
truncated: boundedPrompt.truncated || text.truncated
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
function normalizeAdmission(value) {
|
|
180
|
+
if (value === void 0) return void 0;
|
|
181
|
+
if (!isPlainObject(value)) return false;
|
|
182
|
+
if (!hasOnlyKeys(value, [
|
|
183
|
+
"contextPressure",
|
|
184
|
+
"independentWorkItems",
|
|
185
|
+
"coupling",
|
|
186
|
+
"verificationRequired",
|
|
187
|
+
"verificationAvailable",
|
|
188
|
+
"budgetAllowsChildren",
|
|
189
|
+
"requirementsComplete"
|
|
190
|
+
]) || !["low", "medium", "high"].includes(String(value.contextPressure)) || !Number.isSafeInteger(value.independentWorkItems) || Number(value.independentWorkItems) < 1 || Number(value.independentWorkItems) > 2 || !["dense", "sparse"].includes(String(value.coupling)) || typeof value.verificationRequired !== "boolean" || typeof value.verificationAvailable !== "boolean" || typeof value.budgetAllowsChildren !== "boolean" || typeof value.requirementsComplete !== "boolean") {
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
return {
|
|
194
|
+
contextPressure: value.contextPressure,
|
|
195
|
+
independentWorkItems: Number(value.independentWorkItems),
|
|
196
|
+
coupling: value.coupling,
|
|
197
|
+
verificationRequired: value.verificationRequired,
|
|
198
|
+
verificationAvailable: value.verificationAvailable,
|
|
199
|
+
budgetAllowsChildren: value.budgetAllowsChildren,
|
|
200
|
+
requirementsComplete: value.requirementsComplete
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
function normalizeDependencies(value) {
|
|
204
|
+
if (value === void 0) return [];
|
|
205
|
+
if (!Array.isArray(value) || value.length > MAX_ITEMS) return void 0;
|
|
206
|
+
const result = [];
|
|
207
|
+
const seen = /* @__PURE__ */ new Set();
|
|
208
|
+
for (const item of value) {
|
|
209
|
+
if (!isPlainObject(item) || !hasOnlyKeys(item, ["taskId", "artifactId", "version"]) || typeof item.taskId !== "string") {
|
|
210
|
+
return void 0;
|
|
211
|
+
}
|
|
212
|
+
const taskId = bounded(item.taskId, MAX_IDENTIFIER_BYTES);
|
|
213
|
+
if (!taskId || seen.has(taskId)) return void 0;
|
|
214
|
+
seen.add(taskId);
|
|
215
|
+
const artifactId = optionalString(item.artifactId, MAX_IDENTIFIER_BYTES);
|
|
216
|
+
const version = optionalString(item.version, MAX_IDENTIFIER_BYTES);
|
|
217
|
+
if (artifactId === false || version === false) return void 0;
|
|
218
|
+
result.push({
|
|
219
|
+
taskId,
|
|
220
|
+
...artifactId === void 0 ? {} : { artifactId },
|
|
221
|
+
...version === void 0 ? {} : { version }
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
return result;
|
|
225
|
+
}
|
|
226
|
+
function normalizeAuthority(value) {
|
|
227
|
+
if (value === void 0) return void 0;
|
|
228
|
+
if (!isPlainObject(value)) return false;
|
|
229
|
+
if (!hasOnlyKeys(value, ["capabilities", "tools", "readPaths", "writePaths", "network", "secrets"])) {
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
const capabilities = normalizeOptionalStrings(value.capabilities);
|
|
233
|
+
const tools = normalizeOptionalStrings(value.tools);
|
|
234
|
+
const readPaths = normalizeOptionalStrings(value.readPaths);
|
|
235
|
+
const writePaths = normalizeOptionalStrings(value.writePaths);
|
|
236
|
+
if (capabilities === false || tools === false || readPaths === false || writePaths === false) {
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
const network = normalizeAuthorityRequirement(value.network);
|
|
240
|
+
const secrets = normalizeAuthorityRequirement(value.secrets);
|
|
241
|
+
if (network === false || secrets === false) return false;
|
|
242
|
+
return {
|
|
243
|
+
...capabilities === void 0 ? {} : { capabilities },
|
|
244
|
+
...tools === void 0 ? {} : { tools },
|
|
245
|
+
...readPaths === void 0 ? {} : { readPaths },
|
|
246
|
+
...writePaths === void 0 ? {} : { writePaths },
|
|
247
|
+
...network === void 0 ? {} : { network },
|
|
248
|
+
...secrets === void 0 ? {} : { secrets }
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
function normalizeBudget(value) {
|
|
252
|
+
if (value === void 0) return void 0;
|
|
253
|
+
if (!isPlainObject(value) || !hasOnlyKeys(value, ["timeoutMs", "maxTurns", "maxToolCalls"])) {
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
256
|
+
const timeoutMs = optionalInteger(value.timeoutMs, MAX_SUBAGENT_TIMEOUT_MS);
|
|
257
|
+
const maxTurns = optionalInteger(value.maxTurns, MAX_TURNS_OR_TOOLS);
|
|
258
|
+
const maxToolCalls = optionalInteger(value.maxToolCalls, MAX_TURNS_OR_TOOLS);
|
|
259
|
+
if (timeoutMs === false || maxTurns === false || maxToolCalls === false) return false;
|
|
260
|
+
return {
|
|
261
|
+
...timeoutMs === void 0 ? {} : { timeoutMs },
|
|
262
|
+
...maxTurns === void 0 ? {} : { maxTurns },
|
|
263
|
+
...maxToolCalls === void 0 ? {} : { maxToolCalls }
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
function normalizeStrings(value) {
|
|
267
|
+
if (value === void 0) return [];
|
|
268
|
+
const normalized = normalizeOptionalStrings(value);
|
|
269
|
+
return normalized === false ? void 0 : normalized;
|
|
270
|
+
}
|
|
271
|
+
function normalizeOptionalStrings(value) {
|
|
272
|
+
if (value === void 0) return void 0;
|
|
273
|
+
if (!Array.isArray(value) || value.length > MAX_ITEMS) return false;
|
|
274
|
+
const result = [];
|
|
275
|
+
const seen = /* @__PURE__ */ new Set();
|
|
276
|
+
for (const item of value) {
|
|
277
|
+
if (typeof item !== "string") return false;
|
|
278
|
+
const normalized = bounded(item, MAX_ITEM_BYTES);
|
|
279
|
+
if (!normalized || seen.has(normalized)) continue;
|
|
280
|
+
seen.add(normalized);
|
|
281
|
+
result.push(normalized);
|
|
282
|
+
}
|
|
283
|
+
return result;
|
|
284
|
+
}
|
|
285
|
+
function normalizeAuthorityRequirement(value) {
|
|
286
|
+
if (value === void 0) return void 0;
|
|
287
|
+
if (typeof value !== "string" || !AUTHORITY_REQUIREMENTS.includes(value)) {
|
|
288
|
+
return false;
|
|
289
|
+
}
|
|
290
|
+
return value;
|
|
291
|
+
}
|
|
292
|
+
function optionalString(value, maxBytes) {
|
|
293
|
+
if (value === void 0) return void 0;
|
|
294
|
+
if (typeof value !== "string") return false;
|
|
295
|
+
const normalized = bounded(value, maxBytes);
|
|
296
|
+
return normalized || false;
|
|
297
|
+
}
|
|
298
|
+
function optionalInteger(value, max) {
|
|
299
|
+
if (value === void 0) return void 0;
|
|
300
|
+
if (!Number.isSafeInteger(value) || value < 1 || value > max)
|
|
301
|
+
return false;
|
|
302
|
+
return value;
|
|
303
|
+
}
|
|
304
|
+
function bounded(value, maxBytes) {
|
|
305
|
+
return truncateUtf8(redactPrivateText(value), maxBytes).text.trim();
|
|
306
|
+
}
|
|
307
|
+
function hasOnlyKeys(value, allowed) {
|
|
308
|
+
return Object.keys(value).every((key) => allowed.includes(key));
|
|
309
|
+
}
|
|
310
|
+
function isPlainObject(value) {
|
|
311
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
export {
|
|
315
|
+
DELEGATION_CONTRACT_VERSION,
|
|
316
|
+
DELEGATION_CONTRACT_LEVELS,
|
|
317
|
+
DELEGATION_ENFORCEMENT_MODES,
|
|
318
|
+
AUTHORITY_REQUIREMENTS,
|
|
319
|
+
DELEGATION_SIDE_EFFECT_POLICIES,
|
|
320
|
+
DelegationContractSchema,
|
|
321
|
+
normalizeDelegationContract,
|
|
322
|
+
appendDelegationContract
|
|
323
|
+
};
|
|
324
|
+
//# sourceMappingURL=chunk-I2FAK44T.ts.map
|