@immediately-run/sdk 0.84.1 → 0.85.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/catalog.cjs +2 -0
- package/dist/catalog.cjs.map +1 -1
- package/dist/catalog.js +2 -0
- package/dist/catalog.js.map +1 -1
- package/dist/contribute.cjs.map +1 -1
- package/dist/contribute.d.cts +39 -1
- package/dist/contribute.d.ts +39 -1
- package/dist/contribute.js.map +1 -1
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/openBundle.cjs +44 -0
- package/dist/openBundle.cjs.map +1 -0
- package/dist/openBundle.d.cts +53 -0
- package/dist/openBundle.d.ts +53 -0
- package/dist/openBundle.js +20 -0
- package/dist/openBundle.js.map +1 -0
- package/dist/openRepository.cjs +4 -4
- package/dist/openRepository.cjs.map +1 -1
- package/dist/openRepository.d.cts +12 -2
- package/dist/openRepository.d.ts +12 -2
- package/dist/openRepository.js +4 -4
- package/dist/openRepository.js.map +1 -1
- package/dist/protocolRefusal.cjs.map +1 -1
- package/dist/protocolRefusal.d.cts +1 -1
- package/dist/protocolRefusal.d.ts +1 -1
- package/dist/protocolRefusal.js.map +1 -1
- package/dist/protocolSchemes.cjs +1 -0
- package/dist/protocolSchemes.cjs.map +1 -1
- package/dist/protocolSchemes.d.cts +1 -0
- package/dist/protocolSchemes.d.ts +1 -0
- package/dist/protocolSchemes.js +2 -0
- package/dist/protocolSchemes.js.map +1 -1
- package/dist/vcs.cjs +106 -1
- package/dist/vcs.cjs.map +1 -1
- package/dist/vcs.d.cts +104 -1
- package/dist/vcs.d.ts +104 -1
- package/dist/vcs.js +99 -1
- package/dist/vcs.js.map +1 -1
- package/dist/version.cjs +1 -1
- package/dist/version.cjs.map +1 -1
- package/dist/version.d.cts +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import "./chunk-VHAA22YE.js";
|
|
2
|
+
import { protocolRequest } from "./sandboxUtils.js";
|
|
3
|
+
import { throwOnRefusal } from "./protocolRefusal.js";
|
|
4
|
+
import { PROTOCOL_OPENBUNDLE } from "./generated/protocol.js";
|
|
5
|
+
import { SCHEMES } from "./protocolSchemes.js";
|
|
6
|
+
const OPEN_BUNDLE_REPLY_TIMEOUT_MS = 2e3;
|
|
7
|
+
async function openBundle(target) {
|
|
8
|
+
const { $cap, mountId, relPath, mode } = target?.dir ?? {};
|
|
9
|
+
const params = { dir: { $cap, mountId, relPath, mode } };
|
|
10
|
+
if (target?.view !== void 0) params.view = target.view;
|
|
11
|
+
const res = await protocolRequest(SCHEMES[PROTOCOL_OPENBUNDLE], "open", [params], {
|
|
12
|
+
timeoutMs: OPEN_BUNDLE_REPLY_TIMEOUT_MS
|
|
13
|
+
});
|
|
14
|
+
throwOnRefusal(res, "bundle open refused");
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
OPEN_BUNDLE_REPLY_TIMEOUT_MS,
|
|
18
|
+
openBundle
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=openBundle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/openBundle.ts"],"sourcesContent":["// Host-mediated \"open this bundle in its own tab\" (BUNDLE_EMBEDDING_SPEC §4b.9).\n//\n// Opening a bundle is not a for-result task: the reader stays, the view wants the whole\n// screen, and the bundle's files are what they work on next. So a file manager's\n// \"Open as …\" asks the host for a new tab — an ordinary session of the opener over the\n// bundle — instead of the task overlay. The tab starts in present mode, except for a local\n// dev-server source, whose tab is its editing session.\n//\n// The app names the DIRECTORY it already holds, as the same capability it would hand a\n// task, and optionally a declared view by NAME. It cannot pass a URL, a route or an app:\n// the host maps the capability to a location it can address, builds the destination from\n// its own route grammar, and the opened tab re-reads the bundle's marker and resolves the\n// opener itself. The link grants nothing.\n//\n// Not every directory has an address. A folder in a space, or on a session mount, cannot\n// be named by a URL today; the host refuses those with `unaddressable`, and the caller\n// keeps its overlay open (`invokeTask`) as the fallback.\n//\n// A host that predates this call does not refuse it — it does not answer at all, because\n// it has never heard of the request. A host that knows the request answers on the turn it\n// arrives, so the wait is bounded tightly here and its expiry (`timeout`) is the third\n// reason to fall back.\n//\n// As with `openRepository`, the open needs the HOST document's live transient user\n// activation, which the host samples rather than believes.\nimport { protocolRequest } from './sandboxUtils';\nimport { throwOnRefusal } from './protocolRefusal';\nimport { PROTOCOL_OPENBUNDLE } from './generated/protocol';\nimport { SCHEMES } from './protocolSchemes';\nimport type { DirCap } from './tasks';\n\n/** What to open: a bundle directory the app holds, and optionally one of its declared views. */\nexport interface OpenBundleTarget {\n /** The bundle's directory, as the capability the app holds on it (`capDir(...)`). */\n dir: DirCap;\n /** A view the bundle's marker declares, by name. The host resolves which app shows it. */\n view?: string;\n}\n\n/** Why a bundle did not open in a tab.\n *\n * - `invalid-params` — `dir` is not a directory capability, or `view` is not a string.\n * - `invalid` — `view` is not a view name.\n * - `unaddressable` — the directory is real and the app holds it, but the host has no URL\n * for it (a space folder, a session mount). Fall back to the overlay open.\n * - `no-activation` — no live user gesture on the host document. Call this from a click\n * handler, with no `await` before it.\n * - `forbidden` — the app may not open tabs, or does not hold the directory it named.\n * - `unsupported` — this host knows the request but has no bundle-open surface wired.\n * Fall back to the overlay open.\n * - `timeout` — the host did not answer within {@link OPEN_BUNDLE_REPLY_TIMEOUT_MS}. That\n * is what a host that predates this call does. Fall back to the overlay open.\n * - `unknown` — the host refused without naming a code.\n *\n * The SDK throws a plain `Error` with `.code` assigned; `.code` is whatever string the\n * host sent, so treat an unlisted code as possible. */\nexport type OpenBundleErrorCode =\n | 'invalid-params'\n | 'invalid'\n | 'unaddressable'\n | 'no-activation'\n | 'forbidden'\n | 'unsupported'\n | 'timeout'\n | 'unknown';\n\n/**\n * How long `openBundle` waits for the host's answer, in ms. A host that knows the request\n * decides it synchronously — nothing is fetched and nobody is asked — so the answer is one\n * message round trip away. A host that does not know it never answers, and a click that\n * does nothing for the default thirty seconds before falling back would read as broken.\n */\nexport const OPEN_BUNDLE_REPLY_TIMEOUT_MS = 2000;\n\nexport interface OpenBundleError extends Error {\n code: OpenBundleErrorCode;\n}\n\n/** The wire params: the capability and the view name, and nothing else. */\ninterface OpenBundleParams {\n dir: DirCap;\n view?: string;\n}\n\n/** The host's reply: a refusal is a resolved `{ ok: false }`, not a transport rejection. */\ntype OpenBundleReply = { ok: true } | { ok: false; code?: string; message?: string };\n\n/**\n * Ask the host to open a bundle in a new browser tab.\n *\n * Resolves once the host has performed the open; it does not wait for — and cannot observe —\n * the opened tab loading. Rejects with an {@link OpenBundleError} carrying `code` otherwise.\n * On `unaddressable`, `unsupported` or `timeout`, open the bundle the way you did before\n * this call existed: the `invokeTask` you used (`open-declared` for an app-form marker or a\n * declared view, the marker's own contract for a task-form one).\n *\n * Call it directly from a user gesture: the host samples its own transient activation when\n * the request arrives, so anything that defers the call past the gesture is refused\n * `no-activation`.\n */\nexport async function openBundle(target: OpenBundleTarget): Promise<void> {\n // Whatever was passed as `dir` is narrowed to the capability's four fields and sent: a\n // value that is not a capability is the host's to refuse (`invalid-params`), with a code.\n const { $cap, mountId, relPath, mode } = (target?.dir ?? {}) as DirCap;\n const params: OpenBundleParams = { dir: { $cap, mountId, relPath, mode } };\n if (target?.view !== undefined) params.view = target.view;\n const res = (await protocolRequest(SCHEMES[PROTOCOL_OPENBUNDLE], 'open', [params], {\n timeoutMs: OPEN_BUNDLE_REPLY_TIMEOUT_MS,\n })) as OpenBundleReply;\n throwOnRefusal(res, 'bundle open refused');\n}\n"],"mappings":";AAyBA,SAAS,uBAAuB;AAChC,SAAS,sBAAsB;AAC/B,SAAS,2BAA2B;AACpC,SAAS,eAAe;AA4CjB,MAAM,+BAA+B;AA4B5C,eAAsB,WAAW,QAAyC;AAGxE,QAAM,EAAE,MAAM,SAAS,SAAS,KAAK,IAAK,QAAQ,OAAO,CAAC;AAC1D,QAAM,SAA2B,EAAE,KAAK,EAAE,MAAM,SAAS,SAAS,KAAK,EAAE;AACzE,MAAI,QAAQ,SAAS,OAAW,QAAO,OAAO,OAAO;AACrD,QAAM,MAAO,MAAM,gBAAgB,QAAQ,mBAAmB,GAAG,QAAQ,CAAC,MAAM,GAAG;AAAA,IACjF,WAAW;AAAA,EACb,CAAC;AACD,iBAAe,KAAK,qBAAqB;AAC3C;","names":[]}
|
package/dist/openRepository.cjs
CHANGED
|
@@ -25,11 +25,11 @@ var import_sandboxUtils = require("./sandboxUtils");
|
|
|
25
25
|
var import_protocolRefusal = require("./protocolRefusal");
|
|
26
26
|
var import_protocol = require("./generated/protocol");
|
|
27
27
|
var import_protocolSchemes = require("./protocolSchemes");
|
|
28
|
-
async function openRepository(coordinates) {
|
|
28
|
+
async function openRepository(coordinates, reveal) {
|
|
29
29
|
const { provider, namespace, repository } = coordinates;
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
]);
|
|
30
|
+
const params = { provider, namespace, repository };
|
|
31
|
+
if (reveal !== void 0) params.reveal = reveal;
|
|
32
|
+
const res = await (0, import_sandboxUtils.protocolRequest)(import_protocolSchemes.SCHEMES[import_protocol.PROTOCOL_OPENREPO], "open", [params]);
|
|
33
33
|
(0, import_protocolRefusal.throwOnRefusal)(res, "repository open refused");
|
|
34
34
|
}
|
|
35
35
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/openRepository.ts"],"sourcesContent":["// Host-mediated \"open this repository in a new tab\" (R3-476).\n//\n// An app frame cannot open a first-party tab itself. A `window.open` from inside the\n// sandboxed frame inherits the sandbox — the opened tab runs at the same opaque origin and\n// cannot load the host — and `target=\"_top\"` would replace the app's own frame rather than\n// open a tab. So the app asks the host, and the host performs the open from its own context.\n//\n// The app names COORDINATES and nothing else. It cannot pass a URL, a route prefix or a\n// path: the host builds the destination from its own route grammar, so this call can only\n// ever reach one of the platform's own repository routes. That is the point of the shape —\n// an app that could spell the destination could open anything.\n//\n// Two more conditions hold on the host side, and neither is something this call can assert\n// for itself: the open needs the HOST document's live transient user activation (a real\n// click, which the host samples rather than believes), and one gesture opens exactly one\n// tab. Both surface here as ordinary coded refusals.\nimport { protocolRequest } from './sandboxUtils';\nimport { throwOnRefusal } from './protocolRefusal';\nimport { PROTOCOL_OPENREPO } from './generated/protocol';\nimport { SCHEMES } from './protocolSchemes';\n\n/** Where a repository lives. The same three fields a `RecentProject` carries — this is a\n * location the user may already have navigated to under their own authority. */\nexport interface RepositoryCoordinates {\n provider: string;\n namespace: string;\n repository: string;\n}\n\n/** Why the host refused to open a tab.\n *\n * - `invalid` — the coordinates are not three clean path segments.\n * - `no-activation` — no live user gesture on the host document. Call this from a click\n * handler; a timer or a boot path will always get this. A SECOND call inside one gesture\n * also lands here: `window.open` consumes the host's transient activation, so one click\n * buys exactly one tab and the next needs a real second click.\n * - `forbidden` — the app does not hold the baseline `route:read` capability.\n * - `unsupported` — this host has no repository-open surface wired.\n * - `unknown` — the host refused without naming a code.\n *\n * **What you actually catch.** The SDK throws a plain `Error` with `.code` assigned — a\n * `CodedRefusalError` from `protocolRefusal.ts` — never a distinct class. These are the\n * `.code` VALUES the host sends. Nothing enforces the union at runtime — `.code` is\n * whatever string arrived — so treat an unlisted code as possible and `instanceof Error`\n * as the only reliable test.\n *\n * (This note is on the code alias rather than on the interface because the alias is where\n * the codes are documented. Every doclink in this file names the INTERFACE, so a reader\n * following one lands a hop away from this — a wart, not a plan. Stated without a\n * direction on purpose: two earlier revisions of this sentence asserted a positional\n * claim, and both were wrong.) */\nexport type OpenRepositoryErrorCode = 'invalid' | 'no-activation' | 'forbidden' | 'unsupported' | 'unknown';\n\nexport interface OpenRepositoryError extends Error {\n code: OpenRepositoryErrorCode;\n}\n\n/** The host's reply: the envelope resolves INSIDE the promise, so a refusal is a resolved\n * `{ ok: false }` rather than a rejection at the transport layer. */\ntype OpenRepositoryReply = { ok: true; url?: string } | { ok: false; code?: string; message?: string };\n\n/**\n * Ask the host to open a repository in a new browser tab.\n *\n * Resolves once the host has performed the open; it does not wait for — and cannot observe —\n * the opened tab loading. Rejects with a typed {@link OpenRepositoryError} carrying `code`\n * when the host refuses.\n *\n * Call it directly from a user gesture. The host samples its own transient activation when\n * the request arrives, so anything that defers the call past the gesture (an `await` before\n * it, a `setTimeout`, a retry) will be refused `no-activation`. None of the refusals are\n * worth retrying: each names a condition a retry cannot change.\n */\nexport async function openRepository(coordinates: RepositoryCoordinates): Promise<void> {\n const { provider, namespace, repository } = coordinates;\n
|
|
1
|
+
{"version":3,"sources":["../src/openRepository.ts"],"sourcesContent":["// Host-mediated \"open this repository in a new tab\" (R3-476).\n//\n// An app frame cannot open a first-party tab itself. A `window.open` from inside the\n// sandboxed frame inherits the sandbox — the opened tab runs at the same opaque origin and\n// cannot load the host — and `target=\"_top\"` would replace the app's own frame rather than\n// open a tab. So the app asks the host, and the host performs the open from its own context.\n//\n// The app names COORDINATES and nothing else. It cannot pass a URL, a route prefix or a\n// path: the host builds the destination from its own route grammar, so this call can only\n// ever reach one of the platform's own repository routes. That is the point of the shape —\n// an app that could spell the destination could open anything.\n//\n// R3-1033: an optional REVEAL rides the open — a closed chrome enum, never a destination.\n// The app still cannot pass a URL, a route prefix or a path; the host decides what the\n// reveal means (which surface of ITS chrome opens) and builds every URL itself. A future\n// panel joins the `RepositoryReveal` union deliberately, never by a free string.\n//\n// Two more conditions hold on the host side, and neither is something this call can assert\n// for itself: the open needs the HOST document's live transient user activation (a real\n// click, which the host samples rather than believes), and one gesture opens exactly one\n// tab. Both surface here as ordinary coded refusals.\nimport { protocolRequest } from './sandboxUtils';\nimport { throwOnRefusal } from './protocolRefusal';\nimport { PROTOCOL_OPENREPO } from './generated/protocol';\nimport { SCHEMES } from './protocolSchemes';\n\n/** Where a repository lives. The same three fields a `RecentProject` carries — this is a\n * location the user may already have navigated to under their own authority. */\nexport interface RepositoryCoordinates {\n provider: string;\n namespace: string;\n repository: string;\n}\n\n/** A chrome reveal that may ride an open (R3-1033) — the host's own surface to open at the\n * destination, never a destination the app names. `'agent'` is the conversations panel;\n * the value set is closed on purpose (see the header). */\nexport interface RepositoryReveal {\n panel: 'agent';\n}\n\n/** The `open` wire params — the coordinates plus the optional reveal. Typed as a named\n * interface (not an inline literal) so the protocol-snapshot extractor resolves the wire\n * shape from the type; see `openRepository` below. */\ninterface OpenRepositoryOpenParams extends RepositoryCoordinates {\n reveal?: RepositoryReveal;\n}\n\n/** Why the host refused to open a tab.\n *\n * - `invalid` — the coordinates are not three clean path segments.\n * - `no-activation` — no live user gesture on the host document. Call this from a click\n * handler; a timer or a boot path will always get this. A SECOND call inside one gesture\n * also lands here: `window.open` consumes the host's transient activation, so one click\n * buys exactly one tab and the next needs a real second click.\n * - `forbidden` — the app does not hold the baseline `route:read` capability.\n * - `unsupported` — this host has no repository-open surface wired.\n * - `unknown` — the host refused without naming a code.\n *\n * **What you actually catch.** The SDK throws a plain `Error` with `.code` assigned — a\n * `CodedRefusalError` from `protocolRefusal.ts` — never a distinct class. These are the\n * `.code` VALUES the host sends. Nothing enforces the union at runtime — `.code` is\n * whatever string arrived — so treat an unlisted code as possible and `instanceof Error`\n * as the only reliable test.\n *\n * (This note is on the code alias rather than on the interface because the alias is where\n * the codes are documented. Every doclink in this file names the INTERFACE, so a reader\n * following one lands a hop away from this — a wart, not a plan. Stated without a\n * direction on purpose: two earlier revisions of this sentence asserted a positional\n * claim, and both were wrong.) */\nexport type OpenRepositoryErrorCode = 'invalid' | 'no-activation' | 'forbidden' | 'unsupported' | 'unknown';\n\nexport interface OpenRepositoryError extends Error {\n code: OpenRepositoryErrorCode;\n}\n\n/** The host's reply: the envelope resolves INSIDE the promise, so a refusal is a resolved\n * `{ ok: false }` rather than a rejection at the transport layer. */\ntype OpenRepositoryReply = { ok: true; url?: string } | { ok: false; code?: string; message?: string };\n\n/**\n * Ask the host to open a repository in a new browser tab.\n *\n * `reveal` (R3-1033) optionally asks the host to open one of its own chrome surfaces at\n * the destination — a closed enum (`RepositoryReveal`), never a destination. Omitted,\n * the open lands exactly as before.\n *\n * Resolves once the host has performed the open; it does not wait for — and cannot observe —\n * the opened tab loading. Rejects with a typed {@link OpenRepositoryError} carrying `code`\n * when the host refuses.\n *\n * Call it directly from a user gesture. The host samples its own transient activation when\n * the request arrives, so anything that defers the call past the gesture (an `await` before\n * it, a `setTimeout`, a retry) will be refused `no-activation`. None of the refusals are\n * worth retrying: each names a condition a retry cannot change.\n */\nexport async function openRepository(coordinates: RepositoryCoordinates, reveal?: RepositoryReveal): Promise<void> {\n const { provider, namespace, repository } = coordinates;\n // The reveal rides the one wire arg when the caller asked for it; a caller omitting it\n // sends no field at all (never `undefined` on the wire — the host validates what arrives).\n // Typed as OpenRepositoryOpenParams (the named interface) so the protocol-snapshot\n // extractor resolves the wire shape from the type — an intersection or a bare Record\n // would read shapeless and the check would flag a reshape that is not one.\n const params: OpenRepositoryOpenParams = { provider, namespace, repository };\n if (reveal !== undefined) params.reveal = reveal;\n const res = (await protocolRequest(SCHEMES[PROTOCOL_OPENREPO], 'open', [params])) as OpenRepositoryReply;\n throwOnRefusal(res, 'repository open refused');\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAqBA,0BAAgC;AAChC,6BAA+B;AAC/B,sBAAkC;AAClC,6BAAwB;AAwExB,eAAsB,eAAe,aAAoC,QAA0C;AACjH,QAAM,EAAE,UAAU,WAAW,WAAW,IAAI;AAM5C,QAAM,SAAmC,EAAE,UAAU,WAAW,WAAW;AAC3E,MAAI,WAAW,OAAW,QAAO,SAAS;AAC1C,QAAM,MAAO,UAAM,qCAAgB,+BAAQ,iCAAiB,GAAG,QAAQ,CAAC,MAAM,CAAC;AAC/E,6CAAe,KAAK,yBAAyB;AAC/C;","names":[]}
|
|
@@ -5,6 +5,12 @@ interface RepositoryCoordinates {
|
|
|
5
5
|
namespace: string;
|
|
6
6
|
repository: string;
|
|
7
7
|
}
|
|
8
|
+
/** A chrome reveal that may ride an open (R3-1033) — the host's own surface to open at the
|
|
9
|
+
* destination, never a destination the app names. `'agent'` is the conversations panel;
|
|
10
|
+
* the value set is closed on purpose (see the header). */
|
|
11
|
+
interface RepositoryReveal {
|
|
12
|
+
panel: 'agent';
|
|
13
|
+
}
|
|
8
14
|
/** Why the host refused to open a tab.
|
|
9
15
|
*
|
|
10
16
|
* - `invalid` — the coordinates are not three clean path segments.
|
|
@@ -34,6 +40,10 @@ interface OpenRepositoryError extends Error {
|
|
|
34
40
|
/**
|
|
35
41
|
* Ask the host to open a repository in a new browser tab.
|
|
36
42
|
*
|
|
43
|
+
* `reveal` (R3-1033) optionally asks the host to open one of its own chrome surfaces at
|
|
44
|
+
* the destination — a closed enum (`RepositoryReveal`), never a destination. Omitted,
|
|
45
|
+
* the open lands exactly as before.
|
|
46
|
+
*
|
|
37
47
|
* Resolves once the host has performed the open; it does not wait for — and cannot observe —
|
|
38
48
|
* the opened tab loading. Rejects with a typed {@link OpenRepositoryError} carrying `code`
|
|
39
49
|
* when the host refuses.
|
|
@@ -43,6 +53,6 @@ interface OpenRepositoryError extends Error {
|
|
|
43
53
|
* it, a `setTimeout`, a retry) will be refused `no-activation`. None of the refusals are
|
|
44
54
|
* worth retrying: each names a condition a retry cannot change.
|
|
45
55
|
*/
|
|
46
|
-
declare function openRepository(coordinates: RepositoryCoordinates): Promise<void>;
|
|
56
|
+
declare function openRepository(coordinates: RepositoryCoordinates, reveal?: RepositoryReveal): Promise<void>;
|
|
47
57
|
|
|
48
|
-
export { type OpenRepositoryError, type OpenRepositoryErrorCode, type RepositoryCoordinates, openRepository };
|
|
58
|
+
export { type OpenRepositoryError, type OpenRepositoryErrorCode, type RepositoryCoordinates, type RepositoryReveal, openRepository };
|
package/dist/openRepository.d.ts
CHANGED
|
@@ -5,6 +5,12 @@ interface RepositoryCoordinates {
|
|
|
5
5
|
namespace: string;
|
|
6
6
|
repository: string;
|
|
7
7
|
}
|
|
8
|
+
/** A chrome reveal that may ride an open (R3-1033) — the host's own surface to open at the
|
|
9
|
+
* destination, never a destination the app names. `'agent'` is the conversations panel;
|
|
10
|
+
* the value set is closed on purpose (see the header). */
|
|
11
|
+
interface RepositoryReveal {
|
|
12
|
+
panel: 'agent';
|
|
13
|
+
}
|
|
8
14
|
/** Why the host refused to open a tab.
|
|
9
15
|
*
|
|
10
16
|
* - `invalid` — the coordinates are not three clean path segments.
|
|
@@ -34,6 +40,10 @@ interface OpenRepositoryError extends Error {
|
|
|
34
40
|
/**
|
|
35
41
|
* Ask the host to open a repository in a new browser tab.
|
|
36
42
|
*
|
|
43
|
+
* `reveal` (R3-1033) optionally asks the host to open one of its own chrome surfaces at
|
|
44
|
+
* the destination — a closed enum (`RepositoryReveal`), never a destination. Omitted,
|
|
45
|
+
* the open lands exactly as before.
|
|
46
|
+
*
|
|
37
47
|
* Resolves once the host has performed the open; it does not wait for — and cannot observe —
|
|
38
48
|
* the opened tab loading. Rejects with a typed {@link OpenRepositoryError} carrying `code`
|
|
39
49
|
* when the host refuses.
|
|
@@ -43,6 +53,6 @@ interface OpenRepositoryError extends Error {
|
|
|
43
53
|
* it, a `setTimeout`, a retry) will be refused `no-activation`. None of the refusals are
|
|
44
54
|
* worth retrying: each names a condition a retry cannot change.
|
|
45
55
|
*/
|
|
46
|
-
declare function openRepository(coordinates: RepositoryCoordinates): Promise<void>;
|
|
56
|
+
declare function openRepository(coordinates: RepositoryCoordinates, reveal?: RepositoryReveal): Promise<void>;
|
|
47
57
|
|
|
48
|
-
export { type OpenRepositoryError, type OpenRepositoryErrorCode, type RepositoryCoordinates, openRepository };
|
|
58
|
+
export { type OpenRepositoryError, type OpenRepositoryErrorCode, type RepositoryCoordinates, type RepositoryReveal, openRepository };
|
package/dist/openRepository.js
CHANGED
|
@@ -3,11 +3,11 @@ import { protocolRequest } from "./sandboxUtils.js";
|
|
|
3
3
|
import { throwOnRefusal } from "./protocolRefusal.js";
|
|
4
4
|
import { PROTOCOL_OPENREPO } from "./generated/protocol.js";
|
|
5
5
|
import { SCHEMES } from "./protocolSchemes.js";
|
|
6
|
-
async function openRepository(coordinates) {
|
|
6
|
+
async function openRepository(coordinates, reveal) {
|
|
7
7
|
const { provider, namespace, repository } = coordinates;
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
]);
|
|
8
|
+
const params = { provider, namespace, repository };
|
|
9
|
+
if (reveal !== void 0) params.reveal = reveal;
|
|
10
|
+
const res = await protocolRequest(SCHEMES[PROTOCOL_OPENREPO], "open", [params]);
|
|
11
11
|
throwOnRefusal(res, "repository open refused");
|
|
12
12
|
}
|
|
13
13
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/openRepository.ts"],"sourcesContent":["// Host-mediated \"open this repository in a new tab\" (R3-476).\n//\n// An app frame cannot open a first-party tab itself. A `window.open` from inside the\n// sandboxed frame inherits the sandbox — the opened tab runs at the same opaque origin and\n// cannot load the host — and `target=\"_top\"` would replace the app's own frame rather than\n// open a tab. So the app asks the host, and the host performs the open from its own context.\n//\n// The app names COORDINATES and nothing else. It cannot pass a URL, a route prefix or a\n// path: the host builds the destination from its own route grammar, so this call can only\n// ever reach one of the platform's own repository routes. That is the point of the shape —\n// an app that could spell the destination could open anything.\n//\n// Two more conditions hold on the host side, and neither is something this call can assert\n// for itself: the open needs the HOST document's live transient user activation (a real\n// click, which the host samples rather than believes), and one gesture opens exactly one\n// tab. Both surface here as ordinary coded refusals.\nimport { protocolRequest } from './sandboxUtils';\nimport { throwOnRefusal } from './protocolRefusal';\nimport { PROTOCOL_OPENREPO } from './generated/protocol';\nimport { SCHEMES } from './protocolSchemes';\n\n/** Where a repository lives. The same three fields a `RecentProject` carries — this is a\n * location the user may already have navigated to under their own authority. */\nexport interface RepositoryCoordinates {\n provider: string;\n namespace: string;\n repository: string;\n}\n\n/** Why the host refused to open a tab.\n *\n * - `invalid` — the coordinates are not three clean path segments.\n * - `no-activation` — no live user gesture on the host document. Call this from a click\n * handler; a timer or a boot path will always get this. A SECOND call inside one gesture\n * also lands here: `window.open` consumes the host's transient activation, so one click\n * buys exactly one tab and the next needs a real second click.\n * - `forbidden` — the app does not hold the baseline `route:read` capability.\n * - `unsupported` — this host has no repository-open surface wired.\n * - `unknown` — the host refused without naming a code.\n *\n * **What you actually catch.** The SDK throws a plain `Error` with `.code` assigned — a\n * `CodedRefusalError` from `protocolRefusal.ts` — never a distinct class. These are the\n * `.code` VALUES the host sends. Nothing enforces the union at runtime — `.code` is\n * whatever string arrived — so treat an unlisted code as possible and `instanceof Error`\n * as the only reliable test.\n *\n * (This note is on the code alias rather than on the interface because the alias is where\n * the codes are documented. Every doclink in this file names the INTERFACE, so a reader\n * following one lands a hop away from this — a wart, not a plan. Stated without a\n * direction on purpose: two earlier revisions of this sentence asserted a positional\n * claim, and both were wrong.) */\nexport type OpenRepositoryErrorCode = 'invalid' | 'no-activation' | 'forbidden' | 'unsupported' | 'unknown';\n\nexport interface OpenRepositoryError extends Error {\n code: OpenRepositoryErrorCode;\n}\n\n/** The host's reply: the envelope resolves INSIDE the promise, so a refusal is a resolved\n * `{ ok: false }` rather than a rejection at the transport layer. */\ntype OpenRepositoryReply = { ok: true; url?: string } | { ok: false; code?: string; message?: string };\n\n/**\n * Ask the host to open a repository in a new browser tab.\n *\n * Resolves once the host has performed the open; it does not wait for — and cannot observe —\n * the opened tab loading. Rejects with a typed {@link OpenRepositoryError} carrying `code`\n * when the host refuses.\n *\n * Call it directly from a user gesture. The host samples its own transient activation when\n * the request arrives, so anything that defers the call past the gesture (an `await` before\n * it, a `setTimeout`, a retry) will be refused `no-activation`. None of the refusals are\n * worth retrying: each names a condition a retry cannot change.\n */\nexport async function openRepository(coordinates: RepositoryCoordinates): Promise<void> {\n const { provider, namespace, repository } = coordinates;\n
|
|
1
|
+
{"version":3,"sources":["../src/openRepository.ts"],"sourcesContent":["// Host-mediated \"open this repository in a new tab\" (R3-476).\n//\n// An app frame cannot open a first-party tab itself. A `window.open` from inside the\n// sandboxed frame inherits the sandbox — the opened tab runs at the same opaque origin and\n// cannot load the host — and `target=\"_top\"` would replace the app's own frame rather than\n// open a tab. So the app asks the host, and the host performs the open from its own context.\n//\n// The app names COORDINATES and nothing else. It cannot pass a URL, a route prefix or a\n// path: the host builds the destination from its own route grammar, so this call can only\n// ever reach one of the platform's own repository routes. That is the point of the shape —\n// an app that could spell the destination could open anything.\n//\n// R3-1033: an optional REVEAL rides the open — a closed chrome enum, never a destination.\n// The app still cannot pass a URL, a route prefix or a path; the host decides what the\n// reveal means (which surface of ITS chrome opens) and builds every URL itself. A future\n// panel joins the `RepositoryReveal` union deliberately, never by a free string.\n//\n// Two more conditions hold on the host side, and neither is something this call can assert\n// for itself: the open needs the HOST document's live transient user activation (a real\n// click, which the host samples rather than believes), and one gesture opens exactly one\n// tab. Both surface here as ordinary coded refusals.\nimport { protocolRequest } from './sandboxUtils';\nimport { throwOnRefusal } from './protocolRefusal';\nimport { PROTOCOL_OPENREPO } from './generated/protocol';\nimport { SCHEMES } from './protocolSchemes';\n\n/** Where a repository lives. The same three fields a `RecentProject` carries — this is a\n * location the user may already have navigated to under their own authority. */\nexport interface RepositoryCoordinates {\n provider: string;\n namespace: string;\n repository: string;\n}\n\n/** A chrome reveal that may ride an open (R3-1033) — the host's own surface to open at the\n * destination, never a destination the app names. `'agent'` is the conversations panel;\n * the value set is closed on purpose (see the header). */\nexport interface RepositoryReveal {\n panel: 'agent';\n}\n\n/** The `open` wire params — the coordinates plus the optional reveal. Typed as a named\n * interface (not an inline literal) so the protocol-snapshot extractor resolves the wire\n * shape from the type; see `openRepository` below. */\ninterface OpenRepositoryOpenParams extends RepositoryCoordinates {\n reveal?: RepositoryReveal;\n}\n\n/** Why the host refused to open a tab.\n *\n * - `invalid` — the coordinates are not three clean path segments.\n * - `no-activation` — no live user gesture on the host document. Call this from a click\n * handler; a timer or a boot path will always get this. A SECOND call inside one gesture\n * also lands here: `window.open` consumes the host's transient activation, so one click\n * buys exactly one tab and the next needs a real second click.\n * - `forbidden` — the app does not hold the baseline `route:read` capability.\n * - `unsupported` — this host has no repository-open surface wired.\n * - `unknown` — the host refused without naming a code.\n *\n * **What you actually catch.** The SDK throws a plain `Error` with `.code` assigned — a\n * `CodedRefusalError` from `protocolRefusal.ts` — never a distinct class. These are the\n * `.code` VALUES the host sends. Nothing enforces the union at runtime — `.code` is\n * whatever string arrived — so treat an unlisted code as possible and `instanceof Error`\n * as the only reliable test.\n *\n * (This note is on the code alias rather than on the interface because the alias is where\n * the codes are documented. Every doclink in this file names the INTERFACE, so a reader\n * following one lands a hop away from this — a wart, not a plan. Stated without a\n * direction on purpose: two earlier revisions of this sentence asserted a positional\n * claim, and both were wrong.) */\nexport type OpenRepositoryErrorCode = 'invalid' | 'no-activation' | 'forbidden' | 'unsupported' | 'unknown';\n\nexport interface OpenRepositoryError extends Error {\n code: OpenRepositoryErrorCode;\n}\n\n/** The host's reply: the envelope resolves INSIDE the promise, so a refusal is a resolved\n * `{ ok: false }` rather than a rejection at the transport layer. */\ntype OpenRepositoryReply = { ok: true; url?: string } | { ok: false; code?: string; message?: string };\n\n/**\n * Ask the host to open a repository in a new browser tab.\n *\n * `reveal` (R3-1033) optionally asks the host to open one of its own chrome surfaces at\n * the destination — a closed enum (`RepositoryReveal`), never a destination. Omitted,\n * the open lands exactly as before.\n *\n * Resolves once the host has performed the open; it does not wait for — and cannot observe —\n * the opened tab loading. Rejects with a typed {@link OpenRepositoryError} carrying `code`\n * when the host refuses.\n *\n * Call it directly from a user gesture. The host samples its own transient activation when\n * the request arrives, so anything that defers the call past the gesture (an `await` before\n * it, a `setTimeout`, a retry) will be refused `no-activation`. None of the refusals are\n * worth retrying: each names a condition a retry cannot change.\n */\nexport async function openRepository(coordinates: RepositoryCoordinates, reveal?: RepositoryReveal): Promise<void> {\n const { provider, namespace, repository } = coordinates;\n // The reveal rides the one wire arg when the caller asked for it; a caller omitting it\n // sends no field at all (never `undefined` on the wire — the host validates what arrives).\n // Typed as OpenRepositoryOpenParams (the named interface) so the protocol-snapshot\n // extractor resolves the wire shape from the type — an intersection or a bare Record\n // would read shapeless and the check would flag a reshape that is not one.\n const params: OpenRepositoryOpenParams = { provider, namespace, repository };\n if (reveal !== undefined) params.reveal = reveal;\n const res = (await protocolRequest(SCHEMES[PROTOCOL_OPENREPO], 'open', [params])) as OpenRepositoryReply;\n throwOnRefusal(res, 'repository open refused');\n}\n"],"mappings":";AAqBA,SAAS,uBAAuB;AAChC,SAAS,sBAAsB;AAC/B,SAAS,yBAAyB;AAClC,SAAS,eAAe;AAwExB,eAAsB,eAAe,aAAoC,QAA0C;AACjH,QAAM,EAAE,UAAU,WAAW,WAAW,IAAI;AAM5C,QAAM,SAAmC,EAAE,UAAU,WAAW,WAAW;AAC3E,MAAI,WAAW,OAAW,QAAO,SAAS;AAC1C,QAAM,MAAO,MAAM,gBAAgB,QAAQ,iBAAiB,GAAG,QAAQ,CAAC,MAAM,CAAC;AAC/E,iBAAe,KAAK,yBAAyB;AAC/C;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/protocolRefusal.ts"],"sourcesContent":["// The one place the SDK turns a host reply envelope into a typed, coded rejection (R6).\n//\n// ---------------------------------------------------------------------------\n// THE CENSUS — miscounted four times. COUNT THE GREP, and say which unit.\n// ---------------------------------------------------------------------------\n//\n// R3-708's review said three copies, then five, then \"ten across eight files\". This file\n// then said ten while the list beneath it summed to twelve, and a fourth reviewer caught\n// that. The count is:\n//\n// **seventeen CALL SITES across twelve FILES** — `grep -n 'throwOnRefusal(' src/*.ts`,\n// minus the declaration here and minus `*.test.*`:\n//\n// dnd.ts · editor.ts · feed.ts · ipc.ts (×2) · mounts.ts (×3) · netFetch.ts ·\n// openExternal.ts · openRepository.ts · secrets.ts · spacesMode.ts · theme.ts (×3) ·\n// vcs.ts\n//\n// Every miscount came from the same two mistakes: reading files instead of counting the\n// grep, and never saying which unit was being counted. `mounts.ts` has three separate\n// request helpers, each with its own copy; R3-780 touched five FILES and seven SITES.\n// \"Ten\" was neither.\n//\n// Not folded, deliberately, and the reason is NOT that they are all unalike — that was the\n// previous excuse and it was false for three of them:\n//\n// · `catalog.ts`, `recents.ts`, `tasks.ts` are pure copies of the shape `ipc.ts` had\n// until R3-780 folded it — untyped `Error & { code?: string }`, `res?.code ??\n// 'unknown'`. (`recents.ts` casts `code` as required rather than optional; immaterial,\n// the cast erases.) They are foldable and nothing here argues otherwise;\n// · `feed.ts`, `netFetch.ts` and `theme.ts` (×3) read `res && 'code' in res`, which\n// THREW `TypeError: Cannot use 'in' operator` on a string reply — FOLDED in R3-817\n// (0.74.3), a behaviour change reviewed as its own item, exactly as this bullet\n// prescribed;\n// · `launch.ts` folds `!res.data?.launchId` into the same condition and RETURNS\n// `{ ok: false, code }` instead of throwing. Different control flow entirely.\n//\n// So the remaining work is two items, not one, and they are not the same size.\n//\n// `check:clones` cannot help with any of this: minLines 6, minTokens 50, and no identifier\n// normalisation, so blocks differing only in type names read as distinct.\n//\n// ---------------------------------------------------------------------------\n// THIS FILE'S OWN TEST IS LOAD-BEARING FOR ALL SEVENTEEN SITES\n// ---------------------------------------------------------------------------\n//\n// Measured: changing the guard to `r.ok !== false` compiles clean and leaves **ten of the\n// seventeen SITES** green — seven of the twelve files: `dnd`, `editor`, `ipc`, `mounts`,\n// `secrets`, `spacesMode` and `vcs`. Every one of them stubs an explicit `{ ok: false }`,\n// so they pin \"throws on a refusal envelope\" and nothing about a malformed or absent\n// reply. The catchers: `openExternal`, `openRepository`, the five R3-817 sites (whose\n// string-reply tests reject on a non-envelope — the mutation never throws), plus\n// `protocolRefusal.test.ts`. (Re-run 2026-09-30 on the post-fold tree: suites red —\n// feed, netFetch, theme, openExternal, openRepository, protocolRefusal; the seven\n// families green.)\n//\n// (An earlier version of this paragraph said \"nine of the twelve sites' suites\", which\n// mixes sites with suites — the exact mistake the census block above is headed about —\n// and omitted `secrets` and `spacesMode` from the green list.)\n//\n// Each inline form this replaced carried its own `!res ||` guard, visible at the call site.\n// That guarantee now lives here alone. Do not weaken `protocolRefusal.test.ts` on the\n// grounds that \"the consumers cover it\" — they do not, and seventeen near-duplicate malformed\n// -reply tests would be the duplication this extraction exists to remove.\n//\n// ---------------------------------------------------------------------------\n// WHICH `ok` THIS READS, AND WHY IT MATTERS\n// ---------------------------------------------------------------------------\n//\n// It reads the DISPATCHER ENVELOPE's `ok` — the host's answer to \"did this call\n// succeed\", not a handler's own return value. site-main declares that envelope\n// (`src/editor/requestDispatcher.ts`):\n//\n// type SpaceResult =\n// | { ok: true; data: unknown }\n// | { ok: false; code: string; message: string };\n//\n// and the sandbox resolves it to the SDK unmodified (`src/protocol/iframe.ts`,\n// `resolve(msg.result)`). So a refusal reaches us as `{ok:false, code, message}` — which\n// is exactly what this function unwraps — and the host produces that frame by THROWING\n// `spaceError(code, message)`. The dispatcher's `.catch` turns the throw into the frame.\n//\n// **A handler that RETURNS `{ok:false, code}` instead of throwing does not produce a\n// refusal.** The dispatcher wraps a return value as `result: {ok: true, data: <return>}`,\n// so the envelope says the call succeeded and the refusal is buried one level down, where\n// nothing looks. Two shipped handlers did this until R3-778 closed it (site-main; audited sdk#184 round 2, 2026-09-25; fixed 2026-09-28 — both now throw, and a dispatcher assertion reddens on the shape):\n//\n// `handleOpenRepository` returns `invalid`, `no-activation`\n// `handleOpenLink` returns `invalid`, `no-activation`, **`declined`**\n//\n// `declined` is the user pressing \"no\" on the host's confirmation dialog, and\n// `openExternal()` reported that to the app as a successful open, until R3-778 closed it. Driven against the built\n// SDK with each reply shape:\n//\n// thrown -> threw, code=no-activation\n// returned -> RESOLVED (the app believes the tab opened)\n//\n// That was a live defect in site-main's handlers until R3-778 closed it (2026-09-28), not here — the envelope is the contract\n// and this reads the contract. Filed as R3-778. It is written down here because this is\n// the file a host author will be pointed at when they ask what shape to reply with, and\n// the answer is: **throw `spaceError`; never return `{ok:false}`.**\n//\n// Deliberately NOT done: sniffing `res.data?.ok === false` as a second refusal shape. On a\n// SUCCESS, `data` is whatever the handler returned — so a handler whose legitimate payload\n// happens to carry `ok: false` would be turned into a refusal. It would bless the broken\n// shape and create a second contract where the spec names one.\n\n/** An error carrying a stable, host-supplied `code` the app can branch on. */\nexport interface CodedRefusalError<C extends string = string> extends Error {\n code: C;\n}\n\n/**\n * Throw a typed, coded error unless the host's reply envelope says the call succeeded.\n *\n * `fallbackMessage` is used when the host refused without a message, and `'unknown'` is\n * the code when it refused without one — a refusal is never reported as a success just\n * because it arrived under-specified.\n *\n * `code` and `message` must be STRINGS to be used. Seventeen sites call this;\n * **sixteen** had an inline copy it replaced (`spacesMode.ts` was written against the\n * helper in R3-708 and replaced nothing). All sixteen tested for PRESENCE, in **three**\n * shapes:\n *\n * - **seven** cast the value: `(res?.code as SomeError['code']) ?? 'unknown'` —\n * `dnd`, `editor`, `vcs`, `mounts` (×3), `secrets`;\n * - **seven** used the `in` operator — `openExternal`, `openRepository` (with the cast;\n * folded in R3-708) and `feed`, `netFetch`, `theme` ×3 (without it; folded in R3-817,\n * the TypeError fix disclosed above);\n * - **two** used a bare `res?.code ?? 'unknown'` onto `Error & { code?: string }` —\n * `ipc.ts`.\n *\n * Every one of them let a host sending `code: 42` surface `err.code === 42` on a field\n * declared `string`, and turned `message: 42` into the string `\"42\"`. Both now fall back,\n * to `'unknown'` and `fallbackMessage`. A deliberate tightening, pinned by\n * `protocolRefusal.test.ts` — and since this package ships no changelog, this paragraph is\n * where a consumer learns of it.\n *\n * The `ipc.ts` pair changed one more thing: their anonymous type declared `code` OPTIONAL\n * and `CodedRefusalError` requires it. No runtime difference for a missing code — the old\n * code assigned `'unknown'` exactly when the new one does (a non-string `code` falls back\n * too, as the paragraph above discloses) — but a consumer narrowing on `'code' in err`\n * can stop.\n *\n * Folding the two `in`-operator sites also removed a latent `TypeError`: `'code' in res`\n * throws on a string reply.\n *\n * ONE revision of this paragraph got that backwards, and this is the fourth attempt to\n * describe it accurately. The original text was right FOR ITS REFERENT — it named\n * `'code' in res` as a shape replaced, without saying which sites, and at the time the\n * sites it referred to were R3-708's four, two of which used that form. R3-780 then folded\n * five DIFFERENT files and inherited the sentence unchanged, so it became false in place\n * without anyone editing it. That silent shift is the likeliest reason the next revision\n * \"corrected\" it to say NO replaced site used it — which is false the other way:\n * `openExternal` and `openRepository` did.\n *\n * The mechanism is worth more than the correction, because it is repeatable. `'code' in\n * res` is **gone from `main`** since R3-817 (0.74.3) folded the last five — a reviewer who\n * greps `main` finds nothing, and this paragraph is the record of where it lived and why\n * it misread twice before. What a grep of `main` cannot show is that the\n * form was ALSO at two sites R3-708 folded. The tree that answers the question is the one\n * before the fold, `d4b07cc1^`. Read that before rewriting this paragraph again.\n *\n * It is an ASSERTION function, not a `void` one, because the inline form it replaced\n * narrowed `res` as a side effect of its `if`/`throw`: `secrets.ts` and `mounts.ts` read\n * `res.data` on the next line and stopped compiling without it. A caller that only needs\n * the throw can ignore the narrowing; one that reads the payload gets it for free. (TS\n * requires the call target to be an explicitly-typed declared name — this is why it is a\n * `function` declaration and not an arrow const.)\n *\n * R3-817 (0.74.3): the five remaining inline copies (`feed.ts`, `netFetch.ts`,\n * `theme.ts` ×3) folded onto this — removing a latent defect with them: their\n * `res && 'code' in res` guard threw `TypeError: Cannot use 'in' operator` on a\n * bare-STRING reply (a proxy error page, a relay), escaping past every `err.code`\n * branch an app wrote. This function reads `typeof r?.code === 'string'` and\n * cannot throw on any input; the TypeError path no longer exists.\n */\nexport function throwOnRefusal(res: unknown, fallbackMessage: string): asserts res is { ok: true; data?: unknown } {\n const r = res as { ok?: unknown; code?: unknown; message?: unknown } | null | undefined;\n if (r && r.ok === true) return;\n const err = new Error(typeof r?.message === 'string' ? r.message : fallbackMessage) as CodedRefusalError;\n err.code = typeof r?.code === 'string' ? r.code : 'unknown';\n throw err;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAgLO,SAAS,eAAe,KAAc,iBAAsE;AACjH,QAAM,IAAI;AACV,MAAI,KAAK,EAAE,OAAO,KAAM;AACxB,QAAM,MAAM,IAAI,MAAM,OAAO,GAAG,YAAY,WAAW,EAAE,UAAU,eAAe;AAClF,MAAI,OAAO,OAAO,GAAG,SAAS,WAAW,EAAE,OAAO;AAClD,QAAM;AACR;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/protocolRefusal.ts"],"sourcesContent":["// The one place the SDK turns a host reply envelope into a typed, coded rejection (R6).\n//\n// ---------------------------------------------------------------------------\n// THE CENSUS — miscounted four times. COUNT THE GREP, and say which unit.\n// ---------------------------------------------------------------------------\n//\n// R3-708's review said three copies, then five, then \"ten across eight files\". This file\n// then said ten while the list beneath it summed to twelve, and a fourth reviewer caught\n// that. The count is:\n//\n// **eighteen CALL SITES across thirteen FILES** — `grep -n 'throwOnRefusal(' src/*.ts`,\n// minus the declaration here and minus `*.test.*`:\n//\n// dnd.ts · editor.ts · feed.ts · ipc.ts (×2) · mounts.ts (×3) · netFetch.ts ·\n// openBundle.ts · openExternal.ts · openRepository.ts · secrets.ts · spacesMode.ts · theme.ts (×3) ·\n// vcs.ts\n//\n// Every miscount came from the same two mistakes: reading files instead of counting the\n// grep, and never saying which unit was being counted. `mounts.ts` has three separate\n// request helpers, each with its own copy; R3-780 touched five FILES and seven SITES.\n// \"Ten\" was neither.\n//\n// Not folded, deliberately, and the reason is NOT that they are all unalike — that was the\n// previous excuse and it was false for three of them:\n//\n// · `catalog.ts`, `recents.ts`, `tasks.ts` are pure copies of the shape `ipc.ts` had\n// until R3-780 folded it — untyped `Error & { code?: string }`, `res?.code ??\n// 'unknown'`. (`recents.ts` casts `code` as required rather than optional; immaterial,\n// the cast erases.) They are foldable and nothing here argues otherwise;\n// · `feed.ts`, `netFetch.ts` and `theme.ts` (×3) read `res && 'code' in res`, which\n// THREW `TypeError: Cannot use 'in' operator` on a string reply — FOLDED in R3-817\n// (0.74.3), a behaviour change reviewed as its own item, exactly as this bullet\n// prescribed;\n// · `launch.ts` folds `!res.data?.launchId` into the same condition and RETURNS\n// `{ ok: false, code }` instead of throwing. Different control flow entirely.\n//\n// So the remaining work is two items, not one, and they are not the same size.\n//\n// `check:clones` cannot help with any of this: minLines 6, minTokens 50, and no identifier\n// normalisation, so blocks differing only in type names read as distinct.\n//\n// ---------------------------------------------------------------------------\n// THIS FILE'S OWN TEST IS LOAD-BEARING FOR ALL EIGHTEEN SITES\n// ---------------------------------------------------------------------------\n//\n// Measured: changing the guard to `r.ok !== false` compiles clean and leaves **ten of the\n// eighteen SITES** green — seven of the thirteen files: `dnd`, `editor`, `ipc`, `mounts`,\n// `secrets`, `spacesMode` and `vcs`. Every one of them stubs an explicit `{ ok: false }`,\n// so they pin \"throws on a refusal envelope\" and nothing about a malformed or absent\n// reply. The catchers: `openBundle`, `openExternal`, `openRepository`, the five R3-817 sites (whose\n// string-reply tests reject on a non-envelope — the mutation never throws), plus\n// `protocolRefusal.test.ts`. (Re-run 2026-09-30 on the post-fold tree: suites red —\n// feed, netFetch, theme, openExternal, openRepository, protocolRefusal; the seven\n// families green. `openBundle`, the eighteenth site, was added 2026-10-05 and re-run alone\n// under the same mutation: red.)\n//\n// (An earlier version of this paragraph said \"nine of the twelve sites' suites\", which\n// mixes sites with suites — the exact mistake the census block above is headed about —\n// and omitted `secrets` and `spacesMode` from the green list.)\n//\n// Each inline form this replaced carried its own `!res ||` guard, visible at the call site.\n// That guarantee now lives here alone. Do not weaken `protocolRefusal.test.ts` on the\n// grounds that \"the consumers cover it\" — they do not, and eighteen near-duplicate malformed\n// -reply tests would be the duplication this extraction exists to remove.\n//\n// ---------------------------------------------------------------------------\n// WHICH `ok` THIS READS, AND WHY IT MATTERS\n// ---------------------------------------------------------------------------\n//\n// It reads the DISPATCHER ENVELOPE's `ok` — the host's answer to \"did this call\n// succeed\", not a handler's own return value. site-main declares that envelope\n// (`src/editor/requestDispatcher.ts`):\n//\n// type SpaceResult =\n// | { ok: true; data: unknown }\n// | { ok: false; code: string; message: string };\n//\n// and the sandbox resolves it to the SDK unmodified (`src/protocol/iframe.ts`,\n// `resolve(msg.result)`). So a refusal reaches us as `{ok:false, code, message}` — which\n// is exactly what this function unwraps — and the host produces that frame by THROWING\n// `spaceError(code, message)`. The dispatcher's `.catch` turns the throw into the frame.\n//\n// **A handler that RETURNS `{ok:false, code}` instead of throwing does not produce a\n// refusal.** The dispatcher wraps a return value as `result: {ok: true, data: <return>}`,\n// so the envelope says the call succeeded and the refusal is buried one level down, where\n// nothing looks. Two shipped handlers did this until R3-778 closed it (site-main; audited sdk#184 round 2, 2026-09-25; fixed 2026-09-28 — both now throw, and a dispatcher assertion reddens on the shape):\n//\n// `handleOpenRepository` returns `invalid`, `no-activation`\n// `handleOpenLink` returns `invalid`, `no-activation`, **`declined`**\n//\n// `declined` is the user pressing \"no\" on the host's confirmation dialog, and\n// `openExternal()` reported that to the app as a successful open, until R3-778 closed it. Driven against the built\n// SDK with each reply shape:\n//\n// thrown -> threw, code=no-activation\n// returned -> RESOLVED (the app believes the tab opened)\n//\n// That was a live defect in site-main's handlers until R3-778 closed it (2026-09-28), not here — the envelope is the contract\n// and this reads the contract. Filed as R3-778. It is written down here because this is\n// the file a host author will be pointed at when they ask what shape to reply with, and\n// the answer is: **throw `spaceError`; never return `{ok:false}`.**\n//\n// Deliberately NOT done: sniffing `res.data?.ok === false` as a second refusal shape. On a\n// SUCCESS, `data` is whatever the handler returned — so a handler whose legitimate payload\n// happens to carry `ok: false` would be turned into a refusal. It would bless the broken\n// shape and create a second contract where the spec names one.\n\n/** An error carrying a stable, host-supplied `code` the app can branch on. */\nexport interface CodedRefusalError<C extends string = string> extends Error {\n code: C;\n}\n\n/**\n * Throw a typed, coded error unless the host's reply envelope says the call succeeded.\n *\n * `fallbackMessage` is used when the host refused without a message, and `'unknown'` is\n * the code when it refused without one — a refusal is never reported as a success just\n * because it arrived under-specified.\n *\n * `code` and `message` must be STRINGS to be used. Eighteen sites call this;\n * **sixteen** had an inline copy it replaced (`spacesMode.ts` was written against the\n * helper in R3-708 and replaced nothing). All sixteen tested for PRESENCE, in **three**\n * shapes:\n *\n * - **seven** cast the value: `(res?.code as SomeError['code']) ?? 'unknown'` —\n * `dnd`, `editor`, `vcs`, `mounts` (×3), `secrets`;\n * - **seven** used the `in` operator — `openExternal`, `openRepository` (with the cast;\n * folded in R3-708) and `feed`, `netFetch`, `theme` ×3 (without it; folded in R3-817,\n * the TypeError fix disclosed above);\n * - **two** used a bare `res?.code ?? 'unknown'` onto `Error & { code?: string }` —\n * `ipc.ts`.\n *\n * Every one of them let a host sending `code: 42` surface `err.code === 42` on a field\n * declared `string`, and turned `message: 42` into the string `\"42\"`. Both now fall back,\n * to `'unknown'` and `fallbackMessage`. A deliberate tightening, pinned by\n * `protocolRefusal.test.ts` — and since this package ships no changelog, this paragraph is\n * where a consumer learns of it.\n *\n * The `ipc.ts` pair changed one more thing: their anonymous type declared `code` OPTIONAL\n * and `CodedRefusalError` requires it. No runtime difference for a missing code — the old\n * code assigned `'unknown'` exactly when the new one does (a non-string `code` falls back\n * too, as the paragraph above discloses) — but a consumer narrowing on `'code' in err`\n * can stop.\n *\n * Folding the two `in`-operator sites also removed a latent `TypeError`: `'code' in res`\n * throws on a string reply.\n *\n * ONE revision of this paragraph got that backwards, and this is the fourth attempt to\n * describe it accurately. The original text was right FOR ITS REFERENT — it named\n * `'code' in res` as a shape replaced, without saying which sites, and at the time the\n * sites it referred to were R3-708's four, two of which used that form. R3-780 then folded\n * five DIFFERENT files and inherited the sentence unchanged, so it became false in place\n * without anyone editing it. That silent shift is the likeliest reason the next revision\n * \"corrected\" it to say NO replaced site used it — which is false the other way:\n * `openExternal` and `openRepository` did.\n *\n * The mechanism is worth more than the correction, because it is repeatable. `'code' in\n * res` is **gone from `main`** since R3-817 (0.74.3) folded the last five — a reviewer who\n * greps `main` finds nothing, and this paragraph is the record of where it lived and why\n * it misread twice before. What a grep of `main` cannot show is that the\n * form was ALSO at two sites R3-708 folded. The tree that answers the question is the one\n * before the fold, `d4b07cc1^`. Read that before rewriting this paragraph again.\n *\n * It is an ASSERTION function, not a `void` one, because the inline form it replaced\n * narrowed `res` as a side effect of its `if`/`throw`: `secrets.ts` and `mounts.ts` read\n * `res.data` on the next line and stopped compiling without it. A caller that only needs\n * the throw can ignore the narrowing; one that reads the payload gets it for free. (TS\n * requires the call target to be an explicitly-typed declared name — this is why it is a\n * `function` declaration and not an arrow const.)\n *\n * R3-817 (0.74.3): the five remaining inline copies (`feed.ts`, `netFetch.ts`,\n * `theme.ts` ×3) folded onto this — removing a latent defect with them: their\n * `res && 'code' in res` guard threw `TypeError: Cannot use 'in' operator` on a\n * bare-STRING reply (a proxy error page, a relay), escaping past every `err.code`\n * branch an app wrote. This function reads `typeof r?.code === 'string'` and\n * cannot throw on any input; the TypeError path no longer exists.\n */\nexport function throwOnRefusal(res: unknown, fallbackMessage: string): asserts res is { ok: true; data?: unknown } {\n const r = res as { ok?: unknown; code?: unknown; message?: unknown } | null | undefined;\n if (r && r.ok === true) return;\n const err = new Error(typeof r?.message === 'string' ? r.message : fallbackMessage) as CodedRefusalError;\n err.code = typeof r?.code === 'string' ? r.code : 'unknown';\n throw err;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAiLO,SAAS,eAAe,KAAc,iBAAsE;AACjH,QAAM,IAAI;AACV,MAAI,KAAK,EAAE,OAAO,KAAM;AACxB,QAAM,MAAM,IAAI,MAAM,OAAO,GAAG,YAAY,WAAW,EAAE,UAAU,eAAe;AAClF,MAAI,OAAO,OAAO,GAAG,SAAS,WAAW,EAAE,OAAO;AAClD,QAAM;AACR;","names":[]}
|
|
@@ -9,7 +9,7 @@ interface CodedRefusalError<C extends string = string> extends Error {
|
|
|
9
9
|
* the code when it refused without one — a refusal is never reported as a success just
|
|
10
10
|
* because it arrived under-specified.
|
|
11
11
|
*
|
|
12
|
-
* `code` and `message` must be STRINGS to be used.
|
|
12
|
+
* `code` and `message` must be STRINGS to be used. Eighteen sites call this;
|
|
13
13
|
* **sixteen** had an inline copy it replaced (`spacesMode.ts` was written against the
|
|
14
14
|
* helper in R3-708 and replaced nothing). All sixteen tested for PRESENCE, in **three**
|
|
15
15
|
* shapes:
|
|
@@ -9,7 +9,7 @@ interface CodedRefusalError<C extends string = string> extends Error {
|
|
|
9
9
|
* the code when it refused without one — a refusal is never reported as a success just
|
|
10
10
|
* because it arrived under-specified.
|
|
11
11
|
*
|
|
12
|
-
* `code` and `message` must be STRINGS to be used.
|
|
12
|
+
* `code` and `message` must be STRINGS to be used. Eighteen sites call this;
|
|
13
13
|
* **sixteen** had an inline copy it replaced (`spacesMode.ts` was written against the
|
|
14
14
|
* helper in R3-708 and replaced nothing). All sixteen tested for PRESENCE, in **three**
|
|
15
15
|
* shapes:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/protocolRefusal.ts"],"sourcesContent":["// The one place the SDK turns a host reply envelope into a typed, coded rejection (R6).\n//\n// ---------------------------------------------------------------------------\n// THE CENSUS — miscounted four times. COUNT THE GREP, and say which unit.\n// ---------------------------------------------------------------------------\n//\n// R3-708's review said three copies, then five, then \"ten across eight files\". This file\n// then said ten while the list beneath it summed to twelve, and a fourth reviewer caught\n// that. The count is:\n//\n// **seventeen CALL SITES across twelve FILES** — `grep -n 'throwOnRefusal(' src/*.ts`,\n// minus the declaration here and minus `*.test.*`:\n//\n// dnd.ts · editor.ts · feed.ts · ipc.ts (×2) · mounts.ts (×3) · netFetch.ts ·\n// openExternal.ts · openRepository.ts · secrets.ts · spacesMode.ts · theme.ts (×3) ·\n// vcs.ts\n//\n// Every miscount came from the same two mistakes: reading files instead of counting the\n// grep, and never saying which unit was being counted. `mounts.ts` has three separate\n// request helpers, each with its own copy; R3-780 touched five FILES and seven SITES.\n// \"Ten\" was neither.\n//\n// Not folded, deliberately, and the reason is NOT that they are all unalike — that was the\n// previous excuse and it was false for three of them:\n//\n// · `catalog.ts`, `recents.ts`, `tasks.ts` are pure copies of the shape `ipc.ts` had\n// until R3-780 folded it — untyped `Error & { code?: string }`, `res?.code ??\n// 'unknown'`. (`recents.ts` casts `code` as required rather than optional; immaterial,\n// the cast erases.) They are foldable and nothing here argues otherwise;\n// · `feed.ts`, `netFetch.ts` and `theme.ts` (×3) read `res && 'code' in res`, which\n// THREW `TypeError: Cannot use 'in' operator` on a string reply — FOLDED in R3-817\n// (0.74.3), a behaviour change reviewed as its own item, exactly as this bullet\n// prescribed;\n// · `launch.ts` folds `!res.data?.launchId` into the same condition and RETURNS\n// `{ ok: false, code }` instead of throwing. Different control flow entirely.\n//\n// So the remaining work is two items, not one, and they are not the same size.\n//\n// `check:clones` cannot help with any of this: minLines 6, minTokens 50, and no identifier\n// normalisation, so blocks differing only in type names read as distinct.\n//\n// ---------------------------------------------------------------------------\n// THIS FILE'S OWN TEST IS LOAD-BEARING FOR ALL SEVENTEEN SITES\n// ---------------------------------------------------------------------------\n//\n// Measured: changing the guard to `r.ok !== false` compiles clean and leaves **ten of the\n// seventeen SITES** green — seven of the twelve files: `dnd`, `editor`, `ipc`, `mounts`,\n// `secrets`, `spacesMode` and `vcs`. Every one of them stubs an explicit `{ ok: false }`,\n// so they pin \"throws on a refusal envelope\" and nothing about a malformed or absent\n// reply. The catchers: `openExternal`, `openRepository`, the five R3-817 sites (whose\n// string-reply tests reject on a non-envelope — the mutation never throws), plus\n// `protocolRefusal.test.ts`. (Re-run 2026-09-30 on the post-fold tree: suites red —\n// feed, netFetch, theme, openExternal, openRepository, protocolRefusal; the seven\n// families green.)\n//\n// (An earlier version of this paragraph said \"nine of the twelve sites' suites\", which\n// mixes sites with suites — the exact mistake the census block above is headed about —\n// and omitted `secrets` and `spacesMode` from the green list.)\n//\n// Each inline form this replaced carried its own `!res ||` guard, visible at the call site.\n// That guarantee now lives here alone. Do not weaken `protocolRefusal.test.ts` on the\n// grounds that \"the consumers cover it\" — they do not, and seventeen near-duplicate malformed\n// -reply tests would be the duplication this extraction exists to remove.\n//\n// ---------------------------------------------------------------------------\n// WHICH `ok` THIS READS, AND WHY IT MATTERS\n// ---------------------------------------------------------------------------\n//\n// It reads the DISPATCHER ENVELOPE's `ok` — the host's answer to \"did this call\n// succeed\", not a handler's own return value. site-main declares that envelope\n// (`src/editor/requestDispatcher.ts`):\n//\n// type SpaceResult =\n// | { ok: true; data: unknown }\n// | { ok: false; code: string; message: string };\n//\n// and the sandbox resolves it to the SDK unmodified (`src/protocol/iframe.ts`,\n// `resolve(msg.result)`). So a refusal reaches us as `{ok:false, code, message}` — which\n// is exactly what this function unwraps — and the host produces that frame by THROWING\n// `spaceError(code, message)`. The dispatcher's `.catch` turns the throw into the frame.\n//\n// **A handler that RETURNS `{ok:false, code}` instead of throwing does not produce a\n// refusal.** The dispatcher wraps a return value as `result: {ok: true, data: <return>}`,\n// so the envelope says the call succeeded and the refusal is buried one level down, where\n// nothing looks. Two shipped handlers did this until R3-778 closed it (site-main; audited sdk#184 round 2, 2026-09-25; fixed 2026-09-28 — both now throw, and a dispatcher assertion reddens on the shape):\n//\n// `handleOpenRepository` returns `invalid`, `no-activation`\n// `handleOpenLink` returns `invalid`, `no-activation`, **`declined`**\n//\n// `declined` is the user pressing \"no\" on the host's confirmation dialog, and\n// `openExternal()` reported that to the app as a successful open, until R3-778 closed it. Driven against the built\n// SDK with each reply shape:\n//\n// thrown -> threw, code=no-activation\n// returned -> RESOLVED (the app believes the tab opened)\n//\n// That was a live defect in site-main's handlers until R3-778 closed it (2026-09-28), not here — the envelope is the contract\n// and this reads the contract. Filed as R3-778. It is written down here because this is\n// the file a host author will be pointed at when they ask what shape to reply with, and\n// the answer is: **throw `spaceError`; never return `{ok:false}`.**\n//\n// Deliberately NOT done: sniffing `res.data?.ok === false` as a second refusal shape. On a\n// SUCCESS, `data` is whatever the handler returned — so a handler whose legitimate payload\n// happens to carry `ok: false` would be turned into a refusal. It would bless the broken\n// shape and create a second contract where the spec names one.\n\n/** An error carrying a stable, host-supplied `code` the app can branch on. */\nexport interface CodedRefusalError<C extends string = string> extends Error {\n code: C;\n}\n\n/**\n * Throw a typed, coded error unless the host's reply envelope says the call succeeded.\n *\n * `fallbackMessage` is used when the host refused without a message, and `'unknown'` is\n * the code when it refused without one — a refusal is never reported as a success just\n * because it arrived under-specified.\n *\n * `code` and `message` must be STRINGS to be used. Seventeen sites call this;\n * **sixteen** had an inline copy it replaced (`spacesMode.ts` was written against the\n * helper in R3-708 and replaced nothing). All sixteen tested for PRESENCE, in **three**\n * shapes:\n *\n * - **seven** cast the value: `(res?.code as SomeError['code']) ?? 'unknown'` —\n * `dnd`, `editor`, `vcs`, `mounts` (×3), `secrets`;\n * - **seven** used the `in` operator — `openExternal`, `openRepository` (with the cast;\n * folded in R3-708) and `feed`, `netFetch`, `theme` ×3 (without it; folded in R3-817,\n * the TypeError fix disclosed above);\n * - **two** used a bare `res?.code ?? 'unknown'` onto `Error & { code?: string }` —\n * `ipc.ts`.\n *\n * Every one of them let a host sending `code: 42` surface `err.code === 42` on a field\n * declared `string`, and turned `message: 42` into the string `\"42\"`. Both now fall back,\n * to `'unknown'` and `fallbackMessage`. A deliberate tightening, pinned by\n * `protocolRefusal.test.ts` — and since this package ships no changelog, this paragraph is\n * where a consumer learns of it.\n *\n * The `ipc.ts` pair changed one more thing: their anonymous type declared `code` OPTIONAL\n * and `CodedRefusalError` requires it. No runtime difference for a missing code — the old\n * code assigned `'unknown'` exactly when the new one does (a non-string `code` falls back\n * too, as the paragraph above discloses) — but a consumer narrowing on `'code' in err`\n * can stop.\n *\n * Folding the two `in`-operator sites also removed a latent `TypeError`: `'code' in res`\n * throws on a string reply.\n *\n * ONE revision of this paragraph got that backwards, and this is the fourth attempt to\n * describe it accurately. The original text was right FOR ITS REFERENT — it named\n * `'code' in res` as a shape replaced, without saying which sites, and at the time the\n * sites it referred to were R3-708's four, two of which used that form. R3-780 then folded\n * five DIFFERENT files and inherited the sentence unchanged, so it became false in place\n * without anyone editing it. That silent shift is the likeliest reason the next revision\n * \"corrected\" it to say NO replaced site used it — which is false the other way:\n * `openExternal` and `openRepository` did.\n *\n * The mechanism is worth more than the correction, because it is repeatable. `'code' in\n * res` is **gone from `main`** since R3-817 (0.74.3) folded the last five — a reviewer who\n * greps `main` finds nothing, and this paragraph is the record of where it lived and why\n * it misread twice before. What a grep of `main` cannot show is that the\n * form was ALSO at two sites R3-708 folded. The tree that answers the question is the one\n * before the fold, `d4b07cc1^`. Read that before rewriting this paragraph again.\n *\n * It is an ASSERTION function, not a `void` one, because the inline form it replaced\n * narrowed `res` as a side effect of its `if`/`throw`: `secrets.ts` and `mounts.ts` read\n * `res.data` on the next line and stopped compiling without it. A caller that only needs\n * the throw can ignore the narrowing; one that reads the payload gets it for free. (TS\n * requires the call target to be an explicitly-typed declared name — this is why it is a\n * `function` declaration and not an arrow const.)\n *\n * R3-817 (0.74.3): the five remaining inline copies (`feed.ts`, `netFetch.ts`,\n * `theme.ts` ×3) folded onto this — removing a latent defect with them: their\n * `res && 'code' in res` guard threw `TypeError: Cannot use 'in' operator` on a\n * bare-STRING reply (a proxy error page, a relay), escaping past every `err.code`\n * branch an app wrote. This function reads `typeof r?.code === 'string'` and\n * cannot throw on any input; the TypeError path no longer exists.\n */\nexport function throwOnRefusal(res: unknown, fallbackMessage: string): asserts res is { ok: true; data?: unknown } {\n const r = res as { ok?: unknown; code?: unknown; message?: unknown } | null | undefined;\n if (r && r.ok === true) return;\n const err = new Error(typeof r?.message === 'string' ? r.message : fallbackMessage) as CodedRefusalError;\n err.code = typeof r?.code === 'string' ? r.code : 'unknown';\n throw err;\n}\n"],"mappings":";AAgLO,SAAS,eAAe,KAAc,iBAAsE;AACjH,QAAM,IAAI;AACV,MAAI,KAAK,EAAE,OAAO,KAAM;AACxB,QAAM,MAAM,IAAI,MAAM,OAAO,GAAG,YAAY,WAAW,EAAE,UAAU,eAAe;AAClF,MAAI,OAAO,OAAO,GAAG,SAAS,WAAW,EAAE,OAAO;AAClD,QAAM;AACR;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/protocolRefusal.ts"],"sourcesContent":["// The one place the SDK turns a host reply envelope into a typed, coded rejection (R6).\n//\n// ---------------------------------------------------------------------------\n// THE CENSUS — miscounted four times. COUNT THE GREP, and say which unit.\n// ---------------------------------------------------------------------------\n//\n// R3-708's review said three copies, then five, then \"ten across eight files\". This file\n// then said ten while the list beneath it summed to twelve, and a fourth reviewer caught\n// that. The count is:\n//\n// **eighteen CALL SITES across thirteen FILES** — `grep -n 'throwOnRefusal(' src/*.ts`,\n// minus the declaration here and minus `*.test.*`:\n//\n// dnd.ts · editor.ts · feed.ts · ipc.ts (×2) · mounts.ts (×3) · netFetch.ts ·\n// openBundle.ts · openExternal.ts · openRepository.ts · secrets.ts · spacesMode.ts · theme.ts (×3) ·\n// vcs.ts\n//\n// Every miscount came from the same two mistakes: reading files instead of counting the\n// grep, and never saying which unit was being counted. `mounts.ts` has three separate\n// request helpers, each with its own copy; R3-780 touched five FILES and seven SITES.\n// \"Ten\" was neither.\n//\n// Not folded, deliberately, and the reason is NOT that they are all unalike — that was the\n// previous excuse and it was false for three of them:\n//\n// · `catalog.ts`, `recents.ts`, `tasks.ts` are pure copies of the shape `ipc.ts` had\n// until R3-780 folded it — untyped `Error & { code?: string }`, `res?.code ??\n// 'unknown'`. (`recents.ts` casts `code` as required rather than optional; immaterial,\n// the cast erases.) They are foldable and nothing here argues otherwise;\n// · `feed.ts`, `netFetch.ts` and `theme.ts` (×3) read `res && 'code' in res`, which\n// THREW `TypeError: Cannot use 'in' operator` on a string reply — FOLDED in R3-817\n// (0.74.3), a behaviour change reviewed as its own item, exactly as this bullet\n// prescribed;\n// · `launch.ts` folds `!res.data?.launchId` into the same condition and RETURNS\n// `{ ok: false, code }` instead of throwing. Different control flow entirely.\n//\n// So the remaining work is two items, not one, and they are not the same size.\n//\n// `check:clones` cannot help with any of this: minLines 6, minTokens 50, and no identifier\n// normalisation, so blocks differing only in type names read as distinct.\n//\n// ---------------------------------------------------------------------------\n// THIS FILE'S OWN TEST IS LOAD-BEARING FOR ALL EIGHTEEN SITES\n// ---------------------------------------------------------------------------\n//\n// Measured: changing the guard to `r.ok !== false` compiles clean and leaves **ten of the\n// eighteen SITES** green — seven of the thirteen files: `dnd`, `editor`, `ipc`, `mounts`,\n// `secrets`, `spacesMode` and `vcs`. Every one of them stubs an explicit `{ ok: false }`,\n// so they pin \"throws on a refusal envelope\" and nothing about a malformed or absent\n// reply. The catchers: `openBundle`, `openExternal`, `openRepository`, the five R3-817 sites (whose\n// string-reply tests reject on a non-envelope — the mutation never throws), plus\n// `protocolRefusal.test.ts`. (Re-run 2026-09-30 on the post-fold tree: suites red —\n// feed, netFetch, theme, openExternal, openRepository, protocolRefusal; the seven\n// families green. `openBundle`, the eighteenth site, was added 2026-10-05 and re-run alone\n// under the same mutation: red.)\n//\n// (An earlier version of this paragraph said \"nine of the twelve sites' suites\", which\n// mixes sites with suites — the exact mistake the census block above is headed about —\n// and omitted `secrets` and `spacesMode` from the green list.)\n//\n// Each inline form this replaced carried its own `!res ||` guard, visible at the call site.\n// That guarantee now lives here alone. Do not weaken `protocolRefusal.test.ts` on the\n// grounds that \"the consumers cover it\" — they do not, and eighteen near-duplicate malformed\n// -reply tests would be the duplication this extraction exists to remove.\n//\n// ---------------------------------------------------------------------------\n// WHICH `ok` THIS READS, AND WHY IT MATTERS\n// ---------------------------------------------------------------------------\n//\n// It reads the DISPATCHER ENVELOPE's `ok` — the host's answer to \"did this call\n// succeed\", not a handler's own return value. site-main declares that envelope\n// (`src/editor/requestDispatcher.ts`):\n//\n// type SpaceResult =\n// | { ok: true; data: unknown }\n// | { ok: false; code: string; message: string };\n//\n// and the sandbox resolves it to the SDK unmodified (`src/protocol/iframe.ts`,\n// `resolve(msg.result)`). So a refusal reaches us as `{ok:false, code, message}` — which\n// is exactly what this function unwraps — and the host produces that frame by THROWING\n// `spaceError(code, message)`. The dispatcher's `.catch` turns the throw into the frame.\n//\n// **A handler that RETURNS `{ok:false, code}` instead of throwing does not produce a\n// refusal.** The dispatcher wraps a return value as `result: {ok: true, data: <return>}`,\n// so the envelope says the call succeeded and the refusal is buried one level down, where\n// nothing looks. Two shipped handlers did this until R3-778 closed it (site-main; audited sdk#184 round 2, 2026-09-25; fixed 2026-09-28 — both now throw, and a dispatcher assertion reddens on the shape):\n//\n// `handleOpenRepository` returns `invalid`, `no-activation`\n// `handleOpenLink` returns `invalid`, `no-activation`, **`declined`**\n//\n// `declined` is the user pressing \"no\" on the host's confirmation dialog, and\n// `openExternal()` reported that to the app as a successful open, until R3-778 closed it. Driven against the built\n// SDK with each reply shape:\n//\n// thrown -> threw, code=no-activation\n// returned -> RESOLVED (the app believes the tab opened)\n//\n// That was a live defect in site-main's handlers until R3-778 closed it (2026-09-28), not here — the envelope is the contract\n// and this reads the contract. Filed as R3-778. It is written down here because this is\n// the file a host author will be pointed at when they ask what shape to reply with, and\n// the answer is: **throw `spaceError`; never return `{ok:false}`.**\n//\n// Deliberately NOT done: sniffing `res.data?.ok === false` as a second refusal shape. On a\n// SUCCESS, `data` is whatever the handler returned — so a handler whose legitimate payload\n// happens to carry `ok: false` would be turned into a refusal. It would bless the broken\n// shape and create a second contract where the spec names one.\n\n/** An error carrying a stable, host-supplied `code` the app can branch on. */\nexport interface CodedRefusalError<C extends string = string> extends Error {\n code: C;\n}\n\n/**\n * Throw a typed, coded error unless the host's reply envelope says the call succeeded.\n *\n * `fallbackMessage` is used when the host refused without a message, and `'unknown'` is\n * the code when it refused without one — a refusal is never reported as a success just\n * because it arrived under-specified.\n *\n * `code` and `message` must be STRINGS to be used. Eighteen sites call this;\n * **sixteen** had an inline copy it replaced (`spacesMode.ts` was written against the\n * helper in R3-708 and replaced nothing). All sixteen tested for PRESENCE, in **three**\n * shapes:\n *\n * - **seven** cast the value: `(res?.code as SomeError['code']) ?? 'unknown'` —\n * `dnd`, `editor`, `vcs`, `mounts` (×3), `secrets`;\n * - **seven** used the `in` operator — `openExternal`, `openRepository` (with the cast;\n * folded in R3-708) and `feed`, `netFetch`, `theme` ×3 (without it; folded in R3-817,\n * the TypeError fix disclosed above);\n * - **two** used a bare `res?.code ?? 'unknown'` onto `Error & { code?: string }` —\n * `ipc.ts`.\n *\n * Every one of them let a host sending `code: 42` surface `err.code === 42` on a field\n * declared `string`, and turned `message: 42` into the string `\"42\"`. Both now fall back,\n * to `'unknown'` and `fallbackMessage`. A deliberate tightening, pinned by\n * `protocolRefusal.test.ts` — and since this package ships no changelog, this paragraph is\n * where a consumer learns of it.\n *\n * The `ipc.ts` pair changed one more thing: their anonymous type declared `code` OPTIONAL\n * and `CodedRefusalError` requires it. No runtime difference for a missing code — the old\n * code assigned `'unknown'` exactly when the new one does (a non-string `code` falls back\n * too, as the paragraph above discloses) — but a consumer narrowing on `'code' in err`\n * can stop.\n *\n * Folding the two `in`-operator sites also removed a latent `TypeError`: `'code' in res`\n * throws on a string reply.\n *\n * ONE revision of this paragraph got that backwards, and this is the fourth attempt to\n * describe it accurately. The original text was right FOR ITS REFERENT — it named\n * `'code' in res` as a shape replaced, without saying which sites, and at the time the\n * sites it referred to were R3-708's four, two of which used that form. R3-780 then folded\n * five DIFFERENT files and inherited the sentence unchanged, so it became false in place\n * without anyone editing it. That silent shift is the likeliest reason the next revision\n * \"corrected\" it to say NO replaced site used it — which is false the other way:\n * `openExternal` and `openRepository` did.\n *\n * The mechanism is worth more than the correction, because it is repeatable. `'code' in\n * res` is **gone from `main`** since R3-817 (0.74.3) folded the last five — a reviewer who\n * greps `main` finds nothing, and this paragraph is the record of where it lived and why\n * it misread twice before. What a grep of `main` cannot show is that the\n * form was ALSO at two sites R3-708 folded. The tree that answers the question is the one\n * before the fold, `d4b07cc1^`. Read that before rewriting this paragraph again.\n *\n * It is an ASSERTION function, not a `void` one, because the inline form it replaced\n * narrowed `res` as a side effect of its `if`/`throw`: `secrets.ts` and `mounts.ts` read\n * `res.data` on the next line and stopped compiling without it. A caller that only needs\n * the throw can ignore the narrowing; one that reads the payload gets it for free. (TS\n * requires the call target to be an explicitly-typed declared name — this is why it is a\n * `function` declaration and not an arrow const.)\n *\n * R3-817 (0.74.3): the five remaining inline copies (`feed.ts`, `netFetch.ts`,\n * `theme.ts` ×3) folded onto this — removing a latent defect with them: their\n * `res && 'code' in res` guard threw `TypeError: Cannot use 'in' operator` on a\n * bare-STRING reply (a proxy error page, a relay), escaping past every `err.code`\n * branch an app wrote. This function reads `typeof r?.code === 'string'` and\n * cannot throw on any input; the TypeError path no longer exists.\n */\nexport function throwOnRefusal(res: unknown, fallbackMessage: string): asserts res is { ok: true; data?: unknown } {\n const r = res as { ok?: unknown; code?: unknown; message?: unknown } | null | undefined;\n if (r && r.ok === true) return;\n const err = new Error(typeof r?.message === 'string' ? r.message : fallbackMessage) as CodedRefusalError;\n err.code = typeof r?.code === 'string' ? r.code : 'unknown';\n throw err;\n}\n"],"mappings":";AAiLO,SAAS,eAAe,KAAc,iBAAsE;AACjH,QAAM,IAAI;AACV,MAAI,KAAK,EAAE,OAAO,KAAM;AACxB,QAAM,MAAM,IAAI,MAAM,OAAO,GAAG,YAAY,WAAW,EAAE,UAAU,eAAe;AAClF,MAAI,OAAO,OAAO,GAAG,SAAS,WAAW,EAAE,OAAO;AAClD,QAAM;AACR;","names":[]}
|
package/dist/protocolSchemes.cjs
CHANGED
|
@@ -35,6 +35,7 @@ const SCHEMES = {
|
|
|
35
35
|
[import_protocol.PROTOCOL_LAUNCH]: schemeOf(import_protocol.PROTOCOL_LAUNCH),
|
|
36
36
|
[import_protocol.PROTOCOL_LLM]: schemeOf(import_protocol.PROTOCOL_LLM),
|
|
37
37
|
[import_protocol.PROTOCOL_LOCALSTORE]: schemeOf(import_protocol.PROTOCOL_LOCALSTORE),
|
|
38
|
+
[import_protocol.PROTOCOL_OPENBUNDLE]: schemeOf(import_protocol.PROTOCOL_OPENBUNDLE),
|
|
38
39
|
[import_protocol.PROTOCOL_OPENLINK]: schemeOf(import_protocol.PROTOCOL_OPENLINK),
|
|
39
40
|
[import_protocol.PROTOCOL_OPENREPO]: schemeOf(import_protocol.PROTOCOL_OPENREPO),
|
|
40
41
|
[import_protocol.PROTOCOL_RECENTS]: schemeOf(import_protocol.PROTOCOL_RECENTS),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/protocolSchemes.ts"],"sourcesContent":["// The `protocol-<scheme>` SCHEMES, derived from the wire names.\n//\n// `protocolRequest(scheme, method, params)` takes the scheme — `'theme'` — while the\n// wire name the frame dispatches on is `'protocol-theme'`; the frame adds the prefix.\n// So the typed service wrappers cannot pass the published `PROTOCOL_*` constant\n// directly, and spelling the scheme inline would put a second, unguarded copy of the\n// name back in the tree — exactly what R3-274c removes.\n//\n// Instead the schemes are *derived* from the wire names, keyed BY the wire name:\n//\n// protocolRequest(SCHEMES[PROTOCOL_THEME], 'set', [{ theme }])\n//\n// Keying by the constant is what makes the derivation unfalsifiable — there is no\n// second place to name the family, so there is no pair to get wrong. `schemeOf`\n// returns a template-literal conditional, so each value has a literal type (`'theme'`),\n// which buys two more things:\n//\n// - a wire name that stops matching `protocol-*` stops compiling here, rather than\n// silently producing an empty scheme at runtime;\n// - `check-protocol-snapshot.mjs` resolves `SCHEMES[PROTOCOL_THEME]` through the type\n// checker exactly like a plain literal, so the call sites stay visible to the gate.\n//\n// One export, deliberately: `./*` is a public subpath, so every name added here is\n// public API forever (ways_of_working §6, additive-only).\n//\n// This module is NOT generated — the derivation is the content — so it lives outside\n// `src/generated/`.\nimport {\n PROTOCOL_ANALYTICS,\n PROTOCOL_CONTRIBUTE,\n PROTOCOL_DND,\n PROTOCOL_EDITOR,\n PROTOCOL_FEED,\n PROTOCOL_FETCH,\n PROTOCOL_IPC,\n PROTOCOL_LAUNCH,\n PROTOCOL_LLM,\n PROTOCOL_LOCALSTORE,\n PROTOCOL_OPENLINK,\n PROTOCOL_OPENREPO,\n PROTOCOL_RECENTS,\n PROTOCOL_SECRETS,\n PROTOCOL_SETTINGS,\n PROTOCOL_SPACES,\n PROTOCOL_SPACES_MODE,\n PROTOCOL_TASK,\n PROTOCOL_THEME,\n PROTOCOL_VCS,\n} from './generated/protocol';\n\nconst PREFIX = 'protocol-';\n\n/** The scheme half of a `protocol-<scheme>` wire name. */\ntype SchemeOf<N extends string> = N extends `${typeof PREFIX}${infer S}` ? S : never;\n\n/**\n * `'protocol-theme'` → `'theme'`, as a literal type.\n *\n * The cast is the only place the derivation is asserted rather than computed; the\n * `N extends \\`protocol-${string}\\`` bound is what makes it sound — a wire name that is\n * not scheme-shaped is a compile error at the call, not a `never` at runtime.\n */\nconst schemeOf = <N extends `${typeof PREFIX}${string}`>(name: N): SchemeOf<N> =>\n name.slice(PREFIX.length) as SchemeOf<N>;\n\n/** Every `protocol-*` scheme the SDK speaks, keyed by its wire name. */\nexport const SCHEMES = {\n [PROTOCOL_ANALYTICS]: schemeOf(PROTOCOL_ANALYTICS),\n [PROTOCOL_CONTRIBUTE]: schemeOf(PROTOCOL_CONTRIBUTE),\n [PROTOCOL_DND]: schemeOf(PROTOCOL_DND),\n [PROTOCOL_EDITOR]: schemeOf(PROTOCOL_EDITOR),\n [PROTOCOL_FEED]: schemeOf(PROTOCOL_FEED),\n [PROTOCOL_FETCH]: schemeOf(PROTOCOL_FETCH),\n [PROTOCOL_IPC]: schemeOf(PROTOCOL_IPC),\n [PROTOCOL_LAUNCH]: schemeOf(PROTOCOL_LAUNCH),\n [PROTOCOL_LLM]: schemeOf(PROTOCOL_LLM),\n [PROTOCOL_LOCALSTORE]: schemeOf(PROTOCOL_LOCALSTORE),\n [PROTOCOL_OPENLINK]: schemeOf(PROTOCOL_OPENLINK),\n [PROTOCOL_OPENREPO]: schemeOf(PROTOCOL_OPENREPO),\n [PROTOCOL_RECENTS]: schemeOf(PROTOCOL_RECENTS),\n [PROTOCOL_SECRETS]: schemeOf(PROTOCOL_SECRETS),\n [PROTOCOL_SETTINGS]: schemeOf(PROTOCOL_SETTINGS),\n [PROTOCOL_SPACES]: schemeOf(PROTOCOL_SPACES),\n [PROTOCOL_SPACES_MODE]: schemeOf(PROTOCOL_SPACES_MODE),\n [PROTOCOL_TASK]: schemeOf(PROTOCOL_TASK),\n [PROTOCOL_THEME]: schemeOf(PROTOCOL_THEME),\n [PROTOCOL_VCS]: schemeOf(PROTOCOL_VCS),\n} as const;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA2BA,
|
|
1
|
+
{"version":3,"sources":["../src/protocolSchemes.ts"],"sourcesContent":["// The `protocol-<scheme>` SCHEMES, derived from the wire names.\n//\n// `protocolRequest(scheme, method, params)` takes the scheme — `'theme'` — while the\n// wire name the frame dispatches on is `'protocol-theme'`; the frame adds the prefix.\n// So the typed service wrappers cannot pass the published `PROTOCOL_*` constant\n// directly, and spelling the scheme inline would put a second, unguarded copy of the\n// name back in the tree — exactly what R3-274c removes.\n//\n// Instead the schemes are *derived* from the wire names, keyed BY the wire name:\n//\n// protocolRequest(SCHEMES[PROTOCOL_THEME], 'set', [{ theme }])\n//\n// Keying by the constant is what makes the derivation unfalsifiable — there is no\n// second place to name the family, so there is no pair to get wrong. `schemeOf`\n// returns a template-literal conditional, so each value has a literal type (`'theme'`),\n// which buys two more things:\n//\n// - a wire name that stops matching `protocol-*` stops compiling here, rather than\n// silently producing an empty scheme at runtime;\n// - `check-protocol-snapshot.mjs` resolves `SCHEMES[PROTOCOL_THEME]` through the type\n// checker exactly like a plain literal, so the call sites stay visible to the gate.\n//\n// One export, deliberately: `./*` is a public subpath, so every name added here is\n// public API forever (ways_of_working §6, additive-only).\n//\n// This module is NOT generated — the derivation is the content — so it lives outside\n// `src/generated/`.\nimport {\n PROTOCOL_ANALYTICS,\n PROTOCOL_CONTRIBUTE,\n PROTOCOL_DND,\n PROTOCOL_EDITOR,\n PROTOCOL_FEED,\n PROTOCOL_FETCH,\n PROTOCOL_IPC,\n PROTOCOL_LAUNCH,\n PROTOCOL_LLM,\n PROTOCOL_LOCALSTORE,\n PROTOCOL_OPENBUNDLE,\n PROTOCOL_OPENLINK,\n PROTOCOL_OPENREPO,\n PROTOCOL_RECENTS,\n PROTOCOL_SECRETS,\n PROTOCOL_SETTINGS,\n PROTOCOL_SPACES,\n PROTOCOL_SPACES_MODE,\n PROTOCOL_TASK,\n PROTOCOL_THEME,\n PROTOCOL_VCS,\n} from './generated/protocol';\n\nconst PREFIX = 'protocol-';\n\n/** The scheme half of a `protocol-<scheme>` wire name. */\ntype SchemeOf<N extends string> = N extends `${typeof PREFIX}${infer S}` ? S : never;\n\n/**\n * `'protocol-theme'` → `'theme'`, as a literal type.\n *\n * The cast is the only place the derivation is asserted rather than computed; the\n * `N extends \\`protocol-${string}\\`` bound is what makes it sound — a wire name that is\n * not scheme-shaped is a compile error at the call, not a `never` at runtime.\n */\nconst schemeOf = <N extends `${typeof PREFIX}${string}`>(name: N): SchemeOf<N> =>\n name.slice(PREFIX.length) as SchemeOf<N>;\n\n/** Every `protocol-*` scheme the SDK speaks, keyed by its wire name. */\nexport const SCHEMES = {\n [PROTOCOL_ANALYTICS]: schemeOf(PROTOCOL_ANALYTICS),\n [PROTOCOL_CONTRIBUTE]: schemeOf(PROTOCOL_CONTRIBUTE),\n [PROTOCOL_DND]: schemeOf(PROTOCOL_DND),\n [PROTOCOL_EDITOR]: schemeOf(PROTOCOL_EDITOR),\n [PROTOCOL_FEED]: schemeOf(PROTOCOL_FEED),\n [PROTOCOL_FETCH]: schemeOf(PROTOCOL_FETCH),\n [PROTOCOL_IPC]: schemeOf(PROTOCOL_IPC),\n [PROTOCOL_LAUNCH]: schemeOf(PROTOCOL_LAUNCH),\n [PROTOCOL_LLM]: schemeOf(PROTOCOL_LLM),\n [PROTOCOL_LOCALSTORE]: schemeOf(PROTOCOL_LOCALSTORE),\n [PROTOCOL_OPENBUNDLE]: schemeOf(PROTOCOL_OPENBUNDLE),\n [PROTOCOL_OPENLINK]: schemeOf(PROTOCOL_OPENLINK),\n [PROTOCOL_OPENREPO]: schemeOf(PROTOCOL_OPENREPO),\n [PROTOCOL_RECENTS]: schemeOf(PROTOCOL_RECENTS),\n [PROTOCOL_SECRETS]: schemeOf(PROTOCOL_SECRETS),\n [PROTOCOL_SETTINGS]: schemeOf(PROTOCOL_SETTINGS),\n [PROTOCOL_SPACES]: schemeOf(PROTOCOL_SPACES),\n [PROTOCOL_SPACES_MODE]: schemeOf(PROTOCOL_SPACES_MODE),\n [PROTOCOL_TASK]: schemeOf(PROTOCOL_TASK),\n [PROTOCOL_THEME]: schemeOf(PROTOCOL_THEME),\n [PROTOCOL_VCS]: schemeOf(PROTOCOL_VCS),\n} as const;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA2BA,sBAsBO;AAEP,MAAM,SAAS;AAYf,MAAM,WAAW,CAAwC,SACvD,KAAK,MAAM,OAAO,MAAM;AAGnB,MAAM,UAAU;AAAA,EACrB,CAAC,kCAAkB,GAAG,SAAS,kCAAkB;AAAA,EACjD,CAAC,mCAAmB,GAAG,SAAS,mCAAmB;AAAA,EACnD,CAAC,4BAAY,GAAG,SAAS,4BAAY;AAAA,EACrC,CAAC,+BAAe,GAAG,SAAS,+BAAe;AAAA,EAC3C,CAAC,6BAAa,GAAG,SAAS,6BAAa;AAAA,EACvC,CAAC,8BAAc,GAAG,SAAS,8BAAc;AAAA,EACzC,CAAC,4BAAY,GAAG,SAAS,4BAAY;AAAA,EACrC,CAAC,+BAAe,GAAG,SAAS,+BAAe;AAAA,EAC3C,CAAC,4BAAY,GAAG,SAAS,4BAAY;AAAA,EACrC,CAAC,mCAAmB,GAAG,SAAS,mCAAmB;AAAA,EACnD,CAAC,mCAAmB,GAAG,SAAS,mCAAmB;AAAA,EACnD,CAAC,iCAAiB,GAAG,SAAS,iCAAiB;AAAA,EAC/C,CAAC,iCAAiB,GAAG,SAAS,iCAAiB;AAAA,EAC/C,CAAC,gCAAgB,GAAG,SAAS,gCAAgB;AAAA,EAC7C,CAAC,gCAAgB,GAAG,SAAS,gCAAgB;AAAA,EAC7C,CAAC,iCAAiB,GAAG,SAAS,iCAAiB;AAAA,EAC/C,CAAC,+BAAe,GAAG,SAAS,+BAAe;AAAA,EAC3C,CAAC,oCAAoB,GAAG,SAAS,oCAAoB;AAAA,EACrD,CAAC,6BAAa,GAAG,SAAS,6BAAa;AAAA,EACvC,CAAC,8BAAc,GAAG,SAAS,8BAAc;AAAA,EACzC,CAAC,4BAAY,GAAG,SAAS,4BAAY;AACvC;","names":[]}
|
|
@@ -10,6 +10,7 @@ declare const SCHEMES: {
|
|
|
10
10
|
readonly "protocol-launch": "launch";
|
|
11
11
|
readonly "protocol-llm": "llm";
|
|
12
12
|
readonly "protocol-localstore": "localstore";
|
|
13
|
+
readonly "protocol-openbundle": "openbundle";
|
|
13
14
|
readonly "protocol-openlink": "openlink";
|
|
14
15
|
readonly "protocol-openrepo": "openrepo";
|
|
15
16
|
readonly "protocol-recents": "recents";
|
|
@@ -10,6 +10,7 @@ declare const SCHEMES: {
|
|
|
10
10
|
readonly "protocol-launch": "launch";
|
|
11
11
|
readonly "protocol-llm": "llm";
|
|
12
12
|
readonly "protocol-localstore": "localstore";
|
|
13
|
+
readonly "protocol-openbundle": "openbundle";
|
|
13
14
|
readonly "protocol-openlink": "openlink";
|
|
14
15
|
readonly "protocol-openrepo": "openrepo";
|
|
15
16
|
readonly "protocol-recents": "recents";
|
package/dist/protocolSchemes.js
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
PROTOCOL_LAUNCH,
|
|
11
11
|
PROTOCOL_LLM,
|
|
12
12
|
PROTOCOL_LOCALSTORE,
|
|
13
|
+
PROTOCOL_OPENBUNDLE,
|
|
13
14
|
PROTOCOL_OPENLINK,
|
|
14
15
|
PROTOCOL_OPENREPO,
|
|
15
16
|
PROTOCOL_RECENTS,
|
|
@@ -34,6 +35,7 @@ const SCHEMES = {
|
|
|
34
35
|
[PROTOCOL_LAUNCH]: schemeOf(PROTOCOL_LAUNCH),
|
|
35
36
|
[PROTOCOL_LLM]: schemeOf(PROTOCOL_LLM),
|
|
36
37
|
[PROTOCOL_LOCALSTORE]: schemeOf(PROTOCOL_LOCALSTORE),
|
|
38
|
+
[PROTOCOL_OPENBUNDLE]: schemeOf(PROTOCOL_OPENBUNDLE),
|
|
37
39
|
[PROTOCOL_OPENLINK]: schemeOf(PROTOCOL_OPENLINK),
|
|
38
40
|
[PROTOCOL_OPENREPO]: schemeOf(PROTOCOL_OPENREPO),
|
|
39
41
|
[PROTOCOL_RECENTS]: schemeOf(PROTOCOL_RECENTS),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/protocolSchemes.ts"],"sourcesContent":["// The `protocol-<scheme>` SCHEMES, derived from the wire names.\n//\n// `protocolRequest(scheme, method, params)` takes the scheme — `'theme'` — while the\n// wire name the frame dispatches on is `'protocol-theme'`; the frame adds the prefix.\n// So the typed service wrappers cannot pass the published `PROTOCOL_*` constant\n// directly, and spelling the scheme inline would put a second, unguarded copy of the\n// name back in the tree — exactly what R3-274c removes.\n//\n// Instead the schemes are *derived* from the wire names, keyed BY the wire name:\n//\n// protocolRequest(SCHEMES[PROTOCOL_THEME], 'set', [{ theme }])\n//\n// Keying by the constant is what makes the derivation unfalsifiable — there is no\n// second place to name the family, so there is no pair to get wrong. `schemeOf`\n// returns a template-literal conditional, so each value has a literal type (`'theme'`),\n// which buys two more things:\n//\n// - a wire name that stops matching `protocol-*` stops compiling here, rather than\n// silently producing an empty scheme at runtime;\n// - `check-protocol-snapshot.mjs` resolves `SCHEMES[PROTOCOL_THEME]` through the type\n// checker exactly like a plain literal, so the call sites stay visible to the gate.\n//\n// One export, deliberately: `./*` is a public subpath, so every name added here is\n// public API forever (ways_of_working §6, additive-only).\n//\n// This module is NOT generated — the derivation is the content — so it lives outside\n// `src/generated/`.\nimport {\n PROTOCOL_ANALYTICS,\n PROTOCOL_CONTRIBUTE,\n PROTOCOL_DND,\n PROTOCOL_EDITOR,\n PROTOCOL_FEED,\n PROTOCOL_FETCH,\n PROTOCOL_IPC,\n PROTOCOL_LAUNCH,\n PROTOCOL_LLM,\n PROTOCOL_LOCALSTORE,\n PROTOCOL_OPENLINK,\n PROTOCOL_OPENREPO,\n PROTOCOL_RECENTS,\n PROTOCOL_SECRETS,\n PROTOCOL_SETTINGS,\n PROTOCOL_SPACES,\n PROTOCOL_SPACES_MODE,\n PROTOCOL_TASK,\n PROTOCOL_THEME,\n PROTOCOL_VCS,\n} from './generated/protocol';\n\nconst PREFIX = 'protocol-';\n\n/** The scheme half of a `protocol-<scheme>` wire name. */\ntype SchemeOf<N extends string> = N extends `${typeof PREFIX}${infer S}` ? S : never;\n\n/**\n * `'protocol-theme'` → `'theme'`, as a literal type.\n *\n * The cast is the only place the derivation is asserted rather than computed; the\n * `N extends \\`protocol-${string}\\`` bound is what makes it sound — a wire name that is\n * not scheme-shaped is a compile error at the call, not a `never` at runtime.\n */\nconst schemeOf = <N extends `${typeof PREFIX}${string}`>(name: N): SchemeOf<N> =>\n name.slice(PREFIX.length) as SchemeOf<N>;\n\n/** Every `protocol-*` scheme the SDK speaks, keyed by its wire name. */\nexport const SCHEMES = {\n [PROTOCOL_ANALYTICS]: schemeOf(PROTOCOL_ANALYTICS),\n [PROTOCOL_CONTRIBUTE]: schemeOf(PROTOCOL_CONTRIBUTE),\n [PROTOCOL_DND]: schemeOf(PROTOCOL_DND),\n [PROTOCOL_EDITOR]: schemeOf(PROTOCOL_EDITOR),\n [PROTOCOL_FEED]: schemeOf(PROTOCOL_FEED),\n [PROTOCOL_FETCH]: schemeOf(PROTOCOL_FETCH),\n [PROTOCOL_IPC]: schemeOf(PROTOCOL_IPC),\n [PROTOCOL_LAUNCH]: schemeOf(PROTOCOL_LAUNCH),\n [PROTOCOL_LLM]: schemeOf(PROTOCOL_LLM),\n [PROTOCOL_LOCALSTORE]: schemeOf(PROTOCOL_LOCALSTORE),\n [PROTOCOL_OPENLINK]: schemeOf(PROTOCOL_OPENLINK),\n [PROTOCOL_OPENREPO]: schemeOf(PROTOCOL_OPENREPO),\n [PROTOCOL_RECENTS]: schemeOf(PROTOCOL_RECENTS),\n [PROTOCOL_SECRETS]: schemeOf(PROTOCOL_SECRETS),\n [PROTOCOL_SETTINGS]: schemeOf(PROTOCOL_SETTINGS),\n [PROTOCOL_SPACES]: schemeOf(PROTOCOL_SPACES),\n [PROTOCOL_SPACES_MODE]: schemeOf(PROTOCOL_SPACES_MODE),\n [PROTOCOL_TASK]: schemeOf(PROTOCOL_TASK),\n [PROTOCOL_THEME]: schemeOf(PROTOCOL_THEME),\n [PROTOCOL_VCS]: schemeOf(PROTOCOL_VCS),\n} as const;\n"],"mappings":";AA2BA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,MAAM,SAAS;AAYf,MAAM,WAAW,CAAwC,SACvD,KAAK,MAAM,OAAO,MAAM;AAGnB,MAAM,UAAU;AAAA,EACrB,CAAC,kBAAkB,GAAG,SAAS,kBAAkB;AAAA,EACjD,CAAC,mBAAmB,GAAG,SAAS,mBAAmB;AAAA,EACnD,CAAC,YAAY,GAAG,SAAS,YAAY;AAAA,EACrC,CAAC,eAAe,GAAG,SAAS,eAAe;AAAA,EAC3C,CAAC,aAAa,GAAG,SAAS,aAAa;AAAA,EACvC,CAAC,cAAc,GAAG,SAAS,cAAc;AAAA,EACzC,CAAC,YAAY,GAAG,SAAS,YAAY;AAAA,EACrC,CAAC,eAAe,GAAG,SAAS,eAAe;AAAA,EAC3C,CAAC,YAAY,GAAG,SAAS,YAAY;AAAA,EACrC,CAAC,mBAAmB,GAAG,SAAS,mBAAmB;AAAA,EACnD,CAAC,iBAAiB,GAAG,SAAS,iBAAiB;AAAA,EAC/C,CAAC,iBAAiB,GAAG,SAAS,iBAAiB;AAAA,EAC/C,CAAC,gBAAgB,GAAG,SAAS,gBAAgB;AAAA,EAC7C,CAAC,gBAAgB,GAAG,SAAS,gBAAgB;AAAA,EAC7C,CAAC,iBAAiB,GAAG,SAAS,iBAAiB;AAAA,EAC/C,CAAC,eAAe,GAAG,SAAS,eAAe;AAAA,EAC3C,CAAC,oBAAoB,GAAG,SAAS,oBAAoB;AAAA,EACrD,CAAC,aAAa,GAAG,SAAS,aAAa;AAAA,EACvC,CAAC,cAAc,GAAG,SAAS,cAAc;AAAA,EACzC,CAAC,YAAY,GAAG,SAAS,YAAY;AACvC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/protocolSchemes.ts"],"sourcesContent":["// The `protocol-<scheme>` SCHEMES, derived from the wire names.\n//\n// `protocolRequest(scheme, method, params)` takes the scheme — `'theme'` — while the\n// wire name the frame dispatches on is `'protocol-theme'`; the frame adds the prefix.\n// So the typed service wrappers cannot pass the published `PROTOCOL_*` constant\n// directly, and spelling the scheme inline would put a second, unguarded copy of the\n// name back in the tree — exactly what R3-274c removes.\n//\n// Instead the schemes are *derived* from the wire names, keyed BY the wire name:\n//\n// protocolRequest(SCHEMES[PROTOCOL_THEME], 'set', [{ theme }])\n//\n// Keying by the constant is what makes the derivation unfalsifiable — there is no\n// second place to name the family, so there is no pair to get wrong. `schemeOf`\n// returns a template-literal conditional, so each value has a literal type (`'theme'`),\n// which buys two more things:\n//\n// - a wire name that stops matching `protocol-*` stops compiling here, rather than\n// silently producing an empty scheme at runtime;\n// - `check-protocol-snapshot.mjs` resolves `SCHEMES[PROTOCOL_THEME]` through the type\n// checker exactly like a plain literal, so the call sites stay visible to the gate.\n//\n// One export, deliberately: `./*` is a public subpath, so every name added here is\n// public API forever (ways_of_working §6, additive-only).\n//\n// This module is NOT generated — the derivation is the content — so it lives outside\n// `src/generated/`.\nimport {\n PROTOCOL_ANALYTICS,\n PROTOCOL_CONTRIBUTE,\n PROTOCOL_DND,\n PROTOCOL_EDITOR,\n PROTOCOL_FEED,\n PROTOCOL_FETCH,\n PROTOCOL_IPC,\n PROTOCOL_LAUNCH,\n PROTOCOL_LLM,\n PROTOCOL_LOCALSTORE,\n PROTOCOL_OPENBUNDLE,\n PROTOCOL_OPENLINK,\n PROTOCOL_OPENREPO,\n PROTOCOL_RECENTS,\n PROTOCOL_SECRETS,\n PROTOCOL_SETTINGS,\n PROTOCOL_SPACES,\n PROTOCOL_SPACES_MODE,\n PROTOCOL_TASK,\n PROTOCOL_THEME,\n PROTOCOL_VCS,\n} from './generated/protocol';\n\nconst PREFIX = 'protocol-';\n\n/** The scheme half of a `protocol-<scheme>` wire name. */\ntype SchemeOf<N extends string> = N extends `${typeof PREFIX}${infer S}` ? S : never;\n\n/**\n * `'protocol-theme'` → `'theme'`, as a literal type.\n *\n * The cast is the only place the derivation is asserted rather than computed; the\n * `N extends \\`protocol-${string}\\`` bound is what makes it sound — a wire name that is\n * not scheme-shaped is a compile error at the call, not a `never` at runtime.\n */\nconst schemeOf = <N extends `${typeof PREFIX}${string}`>(name: N): SchemeOf<N> =>\n name.slice(PREFIX.length) as SchemeOf<N>;\n\n/** Every `protocol-*` scheme the SDK speaks, keyed by its wire name. */\nexport const SCHEMES = {\n [PROTOCOL_ANALYTICS]: schemeOf(PROTOCOL_ANALYTICS),\n [PROTOCOL_CONTRIBUTE]: schemeOf(PROTOCOL_CONTRIBUTE),\n [PROTOCOL_DND]: schemeOf(PROTOCOL_DND),\n [PROTOCOL_EDITOR]: schemeOf(PROTOCOL_EDITOR),\n [PROTOCOL_FEED]: schemeOf(PROTOCOL_FEED),\n [PROTOCOL_FETCH]: schemeOf(PROTOCOL_FETCH),\n [PROTOCOL_IPC]: schemeOf(PROTOCOL_IPC),\n [PROTOCOL_LAUNCH]: schemeOf(PROTOCOL_LAUNCH),\n [PROTOCOL_LLM]: schemeOf(PROTOCOL_LLM),\n [PROTOCOL_LOCALSTORE]: schemeOf(PROTOCOL_LOCALSTORE),\n [PROTOCOL_OPENBUNDLE]: schemeOf(PROTOCOL_OPENBUNDLE),\n [PROTOCOL_OPENLINK]: schemeOf(PROTOCOL_OPENLINK),\n [PROTOCOL_OPENREPO]: schemeOf(PROTOCOL_OPENREPO),\n [PROTOCOL_RECENTS]: schemeOf(PROTOCOL_RECENTS),\n [PROTOCOL_SECRETS]: schemeOf(PROTOCOL_SECRETS),\n [PROTOCOL_SETTINGS]: schemeOf(PROTOCOL_SETTINGS),\n [PROTOCOL_SPACES]: schemeOf(PROTOCOL_SPACES),\n [PROTOCOL_SPACES_MODE]: schemeOf(PROTOCOL_SPACES_MODE),\n [PROTOCOL_TASK]: schemeOf(PROTOCOL_TASK),\n [PROTOCOL_THEME]: schemeOf(PROTOCOL_THEME),\n [PROTOCOL_VCS]: schemeOf(PROTOCOL_VCS),\n} as const;\n"],"mappings":";AA2BA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,MAAM,SAAS;AAYf,MAAM,WAAW,CAAwC,SACvD,KAAK,MAAM,OAAO,MAAM;AAGnB,MAAM,UAAU;AAAA,EACrB,CAAC,kBAAkB,GAAG,SAAS,kBAAkB;AAAA,EACjD,CAAC,mBAAmB,GAAG,SAAS,mBAAmB;AAAA,EACnD,CAAC,YAAY,GAAG,SAAS,YAAY;AAAA,EACrC,CAAC,eAAe,GAAG,SAAS,eAAe;AAAA,EAC3C,CAAC,aAAa,GAAG,SAAS,aAAa;AAAA,EACvC,CAAC,cAAc,GAAG,SAAS,cAAc;AAAA,EACzC,CAAC,YAAY,GAAG,SAAS,YAAY;AAAA,EACrC,CAAC,eAAe,GAAG,SAAS,eAAe;AAAA,EAC3C,CAAC,YAAY,GAAG,SAAS,YAAY;AAAA,EACrC,CAAC,mBAAmB,GAAG,SAAS,mBAAmB;AAAA,EACnD,CAAC,mBAAmB,GAAG,SAAS,mBAAmB;AAAA,EACnD,CAAC,iBAAiB,GAAG,SAAS,iBAAiB;AAAA,EAC/C,CAAC,iBAAiB,GAAG,SAAS,iBAAiB;AAAA,EAC/C,CAAC,gBAAgB,GAAG,SAAS,gBAAgB;AAAA,EAC7C,CAAC,gBAAgB,GAAG,SAAS,gBAAgB;AAAA,EAC7C,CAAC,iBAAiB,GAAG,SAAS,iBAAiB;AAAA,EAC/C,CAAC,eAAe,GAAG,SAAS,eAAe;AAAA,EAC3C,CAAC,oBAAoB,GAAG,SAAS,oBAAoB;AAAA,EACrD,CAAC,aAAa,GAAG,SAAS,aAAa;AAAA,EACvC,CAAC,cAAc,GAAG,SAAS,cAAc;AAAA,EACzC,CAAC,YAAY,GAAG,SAAS,YAAY;AACvC;","names":[]}
|
package/dist/vcs.cjs
CHANGED
|
@@ -18,6 +18,13 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var vcs_exports = {};
|
|
20
20
|
__export(vcs_exports, {
|
|
21
|
+
REF_KINDS: () => REF_KINDS,
|
|
22
|
+
bundleCanWrite: () => bundleCanWrite,
|
|
23
|
+
bundleDiffPaths: () => bundleDiffPaths,
|
|
24
|
+
bundleHead: () => bundleHead,
|
|
25
|
+
bundleIsAncestor: () => bundleIsAncestor,
|
|
26
|
+
bundleLog: () => bundleLog,
|
|
27
|
+
bundleRead: () => bundleRead,
|
|
21
28
|
getVcsState: () => getVcsState,
|
|
22
29
|
onVcsStateChange: () => onVcsStateChange,
|
|
23
30
|
refreshDiff: () => refreshDiff,
|
|
@@ -26,6 +33,7 @@ __export(vcs_exports, {
|
|
|
26
33
|
useVcsState: () => useVcsState
|
|
27
34
|
});
|
|
28
35
|
module.exports = __toCommonJS(vcs_exports);
|
|
36
|
+
var import_catalog = require("./catalog");
|
|
29
37
|
var import_pushChannel = require("./pushChannel");
|
|
30
38
|
var import_protocolRefusal = require("./protocolRefusal");
|
|
31
39
|
var import_sandboxUtils = require("./sandboxUtils");
|
|
@@ -48,6 +56,47 @@ const parseAgentSession = (v) => {
|
|
|
48
56
|
...s.updatedAt !== void 0 ? { updatedAt: s.updatedAt } : {}
|
|
49
57
|
};
|
|
50
58
|
};
|
|
59
|
+
const isStringArray = (v) => Array.isArray(v) && v.every((x) => typeof x === "string");
|
|
60
|
+
const isDiffWarningArray = (v) => Array.isArray(v) && v.every(
|
|
61
|
+
(w) => !!w && typeof w === "object" && typeof w.kind === "string" && typeof w.path === "string" && typeof w.message === "string"
|
|
62
|
+
);
|
|
63
|
+
const REF_KINDS = /* @__PURE__ */ new Set(["branch", "tag", "commit"]);
|
|
64
|
+
const parseTarget = (v) => {
|
|
65
|
+
if (v === null) return null;
|
|
66
|
+
if (!v || typeof v !== "object") return void 0;
|
|
67
|
+
const t = v;
|
|
68
|
+
if (typeof t.namespace !== "string" || typeof t.repository !== "string" || typeof t.ref !== "string" || typeof t.refKind !== "string" || !REF_KINDS.has(t.refKind) || !(t.commitSha === null || typeof t.commitSha === "string" && t.commitSha !== "") || !(t.defaultBranch === null || typeof t.defaultBranch === "string")) {
|
|
69
|
+
return void 0;
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
namespace: t.namespace,
|
|
73
|
+
repository: t.repository,
|
|
74
|
+
ref: t.ref,
|
|
75
|
+
refKind: t.refKind,
|
|
76
|
+
commitSha: t.commitSha,
|
|
77
|
+
defaultBranch: t.defaultBranch
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
const parseVcsFacts = (msg) => {
|
|
81
|
+
const out = {};
|
|
82
|
+
const target = parseTarget(msg.target);
|
|
83
|
+
if (target !== void 0) out.target = target;
|
|
84
|
+
const openPR = msg.openPR;
|
|
85
|
+
if (openPR === null) out.openPR = null;
|
|
86
|
+
else if (openPR && typeof openPR === "object" && typeof openPR.number === "number" && Number.isFinite(openPR.number) && typeof openPR.url === "string") {
|
|
87
|
+
out.openPR = { number: openPR.number, url: openPR.url };
|
|
88
|
+
}
|
|
89
|
+
if (msg.defaultSaveMode === "pr" || msg.defaultSaveMode === "direct") out.defaultSaveMode = msg.defaultSaveMode;
|
|
90
|
+
if (msg.canPushUpstream === null || typeof msg.canPushUpstream === "boolean")
|
|
91
|
+
out.canPushUpstream = msg.canPushUpstream;
|
|
92
|
+
if (typeof msg.manifestMissing === "boolean") out.manifestMissing = msg.manifestMissing;
|
|
93
|
+
if (msg.diffError === null || typeof msg.diffError === "string") out.diffError = msg.diffError;
|
|
94
|
+
if (isDiffWarningArray(msg.diffWarnings))
|
|
95
|
+
out.diffWarnings = msg.diffWarnings.map(({ kind, path, message }) => ({ kind, path, message }));
|
|
96
|
+
if (isStringArray(msg.excludedPhantoms)) out.excludedPhantoms = msg.excludedPhantoms;
|
|
97
|
+
if (typeof msg.manifestTruncated === "boolean") out.manifestTruncated = msg.manifestTruncated;
|
|
98
|
+
return out;
|
|
99
|
+
};
|
|
51
100
|
const channel = (0, import_pushChannel.createPushChannel)({
|
|
52
101
|
pushType: import_protocol.VCS_STATE,
|
|
53
102
|
requestType: import_protocol.REQUEST_VCS_STATE,
|
|
@@ -62,7 +111,20 @@ const channel = (0, import_pushChannel.createPushChannel)({
|
|
|
62
111
|
branch,
|
|
63
112
|
prs,
|
|
64
113
|
diffLoading: msg.diffLoading === true,
|
|
65
|
-
...agentSession ? { agentSession } : {}
|
|
114
|
+
...agentSession ? { agentSession } : {},
|
|
115
|
+
// Each key is named here, not inside the helper, so the protocol snapshot's
|
|
116
|
+
// `reads` records every field this parser consumes.
|
|
117
|
+
...parseVcsFacts({
|
|
118
|
+
target: msg.target,
|
|
119
|
+
openPR: msg.openPR,
|
|
120
|
+
defaultSaveMode: msg.defaultSaveMode,
|
|
121
|
+
canPushUpstream: msg.canPushUpstream,
|
|
122
|
+
manifestMissing: msg.manifestMissing,
|
|
123
|
+
diffError: msg.diffError,
|
|
124
|
+
diffWarnings: msg.diffWarnings,
|
|
125
|
+
excludedPhantoms: msg.excludedPhantoms,
|
|
126
|
+
manifestTruncated: msg.manifestTruncated
|
|
127
|
+
})
|
|
66
128
|
};
|
|
67
129
|
}
|
|
68
130
|
});
|
|
@@ -76,8 +138,51 @@ const vcsRequest = async (method, arg = {}) => {
|
|
|
76
138
|
const refreshDiff = () => vcsRequest("refreshDiff");
|
|
77
139
|
const refreshPRs = () => vcsRequest("refreshPRs");
|
|
78
140
|
const resetWorkingTree = () => vcsRequest("reset", { confirm: true });
|
|
141
|
+
const fromBase64 = (s) => {
|
|
142
|
+
const bin = atob(s);
|
|
143
|
+
const out = new Uint8Array(bin.length);
|
|
144
|
+
for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);
|
|
145
|
+
return out;
|
|
146
|
+
};
|
|
147
|
+
const bundleHead = async (mountId) => {
|
|
148
|
+
const params = { mountId };
|
|
149
|
+
return (await (0, import_catalog.invoke)("vcs:bundleHead", params)).sha;
|
|
150
|
+
};
|
|
151
|
+
const bundleLog = async (mountId, opts = {}) => {
|
|
152
|
+
const params = { mountId };
|
|
153
|
+
if (opts.since !== void 0) params.since = opts.since;
|
|
154
|
+
if (opts.until !== void 0) params.until = opts.until;
|
|
155
|
+
if (opts.max !== void 0) params.max = opts.max;
|
|
156
|
+
return (await (0, import_catalog.invoke)("vcs:bundleLog", params)).commits;
|
|
157
|
+
};
|
|
158
|
+
const bundleIsAncestor = async (mountId, a, b) => {
|
|
159
|
+
const params = { mountId, a, b };
|
|
160
|
+
return (await (0, import_catalog.invoke)("vcs:bundleIsAncestor", params)).ancestor;
|
|
161
|
+
};
|
|
162
|
+
const bundleRead = async (mountId, sha, paths) => {
|
|
163
|
+
const params = { mountId, sha, paths };
|
|
164
|
+
const { files } = await (0, import_catalog.invoke)("vcs:bundleRead", params);
|
|
165
|
+
const out = {};
|
|
166
|
+
for (const [path, b64] of Object.entries(files)) out[path] = b64 === null ? null : fromBase64(b64);
|
|
167
|
+
return out;
|
|
168
|
+
};
|
|
169
|
+
const bundleDiffPaths = async (mountId, from, to) => {
|
|
170
|
+
const params = { mountId, from, to };
|
|
171
|
+
return (await (0, import_catalog.invoke)("vcs:bundleDiffPaths", params)).paths;
|
|
172
|
+
};
|
|
173
|
+
const bundleCanWrite = async (mountId) => {
|
|
174
|
+
const params = { mountId };
|
|
175
|
+
return (await (0, import_catalog.invoke)("vcs:bundleCanWrite", params)).canWrite;
|
|
176
|
+
};
|
|
79
177
|
// Annotate the CommonJS export names for ESM import in node:
|
|
80
178
|
0 && (module.exports = {
|
|
179
|
+
REF_KINDS,
|
|
180
|
+
bundleCanWrite,
|
|
181
|
+
bundleDiffPaths,
|
|
182
|
+
bundleHead,
|
|
183
|
+
bundleIsAncestor,
|
|
184
|
+
bundleLog,
|
|
185
|
+
bundleRead,
|
|
81
186
|
getVcsState,
|
|
82
187
|
onVcsStateChange,
|
|
83
188
|
refreshDiff,
|