@wenathlan/extension 1.1.65 → 1.1.66

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.
Files changed (46) hide show
  1. package/README.md +4 -3
  2. package/dist/attentionfeed.d.ts +74 -0
  3. package/dist/attentionfeed.d.ts.map +1 -0
  4. package/dist/backgroundruns.d.ts +71 -0
  5. package/dist/backgroundruns.d.ts.map +1 -0
  6. package/dist/flowlibrary.d.ts +147 -0
  7. package/dist/flowlibrary.d.ts.map +1 -0
  8. package/dist/index.d.ts +7 -1
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +686 -3
  11. package/dist/index.js.map +4 -4
  12. package/dist/memory.d.ts +67 -1
  13. package/dist/memory.d.ts.map +1 -1
  14. package/dist/outputcompare.d.ts +68 -0
  15. package/dist/outputcompare.d.ts.map +1 -0
  16. package/dist/policy.d.ts +63 -0
  17. package/dist/policy.d.ts.map +1 -1
  18. package/dist/protocol.d.ts +167 -0
  19. package/dist/protocol.d.ts.map +1 -1
  20. package/dist/runreplay.d.ts +53 -0
  21. package/dist/runreplay.d.ts.map +1 -0
  22. package/dist/surfaces.d.ts +2 -2
  23. package/dist/surfaces.d.ts.map +1 -1
  24. package/dist/syncbridge.d.ts +80 -0
  25. package/dist/syncbridge.d.ts.map +1 -0
  26. package/dist/types.d.ts +194 -3
  27. package/dist/types.d.ts.map +1 -1
  28. package/dist/version.d.ts +1 -1
  29. package/extension/dist/background.js +944 -6
  30. package/extension/dist/background.js.map +4 -4
  31. package/extension/dist/dashboardpage.html +2 -0
  32. package/extension/dist/dashboardpage.js +90 -0
  33. package/extension/dist/dashboardpage.js.map +2 -2
  34. package/extension/dist/manifest.json +1 -1
  35. package/extension/dist/optionspage.html +1 -0
  36. package/extension/dist/optionspage.js +73 -0
  37. package/extension/dist/optionspage.js.map +2 -2
  38. package/extension/dist/pagebridge.js.map +1 -1
  39. package/extension/dist/popup.html +1 -1
  40. package/extension/dist/popup.js +48 -36
  41. package/extension/dist/popup.js.map +2 -2
  42. package/extension/dist/sidepanel.html +1 -1
  43. package/extension/dist/sidepanel.js +135 -0
  44. package/extension/dist/sidepanel.js.map +2 -2
  45. package/extension/manifest.json +1 -1
  46. package/package.json +1 -1
@@ -5221,6 +5221,111 @@ var sessionmemory = class {
5221
5221
  async addnotificationhistory(payload) {
5222
5222
  await this.adapter.set("notificationhistory", [payload, ...await this.getnotificationhistory()]);
5223
5223
  }
5224
+ /**
5225
+ * Ecosystem stores of the 1.1.66 family live here, scoped per profile workspace: the flowlibrary entries with their manifest digests and provenance, the library install and removal events, the syncbridge hooks with their conflict records, the attentionfeed entries with their configurable retention, the runreplay cursors per viewed run, the outputcompare sessions with their metric results and the background run queue state for restart recovery.
5226
+ * The flowlibrary store deduplicates entries by manifest digest, every entry carries its publisher provenance, and the manifest list exports for audit; the memory adapter seam stays the documented marketplace backend boundary because a future remote registry replaces the adapter only.
5227
+ */
5228
+ /** Returns every flowlibrary entry of the profile workspace, newest first. */
5229
+ async getflowlibrary() {
5230
+ return await this.adapter.get("flowlibrary") ?? [];
5231
+ }
5232
+ /** Replaces the flowlibrary entries of the profile workspace. */
5233
+ async setflowlibrary(entries) {
5234
+ return this.adapter.set("flowlibrary", entries);
5235
+ }
5236
+ /** Adds one flowlibrary entry deduplicated by manifest digest: an entry whose digest already exists replaces its predecessor while its provenance keeps both records. */
5237
+ async addlibraryentry(entry) {
5238
+ const entries = await this.getflowlibrary();
5239
+ const deduped = entries.filter((candidate) => candidate.digest !== entry.digest);
5240
+ await this.setflowlibrary([entry, ...deduped]);
5241
+ return [entry, ...deduped];
5242
+ }
5243
+ /** Removes one flowlibrary entry by its id while the library events keep their record for the audit trail. */
5244
+ async removelibraryentry(entryid) {
5245
+ await this.setflowlibrary((await this.getflowlibrary()).filter((candidate) => candidate.id !== entryid));
5246
+ }
5247
+ /** Returns every library install, update and removal event, newest first. */
5248
+ async getlibraryevents() {
5249
+ return await this.adapter.get("libraryevents") ?? [];
5250
+ }
5251
+ /** Records one library lifecycle event beside the flowlibrary store. */
5252
+ async addlibraryevent(event) {
5253
+ await this.adapter.set("libraryevents", [event, ...await this.getlibraryevents()]);
5254
+ }
5255
+ /** Exports the manifest list of the flowlibrary for audit: one row per entry with its digest, publisher, version, state and provenance and no step payload. */
5256
+ async exportlibrarymanifests() {
5257
+ return (await this.getflowlibrary()).map((entry) => ({ id: entry.id, title: entry.manifest.title, publisher: entry.manifest.publisher, version: entry.manifest.version, digest: entry.digest, state: entry.state, provenance: entry.provenance, addedat: entry.addedat }));
5258
+ }
5259
+ /** Returns every syncbridge hook of the profile workspace; every hook keeps its explicit opt in with no default on. */
5260
+ async getsyncbridgehooks() {
5261
+ return await this.adapter.get("syncbridgehooks") ?? [];
5262
+ }
5263
+ /** Replaces the syncbridge hooks of the profile workspace. */
5264
+ async setsyncbridgehooks(hooks) {
5265
+ return this.adapter.set("syncbridgehooks", hooks);
5266
+ }
5267
+ /** Returns every syncbridge conflict record, newest first, with both versions instead of a silent overwrite. */
5268
+ async getsyncbridgeconflicts() {
5269
+ return await this.adapter.get("syncbridgeconflicts") ?? [];
5270
+ }
5271
+ /** Records one syncbridge conflict with both manifest versions. */
5272
+ async addsyncbridgeconflict(conflict) {
5273
+ await this.adapter.set("syncbridgeconflicts", [conflict, ...await this.getsyncbridgeconflicts()]);
5274
+ }
5275
+ /** Resolves one syncbridge conflict by its id with the resolution the user picked; one conflict resolves exactly once. */
5276
+ async resolvesyncbridgeconflict(id, resolution, now) {
5277
+ const conflicts = await this.getsyncbridgeconflicts();
5278
+ await this.adapter.set("syncbridgeconflicts", conflicts.map((conflict) => conflict.id === id && conflict.resolution === void 0 ? { ...conflict, resolution, resolvedat: now } : conflict));
5279
+ return this.getsyncbridgeconflicts();
5280
+ }
5281
+ /** Returns every attentionfeed entry, newest first, with its cause, refs and deep link. */
5282
+ async getattentionentries() {
5283
+ return await this.adapter.get("attentionfeed") ?? [];
5284
+ }
5285
+ /** Records one attentionfeed entry deduplicated by its cause, run and gate refs while the retention window stays a user setting. */
5286
+ async addattentionentry(entry) {
5287
+ const existing = (await this.getattentionentries()).filter((candidate) => candidate.id !== entry.id);
5288
+ await this.adapter.set("attentionfeed", [entry, ...existing]);
5289
+ }
5290
+ /** Dismisses one attentionfeed entry by its id: the dismissal removes the feed row only while the waiting cause keeps its own resolution path. */
5291
+ async dismissattentionentry(id) {
5292
+ const entries = (await this.getattentionentries()).filter((candidate) => candidate.id !== id);
5293
+ await this.adapter.set("attentionfeed", entries);
5294
+ return entries;
5295
+ }
5296
+ /** Prunes the attentionfeed entries past their retention window; an absent window keeps every entry while the pruned ids return for the audit note. */
5297
+ async pruneattentionentries(now) {
5298
+ const retention = (await this.getsettings())?.attentionretention;
5299
+ const entries = await this.getattentionentries();
5300
+ if (retention === void 0) return { kept: entries, pruned: [] };
5301
+ const kept = entries.filter((entry) => now - entry.at < retention);
5302
+ await this.adapter.set("attentionfeed", kept);
5303
+ return { kept, pruned: entries.filter((entry) => now - entry.at >= retention).map((entry) => entry.id) };
5304
+ }
5305
+ /** Returns the runreplay cursors per viewed run so a reopened replay stands where the viewer left it. */
5306
+ async getreplaycursors() {
5307
+ return await this.adapter.get("replaycursors") ?? {};
5308
+ }
5309
+ /** Stores one runreplay cursor for its viewed run. */
5310
+ async setreplaycursor(runid, cursor) {
5311
+ await this.adapter.set("replaycursors", { ...await this.getreplaycursors(), [runid]: cursor });
5312
+ }
5313
+ /** Returns every outputcompare session with its metric results, newest first. */
5314
+ async getcomparesessions() {
5315
+ return await this.adapter.get("comparesessions") ?? [];
5316
+ }
5317
+ /** Records one outputcompare session with the metric set it used. */
5318
+ async addcomparesession(session) {
5319
+ await this.adapter.set("comparesessions", [session, ...await this.getcomparesessions()]);
5320
+ }
5321
+ /** Returns the background run queue state for restart recovery: every entry with its state and its keepalive hold. */
5322
+ async getbackgroundqueue() {
5323
+ return await this.adapter.get("backgroundqueue") ?? [];
5324
+ }
5325
+ /** Replaces the background run queue state after every transition so the restart recovery reads it in one call. */
5326
+ async setbackgroundqueue(queue) {
5327
+ return this.adapter.set("backgroundqueue", queue);
5328
+ }
5224
5329
  };
5225
5330
  function mediakindof(record2) {
5226
5331
  if ("pages" in record2) return "pdf";
@@ -10813,6 +10918,58 @@ function importexportgate(input) {
10813
10918
  if (input.unmaskedlogs) return { allowed: false, reason: "The importexport bundle carries unmasked log entries; only masked summaries ever move between profiles, so the bundle refuses in full." };
10814
10919
  return { allowed: true, reason: "The importexport bundle carries no secretvault value and no unmasked log; the originprofiles, the siteprofiles, the notes and the preferences move with their honest exclusion list." };
10815
10920
  }
10921
+ function librarymanifestgate(input) {
10922
+ if (input.errors.length > 0) return { allowed: false, reason: `The flowlibrary manifest fails schemastrict with ${input.errors.length} error${input.errors.length === 1 ? "" : "s"}: ${input.errors.slice(0, 3).map((error) => `${error.path} expected ${error.expected}`).join("; ")}; the import refuses before anything else.` };
10923
+ return { allowed: true, reason: "The flowlibrary manifest passes schemastrict with no shape error; the validation names every field it checked." };
10924
+ }
10925
+ function librarycapabilitygate(input) {
10926
+ const missing = [...new Set(input.kinds)].filter((kind) => !input.capabilities.includes(kind));
10927
+ if (missing.length > 0) return { allowed: false, reason: `The flowlibrary manifest uses the kind${missing.length === 1 ? "" : "s"} ${missing.join(", ")} the installed capability set lacks; the import refuses in full.` };
10928
+ return { allowed: true, reason: `Every kind of the flowlibrary manifest sits inside the installed capability set of ${input.capabilities.length} kind${input.capabilities.length === 1 ? "" : "s"}.` };
10929
+ }
10930
+ function librarygrantgate(input) {
10931
+ const missing = [...new Set(input.requiredgrants)].filter((origin) => !input.heldgrants.includes(origin));
10932
+ if (missing.length > 0) return { allowed: false, reason: `The flowlibrary manifest requires the grant${missing.length === 1 ? "" : "s"} ${missing.join(", ")} the profile does not hold; the grant diff shows them and the user grants them before the import completes.` };
10933
+ return { allowed: true, reason: `The profile holds every grant the flowlibrary manifest requires${input.requiredgrants.length === 0 ? " and the manifest requires none" : ""}.` };
10934
+ }
10935
+ function librarysensitivegate(input) {
10936
+ if (!input.sensitive) return { allowed: true, reason: "The flowlibrary manifest carries no sensitive mark, so no fresh consent prompt stands before its import." };
10937
+ if (!input.freshconsent) return { allowed: false, reason: "The flowlibrary manifest is marked sensitive; its import needs a fresh consent prompt the user answers before anything lands." };
10938
+ return { allowed: true, reason: "The user answered the fresh consent prompt of the sensitive flowlibrary manifest; the import proceeds behind the same review." };
10939
+ }
10940
+ function libraryquarantinegate(input) {
10941
+ if (!input.signaturepresent && !input.verified) return { allowed: false, reason: "The flowlibrary entry carries no publisher signature; the entry quarantines until the user verifies its publisher, and a quarantined entry never installs on its own." };
10942
+ if (input.signaturepresent && !input.signaturevalid) return { allowed: false, reason: "The publisher signature of the flowlibrary entry failed its verification; the entry quarantines and never installs under any flag." };
10943
+ return { allowed: true, reason: "The publisher signature of the flowlibrary entry verified over its manifest digest; the entry stays available for the grant diff and the import." };
10944
+ }
10945
+ function syncbridgeoptingate(input) {
10946
+ if (!input.optin) return { allowed: false, reason: "The syncbridge hook stays off because no explicit opt in exists; no hook ever defaults on and no manifest moves without the user turning the hook on." };
10947
+ return { allowed: true, reason: "The user explicitly opted the syncbridge hook in; the hook moves manifests only and never secrets or logs." };
10948
+ }
10949
+ function syncbridgescopegate(input) {
10950
+ if (input.carriessecrets) return { allowed: false, reason: "The syncbridge payload carries a secretvault value shape; the bridge moves manifests only, so the payload refuses in full." };
10951
+ if (input.carrieslogs) return { allowed: false, reason: "The syncbridge payload carries log entries; the bridge moves manifests only, so the payload refuses in full." };
10952
+ return { allowed: true, reason: "The syncbridge payload carries manifests only; secrets and logs never ride the bridge under any flag." };
10953
+ }
10954
+ function runreplaygate(input) {
10955
+ if (!input.sealed) return { allowed: false, reason: "The runreplay walks sealed runs only; an open run keeps moving and its replay would show a chain that still grows." };
10956
+ if (!input.chainvalid) return { allowed: false, reason: "The sealed chain of the run failed its verification; the replay refuses the walk because only a verified chain stands as audit evidence." };
10957
+ return { allowed: true, reason: "The run sealed and its chain verified from the genesis hash to the seal; the replay walks it read only, restoring the observation and capture of each step." };
10958
+ }
10959
+ function outputcomparegate(input) {
10960
+ if (input.signaturea.trim() === "" || input.signatureb.trim() === "") return { allowed: false, reason: "The outputcompare needs the task input signature of both runs; a signatureless run never compares." };
10961
+ if (input.signaturea !== input.signatureb) return { allowed: false, reason: "The two runs carry different task input signatures; only runs that started from the same input compare their outcomes." };
10962
+ return { allowed: true, reason: "The two runs share their task input signature, so their step outcomes compare under the recorded metric set." };
10963
+ }
10964
+ function outputcomparereadonlygate(input) {
10965
+ if (input.executessteps) return { allowed: false, reason: "The outputcompare never executes a step; it reads the stored outcomes of both runs only, so any executing path refuses in full." };
10966
+ return { allowed: true, reason: "The outputcompare joins the stored outcomes of both runs without touching the page; no step executes inside a comparison." };
10967
+ }
10968
+ function backgroundrungate(input) {
10969
+ if (!input.reviewed) return { allowed: false, reason: "The background run queue executes reviewed workflows only; an unreviewed workflow never starts, with or without an open surface." };
10970
+ if (!input.keepaliveheld) return { allowed: false, reason: "A background run holds the keepalive signal for its whole duration; a run that releases the signal early stops being a background run." };
10971
+ return { allowed: true, reason: "The reviewed workflow runs in the background with the keepalive signal held and every checkpoint restoring it on each worker wake." };
10972
+ }
10816
10973
 
10817
10974
  // progress.ts
10818
10975
  function emptyprogress(planid, now) {
@@ -11063,7 +11220,7 @@ function maskexport(record2, shapes) {
11063
11220
  }
11064
11221
 
11065
11222
  // version.ts
11066
- var packageversion = "1.1.65";
11223
+ var packageversion = "1.1.66";
11067
11224
 
11068
11225
  // types.ts
11069
11226
  var protocolversion = packageversion;
@@ -12043,6 +12200,9 @@ function transparencyreport(input) {
12043
12200
  function surfacesnapshot(input) {
12044
12201
  return { version: protocolversion, surface: input.surface, palette: input.palette, timeline: input.timeline, logstream: input.logstream, plancards: input.plancards, ...input.onboarding !== void 0 ? { onboarding: input.onboarding } : {} };
12045
12202
  }
12203
+ function ecosystemviews(input) {
12204
+ return { version: protocolversion, library: input.library, installed: input.installed, syncbridge: input.syncbridge, attention: input.attention, backgroundruns: input.backgroundruns, ...input.replay !== void 0 ? { replay: input.replay } : {}, ...input.compare !== void 0 ? { compare: input.compare } : {} };
12205
+ }
12046
12206
 
12047
12207
  // capture.ts
12048
12208
  var capturekinds = ["shotview", "shotfullpage", "shotelement", "shotregion", "contactsheet"];
@@ -13468,7 +13628,8 @@ function onboardingsteps() {
13468
13628
  { id: "origingrants", surface: "popup", title: "Origin grants", body: "Devthink denies automation by default; grant one exact origin at a time from the popup and every run stays inside the granted origins.", completion: "origingrantscompleted" },
13469
13629
  { id: "planreview", surface: "sidepanel", title: "Plan review", body: "Every task becomes a plan of reviewed steps; read the plancards of each risk class and approve, reject or edit one step at a time.", completion: "planreviewcompleted" },
13470
13630
  { id: "runcontrol", surface: "sidepanel", title: "Run control", body: "Runs start, pause, resume and cancel under your hand; a cancelled run rolls only its queued steps back while the executed steps stay sealed.", completion: "runcontrolcompleted" },
13471
- { id: "logaudit", surface: "dashboardpage", title: "Log audit", body: "The immutable log chains every step transition with masked values; open the dashboard, verify the chain and copy a verified range as an audit excerpt.", completion: "logauditcompleted" }
13631
+ { id: "logaudit", surface: "dashboardpage", title: "Log audit", body: "The immutable log chains every step transition with masked values; open the dashboard, verify the chain and copy a verified range as an audit excerpt.", completion: "logauditcompleted" },
13632
+ { id: "library", surface: "dashboardpage", title: "Flow library", body: "The flowlibrary shares reviewed workflow templates: browse an entry, read its step list and grant diff, and every install still lands as a proposal behind the same review.", completion: "librarycompleted", optional: true }
13472
13633
  ];
13473
13634
  }
13474
13635
  function onboardingstart(previous, now) {
@@ -13479,7 +13640,7 @@ function onboardingcomplete(state, stepid, now) {
13479
13640
  const step = steps.find((candidate) => candidate.id === stepid);
13480
13641
  if (step === void 0) throw new Error(`The onboarding knows no ${stepid} step.`);
13481
13642
  const completed = state.stepscompleted.includes(stepid) ? state.stepscompleted : [...state.stepscompleted, stepid];
13482
- const done = steps.every((candidate) => completed.includes(candidate.id));
13643
+ const done = steps.filter((candidate) => candidate.optional !== true).every((candidate) => completed.includes(candidate.id));
13483
13644
  if (!done) return { state: { ...state, stepscompleted: completed, done: false } };
13484
13645
  const consentevent = "onboardingconsentgranted";
13485
13646
  return { state: { stepscompleted: completed, done: true, ...state.startedat !== void 0 ? { startedat: state.startedat } : {}, consentevent, completedat: now }, consentevent };
@@ -15074,6 +15235,385 @@ function connectallowlist(entries) {
15074
15235
  return entries.map((entry) => ({ senderid: entry.senderid, displayname: entry.displayname, ...entry.origin !== void 0 ? { origin: entry.origin } : {}, addedat: entry.addedat }));
15075
15236
  }
15076
15237
 
15238
+ // flowlibrary.ts
15239
+ async function sha2563(payload) {
15240
+ const bytes = new TextEncoder().encode(payload);
15241
+ const digest = await crypto.subtle.digest("SHA-256", bytes);
15242
+ return [...new Uint8Array(digest)].map((byte) => byte.toString(16).padStart(2, "0")).join("");
15243
+ }
15244
+ function manifestbody(manifest) {
15245
+ return JSON.stringify({ id: manifest.id, title: manifest.title, description: manifest.description, version: manifest.version, publisher: manifest.publisher, ...manifest.registry !== void 0 ? { registry: manifest.registry } : {}, steps: manifest.steps, kinds: manifest.kinds, requiredgrants: manifest.requiredgrants, dataexpectations: manifest.dataexpectations, sensitive: manifest.sensitive });
15246
+ }
15247
+ async function manifestdigest(manifest) {
15248
+ const { publish, ...body } = manifest;
15249
+ void publish;
15250
+ return sha2563(manifestbody(body));
15251
+ }
15252
+ async function validatemanifest(input) {
15253
+ const errors = [];
15254
+ const raw = input.manifest;
15255
+ if (!Boolean(raw) || typeof raw !== "object" || Array.isArray(raw)) return { ok: false, errors: [{ path: "manifest", expected: "object", found: Array.isArray(raw) ? "array" : typeof raw, reason: "Every flowlibrary manifest travels as one plain object." }], reason: "The flowlibrary manifest is no plain object; schemastrict refuses the carrier before any import." };
15256
+ const candidate = raw;
15257
+ if (typeof candidate.id !== "string" || candidate.id.trim() === "") errors.push({ path: "id", expected: "string", found: typeof candidate.id, reason: "The flowlibrary manifest needs its id." });
15258
+ if (typeof candidate.title !== "string" || candidate.title.trim() === "") errors.push({ path: "title", expected: "string", found: typeof candidate.title, reason: "The flowlibrary manifest needs its title." });
15259
+ if (typeof candidate.description !== "string") errors.push({ path: "description", expected: "string", found: typeof candidate.description, reason: "The flowlibrary manifest needs its description." });
15260
+ if (typeof candidate.version !== "string" || candidate.version.trim() === "") errors.push({ path: "version", expected: "string", found: typeof candidate.version, reason: "The flowlibrary manifest needs its version." });
15261
+ if (typeof candidate.publisher !== "string" || candidate.publisher.trim() === "") errors.push({ path: "publisher", expected: "string", found: typeof candidate.publisher, reason: "The flowlibrary manifest names its publisher." });
15262
+ if (!Array.isArray(candidate.steps) || candidate.steps.length === 0) errors.push({ path: "steps", expected: "array", found: Array.isArray(candidate.steps) ? "empty array" : typeof candidate.steps, reason: "The flowlibrary manifest declares its steps." });
15263
+ if (Array.isArray(candidate.steps)) {
15264
+ candidate.steps.forEach((step, index) => {
15265
+ const shape = step;
15266
+ if (!Boolean(shape) || typeof shape !== "object" || typeof shape.id !== "string" || shape.id.trim() === "" || typeof shape.kind !== "string" || shape.kind.trim() === "" || typeof shape.label !== "string") errors.push({ path: `steps.${index}`, expected: "flowlibrarystep", found: typeof step, reason: "Every flowlibrary step needs its id, kind and label." });
15267
+ });
15268
+ }
15269
+ if (!Array.isArray(candidate.kinds) || candidate.kinds.length === 0) errors.push({ path: "kinds", expected: "array", found: typeof candidate.kinds, reason: "The flowlibrary manifest declares the action kinds its steps use." });
15270
+ if (!Array.isArray(candidate.requiredgrants)) errors.push({ path: "requiredgrants", expected: "array", found: typeof candidate.requiredgrants, reason: "The flowlibrary manifest declares its required origin grants." });
15271
+ if (!Array.isArray(candidate.dataexpectations)) errors.push({ path: "dataexpectations", expected: "array", found: typeof candidate.dataexpectations, reason: "The flowlibrary manifest declares its data expectations with minimization hints." });
15272
+ if (typeof candidate.sensitive !== "boolean") errors.push({ path: "sensitive", expected: "boolean", found: typeof candidate.sensitive, reason: "The flowlibrary manifest marks whether it is sensitive." });
15273
+ const unknownfields = Object.keys(candidate).filter((key) => !["id", "title", "description", "version", "publisher", "registry", "steps", "kinds", "requiredgrants", "dataexpectations", "sensitive", "publish"].includes(key));
15274
+ for (const field of unknownfields) errors.push({ path: field, expected: "absent", found: "present", reason: `The flowlibrary manifest carries the unknown field ${field}; schemastrict refuses unknown fields.` });
15275
+ const schemagate = librarymanifestgate({ errors });
15276
+ if (!schemagate.allowed) return { ok: false, errors, reason: schemagate.reason ?? "The flowlibrary manifest fails schemastrict." };
15277
+ const manifest = { id: candidate.id, title: candidate.title, description: candidate.description, version: candidate.version, publisher: candidate.publisher, ...typeof candidate.registry === "string" && candidate.registry.trim() !== "" ? { registry: candidate.registry } : {}, steps: candidate.steps.map((step) => ({ id: step.id, kind: step.kind, label: step.label, ...step.target !== void 0 ? { target: step.target } : {}, ...step.value !== void 0 ? { value: step.value } : {}, ...step.namespace !== void 0 ? { namespace: step.namespace } : {} })), kinds: candidate.kinds, requiredgrants: candidate.requiredgrants, dataexpectations: candidate.dataexpectations, sensitive: candidate.sensitive, ...isPublish(candidate.publish) ? { publish: candidate.publish } : {} };
15278
+ const kinds = [...new Set(manifest.steps.map((step) => step.kind))];
15279
+ const capabilitygate = librarycapabilitygate({ kinds, capabilities: input.capabilities });
15280
+ if (!capabilitygate.allowed) return { ok: false, errors: [], reason: capabilitygate.reason ?? "", manifest };
15281
+ return { ok: true, errors: [], reason: `The manifest ${manifest.id} of ${manifest.publisher} validates under schemastrict with ${manifest.steps.length} step${manifest.steps.length === 1 ? "" : "s"} and ${kinds.length} kind${kinds.length === 1 ? "" : "s"} inside the installed capability set.`, manifest };
15282
+ }
15283
+ function isPublish(value) {
15284
+ if (!Boolean(value) || typeof value !== "object") return false;
15285
+ const shape = value;
15286
+ return typeof shape.publisher === "string" && shape.publisher.trim() !== "" && typeof shape.signature === "string" && shape.signature.trim() !== "" && typeof shape.digest === "string" && shape.digest.trim() !== "" && typeof shape.provenance === "string" && typeof shape.publishedat === "number";
15287
+ }
15288
+ async function verifypublishersignature(manifest) {
15289
+ if (manifest.publish === void 0) return { verified: false, reason: `The manifest ${manifest.id} of ${manifest.publisher} carries no publisher signature; the entry quarantines until the user verifies its publisher.` };
15290
+ const digest = await manifestdigest(manifest);
15291
+ if (manifest.publish.digest !== digest) return { verified: false, reason: `The publisher signature of ${manifest.publish.publisher} covers the digest ${manifest.publish.digest} while the manifest body hashes to ${digest}; the verification refuses the signature in full.` };
15292
+ if (manifest.publish.publisher !== manifest.publisher) return { verified: false, reason: `The publisher signature names ${manifest.publish.publisher} while the manifest carries the publisher ${manifest.publisher}; the verification refuses the signature in full.` };
15293
+ const seal = await sha2563(`${manifest.publish.publisher}
15294
+ ${manifest.publish.digest}
15295
+ ${manifest.publish.provenance}`);
15296
+ if (manifest.publish.signature !== seal) return { verified: false, reason: `The publisher signature of ${manifest.publish.publisher} seals neither the manifest digest nor its provenance; the verification refuses the signature in full.` };
15297
+ return { verified: true, reason: `The publisher signature of ${manifest.publish.publisher} verifies over the manifest digest ${digest.slice(0, 12)}\u2026 with its provenance ${manifest.publish.provenance}.` };
15298
+ }
15299
+ async function libraryentryof(input) {
15300
+ const digest = await manifestdigest(input.manifest);
15301
+ const verification = await verifypublishersignature(input.manifest);
15302
+ const quarantinegate = libraryquarantinegate({ verified: verification.verified, signaturepresent: input.manifest.publish !== void 0, signaturevalid: verification.verified });
15303
+ const state = quarantinegate.allowed ? "available" : "quarantined";
15304
+ return { id: `${input.manifest.id}@${input.manifest.version}`, manifest: input.manifest, digest, state, provenance: `${input.provenance}; ${verification.reason}`, addedat: input.now };
15305
+ }
15306
+ function grantdiffof(input) {
15307
+ const required = [...new Set(input.manifest.requiredgrants)];
15308
+ const added = required.filter((origin) => !input.heldgrants.includes(origin));
15309
+ const kept = required.filter((origin) => input.heldgrants.includes(origin));
15310
+ const originmappings = required.map((origin) => ({ origin, kinds: [...new Set(input.manifest.steps.map((step) => step.kind))] }));
15311
+ return { added, kept, originmappings };
15312
+ }
15313
+ function sensitiveconsentfor(manifest, freshconsent) {
15314
+ const gate = librarysensitivegate({ sensitive: manifest.sensitive, freshconsent });
15315
+ return { required: manifest.sensitive, reason: gate.reason ?? "" };
15316
+ }
15317
+ function manifestrisk(manifest) {
15318
+ let risk = "read";
15319
+ for (const step of manifest.steps) {
15320
+ const candidate = actionrisk(step.kind);
15321
+ if (candidate === "sensitive") return "sensitive";
15322
+ if (candidate === "interaction") risk = "interaction";
15323
+ }
15324
+ return risk;
15325
+ }
15326
+ function installlibrary(input) {
15327
+ const manifest = input.entry.manifest;
15328
+ const prefix = input.selectornamespace?.trim() ?? "";
15329
+ const steps = manifest.steps.map((step) => ({
15330
+ id: `${manifest.id}-${step.id}`,
15331
+ kind: step.kind,
15332
+ label: step.label,
15333
+ ...step.target !== void 0 ? { target: prefix === "" ? step.target : `${prefix} ${step.target}`.trim() } : {},
15334
+ ...step.value !== void 0 ? { value: step.value } : {}
15335
+ }));
15336
+ return { id: `library:${manifest.id}:${manifest.version}`, name: manifest.title, version: 1, origins: [...new Set(manifest.requiredgrants)], steps, blocks: [], risk: manifestrisk(manifest), reviewstate: "pending", createdat: input.now };
15337
+ }
15338
+ function updatelibrary(input) {
15339
+ if (input.incoming.digest === input.existing.digest) return { changedsteps: [], addedgrants: [], versionfrom: input.existing.manifest.version, versionto: input.incoming.manifest.version, replace: false, reason: `The incoming ${input.incoming.manifest.id} carries the same manifest digest as the installed entry; the update replaces nothing.` };
15340
+ const existingsteps = new Set(input.existing.manifest.steps.map((step) => step.id));
15341
+ const incomingsteps = new Set(input.incoming.manifest.steps.map((step) => step.id));
15342
+ const changedsteps = [.../* @__PURE__ */ new Set([...existingsteps, ...incomingsteps])].filter((id) => {
15343
+ const before = input.existing.manifest.steps.find((step) => step.id === id);
15344
+ const after = input.incoming.manifest.steps.find((step) => step.id === id);
15345
+ return before === void 0 || after === void 0 || before.kind !== after.kind || before.target !== after.target || before.value !== after.value;
15346
+ });
15347
+ const addedgrants = [...new Set(input.incoming.manifest.requiredgrants)].filter((origin) => !input.existing.manifest.requiredgrants.includes(origin));
15348
+ return { changedsteps, addedgrants, versionfrom: input.existing.manifest.version, versionto: input.incoming.manifest.version, replace: true, reason: `The update of ${input.incoming.manifest.id} from version ${input.existing.manifest.version} to ${input.incoming.manifest.version} changes ${changedsteps.length} step${changedsteps.length === 1 ? "" : "s"} and adds ${addedgrants.length} grant${addedgrants.length === 1 ? "" : "s"}; the version diff surfaces before the replace.` };
15349
+ }
15350
+ function removelibrary(input) {
15351
+ return { removed: input.entry.id, keptforks: input.forks.map((fork) => fork.id), reason: `The library entry ${input.entry.manifest.title} leaves the store while its ${input.forks.length} local fork${input.forks.length === 1 ? "" : "s"} stay untouched; a fork is an independent local workflow.` };
15352
+ }
15353
+ function forklibrary(input) {
15354
+ const manifest = input.entry.manifest;
15355
+ const steps = manifest.steps.map((step) => ({ id: `fork-${step.id}`, kind: step.kind, label: step.label, ...step.target !== void 0 ? { target: step.target } : {}, ...step.value !== void 0 ? { value: step.value } : {} }));
15356
+ return { id: `fork:${manifest.id}:${input.now}`, name: `${manifest.title} fork`, version: 1, origins: [...new Set(manifest.requiredgrants)], steps, blocks: [], risk: manifestrisk(manifest), reviewstate: "pending", createdat: input.now };
15357
+ }
15358
+ function librarysearch(input) {
15359
+ const query = input.query?.trim().toLowerCase() ?? "";
15360
+ return input.entries.filter((entry) => {
15361
+ if (input.filter?.publisher !== void 0 && entry.manifest.publisher !== input.filter.publisher) return false;
15362
+ if (input.filter?.sensitive !== void 0 && entry.manifest.sensitive !== input.filter.sensitive) return false;
15363
+ if (input.filter?.state !== void 0 && entry.state !== input.filter.state) return false;
15364
+ if (query === "") return true;
15365
+ return [entry.manifest.title, entry.manifest.description, entry.manifest.publisher].some((text2) => text2.toLowerCase().includes(query));
15366
+ });
15367
+ }
15368
+ function librarybrowserow(entry) {
15369
+ return { id: entry.id, title: entry.manifest.title, publisher: entry.manifest.publisher, version: entry.manifest.version, grants: entry.manifest.requiredgrants, sensitive: entry.manifest.sensitive, state: entry.state, ...entry.manifest.registry !== void 0 ? { registry: entry.manifest.registry } : {} };
15370
+ }
15371
+ function librarystepsview(entry) {
15372
+ return entry.manifest.steps.map((step) => {
15373
+ const expectations = entry.manifest.dataexpectations.filter((expectation) => expectation.stepid === step.id);
15374
+ return { id: step.id, kind: step.kind, label: step.label, ...step.target !== void 0 ? { target: step.target } : {}, ...step.namespace !== void 0 ? { namespace: step.namespace } : {}, families: expectations.map((expectation) => expectation.family), fields: [...new Set(expectations.flatMap((expectation) => expectation.fields))] };
15375
+ });
15376
+ }
15377
+ function libraryeventof(input) {
15378
+ if (input.entryid.trim() === "") throw new Error("The library event needs its entry id.");
15379
+ return { id: `libraryevent:${input.kind}:${input.entryid}:${input.now}`, kind: input.kind, entryid: input.entryid, title: input.title, version: input.version, detail: input.detail, at: input.now };
15380
+ }
15381
+
15382
+ // syncbridge.ts
15383
+ async function sha2564(payload) {
15384
+ const bytes = new TextEncoder().encode(payload);
15385
+ const digest = await crypto.subtle.digest("SHA-256", bytes);
15386
+ return [...new Uint8Array(digest)].map((byte) => byte.toString(16).padStart(2, "0")).join("");
15387
+ }
15388
+ async function syncdigestof(manifest) {
15389
+ const { publish, ...body } = manifest;
15390
+ void publish;
15391
+ return sha2564(JSON.stringify(body));
15392
+ }
15393
+ function syncbridgehookof(input) {
15394
+ if (input.endpoint.trim() === "") throw new Error(`The ${input.provider} hook needs its user configured endpoint; no provider address is ever hardcoded.`);
15395
+ const gate = syncbridgeoptingate({ optin: false });
15396
+ if (gate.allowed) throw new Error("The syncbridge hook never starts with its opt in on; no hook ever defaults on.");
15397
+ return { id: `sync:${input.provider}:${input.now}`, provider: input.provider, direction: input.direction, optin: false, endpoint: input.endpoint.trim(), state: "idle", createdat: input.now };
15398
+ }
15399
+ function syncbridgeoptinflip(hook, optin) {
15400
+ return { ...hook, optin, state: "idle" };
15401
+ }
15402
+ function syncbridgeproviders() {
15403
+ return [
15404
+ { provider: "file", label: "File provider", operations: ["pull", "push", "list"], note: "The file provider moves manifests through manual import and export files the user picks; the bridge carries no secret and no log entry under any flag." },
15405
+ { provider: "web", label: "Web provider stub", operations: ["pull", "push", "list"], note: "The web provider stays a stub behind its opt in gate: the endpoint stays the user's configured registry value and no network call ships before the ecosystem part two backend exists." }
15406
+ ];
15407
+ }
15408
+ async function syncbridgeexportpayload(manifests) {
15409
+ const digests = [];
15410
+ for (const manifest of manifests) digests.push(await syncdigestof(manifest));
15411
+ return { version: 1, kind: "syncbridge", manifests, digests, exclusions: ["secretvault values", "logs"] };
15412
+ }
15413
+ function syncbridgevalidate(payload) {
15414
+ const carriessecrets = payload.secrets !== void 0 || Array.isArray(payload.manifests) && payload.manifests.some((manifest) => secretcarrying2(manifest));
15415
+ const gate = syncbridgescopegate({ carriessecrets, carrieslogs: payload.logs !== void 0 });
15416
+ if (!gate.allowed) return { ok: false, reason: gate.reason ?? "The syncbridge payload refuses." };
15417
+ if (payload.kind !== "syncbridge") return { ok: false, reason: "The syncbridge payload names its kind; a foreign payload never imports." };
15418
+ if (!Array.isArray(payload.manifests)) return { ok: false, reason: "The syncbridge payload carries its manifest list." };
15419
+ return { ok: true, reason: `The syncbridge payload carries ${payload.manifests.length} manifest${payload.manifests.length === 1 ? "" : "s"} and no secret and no log entry; the bridge moves manifests only.` };
15420
+ }
15421
+ function secretcarrying2(record2) {
15422
+ if (record2 === null || typeof record2 !== "object") return false;
15423
+ const entries = Object.entries(record2);
15424
+ const secretkeys = ["secret", "token", "password", "apikey", "authorization"];
15425
+ return entries.some(([key, value]) => secretkeys.some((shape) => key.toLowerCase().includes(shape)) && typeof value === "string" && value.trim() !== "");
15426
+ }
15427
+ async function syncbridgescan(input) {
15428
+ const gate = syncbridgeoptingate({ optin: input.hook.optin });
15429
+ if (!gate.allowed) return { conflicts: [], synced: [], reason: gate.reason ?? "" };
15430
+ const conflicts = [];
15431
+ const synced = [];
15432
+ for (const remotemanifest of input.remote) {
15433
+ const localmanifest = input.local.find((candidate) => candidate.manifestid === remotemanifest.manifestid);
15434
+ if (localmanifest === void 0) {
15435
+ synced.push(remotemanifest.manifestid);
15436
+ continue;
15437
+ }
15438
+ if (localmanifest.digest === remotemanifest.digest) {
15439
+ synced.push(remotemanifest.manifestid);
15440
+ continue;
15441
+ }
15442
+ conflicts.push({ id: `conflict:${remotemanifest.manifestid}:${input.now}`, hookid: input.hook.id, manifestid: remotemanifest.manifestid, local: { digest: localmanifest.digest, version: localmanifest.version }, remote: { digest: remotemanifest.digest, version: remotemanifest.version }, detectedat: input.now });
15443
+ }
15444
+ return { conflicts, synced, reason: `The ${input.hook.provider} hook of ${input.hook.endpoint} scanned ${input.remote.length} remote manifest${input.remote.length === 1 ? "" : "s"} against ${input.local.length} local entr${input.local.length === 1 ? "y" : "ies"}: ${synced.length} moved while ${conflicts.length} conflict${conflicts.length === 1 ? "" : "s"} surfaced both versions instead of a silent overwrite.` };
15445
+ }
15446
+ function webproviderstub(hook) {
15447
+ const gate = syncbridgeoptingate({ optin: hook.optin });
15448
+ return { hookid: hook.id, endpoint: hook.endpoint, optin: hook.optin, operations: ["pull", "push", "list"], stub: true, reason: gate.allowed ? `The web provider of ${hook.endpoint} stays a stub behind its explicit opt in; the ecosystem part two backend brings its network path.` : gate.reason ?? "" };
15449
+ }
15450
+
15451
+ // attentionfeed.ts
15452
+ function attentionseverityof(cause) {
15453
+ if (cause === "gatewait" || cause === "phishguard") return "critical";
15454
+ if (cause === "deferral") return "warning";
15455
+ return "info";
15456
+ }
15457
+ function attentiondeeplinkof(cause, runid, gateref) {
15458
+ if (cause === "gatewait") return `devthink://gate/${encodeURIComponent(gateref ?? "unknown")}?run=${encodeURIComponent(runid)}`;
15459
+ if (cause === "phishguard") return `devthink://phishguard?run=${encodeURIComponent(runid)}`;
15460
+ if (cause === "deferral") return `devthink://deferred?run=${encodeURIComponent(runid)}`;
15461
+ return `devthink://error?run=${encodeURIComponent(runid)}`;
15462
+ }
15463
+ function attentionentryof(input) {
15464
+ if (input.runid.trim() === "") throw new Error("The attention entry needs its run ref.");
15465
+ if (input.summary.trim() === "") throw new Error("The attention entry needs its summary in plain language.");
15466
+ return { id: `attention:${input.cause}:${input.runid}:${input.gateref ?? "none"}`, cause: input.cause, severity: attentionseverityof(input.cause), runid: input.runid, ...input.gateref !== void 0 && input.gateref.trim() !== "" ? { gateref: input.gateref } : {}, origin: input.origin, summary: input.summary, deeplink: attentiondeeplinkof(input.cause, input.runid, input.gateref), at: input.at };
15467
+ }
15468
+ function dedupeattention(entries) {
15469
+ const seen = /* @__PURE__ */ new Set();
15470
+ const kept = [];
15471
+ for (const entry of [...entries].sort((a, b) => a.at - b.at)) {
15472
+ const key = `${entry.cause}:${entry.runid}:${entry.gateref ?? "none"}`;
15473
+ if (seen.has(key)) continue;
15474
+ seen.add(key);
15475
+ kept.push(entry);
15476
+ }
15477
+ return kept;
15478
+ }
15479
+ function rankattention(entries) {
15480
+ const order = { critical: 0, warning: 1, info: 2 };
15481
+ return [...entries].sort((a, b) => order[a.severity] - order[b.severity] || b.at - a.at);
15482
+ }
15483
+ function attentioncountof(entries) {
15484
+ return rankattention(dedupeattention(entries)).length;
15485
+ }
15486
+ function attentionnotifications(entries, now) {
15487
+ return rankattention(dedupeattention(entries)).map((entry) => ({ id: `notify:${entry.id}`, kind: "attention", title: entry.cause === "gatewait" ? "A gate waits for you" : entry.cause === "phishguard" ? "The phishguard blocked a step" : entry.cause === "deferral" ? "A command deferred" : "A step failed", body: entry.summary, deeplink: entry.deeplink, runid: entry.runid, ...entry.gateref !== void 0 ? { stepid: entry.gateref } : {}, content: false, at: now }));
15488
+ }
15489
+
15490
+ // backgroundruns.ts
15491
+ function backgroundqueueentryof(input) {
15492
+ if (input.workflowid.trim() === "") throw new Error("The background queue entry needs its workflow id.");
15493
+ return { id: `background:${input.workflowid}:${input.now}`, workflowid: input.workflowid, state: "queued", keepaliveheld: false, queuedat: input.now, summary: input.summary };
15494
+ }
15495
+ function enqueuebackgroundrun(input) {
15496
+ return [...input.queue, backgroundqueueentryof({ workflowid: input.workflowid, summary: input.summary, now: input.now })];
15497
+ }
15498
+ function nextbackgroundrun(queue) {
15499
+ return [...queue].filter((entry) => entry.state === "queued").sort((a, b) => a.queuedat - b.queuedat)[0];
15500
+ }
15501
+ function beginbackgroundrun(entry, now, reviewed) {
15502
+ const gate = backgroundrungate({ reviewed, keepaliveheld: true });
15503
+ return { entry: gate.allowed ? { ...entry, state: "running", keepaliveheld: true, startedat: now } : entry, gate: { allowed: gate.allowed, reason: gate.reason ?? "" } };
15504
+ }
15505
+ function finishbackgroundrun(entry, state, now) {
15506
+ return { ...entry, state, keepaliveheld: false, endedat: now };
15507
+ }
15508
+ function resumebackgroundqueue(queue, now) {
15509
+ const requeued = [];
15510
+ const next = queue.map((entry) => {
15511
+ if (entry.state !== "running") return entry;
15512
+ requeued.push(entry.id);
15513
+ const { startedat, ...rest } = entry;
15514
+ void startedat;
15515
+ return { ...rest, state: "queued", keepaliveheld: false };
15516
+ });
15517
+ void now;
15518
+ return { queue: next, requeued };
15519
+ }
15520
+ function backgroundrunsview(queue) {
15521
+ return queue.map((entry) => ({ id: entry.id, workflowid: entry.workflowid, state: entry.state, keepaliveheld: entry.keepaliveheld, queuedat: entry.queuedat, ...entry.startedat !== void 0 ? { startedat: entry.startedat } : {}, ...entry.endedat !== void 0 ? { endedat: entry.endedat } : {}, summary: entry.summary, progress: entry.state === "running" ? `Running with the keepalive signal held since ${entry.startedat ?? entry.queuedat}` : entry.state === "queued" ? "Queued for the next executor turn" : entry.state === "done" ? "Completed in the background" : "Failed; the attentionfeed carries the cause" }));
15522
+ }
15523
+ function backgroundtrayrows(queue, origin) {
15524
+ return queue.filter((entry) => entry.state === "done" || entry.state === "failed").map((entry) => ({ runid: entry.id, origin, outcome: entry.state === "done" ? "completed" : "failed", title: `Background run of ${entry.workflowid}`, at: entry.endedat ?? entry.queuedat, resumable: false, reopenable: true }));
15525
+ }
15526
+ function cancelbackgroundentry(queue, id) {
15527
+ const cancelled = [];
15528
+ const next = queue.filter((entry) => {
15529
+ if (entry.id === id && entry.state === "queued") {
15530
+ cancelled.push(entry.id);
15531
+ return false;
15532
+ }
15533
+ return true;
15534
+ });
15535
+ return { queue: next, cancelled };
15536
+ }
15537
+
15538
+ // runreplay.ts
15539
+ function restoredrefsof(entry) {
15540
+ const observation = /observation (\d+)/i.exec(entry.summary);
15541
+ const capture = /capture ([a-z0-9-]+)/i.exec(entry.summary);
15542
+ return { ...observation !== null ? { observationversion: Number(observation[1]) } : {}, ...capture !== null ? { captureid: capture[1] } : {} };
15543
+ }
15544
+ function replaystepof(entry, index, gates) {
15545
+ const refs = restoredrefsof(entry);
15546
+ return { stepid: entry.stepid ?? entry.id, index, summary: entry.summary, ...refs.observationversion !== void 0 ? { observationversion: refs.observationversion } : {}, ...refs.captureid !== void 0 ? { captureid: refs.captureid } : {}, gateresolutions: entry.stepid === void 0 ? [] : gates.filter((gate) => gate.gateid === entry.stepid) };
15547
+ }
15548
+ function runreplaysessionof(input) {
15549
+ if (input.runid.trim() === "") throw new Error("The runreplay session needs its recorded run id.");
15550
+ if (input.entries.length === 0) throw new Error("The runreplay session needs at least one verified log entry to walk.");
15551
+ const steps = input.entries.map((entry, index) => replaystepof(entry, index, input.gates ?? []));
15552
+ return { id: `replay:${input.runid}:${input.now}`, runid: input.runid, cursor: 0, playing: false, steps, openedat: input.now, actions: [] };
15553
+ }
15554
+ function replaymove(session, direction, now) {
15555
+ const next = direction === "forward" ? Math.min(session.steps.length - 1, session.cursor + 1) : Math.max(0, session.cursor - 1);
15556
+ const step = session.steps[next];
15557
+ return { ...session, cursor: next, playing: false, actions: [...session.actions, { kind: "step", at: now, ...step !== void 0 ? { stepid: step.stepid } : {} }] };
15558
+ }
15559
+ function replayjump(session, stepid, now) {
15560
+ const index = session.steps.findIndex((step) => step.stepid === stepid);
15561
+ if (index === -1) throw new Error(`The runreplay knows no ${stepid} step in the recorded chain of ${session.runid}.`);
15562
+ return { ...session, cursor: index, playing: false, actions: [...session.actions, { kind: "jump", stepid, at: now }] };
15563
+ }
15564
+ function replayplay(session, playing, now) {
15565
+ return { ...session, playing, actions: [...session.actions, { kind: playing ? "play" : "pause", at: now }] };
15566
+ }
15567
+ function replayrestoredview(step) {
15568
+ return { stepid: step.stepid, index: step.index, summary: step.summary, ...step.observationversion !== void 0 ? { observationversion: step.observationversion } : {}, ...step.captureid !== void 0 ? { captureid: step.captureid } : {}, gateresolutions: step.gateresolutions };
15569
+ }
15570
+
15571
+ // outputcompare.ts
15572
+ function taskinputsignatureof(input) {
15573
+ return `${input.objective.trim()}|${input.steps.length}|${input.steps.join(",")}`;
15574
+ }
15575
+ function comparemetricdefaults() {
15576
+ return ["agreement", "divergence", "durationdelta"];
15577
+ }
15578
+ function joinruns(logsa, logsb) {
15579
+ const sequence = [];
15580
+ for (const entry of logsa) if (!sequence.includes(entry.stepid)) sequence.push(entry.stepid);
15581
+ for (const entry of logsb) if (!sequence.includes(entry.stepid)) sequence.push(entry.stepid);
15582
+ return sequence.map((stepid, index) => {
15583
+ const a = logsa.find((entry) => entry.stepid === stepid);
15584
+ const b = logsb.find((entry) => entry.stepid === stepid);
15585
+ return { stepid, index, ...a !== void 0 ? { a } : {}, ...b !== void 0 ? { b } : {} };
15586
+ });
15587
+ }
15588
+ function stepcomparisonof(pair) {
15589
+ const a = pair.a;
15590
+ const b = pair.b;
15591
+ if (a === void 0 || b === void 0) return { stepid: pair.stepid, index: pair.index, agreement: "onlyone", summarya: a?.summary ?? "", summaryb: b?.summary ?? "", durationdelta: 0 };
15592
+ const agree = a.state === b.state && a.summary === b.summary;
15593
+ return { stepid: pair.stepid, index: pair.index, agreement: agree ? "agree" : "diverge", summarya: a.summary, summaryb: b.summary, durationdelta: a.duration - b.duration };
15594
+ }
15595
+ function firstdivergenceof(steps) {
15596
+ const divergent = steps.find((step) => step.agreement !== "agree");
15597
+ return divergent === void 0 ? void 0 : divergent.index;
15598
+ }
15599
+ function outputcomparesessionof(input) {
15600
+ if (input.runids[0].trim() === "" || input.runids[1].trim() === "") throw new Error("The outputcompare session needs both run ids.");
15601
+ if (input.runids[0] === input.runids[1]) throw new Error("The outputcompare session compares two distinct runs; one run never stands beside itself.");
15602
+ const metrics = input.metrics ?? comparemetricdefaults();
15603
+ const steps = joinruns(input.logsa, input.logsb).map((pair) => stepcomparisonof(pair));
15604
+ const firstdivergence = firstdivergenceof(steps);
15605
+ return { id: `compare:${input.runids[0]}:${input.runids[1]}:${input.now}`, runids: input.runids, metrics, steps, ...firstdivergence !== void 0 ? { firstdivergence } : {}, openedat: input.now };
15606
+ }
15607
+ function comparesessionmetrics(session) {
15608
+ const agree = session.steps.filter((step) => step.agreement === "agree").length;
15609
+ const diverge = session.steps.filter((step) => step.agreement === "diverge").length;
15610
+ const onlyone = session.steps.filter((step) => step.agreement === "onlyone").length;
15611
+ return { metrics: session.metrics, agree, diverge, onlyone, ...session.firstdivergence !== void 0 ? { firstdivergence: session.firstdivergence } : {}, reason: `The comparison of ${session.runids[0]} and ${session.runids[1]} graded ${agree} agreeing, ${diverge} divergent and ${onlyone} single run step${agree + diverge + onlyone === 1 ? "" : "s"} under the metric set ${session.metrics.join(", ")}${session.firstdivergence !== void 0 ? ` with the first divergence at step index ${session.firstdivergence}` : " with agreement across the whole sequence"}.` };
15612
+ }
15613
+ function outputcompareview(session) {
15614
+ return session.steps.map((step) => ({ stepid: step.stepid, index: step.index, agreement: step.agreement, summarya: step.summarya, summaryb: step.summaryb, durationdelta: step.durationdelta, highlighted: session.firstdivergence !== void 0 && step.index === session.firstdivergence }));
15615
+ }
15616
+
15077
15617
  // modelroute.ts
15078
15618
  function routevalid(route) {
15079
15619
  if (route.kind.trim() === "") return { allowed: false, reason: "The model route needs its task kind." };
@@ -16301,9 +16841,14 @@ function extensionpage(sender) {
16301
16841
  async function audit(kind, summary, extra = {}) {
16302
16842
  await memory.addaudi({ id: randomid(), kind, at: Date.now(), summary, ...extra });
16303
16843
  await recordsurfaceevent(kind, summary, extra);
16304
- if (kind === "session" || kind === "pause" || kind === "resume" || kind === "complete" || kind === "cancel" || kind === "gate" || kind === "notify") void updatestatusbadge().catch(() => {
16844
+ if (kind === "session" || kind === "pause" || kind === "resume" || kind === "complete" || kind === "cancel" || kind === "gate" || kind === "notify" || kind === "attention" || kind === "backgroundrun") void updatestatusbadge().catch(() => {
16305
16845
  });
16306
16846
  }
16847
+ async function recordattention(cause, runid, origin, summary, gateref) {
16848
+ const entry = attentionentryof({ cause, runid, origin, summary, ...gateref !== void 0 && gateref.trim() !== "" ? { gateref } : {}, at: Date.now() });
16849
+ await memory.addattentionentry(entry);
16850
+ await audit("attention", `The attentionfeed collected ${entry.cause} of the run ${entry.runid}${entry.gateref !== void 0 ? ` at the gate ${entry.gateref}` : ""}: ${entry.summary} The deep link ${entry.deeplink} opens the exact waiting surface.`, { ...runid !== "" ? { planid: runid } : {} });
16851
+ }
16307
16852
  var surfacechannel = typeof BroadcastChannel === "function" ? new BroadcastChannel("devthinksurfaces") : void 0;
16308
16853
  var logstreamhistory = [];
16309
16854
  var recentframes = [];
@@ -16590,6 +17135,8 @@ async function confirmgatechain(step, session, plan, origin, classification, now
16590
17135
  await appendrunevent("gate", `The ${gate.kind} gate opened for the ${step.kind} step ${step.id} on ${origin}: ${gateprompttext(gate)}`, session, origin, step.id).catch(() => {
16591
17136
  });
16592
17137
  await audit("gate", `The ${gate.kind} gate opened for the ${step.kind} step ${step.id} on ${origin}; the executor pauses until one distinct human action resolves it and no timeout ever resolves a gate.`, { sessionid: session.id, planid: plan.id, stepid: step.id });
17138
+ await recordattention("gatewait", plan.id, origin, `The ${gate.kind} gate of the ${step.kind} step ${step.id} waits for one human action; the executor pauses with no timeout.`, gate.gateid).catch(() => {
17139
+ });
16593
17140
  return { allowed: false, reason: `The ${gate.kind} gate opened for the ${step.kind} step ${step.id} on ${origin}: ${gateprompttext(gate)} The executor pauses until the human resolves it.` };
16594
17141
  }
16595
17142
  }
@@ -16615,6 +17162,8 @@ async function confirmgatechain(step, session, plan, origin, classification, now
16615
17162
  await appendrunevent("phish", `The phishguard blocked the credential step ${step.id} on ${origin}: ${verdict.reason}`, session, origin, step.id).catch(() => {
16616
17163
  });
16617
17164
  await audit("phish", `The phishguard blocked the ${step.kind} step ${step.id} on ${origin}: ${verdict.reason}`, { sessionid: session.id, planid: plan.id, stepid: step.id });
17165
+ await recordattention("phishguard", plan.id, origin, `The phishguard blocked the credential step ${step.id} on ${origin}: ${verdict.reason}`).catch(() => {
17166
+ });
16618
17167
  return { allowed: false, reason: phishgate.reason ?? "" };
16619
17168
  }
16620
17169
  }
@@ -16629,6 +17178,8 @@ async function confirmgatechain(step, session, plan, origin, classification, now
16629
17178
  await appendrunevent("suspend", `The ratelimit bucket of ${origin} deferred the ${step.kind} step ${step.id} until the window resets at ${deferred.resetsat}: ${consumed.reason}`, session, origin, step.id).catch(() => {
16630
17179
  });
16631
17180
  await audit("defer", `The ratelimit bucket of ${origin} deferred the ${step.kind} step ${step.id} until the window resets at ${deferred.resetsat}; the bounds stay user configured choices with no hidden ceiling.`, { sessionid: session.id, planid: plan.id, stepid: step.id });
17181
+ await recordattention("deferral", plan.id, origin, `The ratelimit bucket deferred the ${step.kind} step ${step.id} until the window resets at ${deferred.resetsat}.`).catch(() => {
17182
+ });
16632
17183
  return { allowed: false, reason: consumed.reason };
16633
17184
  }
16634
17185
  await memory.saveratelimitbucket(consumed.bucket);
@@ -21474,10 +22025,16 @@ async function executeworkflowrun(step, session, plan, tabid2, origin, dry) {
21474
22025
  await audit("error", `The background run ${run.id} of the workflow ${record2.name} failed: ${reason}.`, { sessionid: session.id, planid: plan.id, stepid: step.id });
21475
22026
  await refreshbadge().catch(() => {
21476
22027
  });
22028
+ }).finally(() => {
22029
+ void advancebackgroundqueue().catch(() => {
22030
+ });
21477
22031
  });
21478
22032
  return { ok: true, summary: `The workflow run ${run.id} started in the background with ${record2.steps.length} reviewed steps and the panel may close; the checkpoints restore it on every worker wake.`, details: { runid: run.id, state: "running", background: true, executed: 0, total: record2.steps.length } };
21479
22033
  }
21480
- return await performworkflowrun({ record: record2, run, step, session, plan, tabid: tabid2, origin, options, dry });
22034
+ const foregroundoutput = await performworkflowrun({ record: record2, run, step, session, plan, tabid: tabid2, origin, options, dry });
22035
+ void advancebackgroundqueue().catch(() => {
22036
+ });
22037
+ return foregroundoutput;
21481
22038
  }
21482
22039
  function runcauseof(options) {
21483
22040
  const variables = options.variables;
@@ -21967,6 +22524,8 @@ async function executeaction(step, session, plan, tabid2, origin, settings, verd
21967
22524
  const surface = errorsurfaceof({ stepid: step.id, runid: plan.id, message: summary, cause: classifyfailure({ message: summary, policyrefused: false, gatewait: false }), retryallowed: true, retryreason: "The failed step may dispatch again through the full consent gate chain.", context: { origin, kind: step.kind, environment: routing.environment }, now: Date.now() });
21968
22525
  await memory.adderrorsurface(surface).catch(() => {
21969
22526
  });
22527
+ await recordattention("failure", plan.id, origin, `The ${step.kind} step ${step.id} failed: ${summary} The retry stays a reviewed dispatch.`).catch(() => {
22528
+ });
21970
22529
  stepretry = { allowed: true, reason: `The ${surface.cause} failure of the step ${step.id} may retry through a new reviewed dispatch; the retry rides the full consent gate chain and never bypasses the review.` };
21971
22530
  }
21972
22531
  if (session) await appendrunevent("step", `The ${step.kind} step ${step.id} ${outcome.ok ? "completed" : "failed"} on ${origin}: ${summary}${securityverdict.classification.sensitive ? ` The step grades ${securityverdict.classification.reason}` : ""}`, session, origin, step.id).catch(() => {
@@ -22096,6 +22655,7 @@ var commandschemas = {
22096
22655
  transparency: {},
22097
22656
  surface: { palette: "object", task: "object", onboarding: "object", bus: "object", broadcast: "object", layout: "object", logstream: "object", approve: "object", diff: "object", review: "object", timeline: "object", dashboard: "object", settings: "object" },
22098
22657
  views: { datagrid: "object", export: "object", quickaction: "object", shortcut: "object", omnibox: "object", badge: "object", notify: "object", recent: "object", picker: "object", halo: "object", tips: "object", shotpanel: "object", compare: "object", siteprofile: "object", theme: "object", locale: "object", importexport: "object", dropimport: "object", tour: "object", a11y: "object", chip: "object", toast: "object", settings: "object" },
22658
+ ecosystem: { library: "object", sync: "object", attention: "object", replay: "object", compare: "object", background: "object", settings: "object" },
22099
22659
  execute: { stepid: "string" },
22100
22660
  configure: { endpoint: "string" }
22101
22661
  };
@@ -22599,7 +23159,8 @@ async function updatestatusbadge() {
22599
23159
  try {
22600
23160
  const plan = await memory.getplan();
22601
23161
  const progress = await memory.getprogress();
22602
- const waitingcount = plan !== void 0 && progress !== void 0 && progress.planid === plan.id ? Object.keys(progress.gatewaits ?? {}).length : 0;
23162
+ const attentioncount = attentioncountof(await memory.getattentionentries());
23163
+ const waitingcount = (plan !== void 0 && progress !== void 0 && progress.planid === plan.id ? Object.keys(progress.gatewaits ?? {}).length : 0) + attentioncount;
22603
23164
  const state = statusbadgeof({ ...plan !== void 0 && (plan.state === "pending" || plan.state === "approved") ? { planstate: plan.state } : {}, waitingcount, ...plan !== void 0 ? { runid: plan.id } : {} });
22604
23165
  await chrome.action.setBadgeText({ text: badgetextof(state) });
22605
23166
  await chrome.action.setBadgeBackgroundColor({ color: badgecolorof(state) });
@@ -22610,6 +23171,379 @@ function windowmatchmedia() {
22610
23171
  const query = globalThis.matchMedia?.("(prefers-color-scheme: dark)");
22611
23172
  return query?.matches === true ? "dark" : "light";
22612
23173
  }
23174
+ async function installedkindcapabilities() {
23175
+ const granted = await grantedcapabilities();
23176
+ return reviewedkinds().filter((kind) => {
23177
+ const capability = requiredcapability(kind);
23178
+ return capability === void 0 || granted.includes(capability);
23179
+ });
23180
+ }
23181
+ async function ecosystemviewof() {
23182
+ const entries = await memory.getflowlibrary();
23183
+ const installed = entries.filter((entry) => entry.state === "installed");
23184
+ const hooks = await memory.getsyncbridgehooks();
23185
+ const conflicts = await memory.getsyncbridgeconflicts();
23186
+ const attention = rankattention(await memory.getattentionentries()).slice(0, 50).map((entry) => ({ id: entry.id, cause: entry.cause, severity: entry.severity, runid: entry.runid, summary: entry.summary, deeplink: entry.deeplink, at: entry.at }));
23187
+ const queue = await memory.getbackgroundqueue();
23188
+ return ecosystemviews({
23189
+ library: librarysearch({ entries }).map((entry) => librarybrowserow(entry)),
23190
+ installed: installed.map((entry) => ({ id: entry.id, title: entry.manifest.title, version: entry.manifest.version, forkable: true })),
23191
+ syncbridge: { hooks: hooks.map((hook) => ({ id: hook.id, provider: hook.provider, direction: hook.direction, optin: hook.optin, endpoint: hook.endpoint, state: hook.state })), conflicts: conflicts.filter((conflict) => conflict.resolution === void 0).map((conflict) => ({ id: conflict.id, manifestid: conflict.manifestid, localversion: conflict.local.version, remoteversion: conflict.remote.version, ...conflict.resolution !== void 0 ? { resolution: conflict.resolution } : {} })) },
23192
+ attention,
23193
+ backgroundruns: backgroundrunsview(queue)
23194
+ });
23195
+ }
23196
+ async function handleecosystemcommand(message) {
23197
+ const input = message;
23198
+ const now = Date.now();
23199
+ const session = await memory.getsession();
23200
+ const settings = await memory.getsettings();
23201
+ if (input.library !== void 0) {
23202
+ const library = input.library;
23203
+ if (library.browse !== void 0) {
23204
+ const entries = librarysearch({ entries: await memory.getflowlibrary(), ...library.browse.query !== void 0 ? { query: library.browse.query } : {}, ...library.browse.publisher !== void 0 ? { filter: { publisher: library.browse.publisher } } : {}, ...library.browse.sensitive !== void 0 ? { filter: { sensitive: library.browse.sensitive } } : {}, ...library.browse.state !== void 0 ? { filter: { state: library.browse.state } } : {} });
23205
+ await audit("library", `The dashboardpage browsed the flowlibrary with ${entries.length} matching entr${entries.length === 1 ? "y" : "ies"}; every row names its publisher, version, required grants and state.`, { ...session ? { sessionid: session.id } : {} });
23206
+ return { ...await ecosystemviewof(), rows: entries.map((entry) => librarybrowserow(entry)) };
23207
+ }
23208
+ if (library.entry !== void 0) {
23209
+ const entry = (await memory.getflowlibrary()).find((candidate) => candidate.id === (library.entry?.entryid ?? ""));
23210
+ if (!entry) throw new Error(`No flowlibrary entry matches ${library.entry.entryid ?? ""}.`);
23211
+ return { entry, steps: librarystepsview(entry), expectations: entry.manifest.dataexpectations };
23212
+ }
23213
+ if (library.grants !== void 0) {
23214
+ const entry = (await memory.getflowlibrary()).find((candidate) => candidate.id === (library.grants?.entryid ?? ""));
23215
+ if (!entry) throw new Error(`No flowlibrary entry matches ${library.grants.entryid ?? ""}.`);
23216
+ const grants = session ? [.../* @__PURE__ */ new Set([session.origin, ...session.grants ?? []])] : [];
23217
+ const diff = grantdiffof({ manifest: entry.manifest, heldgrants: grants });
23218
+ await audit("library", `The grant diff of ${entry.manifest.title} surfaces ${diff.added.length} added grant${diff.added.length === 1 ? "" : "s"} and ${diff.kept.length} held grant${diff.kept.length === 1 ? "" : "s"} before any import completes.`, { ...session ? { sessionid: session.id } : {} });
23219
+ return { diff };
23220
+ }
23221
+ if (library.import !== void 0) {
23222
+ const capabilities = await installedkindcapabilities();
23223
+ const validation = await validatemanifest({ manifest: library.import.manifest, capabilities });
23224
+ if (!validation.ok || validation.manifest === void 0) throw new Error(validation.reason);
23225
+ const entry = await libraryentryof({ manifest: validation.manifest, provenance: `Imported from ${validation.manifest.registry ?? "a local file"} by the user`, now });
23226
+ const stored = await memory.addlibraryentry(entry);
23227
+ await audit("library", `The manifest ${entry.manifest.id} of ${entry.manifest.publisher} entered the flowlibrary as ${entry.state}${entry.state === "quarantined" ? "; the unverified publisher quarantines the entry until the user verifies it" : " with its verified publisher signature"}; the store deduplicates by the manifest digest and holds ${stored.length} entr${stored.length === 1 ? "y" : "ies"}.`, { ...session ? { sessionid: session.id } : {} });
23228
+ return { ...await ecosystemviewof(), entry };
23229
+ }
23230
+ if (library.install !== void 0) {
23231
+ const entry = (await memory.getflowlibrary()).find((candidate) => candidate.id === (library.install?.entryid ?? ""));
23232
+ if (!entry) throw new Error(`No flowlibrary entry matches ${library.install.entryid ?? ""}.`);
23233
+ if (entry.state === "quarantined") {
23234
+ const quarantinegate = libraryquarantinegate({ verified: false, signaturepresent: entry.manifest.publish !== void 0, signaturevalid: false });
23235
+ throw new Error(quarantinegate.reason ?? "The quarantined entry never installs on its own.");
23236
+ }
23237
+ const capabilities = await installedkindcapabilities();
23238
+ const capabilitygate = librarycapabilitygate({ kinds: [...new Set(entry.manifest.steps.map((step) => step.kind))], capabilities });
23239
+ if (!capabilitygate.allowed) throw new Error(capabilitygate.reason);
23240
+ const grants = session ? [.../* @__PURE__ */ new Set([session.origin, ...session.grants ?? []])] : [];
23241
+ const grantgate = librarygrantgate({ requiredgrants: entry.manifest.requiredgrants, heldgrants: grants });
23242
+ if (!grantgate.allowed) throw new Error(grantgate.reason);
23243
+ const consent = sensitiveconsentfor(entry.manifest, library.install.consent === true);
23244
+ if (consent.required && !library.install.consent) throw new Error(consent.reason);
23245
+ const record2 = installlibrary({ entry, ...library.install.selectornamespace !== void 0 && library.install.selectornamespace.trim() !== "" ? { selectornamespace: library.install.selectornamespace } : {}, now });
23246
+ await memory.addworkflowrecord(record2);
23247
+ await memory.addworkflowimport({ id: randomid(), record: record2, importedat: now, libraryversion: entry.manifest.version });
23248
+ const installedentry = { ...entry, state: "installed", installedat: now };
23249
+ await memory.setflowlibrary((await memory.getflowlibrary()).map((candidate) => candidate.id === entry.id ? installedentry : candidate));
23250
+ const event = libraryeventof({ kind: "install", entryid: entry.id, title: entry.manifest.title, version: entry.manifest.version, detail: `The manifest ${entry.manifest.id} of ${entry.manifest.publisher} resolved into the pending workflow ${record2.id} with ${record2.steps.length} steps and the selector namespace ${library.install.selectornamespace?.trim() || "unchanged"}.`, now });
23251
+ await memory.addlibraryevent(event);
23252
+ if (session) await appendrunevent("library", `The flowlibrary installed ${entry.manifest.title} version ${entry.manifest.version} of ${entry.manifest.publisher} as the pending workflow ${record2.id}; the import review approves its step list before anything runs.`, session, session.origin).catch(() => {
23253
+ });
23254
+ await audit("library", `The user installed ${entry.manifest.title} version ${entry.manifest.version} of ${entry.manifest.publisher}: the import landed as the pending workflow ${record2.id} with ${record2.steps.length} steps, the selector namespaces rewrote for the local profile and the import review gates every step before any run.`, { ...session ? { sessionid: session.id } : {}, planid: record2.id });
23255
+ return { ...await ecosystemviewof(), record: record2, event };
23256
+ }
23257
+ if (library.update !== void 0) {
23258
+ const entries = await memory.getflowlibrary();
23259
+ const existing = entries.find((candidate) => candidate.id === (library.update?.entryid ?? ""));
23260
+ if (!existing) throw new Error(`No installed flowlibrary entry matches ${library.update.entryid ?? ""}.`);
23261
+ const incoming = await libraryentryof({ manifest: { ...existing.manifest, version: `${existing.manifest.version}+${now}` }, provenance: existing.provenance, now });
23262
+ const diff = updatelibrary({ incoming, existing });
23263
+ if (diff.replace) {
23264
+ await memory.setflowlibrary((await memory.getflowlibrary()).map((candidate) => candidate.id === existing.id ? incoming : candidate));
23265
+ const event = libraryeventof({ kind: "update", entryid: existing.id, title: existing.manifest.title, version: incoming.manifest.version, detail: diff.reason, now });
23266
+ await memory.addlibraryevent(event);
23267
+ if (session) await appendrunevent("library", `The flowlibrary updated ${existing.manifest.title} from version ${diff.versionfrom} to ${diff.versionto} with ${diff.changedsteps.length} changed steps and ${diff.addedgrants.length} added grants; the version diff surfaced before the replace.`, session, session.origin).catch(() => {
23268
+ });
23269
+ await audit("library", `The user updated ${existing.manifest.title} from version ${diff.versionfrom} to ${diff.versionto}: ${diff.changedsteps.length} step${diff.changedsteps.length === 1 ? "" : "s"} changed and ${diff.addedgrants.length} grant${diff.addedgrants.length === 1 ? "" : "s"} added; the version diff surfaced before the replace and the local forks stay untouched.`, { ...session ? { sessionid: session.id } : {} });
23270
+ }
23271
+ return { diff, ...await ecosystemviewof() };
23272
+ }
23273
+ if (library.remove !== void 0) {
23274
+ const entry = (await memory.getflowlibrary()).find((candidate) => candidate.id === (library.remove?.entryid ?? ""));
23275
+ if (!entry) throw new Error(`No flowlibrary entry matches ${library.remove.entryid ?? ""}.`);
23276
+ const forks = (await memory.getworkflowrecordversions()).filter((record2) => record2.id.startsWith(`fork:${entry.manifest.id}:`));
23277
+ const outcome = removelibrary({ entry, forks });
23278
+ await memory.removelibraryentry(entry.id);
23279
+ const event = libraryeventof({ kind: "remove", entryid: entry.id, title: entry.manifest.title, version: entry.manifest.version, detail: outcome.reason, now });
23280
+ await memory.addlibraryevent(event);
23281
+ if (session) await appendrunevent("library", `The flowlibrary removed ${entry.manifest.title} version ${entry.manifest.version} while its ${forks.length} local fork${forks.length === 1 ? "" : "s"} stayed untouched.`, session, session.origin).catch(() => {
23282
+ });
23283
+ await audit("library", `The user removed ${entry.manifest.title} version ${entry.manifest.version} from the flowlibrary; the ${forks.length} local fork${forks.length === 1 ? "" : "s"} stay untouched because a fork is an independent local workflow.`, { ...session ? { sessionid: session.id } : {} });
23284
+ return { ...outcome, ...await ecosystemviewof() };
23285
+ }
23286
+ if (library.fork !== void 0) {
23287
+ const entry = (await memory.getflowlibrary()).find((candidate) => candidate.id === (library.fork?.entryid ?? ""));
23288
+ if (!entry) throw new Error(`No flowlibrary entry matches ${library.fork.entryid ?? ""}.`);
23289
+ const fork = forklibrary({ entry, now });
23290
+ await memory.addworkflowrecord(fork);
23291
+ await audit("library", `The user forked ${entry.manifest.title} version ${entry.manifest.version} into the independent local workflow ${fork.id} with ${fork.steps.length} steps; the fork owns its name from its creation on and reviews pending.`, { ...session ? { sessionid: session.id } : {} });
23292
+ return { fork, ...await ecosystemviewof() };
23293
+ }
23294
+ if (library.export === true) {
23295
+ const manifests = await memory.exportlibrarymanifests();
23296
+ await audit("library", `The flowlibrary exported its manifest list for audit: ${manifests.length} entr${manifests.length === 1 ? "y" : "ies"} with digest, publisher, version, state and provenance and no step payload.`, { ...session ? { sessionid: session.id } : {} });
23297
+ return { manifests };
23298
+ }
23299
+ throw new Error("The library command carries no browse, entry, grants, import, install, update, remove, fork or export action.");
23300
+ }
23301
+ if (input.sync !== void 0) {
23302
+ const sync = input.sync;
23303
+ if (sync.providers === true) return { providers: syncbridgeproviders() };
23304
+ if (sync.hooks === true) return { hooks: await memory.getsyncbridgehooks() };
23305
+ if (sync.hook?.add !== void 0) {
23306
+ const provider = sync.hook.add.provider === "web" ? "web" : "file";
23307
+ const direction = sync.hook.add.direction === "pull" ? "pull" : sync.hook.add.direction === "push" ? "push" : "both";
23308
+ const hook = syncbridgehookof({ provider, direction, endpoint: sync.hook.add.endpoint ?? "", now });
23309
+ await memory.setsyncbridgehooks([...await memory.getsyncbridgehooks(), hook]);
23310
+ await audit("syncbridge", `The user added the ${provider} hook of ${hook.endpoint} with the direction ${direction}; the hook starts opted out because no hook ever defaults on.`, { ...session ? { sessionid: session.id } : {} });
23311
+ return { hook, hooks: await memory.getsyncbridgehooks() };
23312
+ }
23313
+ if (sync.hook?.optin !== void 0) {
23314
+ const hooks = await memory.getsyncbridgehooks();
23315
+ const hook = hooks.find((candidate) => candidate.id === sync.hook?.optin?.hookid);
23316
+ if (!hook) throw new Error(`No syncbridge hook matches ${sync.hook.optin.hookid ?? ""}.`);
23317
+ const flipped = syncbridgeoptinflip(hook, sync.hook.optin.optin === true);
23318
+ await memory.setsyncbridgehooks(hooks.map((candidate) => candidate.id === hook.id ? flipped : candidate));
23319
+ await audit("syncbridge", `The user ${flipped.optin ? "opted the" : "opted the"} ${hook.provider} hook of ${hook.endpoint} ${flipped.optin ? "in" : "out"}; the explicit opt in stays the only switch and no hook ever defaults on.`, { ...session ? { sessionid: session.id } : {} });
23320
+ return { hook: flipped, hooks: await memory.getsyncbridgehooks() };
23321
+ }
23322
+ if (sync.pull !== void 0) {
23323
+ const hooks = await memory.getsyncbridgehooks();
23324
+ const hook = hooks.find((candidate) => candidate.id === sync.pull?.hookid);
23325
+ if (!hook) throw new Error(`No syncbridge hook matches ${sync.pull.hookid ?? ""}.`);
23326
+ const optingate = syncbridgeoptingate({ optin: hook.optin });
23327
+ if (!optingate.allowed) throw new Error(optingate.reason);
23328
+ if (hook.provider === "web") return { stub: webproviderstub(hook) };
23329
+ const validation = syncbridgevalidate(sync.pull.payload ?? {});
23330
+ if (!validation.ok) throw new Error(validation.reason);
23331
+ const payload = sync.pull.payload;
23332
+ const entries = await memory.getflowlibrary();
23333
+ const local = [];
23334
+ for (const entry of entries) local.push({ manifestid: entry.manifest.id, version: entry.manifest.version, digest: entry.digest });
23335
+ const remote = [];
23336
+ for (const manifest of payload.manifests) remote.push({ manifestid: manifest.id, version: manifest.version, digest: await syncdigestof(manifest) });
23337
+ const scan = await syncbridgescan({ hook, local, remote, now });
23338
+ for (const manifest of payload.manifests) {
23339
+ if (scan.synced.includes(manifest.id)) {
23340
+ const entry = await libraryentryof({ manifest, provenance: `Pulled from the ${hook.provider} hook of ${hook.endpoint}`, now });
23341
+ await memory.addlibraryentry(entry);
23342
+ }
23343
+ }
23344
+ for (const conflict of scan.conflicts) await memory.addsyncbridgeconflict(conflict);
23345
+ await memory.setsyncbridgehooks(hooks.map((candidate) => candidate.id === hook.id ? { ...candidate, state: "idle", lastsyncat: now } : candidate));
23346
+ await audit("syncbridge", `The file hook of ${hook.endpoint} pulled ${payload.manifests.length} manifest${payload.manifests.length === 1 ? "" : "s"}: ${scan.synced.length} moved while ${scan.conflicts.length} conflict${scan.conflicts.length === 1 ? "" : "s"} surfaced both versions instead of a silent overwrite.`, { ...session ? { sessionid: session.id } : {} });
23347
+ return { scan, ...await ecosystemviewof() };
23348
+ }
23349
+ if (sync.push !== void 0) {
23350
+ const hooks = await memory.getsyncbridgehooks();
23351
+ const hook = hooks.find((candidate) => candidate.id === sync.push?.hookid);
23352
+ if (!hook) throw new Error(`No syncbridge hook matches ${sync.push.hookid ?? ""}.`);
23353
+ const optingate = syncbridgeoptingate({ optin: hook.optin });
23354
+ if (!optingate.allowed) throw new Error(optingate.reason);
23355
+ if (hook.provider === "web") return { stub: webproviderstub(hook) };
23356
+ const payload = await syncbridgeexportpayload((await memory.getflowlibrary()).map((entry) => entry.manifest));
23357
+ await memory.setsyncbridgehooks(hooks.map((candidate) => candidate.id === hook.id ? { ...candidate, state: "idle", lastsyncat: now } : candidate));
23358
+ await audit("syncbridge", `The file hook of ${hook.endpoint} pushed ${payload.manifests.length} manifest${payload.manifests.length === 1 ? "" : "s"} with its digest list; secrets and logs never ride the bridge under any flag.`, { ...session ? { sessionid: session.id } : {} });
23359
+ return { payload, providers: syncbridgeproviders() };
23360
+ }
23361
+ if (sync.conflicts === true) return { conflicts: await memory.getsyncbridgeconflicts() };
23362
+ if (sync.resolve !== void 0) {
23363
+ const resolution = sync.resolve.resolution === "local" ? "local" : sync.resolve.resolution === "remote" ? "remote" : "merge";
23364
+ const conflicts = await memory.resolvesyncbridgeconflict(sync.resolve.conflictid ?? "", resolution, now);
23365
+ await audit("syncbridge", `The user resolved the syncbridge conflict ${sync.resolve.conflictid} with ${resolution}; one distinct action resolved the conflict and both versions stayed on record.`, { ...session ? { sessionid: session.id } : {} });
23366
+ return { conflicts };
23367
+ }
23368
+ throw new Error("The sync command carries no providers, hooks, hook, pull, push, conflicts or resolve action.");
23369
+ }
23370
+ if (input.attention !== void 0) {
23371
+ if (input.attention.dismiss !== void 0) {
23372
+ const entries2 = await memory.dismissattentionentry(input.attention.dismiss.id ?? "");
23373
+ await updatestatusbadge();
23374
+ await audit("attention", `The user dismissed the attention entry ${input.attention.dismiss.id ?? ""}; the dismissal removes the feed row only while the waiting cause keeps its own resolution path.`, { ...session ? { sessionid: session.id } : {} });
23375
+ return { attention: rankattention(entries2).map((entry) => ({ id: entry.id, cause: entry.cause, severity: entry.severity, runid: entry.runid, summary: entry.summary, deeplink: entry.deeplink, at: entry.at })) };
23376
+ }
23377
+ const entries = rankattention(await memory.getattentionentries());
23378
+ const pruned = await memory.pruneattentionentries(now);
23379
+ if (pruned.pruned.length > 0) await audit("attention", `The attentionfeed pruned ${pruned.pruned.length} entr${pruned.pruned.length === 1 ? "y" : "ies"} past the user configured retention window while the resolutions stay in the audit trail.`, {});
23380
+ await updatestatusbadge();
23381
+ return { attention: entries.map((entry) => ({ id: entry.id, cause: entry.cause, severity: entry.severity, runid: entry.runid, summary: entry.summary, deeplink: entry.deeplink, at: entry.at })), notifications: attentionnotifications(entries, now) };
23382
+ }
23383
+ if (input.replay !== void 0) {
23384
+ if (input.replay.open !== void 0) {
23385
+ const runid = input.replay.open.runid?.trim() ?? "";
23386
+ if (runid === "") throw new Error("The runreplay needs its recorded run id.");
23387
+ const log = await memory.getimmutablelog(runid);
23388
+ if (!log) throw new Error(`No sealed run log matches ${runid}.`);
23389
+ const report = await chainreportof(log);
23390
+ const gate = runreplaygate({ sealed: log.seal !== void 0, chainvalid: report.valid });
23391
+ if (!gate.allowed) throw new Error(gate.reason);
23392
+ const read = await readverifiedlog(log);
23393
+ const gates = (await memory.getgates()).map((record2) => ({ gateid: record2.gateid, kind: record2.kind, resolution: record2.state === "resolved" ? "approve" : record2.state === "refused" ? "refuse" : "waiting", at: record2.openedat }));
23394
+ const cursors = await memory.getreplaycursors();
23395
+ const stored = cursors[runid];
23396
+ const sessionbuilt = runreplaysessionof({ runid, entries: read.entries, gates, now });
23397
+ const replay = stored === void 0 ? sessionbuilt : { ...sessionbuilt, cursor: Math.min(stored.cursor, sessionbuilt.steps.length - 1), playing: stored.playing };
23398
+ const current = replay.steps[replay.cursor] ?? replay.steps[0];
23399
+ await audit("runreplay", `The runreplay opened the sealed run ${runid} whose chain verified across ${read.entries.length} entries; the replay walks it read only with the cursor at step ${replay.cursor} and every viewer action records here.`, { ...session ? { sessionid: session.id } : {} });
23400
+ return { replay, ...current !== void 0 ? { restored: replayrestoredview(current) } : {} };
23401
+ }
23402
+ if (input.replay.move !== void 0 || input.replay.jump !== void 0 || input.replay.play !== void 0) {
23403
+ const runid = (input.replay.move?.runid ?? input.replay.jump?.runid ?? input.replay.play?.runid ?? "").trim();
23404
+ if (runid === "") throw new Error("The runreplay action needs its recorded run id.");
23405
+ const log = await memory.getimmutablelog(runid);
23406
+ if (!log) throw new Error(`No sealed run log matches ${runid}.`);
23407
+ const report = await chainreportof(log);
23408
+ const gate = runreplaygate({ sealed: log.seal !== void 0, chainvalid: report.valid });
23409
+ if (!gate.allowed) throw new Error(gate.reason);
23410
+ const read = await readverifiedlog(log);
23411
+ const gates = (await memory.getgates()).map((record2) => ({ gateid: record2.gateid, kind: record2.kind, resolution: record2.state === "resolved" ? "approve" : record2.state === "refused" ? "refuse" : "waiting", at: record2.openedat }));
23412
+ let replay = runreplaysessionof({ runid, entries: read.entries, gates, now });
23413
+ const cursors = await memory.getreplaycursors();
23414
+ const stored = cursors[runid];
23415
+ if (stored !== void 0) replay = { ...replay, cursor: Math.min(stored.cursor, replay.steps.length - 1), playing: stored.playing };
23416
+ if (input.replay.move !== void 0) replay = replaymove(replay, input.replay.move.direction === "backward" ? "backward" : "forward", now);
23417
+ if (input.replay.jump !== void 0) replay = replayjump(replay, input.replay.jump.stepid ?? "", now);
23418
+ if (input.replay.play !== void 0) replay = replayplay(replay, input.replay.play.playing === true, now);
23419
+ await memory.setreplaycursor(runid, { cursor: replay.cursor, playing: replay.playing });
23420
+ const current = replay.steps[replay.cursor] ?? replay.steps[0];
23421
+ await audit("runreplay", `The runreplay viewer moved the cursor of ${runid} to step ${replay.cursor}${replay.playing ? " and plays" : ""}; the ${replay.actions[replay.actions.length - 1]?.kind ?? "step"} action records with its time and the replay touched no page state.`, { ...session ? { sessionid: session.id } : {} });
23422
+ return { replay, ...current !== void 0 ? { restored: replayrestoredview(current) } : {} };
23423
+ }
23424
+ throw new Error("The replay command carries no open, move, jump or play action.");
23425
+ }
23426
+ if (input.compare !== void 0 && input.compare.open !== void 0) {
23427
+ const runida = input.compare.open.runida?.trim() ?? "";
23428
+ const runidb = input.compare.open.runidb?.trim() ?? "";
23429
+ if (runida === "" || runidb === "") throw new Error("The outputcompare needs both run ids.");
23430
+ const runa = (await memory.listworkflowruns()).find((run) => run.id === runida);
23431
+ const runb = (await memory.listworkflowruns()).find((run) => run.id === runidb);
23432
+ if (!runa || !runb) throw new Error("The outputcompare needs the stored runs of both run ids.");
23433
+ const recorda = await memory.getworkflowrecord(runa.workflowid);
23434
+ const recordb = await memory.getworkflowrecord(runb.workflowid);
23435
+ if (!recorda || !recordb) throw new Error("The outputcompare needs the composed workflows of both runs.");
23436
+ const logsa = await memory.getrunlog(runida);
23437
+ const logsb = await memory.getrunlog(runidb);
23438
+ const signaturea = taskinputsignatureof({ objective: recorda.name, steps: recorda.steps.map((step) => step.kind) });
23439
+ const signatureb = taskinputsignatureof({ objective: recordb.name, steps: recordb.steps.map((step) => step.kind) });
23440
+ const comparegate = outputcomparegate({ signaturea, signatureb });
23441
+ if (!comparegate.allowed) throw new Error(comparegate.reason);
23442
+ const readonlygate = outputcomparereadonlygate({ executessteps: false });
23443
+ if (!readonlygate.allowed) throw new Error(readonlygate.reason);
23444
+ const sessionbuilt = outputcomparesessionof({ runids: [runida, runidb], logsa, logsb, now });
23445
+ await memory.addcomparesession(sessionbuilt);
23446
+ const metrics = comparesessionmetrics(sessionbuilt);
23447
+ await audit("outputcompare", `The outputcompare opened the runs ${runida} and ${runidb} that share their step sequence: ${metrics.reason} The comparison read the stored runlog outcomes only and executed no step.`, { ...session ? { sessionid: session.id } : {} });
23448
+ return { session: sessionbuilt, metrics, view: outputcompareview(sessionbuilt) };
23449
+ }
23450
+ if (input.background !== void 0) {
23451
+ if (input.background.queue !== void 0) {
23452
+ const workflowid = input.background.queue.workflowid?.trim() ?? "";
23453
+ if (workflowid === "") throw new Error("The background run queue needs its workflow id.");
23454
+ const record2 = await memory.getworkflowrecord(workflowid);
23455
+ if (!record2) throw new Error(`No composed workflow matches ${workflowid}.`);
23456
+ const reviewgate = runreviewgranted(record2);
23457
+ if (!reviewgate.allowed) throw new Error(reviewgate.reason ?? "The background run queue executes reviewed workflows only.");
23458
+ const queue = enqueuebackgroundrun({ queue: await memory.getbackgroundqueue(), workflowid, summary: input.background.queue.summary ?? `Background run of ${record2.name}`, now });
23459
+ await memory.setbackgroundqueue(queue);
23460
+ await audit("backgroundrun", `The user queued the workflow ${record2.name} for a background run; the queue holds ${queue.filter((entry) => entry.state === "queued").length} waiting entr${queue.filter((entry) => entry.state === "queued").length === 1 ? "y" : "ies"} and the executor picks the oldest first.`, { ...session ? { sessionid: session.id } : {} });
23461
+ void advancebackgroundqueue().catch(() => {
23462
+ });
23463
+ return { queue: backgroundrunsview(await memory.getbackgroundqueue()) };
23464
+ }
23465
+ if (input.background.cancel !== void 0) {
23466
+ const cancelled = cancelbackgroundentry(await memory.getbackgroundqueue(), input.background.cancel.id ?? "");
23467
+ await memory.setbackgroundqueue(cancelled.queue);
23468
+ await audit("backgroundrun", `The user cancelled ${cancelled.cancelled.length} queued background run${cancelled.cancelled.length === 1 ? "" : "s"}; a running entry keeps its executor path.`, { ...session ? { sessionid: session.id } : {} });
23469
+ return { queue: backgroundrunsview(cancelled.queue) };
23470
+ }
23471
+ await advancebackgroundqueue();
23472
+ return { queue: backgroundrunsview(await memory.getbackgroundqueue()), tray: backgroundtrayrows(await memory.getbackgroundqueue(), session?.origin ?? "") };
23473
+ }
23474
+ if (input.settings !== void 0) {
23475
+ const next = { ...settings ?? {}, ...input.settings.attentionretention !== void 0 ? { attentionretention: input.settings.attentionretention } : {} };
23476
+ await memory.setsettings(next);
23477
+ const pruned = await memory.pruneattentionentries(now);
23478
+ await audit("attention", `The user set the attentionfeed retention window${input.settings.attentionretention !== void 0 ? ` to ${input.settings.attentionretention} milliseconds` : ""}; ${pruned.pruned.length} entr${pruned.pruned.length === 1 ? "y" : "ies"} left the feed while the resolutions stay in the audit trail.`, { ...session ? { sessionid: session.id } : {} });
23479
+ return { settings: next };
23480
+ }
23481
+ return ecosystemviewof();
23482
+ }
23483
+ async function advancebackgroundqueue() {
23484
+ const now = Date.now();
23485
+ let queue = await memory.getbackgroundqueue();
23486
+ if (queue.length === 0) return;
23487
+ const session = await memory.getsession();
23488
+ for (const entry of queue.filter((candidate) => candidate.state === "running")) {
23489
+ if (await runofworkflowactive(entry.workflowid)) continue;
23490
+ const runs = (await memory.listworkflowruns()).filter((run) => run.workflowid === entry.workflowid).sort((a, b) => b.startedat - a.startedat);
23491
+ const last = runs[0];
23492
+ const state = last?.state === "failed" ? "failed" : "done";
23493
+ queue = queue.map((candidate) => candidate.id === entry.id ? finishbackgroundrun(candidate, state, now) : candidate);
23494
+ if (session) await appendrunevent("background", `The background run of ${entry.workflowid} ${state === "done" ? "completed" : "failed"} and released its keepalive hold.`, session, session.origin).catch(() => {
23495
+ });
23496
+ await audit("backgroundrun", `The background run of ${entry.workflowid} ${state === "done" ? "completed" : "failed"} and released its keepalive hold${state === "failed" ? "; the attentionfeed carries the failure with its deep link" : ""}.`, { ...session ? { sessionid: session.id } : {} });
23497
+ if (state === "failed") await recordattention("failure", entry.id, session?.origin ?? "", `The background run of ${entry.workflowid} failed: ${entry.summary}`).catch(() => {
23498
+ });
23499
+ }
23500
+ await memory.setbackgroundqueue(queue);
23501
+ if (queue.some((entry) => entry.state === "running")) return;
23502
+ const next = nextbackgroundrun(queue);
23503
+ if (next === void 0) return;
23504
+ const record2 = await memory.getworkflowrecord(next.workflowid);
23505
+ if (!record2) return;
23506
+ const reviewgate = runreviewgranted(record2);
23507
+ const begun = beginbackgroundrun(next, now, reviewgate.allowed);
23508
+ if (!begun.gate.allowed) {
23509
+ await audit("backgroundrun", `The background run of ${record2.name} stayed queued: ${begun.gate.reason}`, {});
23510
+ return;
23511
+ }
23512
+ queue = queue.map((candidate) => candidate.id === next.id ? begun.entry : candidate);
23513
+ await memory.setbackgroundqueue(queue);
23514
+ if (!session || session.stoppedat || session.pausedat || session.expiresat <= now) return;
23515
+ const plan = await memory.getplan();
23516
+ if (!plan || plan.state !== "approved") return;
23517
+ let granted = true;
23518
+ for (const workfloworigin of record2.origins) {
23519
+ if (!origingranted(session, workfloworigin)) granted = false;
23520
+ }
23521
+ if (!granted) return;
23522
+ startkeepaliveport(next.workflowid);
23523
+ await appendrunevent("background", `The background run queue started the workflow ${record2.name} version ${record2.version} with ${record2.steps.length} reviewed steps and holds the keepalive signal for its duration.`, session, session.origin).catch(() => {
23524
+ });
23525
+ await audit("backgroundrun", `The background run queue started the workflow ${record2.name} version ${record2.version} with ${record2.steps.length} reviewed steps; the keepalive signal holds for the whole run and every checkpoint restores it on each worker wake.`, { sessionid: session.id, planid: plan.id });
23526
+ const runstep2 = { id: `background${next.id}`, kind: "runworkflow", summary: `The background queue run of ${record2.name}`, risk: "sensitive", options: JSON.stringify({ workflowid: next.workflowid, reviewed: true, background: true, variables: { backgroundqueue: next.id } }) };
23527
+ const output = await executeworkflowstep(runstep2, session, plan, session.tabid, session.origin).catch((error) => ({ ok: false, summary: error instanceof Error ? error.message : String(error), details: {} }));
23528
+ if (!output.ok) {
23529
+ queue = queue.map((candidate) => candidate.id === next.id ? finishbackgroundrun(candidate, "failed", Date.now()) : candidate);
23530
+ await memory.setbackgroundqueue(queue);
23531
+ await recordattention("failure", next.id, session.origin, `The background run of ${record2.name} failed to start: ${output.summary}`).catch(() => {
23532
+ });
23533
+ await audit("backgroundrun", `The background run of ${record2.name} failed to start: ${output.summary}.`, { sessionid: session.id, planid: plan.id });
23534
+ }
23535
+ await refreshbadge().catch(() => {
23536
+ });
23537
+ }
23538
+ async function recoverbackgroundqueue() {
23539
+ const recovered = resumebackgroundqueue(await memory.getbackgroundqueue(), Date.now());
23540
+ if (recovered.requeued.length > 0) {
23541
+ await memory.setbackgroundqueue(recovered.queue);
23542
+ await audit("backgroundrun", `The worker restart requeued ${recovered.requeued.length} interrupted background run${recovered.requeued.length === 1 ? "" : "s"}; the queue state persisted for exactly this recovery.`, {});
23543
+ }
23544
+ await advancebackgroundqueue().catch(() => {
23545
+ });
23546
+ }
22613
23547
  async function handlesurfaceviewcommand(message) {
22614
23548
  const input = message;
22615
23549
  const now = Date.now();
@@ -26135,6 +27069,8 @@ async function handlerequest(message, sender) {
26135
27069
  return handlesurfacecommand(message);
26136
27070
  case "views":
26137
27071
  return handlesurfaceviewcommand(message);
27072
+ case "ecosystem":
27073
+ return handleecosystemcommand(message);
26138
27074
  case "security": {
26139
27075
  const input2 = message;
26140
27076
  const now = Date.now();
@@ -27183,6 +28119,8 @@ chrome.runtime.onStartup.addListener(() => {
27183
28119
  void detectcrash();
27184
28120
  void pauseinterruptedworkflowruns().then(() => restorebackgroundruns()).catch(() => {
27185
28121
  });
28122
+ void recoverbackgroundqueue().catch(() => {
28123
+ });
27186
28124
  void runwatchdog().catch(() => {
27187
28125
  });
27188
28126
  });