@parlor/agent-host 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/acp.d.ts +21 -0
- package/dist/acp.d.ts.map +1 -1
- package/dist/acp.js +138 -12
- package/dist/acp.js.map +1 -1
- package/dist/agent-options.d.ts +22 -0
- package/dist/agent-options.d.ts.map +1 -0
- package/dist/agent-options.js +105 -0
- package/dist/agent-options.js.map +1 -0
- package/dist/agent-survey.d.ts +15 -0
- package/dist/agent-survey.d.ts.map +1 -0
- package/dist/agent-survey.js +51 -0
- package/dist/agent-survey.js.map +1 -0
- package/dist/agent-tools.d.ts +30 -0
- package/dist/agent-tools.d.ts.map +1 -0
- package/dist/agent-tools.js +71 -0
- package/dist/agent-tools.js.map +1 -0
- package/dist/codex-app-server.d.ts +7 -0
- package/dist/codex-app-server.d.ts.map +1 -0
- package/dist/codex-app-server.js +46 -0
- package/dist/codex-app-server.js.map +1 -0
- package/dist/control.d.ts +15 -0
- package/dist/control.d.ts.map +1 -1
- package/dist/control.js.map +1 -1
- package/dist/daemon.d.ts +10 -2
- package/dist/daemon.d.ts.map +1 -1
- package/dist/daemon.js +217 -16
- package/dist/daemon.js.map +1 -1
- package/dist/fold.d.ts.map +1 -1
- package/dist/fold.js +2 -0
- package/dist/fold.js.map +1 -1
- package/dist/grants.d.ts +9 -0
- package/dist/grants.d.ts.map +1 -1
- package/dist/grants.js.map +1 -1
- package/dist/learned.d.ts +25 -0
- package/dist/learned.d.ts.map +1 -0
- package/dist/learned.js +37 -0
- package/dist/learned.js.map +1 -0
- package/dist/link.d.ts +3 -1
- package/dist/link.d.ts.map +1 -1
- package/dist/link.js +23 -1
- package/dist/link.js.map +1 -1
- package/dist/main.js +105 -9
- package/dist/main.js.map +1 -1
- package/dist/mcp-proxy.d.ts +26 -3
- package/dist/mcp-proxy.d.ts.map +1 -1
- package/dist/mcp-proxy.js +288 -25
- package/dist/mcp-proxy.js.map +1 -1
- package/dist/pairing.d.ts +2 -0
- package/dist/pairing.d.ts.map +1 -1
- package/dist/pairing.js +25 -3
- package/dist/pairing.js.map +1 -1
- package/dist/paths.d.ts +2 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +1 -0
- package/dist/paths.js.map +1 -1
- package/dist/policy.d.ts +12 -2
- package/dist/policy.d.ts.map +1 -1
- package/dist/policy.js +13 -3
- package/dist/policy.js.map +1 -1
- package/dist/prompter.d.ts +5 -0
- package/dist/prompter.d.ts.map +1 -1
- package/dist/prompter.js +15 -0
- package/dist/prompter.js.map +1 -1
- package/dist/spec-kit.d.ts +4 -1
- package/dist/spec-kit.d.ts.map +1 -1
- package/dist/spec-kit.js +12 -2
- package/dist/spec-kit.js.map +1 -1
- package/dist/testing/fake-agent.d.ts +12 -0
- package/dist/testing/fake-agent.d.ts.map +1 -1
- package/dist/testing/fake-agent.js +11 -1
- package/dist/testing/fake-agent.js.map +1 -1
- package/dist/turn.d.ts +7 -1
- package/dist/turn.d.ts.map +1 -1
- package/dist/turn.js +16 -3
- package/dist/turn.js.map +1 -1
- package/package.json +9 -9
package/dist/pairing.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createHash, randomBytes, randomInt } from "node:crypto";
|
|
2
2
|
import { createServer } from "node:http";
|
|
3
3
|
import { HOST_PAIRING_FRAGMENT, } from "@parlor/auth";
|
|
4
|
+
import { agentToolsName } from "./agent-tools.js";
|
|
4
5
|
import { hostAssertion } from "./assertion.js";
|
|
5
6
|
import { workspaceOf } from "./naming.js";
|
|
6
7
|
import { printable } from "./prompter.js";
|
|
@@ -52,7 +53,10 @@ async function loopback(state) {
|
|
|
52
53
|
}
|
|
53
54
|
waiting = response;
|
|
54
55
|
const code = url.searchParams.get("code");
|
|
55
|
-
|
|
56
|
+
const agentTools = url.searchParams.get("agentTools");
|
|
57
|
+
deliver(code
|
|
58
|
+
? { code, ...(agentTools === null ? {} : { agentTools: agentTools === "on" }) }
|
|
59
|
+
: { declined: true });
|
|
56
60
|
});
|
|
57
61
|
await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
|
|
58
62
|
const { port } = server.address();
|
|
@@ -102,6 +106,11 @@ function timeout(ms) {
|
|
|
102
106
|
});
|
|
103
107
|
return { expired, clear: () => clearTimeout(timer) };
|
|
104
108
|
}
|
|
109
|
+
/** The pairing secret goes nowhere but the app's own origin; an older app has no landing page. */
|
|
110
|
+
function landingOf(origin, landing) {
|
|
111
|
+
const url = landing === undefined ? undefined : URL.parse(landing, origin);
|
|
112
|
+
return url?.origin === origin ? url : new URL("/", origin);
|
|
113
|
+
}
|
|
105
114
|
/**
|
|
106
115
|
* Only the host starts a pairing: it makes the PKCE verifier, `state`, the matching code
|
|
107
116
|
* and the key pair, so nothing from the web side can complete one.
|
|
@@ -109,6 +118,7 @@ function timeout(ms) {
|
|
|
109
118
|
export async function pair(input) {
|
|
110
119
|
const origin = new URL(input.appOrigin).origin;
|
|
111
120
|
const appName = await appNameOf(origin);
|
|
121
|
+
const toolsName = input.offerAgentTools ? agentToolsName(appName, origin) : undefined;
|
|
112
122
|
const key = await input.keys.create(origin);
|
|
113
123
|
const codeVerifier = base64url(randomBytes(32));
|
|
114
124
|
const pairing = {
|
|
@@ -136,6 +146,7 @@ export async function pair(input) {
|
|
|
136
146
|
const query = new URLSearchParams({
|
|
137
147
|
redirectUri: listener.redirectUri,
|
|
138
148
|
...pairing,
|
|
149
|
+
...(toolsName ? { agentTools: "offered" } : {}),
|
|
139
150
|
});
|
|
140
151
|
await input.channel.open(`${origin}/_parlor/auth/hosts/authorize?${query}`);
|
|
141
152
|
const callback = await Promise.race([listener.callback, deadline.expired]);
|
|
@@ -155,10 +166,21 @@ export async function pair(input) {
|
|
|
155
166
|
}
|
|
156
167
|
await key.keep(granted.grant.id);
|
|
157
168
|
const pairingSecret = base64url(randomBytes(32));
|
|
158
|
-
|
|
169
|
+
const landing = landingOf(origin, granted.landing);
|
|
170
|
+
const agentTools = toolsName && "agentTools" in callback ? callback.agentTools : undefined;
|
|
171
|
+
if (agentTools && toolsName)
|
|
172
|
+
landing.searchParams.set("agentTools", toolsName);
|
|
173
|
+
landing.hash = new URLSearchParams({
|
|
174
|
+
[HOST_PAIRING_FRAGMENT]: pairingSecret,
|
|
175
|
+
}).toString();
|
|
176
|
+
listener.redirect(landing.href);
|
|
159
177
|
return {
|
|
160
178
|
paired: true,
|
|
161
|
-
grant: {
|
|
179
|
+
grant: {
|
|
180
|
+
...grantOf(granted),
|
|
181
|
+
pairingSecret,
|
|
182
|
+
...(agentTools === undefined ? {} : { agentTools: { on: agentTools } }),
|
|
183
|
+
},
|
|
162
184
|
approvedBy: granted.approvedBy,
|
|
163
185
|
};
|
|
164
186
|
}
|
package/dist/pairing.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pairing.js","sourceRoot":"","sources":["../src/pairing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,YAAY,EAAoC,MAAM,WAAW,CAAC;AAG3E,OAAO,EAEL,qBAAqB,GAEtB,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,GAAG,MAAM,CAAC;AA2C9C,MAAM,OAAO,cAAe,SAAQ,KAAK;IAG5B,KAAK;IAFE,IAAI,GAAG,gBAAgB,CAAC;IAC1C,YACW,KAAe,EACxB,KAAY;QAEZ,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;qBAHvB,KAAK;IAIhB,CAAC;CACF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,CAAC;QACpD,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,SAAS,EAAE,CAAC;IAC9D,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,KAAc;IAC5C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,SAAS,CAAC;IAClE,MAAM,MAAM,GAAG,KAAgC,CAAC;IAChD,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;QACjF,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC;QAAE,OAAO,SAAS,CAAC;IAClD,OAAO;QACL,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,UAAU,EAAE;YACV,GAAG,EAAE,IAAI;YACT,GAAG,EAAE,OAAO;YACZ,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;YACtB,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;SACvB;QACD,WAAW,EAAE,aAAa,CAAC,MAAM,CAAC,WAAW,CAAC;KAC/C,CAAC;AACJ,CAAC","sourcesContent":["import { createHash, randomBytes, randomInt } from \"node:crypto\";\nimport { createServer, type Server, type ServerResponse } from \"node:http\";\nimport type { AddressInfo } from \"node:net\";\n\nimport {\n type AccountSummary,\n HOST_PAIRING_FRAGMENT,\n type HostGrantResponse,\n} from \"@parlor/auth\";\nimport type { HostPairing, PairingDevice } from \"@parlor/capabilities\";\n\nimport { hostAssertion } from \"./assertion.js\";\nimport type { AppGrant, HostKeyPair, HostKeys } from \"./grants.js\";\nimport { workspaceOf } from \"./naming.js\";\nimport { printable } from \"./prompter.js\";\nimport { revokeGrant } from \"./revoke.js\";\n\nexport const PAIRING_TIMEOUT_MS = 10 * 60_000;\n\nexport interface PairingReview {\n readonly appName: string;\n readonly appOrigin: string;\n readonly account: AccountSummary;\n readonly matchingCode: string;\n}\n\n/**\n * `browser`: a one-shot 127.0.0.1 listener (RFC 8252) accepting exactly this attempt's\n * `state`; the consent page is the one decision. `ipc`: the desktop shell's signed-in\n * webview gets the code from the backend and hands it over Tauri IPC, with no consent page,\n * so the shell's native dialog confirms the account the host got back.\n */\nexport type PairingChannel =\n | { readonly kind: \"browser\"; open(url: string): Promise<void> }\n | {\n readonly kind: \"ipc\";\n authorize(pairing: HostPairing): Promise<string>;\n confirm(review: PairingReview): Promise<boolean>;\n };\n\nexport interface PairInput {\n readonly appOrigin: string;\n readonly hostName: string;\n readonly platform: string;\n readonly channel: PairingChannel;\n readonly keys: HostKeys;\n readonly workspaceRoot: string;\n}\n\nexport type PairOutcome =\n | {\n readonly paired: true;\n readonly grant: AppGrant;\n readonly approvedBy: HostGrantResponse[\"approvedBy\"];\n }\n | {\n readonly paired: false;\n readonly reason: \"declined_locally\" | \"declined_in_app\" | \"timeout\";\n };\n\nexport class UnrevokedGrant extends Error {\n override readonly name = \"UnrevokedGrant\";\n constructor(\n readonly grant: AppGrant,\n cause: Error,\n ) {\n super(cause.message, { cause });\n }\n}\n\nconst MATCHING_ALPHABET = \"ABCDEFGHJKLMNPQRSTUVWXYZ23456789\";\n\nconst base64url = (bytes: Buffer) => bytes.toString(\"base64url\");\n\nfunction matchingCode(): string {\n const part = () =>\n Array.from(\n { length: 3 },\n () => MATCHING_ALPHABET[randomInt(MATCHING_ALPHABET.length)],\n ).join(\"\");\n return `${part()}-${part()}`;\n}\n\nasync function appNameOf(origin: string): Promise<string> {\n const response = await fetch(`${origin}/_parlor/manifest`);\n if (!response.ok) {\n throw new Error(`${origin} answered HTTP ${response.status}; is it a Parlor app?`);\n }\n const manifest = (await response.json()) as {\n readonly app?: { readonly name?: unknown };\n };\n return typeof manifest.app?.name === \"string\"\n ? manifest.app.name\n : new URL(origin).host;\n}\n\ntype Callback = { readonly code: string } | { readonly declined: true };\n\nconst escapeHtml = (text: string) =>\n printable(text).replace(/[&<>\"']/g, (char) => `&#${char.charCodeAt(0)};`);\n\nconst RESULT_STYLE = `:root{color-scheme:light dark;--bg:#f6f6f4;--card:#fff;--text:#1d1d1b;--muted:#5f5f5a;--line:#e2e2dc}@media (prefers-color-scheme:dark){:root{--bg:#151514;--card:#1f1f1d;--text:#ededea;--muted:#a3a39d;--line:#34342f}}*{box-sizing:border-box}body{margin:0;min-height:100vh;display:grid;place-items:center;padding:16px;background:var(--bg);color:var(--text);font:15px/1.5 system-ui,-apple-system,\"Segoe UI\",sans-serif}main{width:100%;max-width:420px;background:var(--card);border:1px solid var(--line);border-radius:12px;padding:28px}h1{font-size:20px;line-height:1.3;margin:0 0 8px}p{margin:0;color:var(--muted)}`;\n\nfunction resultPage(heading: string, detail: string): string {\n return `<!doctype html><html lang=\"en\"><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><title>${escapeHtml(heading)}</title><style>${RESULT_STYLE}</style></head><body><main><h1>${escapeHtml(heading)}</h1><p>${escapeHtml(detail)}</p></main></body></html>`;\n}\n\n/** Holds the browser's request until the exchange settles, so the tab says what happened. */\nasync function loopback(state: string): Promise<{\n readonly redirectUri: string;\n readonly callback: Promise<Callback>;\n readonly answer: (heading: string, detail: string) => void;\n readonly redirect: (url: string) => void;\n readonly close: () => void;\n}> {\n let deliver: (callback: Callback) => void = () => undefined;\n const callback = new Promise<Callback>((resolve) => (deliver = resolve));\n let waiting: ServerResponse | undefined;\n const server: Server = createServer((request, response) => {\n const url = new URL(request.url ?? \"/\", \"http://127.0.0.1\");\n if (\n waiting ||\n url.pathname !== \"/callback\" ||\n url.searchParams.get(\"state\") !== state\n ) {\n response\n .writeHead(404, { \"content-type\": \"text/plain\" })\n .end(\"Not this connection.\");\n return;\n }\n waiting = response;\n const code = url.searchParams.get(\"code\");\n deliver(code ? { code } : { declined: true });\n });\n await new Promise<void>((resolve) => server.listen(0, \"127.0.0.1\", resolve));\n const { port } = server.address() as AddressInfo;\n const answer = (heading: string, detail: string) => {\n if (!waiting || waiting.headersSent) return;\n waiting\n .writeHead(200, { \"content-type\": \"text/html; charset=utf-8\" })\n .end(resultPage(heading, detail));\n };\n return {\n redirectUri: `http://127.0.0.1:${port}/callback`,\n callback,\n answer,\n redirect: (url) => {\n if (!waiting || waiting.headersSent) return;\n waiting.writeHead(303, { location: url, \"cache-control\": \"no-store\" }).end();\n },\n close: () => {\n answer(\"Parlor Host stopped\", \"Go back to your terminal.\");\n server.close();\n },\n };\n}\n\nasync function exchange(\n origin: string,\n key: HostKeyPair,\n code: string,\n codeVerifier: string,\n): Promise<HostGrantResponse> {\n const response = await fetch(`${origin}/_parlor/auth/hosts/token`, {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({\n code,\n codeVerifier,\n publicKey: key.publicKey,\n proof: await key.sign(new TextEncoder().encode(code)),\n }),\n });\n const body = (await response.json().catch(() => undefined)) as\n | (HostGrantResponse & { readonly error?: { readonly message?: string } })\n | undefined;\n if (!response.ok || !body?.grant) {\n throw new Error(body?.error?.message ?? `The app answered HTTP ${response.status}.`);\n }\n return body;\n}\n\nfunction timeout(ms: number): {\n readonly expired: Promise<\"timeout\">;\n readonly clear: () => void;\n} {\n let timer: NodeJS.Timeout | undefined;\n const expired = new Promise<\"timeout\">((resolve) => {\n timer = setTimeout(() => resolve(\"timeout\"), ms);\n });\n return { expired, clear: () => clearTimeout(timer) };\n}\n\n/**\n * Only the host starts a pairing: it makes the PKCE verifier, `state`, the matching code\n * and the key pair, so nothing from the web side can complete one.\n */\nexport async function pair(input: PairInput): Promise<PairOutcome> {\n const origin = new URL(input.appOrigin).origin;\n const appName = await appNameOf(origin);\n const key = await input.keys.create(origin);\n const codeVerifier = base64url(randomBytes(32));\n const pairing: HostPairing = {\n hostName: input.hostName,\n platform: input.platform,\n codeChallenge: base64url(createHash(\"sha256\").update(codeVerifier).digest()),\n state: base64url(randomBytes(16)),\n matchingCode: matchingCode(),\n keyThumbprint: key.thumbprint,\n };\n const grantOf = (granted: HostGrantResponse): AppGrant => ({\n appOrigin: origin,\n appName,\n grantId: granted.grant.id,\n hostId: granted.grant.hostId,\n account: granted.account,\n workspace: workspaceOf(input.workspaceRoot, origin),\n createdAt: Date.now(),\n });\n const deadline = timeout(PAIRING_TIMEOUT_MS);\n try {\n if (input.channel.kind === \"browser\") {\n const listener = await loopback(pairing.state);\n try {\n const query = new URLSearchParams({\n redirectUri: listener.redirectUri,\n ...pairing,\n });\n await input.channel.open(`${origin}/_parlor/auth/hosts/authorize?${query}`);\n const callback = await Promise.race([listener.callback, deadline.expired]);\n if (callback === \"timeout\") return { paired: false, reason: \"timeout\" };\n if (!(\"code\" in callback)) {\n listener.answer(\"Not connected\", \"You cancelled the connection.\");\n return { paired: false, reason: \"declined_in_app\" };\n }\n let granted: HostGrantResponse;\n try {\n granted = await exchange(origin, key, callback.code, codeVerifier);\n } catch (error) {\n listener.answer(\"Not connected\", (error as Error).message);\n throw error;\n }\n await key.keep(granted.grant.id);\n const pairingSecret = base64url(randomBytes(32));\n listener.redirect(\n `${origin}/#${new URLSearchParams({ [HOST_PAIRING_FRAGMENT]: pairingSecret })}`,\n );\n return {\n paired: true,\n grant: { ...grantOf(granted), pairingSecret },\n approvedBy: granted.approvedBy,\n };\n } finally {\n listener.close();\n }\n }\n\n const callback = await Promise.race([\n input.channel.authorize(pairing).then((code) => ({ code })),\n deadline.expired,\n ]);\n if (callback === \"timeout\") return { paired: false, reason: \"timeout\" };\n const granted = await exchange(origin, key, callback.code, codeVerifier);\n const grant = grantOf(granted);\n const confirmed = await Promise.race([\n input.channel.confirm({\n appName,\n appOrigin: origin,\n account: granted.account,\n matchingCode: pairing.matchingCode,\n }),\n deadline.expired,\n ]);\n if (confirmed !== true) {\n await revokeGrant({\n appOrigin: origin,\n appName,\n assert: (request) =>\n hostAssertion(\n (payload) => key.sign(payload),\n { kid: key.thumbprint, grantId: grant.grantId },\n request,\n ),\n }).catch(async (error: Error) => {\n await key.keep(grant.grantId);\n throw new UnrevokedGrant({ ...grant, declined: true }, error);\n });\n return {\n paired: false,\n reason: confirmed === \"timeout\" ? \"timeout\" : \"declined_locally\",\n };\n }\n await key.keep(grant.grantId);\n return { paired: true, grant, approvedBy: granted.approvedBy };\n } finally {\n deadline.clear();\n }\n}\n\ninterface Deferred<T> {\n readonly promise: Promise<T>;\n readonly resolve: (value: T) => void;\n readonly reject: (error: unknown) => void;\n}\n\nfunction deferred<T>(): Deferred<T> {\n let resolve!: (value: T) => void;\n let reject!: (error: unknown) => void;\n const promise = new Promise<T>((done, fail) => {\n resolve = done;\n reject = fail;\n });\n promise.catch(() => undefined);\n return { promise, resolve, reject };\n}\n\nexport interface LocalPairingReview {\n readonly account: string;\n readonly appName: string;\n readonly matchingCode: string;\n}\n\n/**\n * A pairing driven over the control socket by the desktop shell: `pairing` once the host\n * made its key and code, `finish` with the code the signed-in page got from the backend,\n * `confirm` with the user's answer in the native dialog.\n */\nexport interface LocalPairing {\n readonly pairing: Promise<HostPairing>;\n finish(code: string): Promise<LocalPairingReview>;\n confirm(connect: boolean): Promise<PairOutcome>;\n}\n\nexport function startLocalPairing(input: Omit<PairInput, \"channel\">): LocalPairing {\n const ready = deferred<HostPairing>();\n const code = deferred<string>();\n const review = deferred<LocalPairingReview>();\n const decision = deferred<boolean>();\n const outcome = pair({\n ...input,\n channel: {\n kind: \"ipc\",\n authorize: (pairing) => {\n ready.resolve(pairing);\n return code.promise;\n },\n confirm: (shown) => {\n review.resolve({\n account: printable(shown.account.email ?? shown.account.name),\n appName: printable(shown.appName),\n matchingCode: shown.matchingCode,\n });\n return decision.promise;\n },\n },\n });\n outcome.then(\n (result) => {\n if (result.paired) return;\n const stopped = new Error(`The pairing ended: ${result.reason}.`);\n ready.reject(stopped);\n review.reject(stopped);\n },\n (error: unknown) => {\n ready.reject(error);\n review.reject(error);\n },\n );\n outcome.catch(() => undefined);\n return {\n pairing: ready.promise,\n finish: (value) => {\n code.resolve(value);\n return review.promise;\n },\n confirm: (connect) => {\n decision.resolve(connect);\n return outcome;\n },\n };\n}\n\nconst isText = (value: unknown): value is string =>\n typeof value === \"string\" && value !== \"\";\n\ntype Point = JsonWebKey & { readonly x: string; readonly y: string };\n\nconst isPoint = (value: unknown): value is Point => {\n if (typeof value !== \"object\" || value === null) return false;\n const key = value as Record<string, unknown>;\n return key.kty === \"EC\" && key.crv === \"P-256\" && isText(key.x) && isText(key.y);\n};\n\nfunction presenceKeyOf(value: unknown): PairingDevice[\"presenceKey\"] {\n if (typeof value !== \"object\" || value === null) return undefined;\n const key = value as Record<string, unknown>;\n if (!isPoint(key.publicKey)) return undefined;\n const publicKey = { kty: \"EC\", crv: \"P-256\", x: key.publicKey.x, y: key.publicKey.y };\n if (key.format === \"webauthn\" && isText(key.credentialId) && isText(key.rpId)) {\n return {\n format: \"webauthn\",\n credentialId: key.credentialId,\n rpId: key.rpId,\n publicKey,\n };\n }\n if (key.format === \"es256-raw\" && isText(key.keyId)) {\n return { format: \"es256-raw\", keyId: key.keyId, publicKey };\n }\n return undefined;\n}\n\nexport function pairingDeviceOf(value: unknown): PairingDevice | undefined {\n if (typeof value !== \"object\" || value === null) return undefined;\n const device = value as Record<string, unknown>;\n if (!isText(device.deviceId) || !isText(device.name) || !isText(device.platform)) {\n return undefined;\n }\n if (!isPoint(device.signingKey)) return undefined;\n return {\n deviceId: device.deviceId,\n name: device.name,\n platform: device.platform,\n signingKey: {\n kty: \"EC\",\n crv: \"P-256\",\n x: device.signingKey.x,\n y: device.signingKey.y,\n },\n presenceKey: presenceKeyOf(device.presenceKey),\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"pairing.js","sourceRoot":"","sources":["../src/pairing.ts"],"names":[],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CAAC;QACjF,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC;QAAE,OAAO,SAAS,CAAC;IAClD,OAAO;QACL,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,UAAU,EAAE;YACV,GAAG,EAAE,IAAI;YACT,GAAG,EAAE,OAAO;YACZ,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;YACtB,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;SACvB;QACD,WAAW,EAAE,aAAa,CAAC,MAAM,CAAC,WAAW,CAAC;KAC/C,CAAC;AACJ,CAAC","sourcesContent":["import { createHash, randomBytes, randomInt } from \"node:crypto\";\nimport { createServer, type Server, type ServerResponse } from \"node:http\";\nimport type { AddressInfo } from \"node:net\";\n\nimport {\n type AccountSummary,\n HOST_PAIRING_FRAGMENT,\n type HostGrantResponse,\n} from \"@parlor/auth\";\nimport type { HostPairing, PairingDevice } from \"@parlor/capabilities\";\n\nimport { agentToolsName } from \"./agent-tools.js\";\nimport { hostAssertion } from \"./assertion.js\";\nimport type { AppGrant, HostKeyPair, HostKeys } from \"./grants.js\";\nimport { workspaceOf } from \"./naming.js\";\nimport { printable } from \"./prompter.js\";\nimport { revokeGrant } from \"./revoke.js\";\n\nexport const PAIRING_TIMEOUT_MS = 10 * 60_000;\n\nexport interface PairingReview {\n readonly appName: string;\n readonly appOrigin: string;\n readonly account: AccountSummary;\n readonly matchingCode: string;\n}\n\n/**\n * `browser`: a one-shot 127.0.0.1 listener (RFC 8252) accepting exactly this attempt's\n * `state`; the consent page is the one decision. `ipc`: the desktop shell's signed-in\n * webview gets the code from the backend and hands it over Tauri IPC, with no consent page,\n * so the shell's native dialog confirms the account the host got back.\n */\nexport type PairingChannel =\n | { readonly kind: \"browser\"; open(url: string): Promise<void> }\n | {\n readonly kind: \"ipc\";\n authorize(pairing: HostPairing): Promise<string>;\n confirm(review: PairingReview): Promise<boolean>;\n };\n\nexport interface PairInput {\n readonly appOrigin: string;\n readonly hostName: string;\n readonly platform: string;\n readonly channel: PairingChannel;\n readonly keys: HostKeys;\n readonly workspaceRoot: string;\n /** Offers, on the consent page, to let the coding agents here use the app outside its sidebar. */\n readonly offerAgentTools?: boolean | undefined;\n}\n\nexport type PairOutcome =\n | {\n readonly paired: true;\n readonly grant: AppGrant;\n readonly approvedBy: HostGrantResponse[\"approvedBy\"];\n }\n | {\n readonly paired: false;\n readonly reason: \"declined_locally\" | \"declined_in_app\" | \"timeout\";\n };\n\nexport class UnrevokedGrant extends Error {\n override readonly name = \"UnrevokedGrant\";\n constructor(\n readonly grant: AppGrant,\n cause: Error,\n ) {\n super(cause.message, { cause });\n }\n}\n\nconst MATCHING_ALPHABET = \"ABCDEFGHJKLMNPQRSTUVWXYZ23456789\";\n\nconst base64url = (bytes: Buffer) => bytes.toString(\"base64url\");\n\nfunction matchingCode(): string {\n const part = () =>\n Array.from(\n { length: 3 },\n () => MATCHING_ALPHABET[randomInt(MATCHING_ALPHABET.length)],\n ).join(\"\");\n return `${part()}-${part()}`;\n}\n\nasync function appNameOf(origin: string): Promise<string> {\n const response = await fetch(`${origin}/_parlor/manifest`);\n if (!response.ok) {\n throw new Error(`${origin} answered HTTP ${response.status}; is it a Parlor app?`);\n }\n const manifest = (await response.json()) as {\n readonly app?: { readonly name?: unknown };\n };\n return typeof manifest.app?.name === \"string\"\n ? manifest.app.name\n : new URL(origin).host;\n}\n\ntype Callback =\n | { readonly code: string; readonly agentTools?: boolean | undefined }\n | { readonly declined: true };\n\nconst escapeHtml = (text: string) =>\n printable(text).replace(/[&<>\"']/g, (char) => `&#${char.charCodeAt(0)};`);\n\nconst RESULT_STYLE = `:root{color-scheme:light dark;--bg:#f6f6f4;--card:#fff;--text:#1d1d1b;--muted:#5f5f5a;--line:#e2e2dc}@media (prefers-color-scheme:dark){:root{--bg:#151514;--card:#1f1f1d;--text:#ededea;--muted:#a3a39d;--line:#34342f}}*{box-sizing:border-box}body{margin:0;min-height:100vh;display:grid;place-items:center;padding:16px;background:var(--bg);color:var(--text);font:15px/1.5 system-ui,-apple-system,\"Segoe UI\",sans-serif}main{width:100%;max-width:420px;background:var(--card);border:1px solid var(--line);border-radius:12px;padding:28px}h1{font-size:20px;line-height:1.3;margin:0 0 8px}p{margin:0;color:var(--muted)}`;\n\nfunction resultPage(heading: string, detail: string): string {\n return `<!doctype html><html lang=\"en\"><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><title>${escapeHtml(heading)}</title><style>${RESULT_STYLE}</style></head><body><main><h1>${escapeHtml(heading)}</h1><p>${escapeHtml(detail)}</p></main></body></html>`;\n}\n\n/** Holds the browser's request until the exchange settles, so the tab says what happened. */\nasync function loopback(state: string): Promise<{\n readonly redirectUri: string;\n readonly callback: Promise<Callback>;\n readonly answer: (heading: string, detail: string) => void;\n readonly redirect: (url: string) => void;\n readonly close: () => void;\n}> {\n let deliver: (callback: Callback) => void = () => undefined;\n const callback = new Promise<Callback>((resolve) => (deliver = resolve));\n let waiting: ServerResponse | undefined;\n const server: Server = createServer((request, response) => {\n const url = new URL(request.url ?? \"/\", \"http://127.0.0.1\");\n if (\n waiting ||\n url.pathname !== \"/callback\" ||\n url.searchParams.get(\"state\") !== state\n ) {\n response\n .writeHead(404, { \"content-type\": \"text/plain\" })\n .end(\"Not this connection.\");\n return;\n }\n waiting = response;\n const code = url.searchParams.get(\"code\");\n const agentTools = url.searchParams.get(\"agentTools\");\n deliver(\n code\n ? { code, ...(agentTools === null ? {} : { agentTools: agentTools === \"on\" }) }\n : { declined: true },\n );\n });\n await new Promise<void>((resolve) => server.listen(0, \"127.0.0.1\", resolve));\n const { port } = server.address() as AddressInfo;\n const answer = (heading: string, detail: string) => {\n if (!waiting || waiting.headersSent) return;\n waiting\n .writeHead(200, { \"content-type\": \"text/html; charset=utf-8\" })\n .end(resultPage(heading, detail));\n };\n return {\n redirectUri: `http://127.0.0.1:${port}/callback`,\n callback,\n answer,\n redirect: (url) => {\n if (!waiting || waiting.headersSent) return;\n waiting.writeHead(303, { location: url, \"cache-control\": \"no-store\" }).end();\n },\n close: () => {\n answer(\"Parlor Host stopped\", \"Go back to your terminal.\");\n server.close();\n },\n };\n}\n\nasync function exchange(\n origin: string,\n key: HostKeyPair,\n code: string,\n codeVerifier: string,\n): Promise<HostGrantResponse> {\n const response = await fetch(`${origin}/_parlor/auth/hosts/token`, {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify({\n code,\n codeVerifier,\n publicKey: key.publicKey,\n proof: await key.sign(new TextEncoder().encode(code)),\n }),\n });\n const body = (await response.json().catch(() => undefined)) as\n | (HostGrantResponse & { readonly error?: { readonly message?: string } })\n | undefined;\n if (!response.ok || !body?.grant) {\n throw new Error(body?.error?.message ?? `The app answered HTTP ${response.status}.`);\n }\n return body;\n}\n\nfunction timeout(ms: number): {\n readonly expired: Promise<\"timeout\">;\n readonly clear: () => void;\n} {\n let timer: NodeJS.Timeout | undefined;\n const expired = new Promise<\"timeout\">((resolve) => {\n timer = setTimeout(() => resolve(\"timeout\"), ms);\n });\n return { expired, clear: () => clearTimeout(timer) };\n}\n\n/** The pairing secret goes nowhere but the app's own origin; an older app has no landing page. */\nfunction landingOf(origin: string, landing: string | undefined): URL {\n const url = landing === undefined ? undefined : URL.parse(landing, origin);\n return url?.origin === origin ? url : new URL(\"/\", origin);\n}\n\n/**\n * Only the host starts a pairing: it makes the PKCE verifier, `state`, the matching code\n * and the key pair, so nothing from the web side can complete one.\n */\nexport async function pair(input: PairInput): Promise<PairOutcome> {\n const origin = new URL(input.appOrigin).origin;\n const appName = await appNameOf(origin);\n const toolsName = input.offerAgentTools ? agentToolsName(appName, origin) : undefined;\n const key = await input.keys.create(origin);\n const codeVerifier = base64url(randomBytes(32));\n const pairing: HostPairing = {\n hostName: input.hostName,\n platform: input.platform,\n codeChallenge: base64url(createHash(\"sha256\").update(codeVerifier).digest()),\n state: base64url(randomBytes(16)),\n matchingCode: matchingCode(),\n keyThumbprint: key.thumbprint,\n };\n const grantOf = (granted: HostGrantResponse): AppGrant => ({\n appOrigin: origin,\n appName,\n grantId: granted.grant.id,\n hostId: granted.grant.hostId,\n account: granted.account,\n workspace: workspaceOf(input.workspaceRoot, origin),\n createdAt: Date.now(),\n });\n const deadline = timeout(PAIRING_TIMEOUT_MS);\n try {\n if (input.channel.kind === \"browser\") {\n const listener = await loopback(pairing.state);\n try {\n const query = new URLSearchParams({\n redirectUri: listener.redirectUri,\n ...pairing,\n ...(toolsName ? { agentTools: \"offered\" } : {}),\n });\n await input.channel.open(`${origin}/_parlor/auth/hosts/authorize?${query}`);\n const callback = await Promise.race([listener.callback, deadline.expired]);\n if (callback === \"timeout\") return { paired: false, reason: \"timeout\" };\n if (!(\"code\" in callback)) {\n listener.answer(\"Not connected\", \"You cancelled the connection.\");\n return { paired: false, reason: \"declined_in_app\" };\n }\n let granted: HostGrantResponse;\n try {\n granted = await exchange(origin, key, callback.code, codeVerifier);\n } catch (error) {\n listener.answer(\"Not connected\", (error as Error).message);\n throw error;\n }\n await key.keep(granted.grant.id);\n const pairingSecret = base64url(randomBytes(32));\n const landing = landingOf(origin, granted.landing);\n const agentTools =\n toolsName && \"agentTools\" in callback ? callback.agentTools : undefined;\n if (agentTools && toolsName) landing.searchParams.set(\"agentTools\", toolsName);\n landing.hash = new URLSearchParams({\n [HOST_PAIRING_FRAGMENT]: pairingSecret,\n }).toString();\n listener.redirect(landing.href);\n return {\n paired: true,\n grant: {\n ...grantOf(granted),\n pairingSecret,\n ...(agentTools === undefined ? {} : { agentTools: { on: agentTools } }),\n },\n approvedBy: granted.approvedBy,\n };\n } finally {\n listener.close();\n }\n }\n\n const callback = await Promise.race([\n input.channel.authorize(pairing).then((code) => ({ code })),\n deadline.expired,\n ]);\n if (callback === \"timeout\") return { paired: false, reason: \"timeout\" };\n const granted = await exchange(origin, key, callback.code, codeVerifier);\n const grant = grantOf(granted);\n const confirmed = await Promise.race([\n input.channel.confirm({\n appName,\n appOrigin: origin,\n account: granted.account,\n matchingCode: pairing.matchingCode,\n }),\n deadline.expired,\n ]);\n if (confirmed !== true) {\n await revokeGrant({\n appOrigin: origin,\n appName,\n assert: (request) =>\n hostAssertion(\n (payload) => key.sign(payload),\n { kid: key.thumbprint, grantId: grant.grantId },\n request,\n ),\n }).catch(async (error: Error) => {\n await key.keep(grant.grantId);\n throw new UnrevokedGrant({ ...grant, declined: true }, error);\n });\n return {\n paired: false,\n reason: confirmed === \"timeout\" ? \"timeout\" : \"declined_locally\",\n };\n }\n await key.keep(grant.grantId);\n return { paired: true, grant, approvedBy: granted.approvedBy };\n } finally {\n deadline.clear();\n }\n}\n\ninterface Deferred<T> {\n readonly promise: Promise<T>;\n readonly resolve: (value: T) => void;\n readonly reject: (error: unknown) => void;\n}\n\nfunction deferred<T>(): Deferred<T> {\n let resolve!: (value: T) => void;\n let reject!: (error: unknown) => void;\n const promise = new Promise<T>((done, fail) => {\n resolve = done;\n reject = fail;\n });\n promise.catch(() => undefined);\n return { promise, resolve, reject };\n}\n\nexport interface LocalPairingReview {\n readonly account: string;\n readonly appName: string;\n readonly matchingCode: string;\n}\n\n/**\n * A pairing driven over the control socket by the desktop shell: `pairing` once the host\n * made its key and code, `finish` with the code the signed-in page got from the backend,\n * `confirm` with the user's answer in the native dialog.\n */\nexport interface LocalPairing {\n readonly pairing: Promise<HostPairing>;\n finish(code: string): Promise<LocalPairingReview>;\n confirm(connect: boolean): Promise<PairOutcome>;\n}\n\nexport function startLocalPairing(input: Omit<PairInput, \"channel\">): LocalPairing {\n const ready = deferred<HostPairing>();\n const code = deferred<string>();\n const review = deferred<LocalPairingReview>();\n const decision = deferred<boolean>();\n const outcome = pair({\n ...input,\n channel: {\n kind: \"ipc\",\n authorize: (pairing) => {\n ready.resolve(pairing);\n return code.promise;\n },\n confirm: (shown) => {\n review.resolve({\n account: printable(shown.account.email ?? shown.account.name),\n appName: printable(shown.appName),\n matchingCode: shown.matchingCode,\n });\n return decision.promise;\n },\n },\n });\n outcome.then(\n (result) => {\n if (result.paired) return;\n const stopped = new Error(`The pairing ended: ${result.reason}.`);\n ready.reject(stopped);\n review.reject(stopped);\n },\n (error: unknown) => {\n ready.reject(error);\n review.reject(error);\n },\n );\n outcome.catch(() => undefined);\n return {\n pairing: ready.promise,\n finish: (value) => {\n code.resolve(value);\n return review.promise;\n },\n confirm: (connect) => {\n decision.resolve(connect);\n return outcome;\n },\n };\n}\n\nconst isText = (value: unknown): value is string =>\n typeof value === \"string\" && value !== \"\";\n\ntype Point = JsonWebKey & { readonly x: string; readonly y: string };\n\nconst isPoint = (value: unknown): value is Point => {\n if (typeof value !== \"object\" || value === null) return false;\n const key = value as Record<string, unknown>;\n return key.kty === \"EC\" && key.crv === \"P-256\" && isText(key.x) && isText(key.y);\n};\n\nfunction presenceKeyOf(value: unknown): PairingDevice[\"presenceKey\"] {\n if (typeof value !== \"object\" || value === null) return undefined;\n const key = value as Record<string, unknown>;\n if (!isPoint(key.publicKey)) return undefined;\n const publicKey = { kty: \"EC\", crv: \"P-256\", x: key.publicKey.x, y: key.publicKey.y };\n if (key.format === \"webauthn\" && isText(key.credentialId) && isText(key.rpId)) {\n return {\n format: \"webauthn\",\n credentialId: key.credentialId,\n rpId: key.rpId,\n publicKey,\n };\n }\n if (key.format === \"es256-raw\" && isText(key.keyId)) {\n return { format: \"es256-raw\", keyId: key.keyId, publicKey };\n }\n return undefined;\n}\n\nexport function pairingDeviceOf(value: unknown): PairingDevice | undefined {\n if (typeof value !== \"object\" || value === null) return undefined;\n const device = value as Record<string, unknown>;\n if (!isText(device.deviceId) || !isText(device.name) || !isText(device.platform)) {\n return undefined;\n }\n if (!isPoint(device.signingKey)) return undefined;\n return {\n deviceId: device.deviceId,\n name: device.name,\n platform: device.platform,\n signingKey: {\n kty: \"EC\",\n crv: \"P-256\",\n x: device.signingKey.x,\n y: device.signingKey.y,\n },\n presenceKey: presenceKeyOf(device.presenceKey),\n };\n}\n"]}
|
package/dist/paths.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ export interface HostPaths {
|
|
|
5
5
|
readonly policy: string;
|
|
6
6
|
readonly sessions: string;
|
|
7
7
|
readonly agents: string;
|
|
8
|
+
/** What each agent last said about itself: its options and the account's allowance. */
|
|
9
|
+
readonly learned: string;
|
|
8
10
|
readonly control: string;
|
|
9
11
|
readonly proxy: string;
|
|
10
12
|
readonly versions: string;
|
package/dist/paths.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,kGAAkG;IAClG,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAED,wBAAgB,SAAS,CAAC,IAAI,GAAE,MAA2C,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,uFAAuF;IACvF,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,kGAAkG;IAClG,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAED,wBAAgB,SAAS,CAAC,IAAI,GAAE,MAA2C,GAAG,SAAS,CAoBtF"}
|
package/dist/paths.js
CHANGED
|
@@ -10,6 +10,7 @@ export function hostPaths(root = join(homedir(), ".parlor", "host")) {
|
|
|
10
10
|
policy: join(root, "policy.json"),
|
|
11
11
|
sessions: join(root, "sessions.json"),
|
|
12
12
|
agents: join(root, "agents.json"),
|
|
13
|
+
learned: join(root, "learned.json"),
|
|
13
14
|
control: join(run, "control.sock"),
|
|
14
15
|
proxy: join(run, "proxy.sock"),
|
|
15
16
|
versions: join(root, "versions"),
|
package/dist/paths.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,M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c,EAAE,uBAAuB,CAAC;QAC3E,UAAU,EAAE,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC;KACjC,CAAC;AACJ,CAAC","sourcesContent":["import { homedir } from \"node:os\";\nimport { dirname, join } from \"node:path\";\n\nexport interface HostPaths {\n readonly root: string;\n readonly grants: string;\n readonly trust: string;\n readonly policy: string;\n readonly sessions: string;\n readonly agents: string;\n /** What each agent last said about itself: its options and the account's allowance. */\n readonly learned: string;\n readonly control: string;\n readonly proxy: string;\n readonly versions: string;\n /** What the login item points at; a link into `versions/<version>/`, never into an app bundle. */\n readonly current: string;\n readonly lock: string;\n readonly logs: string;\n readonly launchAgent: string;\n readonly workspaces: string;\n}\n\nexport function hostPaths(root: string = join(homedir(), \".parlor\", \"host\")): HostPaths {\n const run = join(root, \"run\");\n const home = dirname(dirname(root));\n return {\n root,\n grants: join(root, \"grants.json\"),\n trust: join(root, \"trust.json\"),\n policy: join(root, \"policy.json\"),\n sessions: join(root, \"sessions.json\"),\n agents: join(root, \"agents.json\"),\n learned: join(root, \"learned.json\"),\n control: join(run, \"control.sock\"),\n proxy: join(run, \"proxy.sock\"),\n versions: join(root, \"versions\"),\n current: join(root, \"current\"),\n lock: join(root, \"service.lock\"),\n logs: join(root, \"logs\"),\n launchAgent: join(home, \"Library\", \"LaunchAgents\", \"dev.parlor.host.plist\"),\n workspaces: join(home, \"Parlor\"),\n };\n}\n"]}
|
package/dist/policy.d.ts
CHANGED
|
@@ -19,6 +19,11 @@ export interface RemotePolicy {
|
|
|
19
19
|
readonly promptPresence?: {
|
|
20
20
|
readonly maxAgeHours: number;
|
|
21
21
|
} | "off" | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* `auto`: the agent's own safety review decides, asking only for what it flags, where the
|
|
24
|
+
* agent has one. `ask`: it asks before every action. Absent: `auto`.
|
|
25
|
+
*/
|
|
26
|
+
readonly agentMode?: "auto" | "ask" | undefined;
|
|
22
27
|
}
|
|
23
28
|
export declare const DEFAULT_POLICY: RemotePolicy;
|
|
24
29
|
export declare const DEV_POLICY: RemotePolicy;
|
|
@@ -29,8 +34,13 @@ export declare function presenceDueAt(policy: RemotePolicy, device: TrustedDevic
|
|
|
29
34
|
* app's `confirm: true`, and asking twice only teaches users to click through.
|
|
30
35
|
*/
|
|
31
36
|
export declare function isAppTool(ask: AgentAsk, appServer: string): boolean;
|
|
32
|
-
/**
|
|
33
|
-
|
|
37
|
+
/**
|
|
38
|
+
* The ask item's `approval`; `undefined` lets any trusted device answer without presence.
|
|
39
|
+
* Where presence is wanted, the browser that approved `connect` here answers its own turn's
|
|
40
|
+
* asks in the chat, since the loopback redirect put it on this computer; any other device
|
|
41
|
+
* without presence leaves them to this computer.
|
|
42
|
+
*/
|
|
43
|
+
export declare function approvalFor(policy: RemotePolicy, ask: AgentAsk, device?: Pick<TrustedDevice, "presenceKey" | "via">): "presence" | "computer" | "device" | undefined;
|
|
34
44
|
/** `base` with the settings `parlor-host config` wrote to `file`; read afresh on every call. */
|
|
35
45
|
export declare function loadPolicy(file: string, base: RemotePolicy): Promise<RemotePolicy>;
|
|
36
46
|
export declare function changePolicy(file: string, base: RemotePolicy, change: Partial<RemotePolicy>): Promise<RemotePolicy>;
|
package/dist/policy.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../src/policy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,8FAA8F;IAC9F,QAAQ,CAAC,cAAc,EAAE,OAAO,GAAG,KAAK,CAAC;IACzC;;;OAGG;IACH,QAAQ,CAAC,OAAO,EAAE,UAAU,GAAG,UAAU,GAAG,KAAK,CAAC;IAClD;;;OAGG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE;QAAE,QAAQ,CAAC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MAAM,EACZ,IAAI,EAAE,YAAY,GACjB,OAAO,CAAC,YAAY,CAAC,CAiBvB;AAaD,wBAAsB,YAAY,CAChC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,YAAY,EAClB,MAAM,EAAE,OAAO,CAAC,YAAY,CAAC,GAC5B,OAAO,CAAC,YAAY,CAAC,CAGvB"}
|
package/dist/policy.js
CHANGED
|
@@ -3,11 +3,13 @@ export const DEFAULT_POLICY = {
|
|
|
3
3
|
deviceApproval: "local",
|
|
4
4
|
answers: "presence",
|
|
5
5
|
promptPresence: { maxAgeHours: 18 },
|
|
6
|
+
agentMode: "auto",
|
|
6
7
|
};
|
|
7
8
|
export const DEV_POLICY = {
|
|
8
9
|
deviceApproval: "off",
|
|
9
10
|
answers: "off",
|
|
10
11
|
promptPresence: "off",
|
|
12
|
+
agentMode: "auto",
|
|
11
13
|
};
|
|
12
14
|
/** When `device`'s prompts need Face ID or Touch ID again; undefined when they never do. */
|
|
13
15
|
export function presenceDueAt(policy, device) {
|
|
@@ -23,11 +25,18 @@ export function presenceDueAt(policy, device) {
|
|
|
23
25
|
export function isAppTool(ask, appServer) {
|
|
24
26
|
return ask.kind === "permission" && ask.mcp?.server === appServer;
|
|
25
27
|
}
|
|
26
|
-
/**
|
|
27
|
-
|
|
28
|
+
/**
|
|
29
|
+
* The ask item's `approval`; `undefined` lets any trusted device answer without presence.
|
|
30
|
+
* Where presence is wanted, the browser that approved `connect` here answers its own turn's
|
|
31
|
+
* asks in the chat, since the loopback redirect put it on this computer; any other device
|
|
32
|
+
* without presence leaves them to this computer.
|
|
33
|
+
*/
|
|
34
|
+
export function approvalFor(policy, ask, device) {
|
|
28
35
|
if (ask.kind === "question" || policy.answers === "off")
|
|
29
36
|
return undefined;
|
|
30
|
-
|
|
37
|
+
if (policy.answers === "computer" || !device || device.presenceKey)
|
|
38
|
+
return policy.answers;
|
|
39
|
+
return device.via === "pairing" ? "device" : "computer";
|
|
31
40
|
}
|
|
32
41
|
const choose = (allowed, value, base) => allowed.find((candidate) => candidate === value) ?? base;
|
|
33
42
|
/** `base` with the settings `parlor-host config` wrote to `file`; read afresh on every call. */
|
|
@@ -43,6 +52,7 @@ export async function loadPolicy(file, base) {
|
|
|
43
52
|
deviceApproval: choose(["local", "off"], overlay.deviceApproval, base.deviceApproval),
|
|
44
53
|
answers: choose(["presence", "computer", "off"], overlay.answers, base.answers),
|
|
45
54
|
promptPresence: promptPresenceOf(overlay.promptPresence, base.promptPresence),
|
|
55
|
+
agentMode: choose(["auto", "ask"], overlay.agentMode, base.agentMode ?? "auto"),
|
|
46
56
|
};
|
|
47
57
|
}
|
|
48
58
|
function promptPresenceOf(value, base) {
|
package/dist/policy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"policy.js","sourceRoot":"","sources":["../src/policy.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"policy.js","sourceRoot":"","sources":["../src/policy.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AA2B1C,MAAM,CAAC,MAAM,cAAc,GAAiB;IAC1C,cAAc,EAAE,OAAO;IACvB,OAAO,EAAE,UAAU;IACnB,cAAc,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE;IACnC,SAAS,EAAE,MAAM;CAClB,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAiB;IACtC,cAAc,EAAE,KAAK;IACrB,OAAO,EAAE,KAAK;IACd,cAAc,EAAE,KAAK;IACrB,SAAS,EAAE,MAAM;CAClB,CAAC;AAEF,4FAA4F;AAC5F,MAAM,UAAU,aAAa,CAC3B,MAAoB,EACpB,MAAqB;IAErB,MAAM,OAAO,GAAG,MAAM,CAAC,cAAc,CAAC;IACtC,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,KAAK,KAAK,IAAI,CAAC,MAAM,CAAC,WAAW;QAAE,OA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CAAC,cAAc,EAAE,IAAI,CAAC,cAAc,CAAC;QACrF,OAAO,EAAE,MAAM,CAAC,CAAC,UAAU,EAAE,UAAU,EAAE,KAAK,CAAC,EAAE,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC;QAC/E,cAAc,EAAE,gBAAgB,CAAC,OAAO,CAAC,cAAc,EAAE,IAAI,CAAC,cAAc,CAAC;QAC7E,SAAS,EAAE,MAAM,CACf,CAAC,MAAM,EAAE,KAAK,CAAU,EACxB,OAAO,CAAC,SAAS,EACjB,IAAI,CAAC,SAAS,IAAI,MAAM,CACzB;KACF,CAAC;AACJ,CAAC;AAED,SAAS,gBAAgB,CACvB,KAAc,EACd,IAAoC;IAEpC,IAAI,KAAK,KAAK,KAAK;QAAE,OAAO,KAAK,CAAC;IAClC,MAAM,KAAK,GAAI,KAAmD,EAAE,WAAW,CAAC;IAChF,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC;QACrE,CAAC,CAAC,EAAE,WAAW,EAAE,KAAK,EAAE;QACxB,CAAC,CAAC,IAAI,CAAC;AACX,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,IAAY,EACZ,IAAkB,EAClB,MAA6B;IAE7B,MAAM,QAAQ,CAAU,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;IAClF,OAAO,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AAChC,CAAC","sourcesContent":["import type { AgentAsk } from \"./acp.js\";\nimport { jsonFile } from \"./json-file.js\";\nimport type { TrustedDevice } from \"./trust.js\";\n\n/**\n * What this computer enforces on remote turns, whatever the app or its backend says. Set\n * only on this computer (`parlor-host config` or the Mac app's settings).\n */\nexport interface RemotePolicy {\n /** `local`: an untrusted device is approved in a dialog here before its first prompt runs. */\n readonly deviceApproval: \"local\" | \"off\";\n /**\n * Where an answer to the agent's own permission prompts counts: on any trusted device\n * with presence, only on this computer, or (`parlor dev` only) anywhere.\n */\n readonly answers: \"presence\" | \"computer\" | \"off\";\n /**\n * How long a linked device with Face ID or Touch ID sends before its next prompt needs them\n * again. Absent: never.\n */\n readonly promptPresence?: { readonly maxAgeHours: number } | \"off\" | undefined;\n /**\n * `auto`: the agent's own safety review decides, asking only for what it flags, where the\n * agent has one. `ask`: it asks before every action. Absent: `auto`.\n */\n readonly agentMode?: \"auto\" | \"ask\" | undefined;\n}\n\nexport const DEFAULT_POLICY: RemotePolicy = {\n deviceApproval: \"local\",\n answers: \"presence\",\n promptPresence: { maxAgeHours: 18 },\n agentMode: \"auto\",\n};\n\nexport const DEV_POLICY: RemotePolicy = {\n deviceApproval: \"off\",\n answers: \"off\",\n promptPresence: \"off\",\n agentMode: \"auto\",\n};\n\n/** When `device`'s prompts need Face ID or Touch ID again; undefined when they never do. */\nexport function presenceDueAt(\n policy: RemotePolicy,\n device: TrustedDevice,\n): number | undefined {\n const setting = policy.promptPresence;\n if (setting === undefined || setting === \"off\" || !device.presenceKey) return undefined;\n return (device.presenceAt ?? device.approvedAt) + setting.maxAgeHours * 3_600_000;\n}\n\n/**\n * The app's own tools are allowed once without asking: the server already enforces the\n * app's `confirm: true`, and asking twice only teaches users to click through.\n */\nexport function isAppTool(ask: AgentAsk, appServer: string): boolean {\n return ask.kind === \"permission\" && ask.mcp?.server === appServer;\n}\n\n/**\n * The ask item's `approval`; `undefined` lets any trusted device answer without presence.\n * Where presence is wanted, the browser that approved `connect` here answers its own turn's\n * asks in the chat, since the loopback redirect put it on this computer; any other device\n * without presence leaves them to this computer.\n */\nexport function approvalFor(\n policy: RemotePolicy,\n ask: AgentAsk,\n device?: Pick<TrustedDevice, \"presenceKey\" | \"via\">,\n): \"presence\" | \"computer\" | \"device\" | undefined {\n if (ask.kind === \"question\" || policy.answers === \"off\") return undefined;\n if (policy.answers === \"computer\" || !device || device.presenceKey)\n return policy.answers;\n return device.via === \"pairing\" ? \"device\" : \"computer\";\n}\n\ntype Overlay = { readonly [K in keyof RemotePolicy]?: unknown };\n\nconst choose = <T extends string>(allowed: readonly T[], value: unknown, base: T): T =>\n allowed.find((candidate) => candidate === value) ?? base;\n\n/** `base` with the settings `parlor-host config` wrote to `file`; read afresh on every call. */\nexport async function loadPolicy(\n file: string,\n base: RemotePolicy,\n): Promise<RemotePolicy> {\n let overlay: Overlay;\n try {\n overlay = await jsonFile<Overlay>(file).read();\n } catch {\n return base;\n }\n return {\n deviceApproval: choose([\"local\", \"off\"], overlay.deviceApproval, base.deviceApproval),\n answers: choose([\"presence\", \"computer\", \"off\"], overlay.answers, base.answers),\n promptPresence: promptPresenceOf(overlay.promptPresence, base.promptPresence),\n agentMode: choose(\n [\"auto\", \"ask\"] as const,\n overlay.agentMode,\n base.agentMode ?? \"auto\",\n ),\n };\n}\n\nfunction promptPresenceOf(\n value: unknown,\n base: RemotePolicy[\"promptPresence\"],\n): RemotePolicy[\"promptPresence\"] {\n if (value === \"off\") return \"off\";\n const hours = (value as { readonly maxAgeHours?: unknown } | null)?.maxAgeHours;\n return typeof hours === \"number\" && Number.isFinite(hours) && hours > 0\n ? { maxAgeHours: hours }\n : base;\n}\n\nexport async function changePolicy(\n file: string,\n base: RemotePolicy,\n change: Partial<RemotePolicy>,\n): Promise<RemotePolicy> {\n await jsonFile<Overlay>(file).change((overlay) => Object.assign(overlay, change));\n return loadPolicy(file, base);\n}\n"]}
|
package/dist/prompter.d.ts
CHANGED
|
@@ -23,6 +23,11 @@ export interface LocalPrompter {
|
|
|
23
23
|
readonly appName: string;
|
|
24
24
|
readonly device: string;
|
|
25
25
|
}): void;
|
|
26
|
+
/** Passive: the app ended this computer's connection, and the agents here lost it too. */
|
|
27
|
+
disconnected?(input: {
|
|
28
|
+
readonly appName: string;
|
|
29
|
+
readonly removedFrom?: string | undefined;
|
|
30
|
+
}): void;
|
|
26
31
|
}
|
|
27
32
|
export declare const printable: (text: string) => string;
|
|
28
33
|
/** A `[y/N]` question on the terminal that ran a command; only yes is yes. */
|
package/dist/prompter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompter.d.ts","sourceRoot":"","sources":["../src/prompter.ts"],"names":[],"mappings":"AAGA,8EAA8E;AAC9E,MAAM,WAAW,aAAa;IAC5B,yDAAyD;IACzD,UAAU,CAAC,KAAK,EAAE;QAChB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;QACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QACvB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;QAC1B,QAAQ,CAAC,OAAO,EAAE,SAAS;YAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;YAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;SAAE,EAAE,CAAC;QAC7E,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;KAC3C,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IAChC,6FAA6F;IAC7F,WAAW,CAAC,KAAK,EAAE;QACjB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;QACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;KAC1B,GAAG,IAAI,CAAC;IACT,uDAAuD;IACvD,YAAY,CAAC,CAAC,KAAK,EAAE;QAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"prompter.d.ts","sourceRoot":"","sources":["../src/prompter.ts"],"names":[],"mappings":"AAGA,8EAA8E;AAC9E,MAAM,WAAW,aAAa;IAC5B,yDAAyD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AAiB,IAAI,aAAa,CAyDjD"}
|
package/dist/prompter.js
CHANGED
|
@@ -30,6 +30,9 @@ export function terminalPrompter() {
|
|
|
30
30
|
const answer = await ask(`${printable(agent)} for ${printable(appName)} asks: ${printable(question)}\n${menu}\nChoice: `);
|
|
31
31
|
return choices[Number(answer?.trim()) - 1]?.id;
|
|
32
32
|
},
|
|
33
|
+
disconnected: ({ appName, removedFrom }) => {
|
|
34
|
+
process.stdout.write(`${printable(appName)} disconnected this computer.${removedFrom ? ` Removed it from ${printable(removedFrom)}.` : ""}\n`);
|
|
35
|
+
},
|
|
33
36
|
deviceLinked: ({ appName, device }) => {
|
|
34
37
|
process.stdout.write(`${printable(device)} was linked to your agents for ${printable(appName)}.\n`);
|
|
35
38
|
},
|
|
@@ -82,6 +85,18 @@ export function macDialogPrompter() {
|
|
|
82
85
|
clipped(`It can use your agents for ${appName}. Not you? Remove it under Devices in the app's Agent sidebar.`),
|
|
83
86
|
]);
|
|
84
87
|
},
|
|
88
|
+
disconnected: ({ appName, removedFrom }) => {
|
|
89
|
+
void osascript([
|
|
90
|
+
"on run argv",
|
|
91
|
+
`display notification (item 2 of argv) with title "${DIALOG_TITLE}" subtitle (item 1 of argv)`,
|
|
92
|
+
"end run",
|
|
93
|
+
], [
|
|
94
|
+
clipped(`${appName} disconnected this computer`),
|
|
95
|
+
clipped(removedFrom
|
|
96
|
+
? `Its sidebar and ${removedFrom} here can no longer use it.`
|
|
97
|
+
: "Its sidebar can no longer use your agents here."),
|
|
98
|
+
]);
|
|
99
|
+
},
|
|
85
100
|
turnStarted: ({ appName, device, agent, preview }) => {
|
|
86
101
|
void osascript([
|
|
87
102
|
"on run argv",
|
package/dist/prompter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompter.js","sourceRoot":"","sources":["../src/prompter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,eAAe,EA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M,EAAE,EAAE,EAAE;YAClE,MAAM,KAAK,GAAG,MAAM,MAAM,CACxB,GAAG,KAAK,QAAQ,OAAO,UAAU,QAAQ,EAAE,EAC3C,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,EACrC,MAAM,CACP,CAAC;YACF,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC,EAAE,EAAE,CAAC;QACvE,CAAC;QACD,YAAY,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE;YACpC,KAAK,SAAS,CACZ;gBACE,aAAa;gBACb,qDAAqD,YAAY,6BAA6B;gBAC9F,SAAS;aACV,EACD;gBACE,OAAO,CAAC,GAAG,MAAM,aAAa,CAAC;gBAC/B,OAAO,CACL,8BAA8B,OAAO,gEAAgE,CACtG;aACF,CACF,CAAC;QACJ,CAAC;QACD,WAAW,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE;YACnD,KAAK,SAAS,CACZ;gBACE,aAAa;gBACb,qDAAqD,YAAY,yDAAyD;gBAC1H,SAAS;aACV,EACD;gBACE,OAAO,CAAC,GAAG,KAAK,mBAAmB,OAAO,EAAE,CAAC;gBAC7C,OAAO,CAAC,MAAM,CAAC;gBACf,OAAO,CAAC,OAAO,CAAC;aACjB,CACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { execFile } from \"node:child_process\";\nimport { createInterface } from \"node:readline\";\n\n/** The computer's own surface, which no app, backend or web page can draw. */\nexport interface LocalPrompter {\n /** The chosen option id, or undefined when dismissed. */\n answerHere(input: {\n readonly appName: string;\n readonly agent: string;\n readonly question: string;\n readonly choices: readonly { readonly id: string; readonly label: string }[];\n readonly signal?: AbortSignal | undefined;\n }): Promise<string | undefined>;\n /** Passive: a turn from another device started here; none for a browser on this computer. */\n turnStarted(input: {\n readonly appName: string;\n readonly device: string;\n readonly agent: string;\n readonly preview: string;\n }): void;\n /** Passive: a device was linked to the agents here. */\n deviceLinked?(input: { readonly appName: string; readonly device: string }): void;\n}\n\nconst UNPRINTABLE = /[\\p{Cc}\\u061c\\u200e\\u200f\\u202a-\\u202e\\u2066-\\u2069]/gu;\n\nexport const printable = (text: string) => text.replace(UNPRINTABLE, \"\");\n\nfunction ask(question: string): Promise<string | undefined> {\n return new Promise((resolve) => {\n const lines = createInterface({ input: process.stdin, output: process.stdout });\n let answered = false;\n lines.question(question, (answer) => {\n answered = true;\n lines.close();\n resolve(answer);\n });\n lines.once(\"close\", () => {\n if (!answered) resolve(undefined);\n });\n });\n}\n\nconst yes = (answer: string | undefined) => /^y(es)?$/i.test(answer?.trim() ?? \"\");\n\n/** A `[y/N]` question on the terminal that ran a command; only yes is yes. */\nexport const askYesNo = async (question: string): Promise<boolean> =>\n yes(await ask(`${printable(question)} [y/N] `));\n\n/** Interactive `connect`: asks on the TTY that ran it. */\nexport function terminalPrompter(): LocalPrompter {\n return {\n answerHere: async ({ appName, agent, question, choices }) => {\n const menu = choices\n .map((choice, at) => ` ${at + 1}. ${printable(choice.label)}`)\n .join(\"\\n\");\n const answer = await ask(\n `${printable(agent)} for ${printable(appName)} asks: ${printable(question)}\\n${menu}\\nChoice: `,\n );\n return choices[Number(answer?.trim()) - 1]?.id;\n },\n deviceLinked: ({ appName, device }) => {\n process.stdout.write(\n `${printable(device)} was linked to your agents for ${printable(appName)}.\\n`,\n );\n },\n turnStarted: ({ appName, device, agent, preview }) => {\n process.stdout.write(\n `${printable(agent)} is working for ${printable(appName)} from ${printable(device)}: ${printable(preview)}\\n`,\n );\n },\n };\n}\n\nconst DIALOG_TITLE = \"Parlor Host\";\nconst MAX_DIALOG_BUTTONS = 3;\nconst MAX_DIALOG_TEXT = 600;\n\nconst clipped = (text: string) =>\n printable(text).length > MAX_DIALOG_TEXT\n ? `${printable(text).slice(0, MAX_DIALOG_TEXT)}...`\n : printable(text);\n\nfunction osascript(\n lines: readonly string[],\n args: readonly string[],\n signal?: AbortSignal,\n): Promise<string | undefined> {\n return new Promise((resolve) => {\n execFile(\n \"osascript\",\n [...lines.flatMap((line) => [\"-e\", line]), \"--\", ...args],\n { signal },\n (error, stdout) => resolve(error ? undefined : stdout.trim()),\n );\n });\n}\n\nfunction choose(\n text: string,\n labels: readonly string[],\n signal?: AbortSignal,\n): Promise<string | undefined> {\n const options = labels.map(clipped);\n return osascript(\n labels.length <= MAX_DIALOG_BUTTONS\n ? [\n \"on run argv\",\n `set reply to display dialog (item 1 of argv) with title \"${DIALOG_TITLE}\" buttons (rest of argv)`,\n \"return button returned of reply\",\n \"end run\",\n ]\n : [\n \"on run argv\",\n `set picked to choose from list (rest of argv) with title \"${DIALOG_TITLE}\" with prompt (item 1 of argv)`,\n \"if picked is false then error number -128\",\n \"return item 1 of picked\",\n \"end run\",\n ],\n [clipped(text), ...options],\n signal,\n );\n}\n\nexport function macDialogPrompter(): LocalPrompter {\n return {\n answerHere: async ({ appName, agent, question, choices, signal }) => {\n const label = await choose(\n `${agent} for ${appName} asks: ${question}`,\n choices.map((choice) => choice.label),\n signal,\n );\n return choices.find((choice) => clipped(choice.label) === label)?.id;\n },\n deviceLinked: ({ appName, device }) => {\n void osascript(\n [\n \"on run argv\",\n `display notification (item 2 of argv) with title \"${DIALOG_TITLE}\" subtitle (item 1 of argv)`,\n \"end run\",\n ],\n [\n clipped(`${device} was linked`),\n clipped(\n `It can use your agents for ${appName}. Not you? Remove it under Devices in the app's Agent sidebar.`,\n ),\n ],\n );\n },\n turnStarted: ({ appName, device, agent, preview }) => {\n void osascript(\n [\n \"on run argv\",\n `display notification (item 3 of argv) with title \"${DIALOG_TITLE}\" subtitle (item 1 of argv & \" from \" & item 2 of argv)`,\n \"end run\",\n ],\n [\n clipped(`${agent} is working for ${appName}`),\n clipped(device),\n clipped(preview),\n ],\n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AAO,CAAC,GAAG,OAAO,6BAA6B,CAAC;gBAChD,OAAO,CACL,WAAW;oBACT,CAAC,CAAC,mBAAmB,WAAW,6BAA6B;oBAC7D,CAAC,CAAC,iDAAiD,CACtD;aACF,CACF,CAAC;QACJ,CAAC;QACD,WAAW,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE;YACnD,KAAK,SAAS,CACZ;gBACE,aAAa;gBACb,qDAAqD,YAAY,yDAAyD;gBAC1H,SAAS;aACV,EACD;gBACE,OAAO,CAAC,GAAG,KAAK,mBAAmB,OAAO,EAAE,CAAC;gBAC7C,OAAO,CAAC,MAAM,CAAC;gBACf,OAAO,CAAC,OAAO,CAAC;aACjB,CACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { execFile } from \"node:child_process\";\nimport { createInterface } from \"node:readline\";\n\n/** The computer's own surface, which no app, backend or web page can draw. */\nexport interface LocalPrompter {\n /** The chosen option id, or undefined when dismissed. */\n answerHere(input: {\n readonly appName: string;\n readonly agent: string;\n readonly question: string;\n readonly choices: readonly { readonly id: string; readonly label: string }[];\n readonly signal?: AbortSignal | undefined;\n }): Promise<string | undefined>;\n /** Passive: a turn from another device started here; none for a browser on this computer. */\n turnStarted(input: {\n readonly appName: string;\n readonly device: string;\n readonly agent: string;\n readonly preview: string;\n }): void;\n /** Passive: a device was linked to the agents here. */\n deviceLinked?(input: { readonly appName: string; readonly device: string }): void;\n /** Passive: the app ended this computer's connection, and the agents here lost it too. */\n disconnected?(input: {\n readonly appName: string;\n readonly removedFrom?: string | undefined;\n }): void;\n}\n\nconst UNPRINTABLE = /[\\p{Cc}\\u061c\\u200e\\u200f\\u202a-\\u202e\\u2066-\\u2069]/gu;\n\nexport const printable = (text: string) => text.replace(UNPRINTABLE, \"\");\n\nfunction ask(question: string): Promise<string | undefined> {\n return new Promise((resolve) => {\n const lines = createInterface({ input: process.stdin, output: process.stdout });\n let answered = false;\n lines.question(question, (answer) => {\n answered = true;\n lines.close();\n resolve(answer);\n });\n lines.once(\"close\", () => {\n if (!answered) resolve(undefined);\n });\n });\n}\n\nconst yes = (answer: string | undefined) => /^y(es)?$/i.test(answer?.trim() ?? \"\");\n\n/** A `[y/N]` question on the terminal that ran a command; only yes is yes. */\nexport const askYesNo = async (question: string): Promise<boolean> =>\n yes(await ask(`${printable(question)} [y/N] `));\n\n/** Interactive `connect`: asks on the TTY that ran it. */\nexport function terminalPrompter(): LocalPrompter {\n return {\n answerHere: async ({ appName, agent, question, choices }) => {\n const menu = choices\n .map((choice, at) => ` ${at + 1}. ${printable(choice.label)}`)\n .join(\"\\n\");\n const answer = await ask(\n `${printable(agent)} for ${printable(appName)} asks: ${printable(question)}\\n${menu}\\nChoice: `,\n );\n return choices[Number(answer?.trim()) - 1]?.id;\n },\n disconnected: ({ appName, removedFrom }) => {\n process.stdout.write(\n `${printable(appName)} disconnected this computer.${removedFrom ? ` Removed it from ${printable(removedFrom)}.` : \"\"}\\n`,\n );\n },\n deviceLinked: ({ appName, device }) => {\n process.stdout.write(\n `${printable(device)} was linked to your agents for ${printable(appName)}.\\n`,\n );\n },\n turnStarted: ({ appName, device, agent, preview }) => {\n process.stdout.write(\n `${printable(agent)} is working for ${printable(appName)} from ${printable(device)}: ${printable(preview)}\\n`,\n );\n },\n };\n}\n\nconst DIALOG_TITLE = \"Parlor Host\";\nconst MAX_DIALOG_BUTTONS = 3;\nconst MAX_DIALOG_TEXT = 600;\n\nconst clipped = (text: string) =>\n printable(text).length > MAX_DIALOG_TEXT\n ? `${printable(text).slice(0, MAX_DIALOG_TEXT)}...`\n : printable(text);\n\nfunction osascript(\n lines: readonly string[],\n args: readonly string[],\n signal?: AbortSignal,\n): Promise<string | undefined> {\n return new Promise((resolve) => {\n execFile(\n \"osascript\",\n [...lines.flatMap((line) => [\"-e\", line]), \"--\", ...args],\n { signal },\n (error, stdout) => resolve(error ? undefined : stdout.trim()),\n );\n });\n}\n\nfunction choose(\n text: string,\n labels: readonly string[],\n signal?: AbortSignal,\n): Promise<string | undefined> {\n const options = labels.map(clipped);\n return osascript(\n labels.length <= MAX_DIALOG_BUTTONS\n ? [\n \"on run argv\",\n `set reply to display dialog (item 1 of argv) with title \"${DIALOG_TITLE}\" buttons (rest of argv)`,\n \"return button returned of reply\",\n \"end run\",\n ]\n : [\n \"on run argv\",\n `set picked to choose from list (rest of argv) with title \"${DIALOG_TITLE}\" with prompt (item 1 of argv)`,\n \"if picked is false then error number -128\",\n \"return item 1 of picked\",\n \"end run\",\n ],\n [clipped(text), ...options],\n signal,\n );\n}\n\nexport function macDialogPrompter(): LocalPrompter {\n return {\n answerHere: async ({ appName, agent, question, choices, signal }) => {\n const label = await choose(\n `${agent} for ${appName} asks: ${question}`,\n choices.map((choice) => choice.label),\n signal,\n );\n return choices.find((choice) => clipped(choice.label) === label)?.id;\n },\n deviceLinked: ({ appName, device }) => {\n void osascript(\n [\n \"on run argv\",\n `display notification (item 2 of argv) with title \"${DIALOG_TITLE}\" subtitle (item 1 of argv)`,\n \"end run\",\n ],\n [\n clipped(`${device} was linked`),\n clipped(\n `It can use your agents for ${appName}. Not you? Remove it under Devices in the app's Agent sidebar.`,\n ),\n ],\n );\n },\n disconnected: ({ appName, removedFrom }) => {\n void osascript(\n [\n \"on run argv\",\n `display notification (item 2 of argv) with title \"${DIALOG_TITLE}\" subtitle (item 1 of argv)`,\n \"end run\",\n ],\n [\n clipped(`${appName} disconnected this computer`),\n clipped(\n removedFrom\n ? `Its sidebar and ${removedFrom} here can no longer use it.`\n : \"Its sidebar can no longer use your agents here.\",\n ),\n ],\n );\n },\n turnStarted: ({ appName, device, agent, preview }) => {\n void osascript(\n [\n \"on run argv\",\n `display notification (item 3 of argv) with title \"${DIALOG_TITLE}\" subtitle (item 1 of argv & \" from \" & item 2 of argv)`,\n \"end run\",\n ],\n [\n clipped(`${agent} is working for ${appName}`),\n clipped(device),\n clipped(preview),\n ],\n );\n },\n };\n}\n"]}
|
package/dist/spec-kit.d.ts
CHANGED
|
@@ -9,7 +9,8 @@ export declare class Browser {
|
|
|
9
9
|
readonly origin: string;
|
|
10
10
|
constructor(origin: string);
|
|
11
11
|
fetch(url: string, init?: RequestInit): Promise<Response>;
|
|
12
|
-
consent
|
|
12
|
+
/** Answers the consent page as a browser would, sending its checked boxes but `uncheck`. */
|
|
13
|
+
consent(url: string, decision: "connect" | "cancel", uncheck?: readonly string[]): Promise<{
|
|
13
14
|
readonly page: string;
|
|
14
15
|
readonly answer: Response;
|
|
15
16
|
}>;
|
|
@@ -65,6 +66,8 @@ export declare const welcome: {
|
|
|
65
66
|
export declare function hostRoutes(options: {
|
|
66
67
|
readonly wake: boolean;
|
|
67
68
|
readonly turn?: () => unknown;
|
|
69
|
+
/** Pushed on the stream's `chat` channel, as a server on host protocol 3 does. */
|
|
70
|
+
readonly push?: () => unknown;
|
|
68
71
|
}): Route;
|
|
69
72
|
export declare const claimedTurn: (turnId: string, agentId: string, context: string, text: string) => {
|
|
70
73
|
id: string;
|
package/dist/spec-kit.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spec-kit.d.ts","sourceRoot":"","sources":["../src/spec-kit.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,eAAe,EAEpB,KAAK,cAAc,EACpB,MAAM,WAAW,CAAC;AAYnB,OAAO,EACL,KAAK,YAAY,EAEjB,KAAK,aAAa,EAClB,KAAK,YAAY,EAClB,MAAM,cAAc,CAAC;AAKtB,OAAO,EAEL,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,eAAe,EACrB,MAAM,gBAAgB,CAAC;AAQxB,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE5D,eAAO,MAAM,QAAQ,iCAAiC,CAAC;AAIvD,qBAAa,OAAO;;IAGN,QA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/** Answers the consent page as a browser would, sending its checked boxes but `uncheck`. */
|
|
44
|
+
async consent(url, decision, uncheck = []) {
|
|
44
45
|
const page = await (await this.fetch(url)).text();
|
|
45
46
|
const fields = new URLSearchParams([...page.matchAll(/<input type="hidden" name="([^"]+)" value="([^"]*)">/g)].map((match) => [match[1], match[2].replaceAll("&", "&")]));
|
|
47
|
+
for (const [, name, value] of page.matchAll(/<input type="checkbox" name="([^"]+)" value="([^"]*)" checked>/g)) {
|
|
48
|
+
if (!uncheck.includes(name))
|
|
49
|
+
fields.set(name, value);
|
|
50
|
+
}
|
|
46
51
|
fields.set("decision", decision);
|
|
47
52
|
const action = /<form method="post" action="([^"]+)"/.exec(page)?.[1] ?? "";
|
|
48
53
|
const answer = await this.fetch(action, {
|
|
@@ -315,7 +320,12 @@ export function hostRoutes(options) {
|
|
|
315
320
|
}
|
|
316
321
|
if (path === "/_parlor/sync/stream") {
|
|
317
322
|
response.writeHead(200, { "content-type": "text/event-stream" });
|
|
318
|
-
|
|
323
|
+
const capabilities = options.push ? ["chat"] : [];
|
|
324
|
+
response.write(`event: handshake\ndata: ${JSON.stringify({ capabilities, keepAliveMs: 10_000 })}\n\n`);
|
|
325
|
+
if (options.push) {
|
|
326
|
+
const frame = { type: "claimed", turn: options.push() };
|
|
327
|
+
response.write(`event: chat\ndata: ${JSON.stringify(frame)}\n\n`);
|
|
328
|
+
}
|
|
319
329
|
if (options.wake) {
|
|
320
330
|
const events = [{ version: 1, id: "e1", tags: [["parlor_chat", "t1"]] }];
|
|
321
331
|
response.write(`event: message\ndata: ${JSON.stringify({ events, cursor: "1.e1" })}\n\n`);
|