@framers/agentos 0.12.14 → 0.12.16

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.
@@ -59,9 +59,9 @@ export interface TransferStyleOptions {
59
59
  /** Provider-specific options passthrough. */
60
60
  providerOptions?: Record<string, unknown>;
61
61
  /**
62
- * API key for the provider, instead of its environment variable. It applies
63
- * to the provider named in `provider` (or `model`), or to the one detected
64
- * from the environment when neither is set.
62
+ * API key for the provider, instead of its environment variable. The call
63
+ * must name the provider, with `provider` or a provider-prefixed `model`
64
+ * (`openai:gpt-image-1`); a key with neither is refused.
65
65
  */
66
66
  apiKey?: string;
67
67
  /** Base URL for the provider, instead of its default or its environment variable. */
@@ -1 +1 @@
1
- {"version":3,"file":"transferStyle.d.ts","sourceRoot":"","sources":["../../src/api/transferStyle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAIH,OAAO,KAAK,EACV,cAAc,EAEf,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EAAsB,KAAK,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AAkB9F;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,uEAAuE;IACvE,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,uDAAuD;IACvD,cAAc,EAAE,MAAM,GAAG,MAAM,CAAC;IAChC,kDAAkD;IAClD,MAAM,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gEAAgE;IAChE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,yCAAyC;IACzC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wCAAwC;IACxC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,mDAAmD;IACnD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,oCAAoC;IACpC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wCAAwC;IACxC,UAAU,CAAC,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AAC;IAClB,yCAAyC;IACzC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wCAAwC;IACxC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,mDAAmD;IACnD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,oCAAoC;IACpC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wCAAwC;IACxC,UAAU,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,QAAQ,GAAG,eAAe,CAAC;IAC9D,6CAA6C;IAC7C,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC1C;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,qFAAqF;IACrF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,kCAAkC;IAClC,WAAW,CAAC,EAAE,yBAAyB,CAAC;CACzC;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,+CAA+C;IAC/C,MAAM,EAAE,cAAc,EAAE,CAAC;IACzB,wCAAwC;IACxC,QAAQ,EAAE,MAAM,CAAC;IACjB,mCAAmC;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,2BAA2B;IAC3B,KAAK,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAC7B;AAMD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAsB,aAAa,CAAC,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAqH5F"}
@@ -28,7 +28,7 @@
28
28
  */
29
29
  import { createImageProvider, hasImageProviderFactory } from '../io/media/images/index.js';
30
30
  import { imageToBuffer } from '../io/media/images/imageToBuffer.js';
31
- import { resolveModelOption, resolveMediaProvider } from './model.js';
31
+ import { knownProviderPrefixOf, resolveModelOption, resolveMediaProvider } from './model.js';
32
32
  import { recordAgentOSUsage } from './runtime/usageLedger.js';
33
33
  import { recordAgentOSTurnMetrics, withAgentOSSpan } from '../safety/evaluation/observability/otel.js';
34
34
  // ---------------------------------------------------------------------------
@@ -77,7 +77,15 @@ export async function transferStyle(opts) {
77
77
  // Resolve provider
78
78
  let providerId;
79
79
  let modelId;
80
- if (opts.provider) {
80
+ // The provider the call names: `provider`, or the prefix of `model`
81
+ // (`openai:gpt-image-1`). A key belongs to one vendor, so a call with a
82
+ // key must name its provider: otherwise the key would go to whichever
83
+ // provider the environment selects.
84
+ const namedProvider = opts.provider ?? knownProviderPrefixOf(opts.model);
85
+ if (opts.apiKey && !namedProvider) {
86
+ throw new Error('transferStyle: an apiKey needs `provider`, or a model with a provider prefix such as "openai:gpt-image-1"; it is not sent to a provider chosen from the environment.');
87
+ }
88
+ if (namedProvider) {
81
89
  ({ providerId, modelId } = resolveModelOption(opts, 'image'));
82
90
  }
83
91
  else {
@@ -1 +1 @@
1
- {"version":3,"file":"transferStyle.js","sourceRoot":"","sources":["../../src/api/transferStyle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAC3F,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAC;AAKpE,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAkC,MAAM,0BAA0B,CAAC;AAC9F,OAAO,EAAE,wBAAwB,EAAE,eAAe,EAAE,MAAM,4CAA4C,CAAC;AAEvG,8EAA8E;AAC9E,4DAA4D;AAC5D,8EAA8E;AAE9E,MAAM,gCAAgC,GAAmE;IACvG,EAAE,MAAM,EAAE,qBAAqB,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE,kCAAkC,EAAE;IACvG,EAAE,MAAM,EAAE,aAAa,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE;IACxE,EAAE,MAAM,EAAE,mBAAmB,EAAE,UAAU,EAAE,W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AAK,EAAE,CAAC;QACf,YAAY,GAAG,OAAO,CAAC;QACvB,MAAM,KAAK,CAAC;IACd,CAAC;YAAS,CAAC;QACT,IAAI,CAAC;YACH,MAAM,kBAAkB,CAAC;gBACvB,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,WAAW,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,SAAS;gBACtE,OAAO,EAAE,EAAE,GAAG,IAAI,CAAC,WAAW,EAAE,MAAM,EAAE,IAAI,CAAC,WAAW,EAAE,MAAM,IAAI,eAAe,EAAE;aACtF,CAAC,CAAC;QACL,CAAC;QAAC,MAAM,CAAC,CAAC,iBAAiB,CAAC,CAAC;QAC7B,wBAAwB,CAAC;YACvB,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS;YAClC,MAAM,EAAE,YAAY;SACrB,CAAC,CAAC;IACL,CAAC;AACH,CAAC"}
@@ -161,6 +161,13 @@ export interface EmergentCapabilityEngineDeps {
161
161
  onToolPromoted?: (tool: EmergentTool) => Promise<void>;
162
162
  /** Optional callback used when a tool is removed from the live runtime. */
163
163
  onToolRemoved?: (tool: EmergentTool) => Promise<void>;
164
+ /**
165
+ * Optional callback used to register again a tool of the host's whose name
166
+ * a forged composition's executable took, when the forge takes that
167
+ * executable out again (the composition reached itself once registered).
168
+ * Without it the name is left empty in that case.
169
+ */
170
+ onToolRestored?: (tool: ITool) => Promise<void>;
164
171
  }
165
172
  export declare class EmergentCapabilityEngine {
166
173
  /** Injected dependencies. */
@@ -172,6 +179,7 @@ export declare class EmergentCapabilityEngine {
172
179
  private readonly onToolForged?;
173
180
  private readonly onToolPromoted?;
174
181
  private readonly onToolRemoved?;
182
+ private readonly onToolRestored?;
175
183
  /** The host's ceiling for code-forged tools, resolved; absent on the legacy path. */
176
184
  private readonly ceiling?;
177
185
  /** The broker the forge's injected functions come from under a ceiling. */
@@ -374,6 +382,14 @@ export declare class EmergentCapabilityEngine {
374
382
  private settleRegistration;
375
383
  /** Take a tool's executable out of the host, best-effort. */
376
384
  private dropExecutable;
385
+ /**
386
+ * Register again the tool a forge's executable took the name from, after
387
+ * the forge took its own executable out: only while nothing holds the name.
388
+ * A host's tool goes back through `onToolRestored`; another forged tool of
389
+ * the name, when this process still holds it active, through
390
+ * `onToolForged`. Best-effort.
391
+ */
392
+ private restoreDisplaced;
377
393
  /**
378
394
  * The forge's refusal of a composition under what is registered now: a step
379
395
  * that may not be chained, or a chain that reaches the composition itself,
@@ -400,9 +416,11 @@ export declare class EmergentCapabilityEngine {
400
416
  * the library's (so a later load, or a registration of the missing step
401
417
  * tool, re-checks it), held here, and the executable taken out. It gives
402
418
  * way to the host's word: when this process holds a host's suspension or a
403
- * demotion nothing is written, and a row another process restricted that
404
- * way is left as it is and held here (`yieldToHost`), so the library never
405
- * turns a host's restriction into one of its own that a re-check lifts.
419
+ * demotion nothing is written, a row another process restricted that way
420
+ * is left as it is and held here (`yieldToHost`), and a row the host turned
421
+ * off with its own SQL (active, its flag lowered, the mark clear) is
422
+ * recorded as the host's demotion, so the library never turns a host's
423
+ * restriction into one of its own that a re-check lifts.
406
424
  *
407
425
  * It takes its turn with the tool's admissions (`serializeAdmission`): a
408
426
  * re-check that a registration starts while the suspension is written runs
@@ -414,6 +432,14 @@ export declare class EmergentCapabilityEngine {
414
432
  */
415
433
  private suspendAsLibrary;
416
434
  private suspendAsLibraryNow;
435
+ /**
436
+ * A row that reads active, its mark clear, with its tool row's flag
437
+ * lowered: the host turned the tool off with its own SQL. Recorded as the
438
+ * host's demotion (`legacy_inactive`), as a load records it, only while the
439
+ * state row is still the one read here, so a host that reactivated the
440
+ * tool meanwhile is not written over. Only `reactivateTool` lifts it.
441
+ */
442
+ private demoteIfHostTurnedOff;
417
443
  private unregisterIfLive;
418
444
  /**
419
445
  * A restriction this process holds that the row read from `readAt` on may
@@ -426,7 +452,19 @@ export declare class EmergentCapabilityEngine {
426
452
  * process lifted after it, whatever the processes' clocks say.
427
453
  */
428
454
  private newerRestrictionHeld;
429
- /** A stored restriction, held in this process too when the tool is live here. */
455
+ /**
456
+ * A host's restriction (its suspension, or a demotion) this process holds
457
+ * that the row read from `readAt` on may not show: its write is still under
458
+ * way, landed after the read began, or failed. Only `reactivateTool` lifts
459
+ * it; nothing read from that row replaces it.
460
+ */
461
+ private unreadHostRestriction;
462
+ /**
463
+ * A stored restriction, held in this process too when the tool is live
464
+ * here. With `readAt`, the point the record's row was read at, a host's
465
+ * restriction this process holds that the row may not show stays instead
466
+ * (see {@link unreadHostRestriction}).
467
+ */
430
468
  private holdStored;
431
469
  /**
432
470
  * Factory method that creates the four self-improvement tools when
@@ -1 +1 @@
1
- {"version":3,"file":"EmergentCapabilityEngine.d.ts","sourceRoot":"","sources":["../../../src/cognition/emergent/EmergentCapabilityEngine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EACV,cAAc,EACd,gBAAgB,EAChB,WAAW,EACX,eAAe,EACf,YAAY,EAKZ,SAAS,EAET,QAAQ,EAKT,MAAM,YAAY,CAAC;AAmBpB,OAAO,KAAK,EAAE,KAAK,EAAoB,oBAAoB,EAAuB,MAAM,2BAA2B,CAAC;AACpH,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAE9E,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAMjE;;;;;;GAMG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;;OAIG;IACH,cAAc,EAAE,CAAC,OAAO,CAAC,EAAE,oBAAoB,KAAK,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAE3E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;;;OASG;IACH,oBAAoB,CAAC,IAAI,EAAE,YAAY,GAAG,sBAAsB;IAuKhE;;;;;;OAMG;IACH,OAAO,CAAC,SAAS;IAcjB,OAAO,CAAC,iBAAiB;IAKzB,OAAO,CAAC,2BAA2B;IASnC,OAAO,CAAC,gBAAgB;IAIxB,OAAO,CAAC,sBAAsB;IAkC9B;;;;;;;OAOG;YACW,YAAY;CAqC3B"}
@@ -155,6 +155,7 @@ export class EmergentCapabilityEngine {
155
155
  this.onToolForged = deps.onToolForged;
156
156
  this.onToolPromoted = deps.onToolPromoted;
157
157
  this.onToolRemoved = deps.onToolRemoved;
158
+ this.onToolRestored = deps.onToolRestored;
158
159
  if (deps.stepGate) {
159
160
  this.composableBuilder.bind({ gate: deps.stepGate });
160
161
  }
@@ -422,7 +423,34 @@ export class EmergentCapabilityEngine {
422
423
  console.warn(`[agentos:emergent] "${request.name}" (${toolId}) was ${written.state} before its forge finished ` +
423
424
  `(${written.reason ?? 'no reason recorded'})`);
424
425
  }
426
+ if (request.implementation.mode === 'compose') {
427
+ // A composition forged while this one's state was written can close a
428
+ // cycle with it. Checked again here, with nothing awaited between this
429
+ // check and the registration of the executable below, so a cycle seen
430
+ // now is refused before the executor is touched and the name keeps the
431
+ // tool it has.
432
+ const cycle = this.compositionCycle(request.name, request.implementation.steps);
433
+ if (cycle) {
434
+ const held = this.registry.get(toolId);
435
+ // A load that adopted the tool from its row meanwhile registered its
436
+ // executable: that one goes too.
437
+ const registeredMeanwhile = this.composableBuilder.resolve(request.name)?.id === `emergent-tool:${toolId}`;
438
+ this.registry.remove(toolId);
439
+ this.removeIndexedToolEverywhere(toolId);
440
+ if (held && registeredMeanwhile) {
441
+ await this.dropExecutable(held);
442
+ }
443
+ return {
444
+ success: false,
445
+ verdict,
446
+ error: `step_cycle: "${request.name}" reaches itself through ${cycle.join(' -> ')}`,
447
+ };
448
+ }
449
+ }
425
450
  this.indexTool(toolId, context.agentId, context.sessionId);
451
+ // What the name resolves to before this tool's executable takes it: a
452
+ // forge that takes its own executable out again hands the name back.
453
+ const displaced = this.composableBuilder.resolve(request.name);
426
454
  if (this.onToolForged) {
427
455
  // The object the registry holds (a registration stores a stamped copy;
428
456
  // an adoption above stores the object itself), so the settlement
@@ -455,10 +483,12 @@ export class EmergentCapabilityEngine {
455
483
  }
456
484
  }
457
485
  if (request.implementation.mode === 'compose') {
458
- // A composition registered between the check above and this one's own
459
- // registration can close a cycle with it, and neither check saw the
460
- // other: checked once more now that this one resolves by its name, and
461
- // taken out again when it reaches itself.
486
+ // A composition forged while the host was registering this one's
487
+ // executable (inside its registerTool) can close a cycle with it, and
488
+ // neither check saw the other: checked once more now that this one
489
+ // resolves by its name, and taken out again when it reaches itself.
490
+ // The tool the name resolved to before is registered again, so a
491
+ // composition forged over that tool meanwhile keeps working.
462
492
  const cycle = this.compositionCycle(request.name, request.implementation.steps);
463
493
  if (cycle) {
464
494
  const held = this.registry.get(toolId);
@@ -467,6 +497,7 @@ export class EmergentCapabilityEngine {
467
497
  }
468
498
  this.registry.remove(toolId);
469
499
  this.removeIndexedToolEverywhere(toolId);
500
+ await this.restoreDisplaced(request.name, displaced, toolId);
470
501
  return {
471
502
  success: false,
472
503
  verdict,
@@ -521,7 +552,20 @@ export class EmergentCapabilityEngine {
521
552
  // A tool that no longer fits what is in force is suspended, not promoted.
522
553
  const refusal = this.refusalFor(tool.implementation, tool.name);
523
554
  if (refusal) {
524
- await this.suspendAsLibrary(toolId, refusal);
555
+ const suspended = await this.suspendAsLibrary(toolId, refusal);
556
+ // The suspension took its turn behind the tool's admissions, and a
557
+ // fitting tool registered while it waited re-checked nothing (the tool
558
+ // was not suspended yet): checked again now against the tools
559
+ // registered now, as a run's suspension is.
560
+ const implementation = this.registry.get(toolId)?.implementation ?? tool.implementation;
561
+ if (suspended && this.refusalFor(implementation, tool.name) === null) {
562
+ try {
563
+ await this.recheck(toolId, false);
564
+ }
565
+ catch (recheckError) {
566
+ console.warn(`[agentos:emergent] could not re-check "${tool.name}" (${toolId}) after the promotion check suspended it:`, recheckError instanceof Error ? recheckError.message : recheckError);
567
+ }
568
+ }
525
569
  return { success: false, error: `${refusal}: the tool no longer fits and was suspended.` };
526
570
  }
527
571
  // Only session-tier tools are eligible for auto-promotion.
@@ -678,6 +722,7 @@ export class EmergentCapabilityEngine {
678
722
  legacyActive: tool.isActive ?? true,
679
723
  tier: tool.tier,
680
724
  createdBy: tool.createdBy,
725
+ session: sessionFromSource(tool.source) ?? undefined,
681
726
  buildTool: () => tool,
682
727
  }, { readAt });
683
728
  });
@@ -819,6 +864,9 @@ export class EmergentCapabilityEngine {
819
864
  if (!row) {
820
865
  return false;
821
866
  }
867
+ if (row.tier === 'session') {
868
+ this.registry.noteStoredSession(toolId, row.created_by_session);
869
+ }
822
870
  await this.registry.setState(toolId, 'suspended', reason, { setBy: 'host' });
823
871
  return true;
824
872
  }
@@ -841,6 +889,9 @@ export class EmergentCapabilityEngine {
841
889
  if (!row) {
842
890
  return false;
843
891
  }
892
+ if (row.tier === 'session') {
893
+ this.registry.noteStoredSession(toolId, row.created_by_session);
894
+ }
844
895
  await this.registry.setState(toolId, 'demoted', reason, { setBy: 'host' });
845
896
  return true;
846
897
  }
@@ -913,6 +964,7 @@ export class EmergentCapabilityEngine {
913
964
  legacyActive: true,
914
965
  tier: tool.tier,
915
966
  createdBy: tool.createdBy,
967
+ session: sessionFromSource(tool.source) ?? undefined,
916
968
  buildTool: () => tool,
917
969
  }, { force, readAt });
918
970
  });
@@ -981,6 +1033,7 @@ export class EmergentCapabilityEngine {
981
1033
  flagSynced: row.flag_synced == null ? undefined : !(row.flag_synced === 0 || row.flag_synced === false),
982
1034
  tier: row.tier,
983
1035
  createdBy: row.created_by_agent,
1036
+ session: row.created_by_session,
984
1037
  buildTool: (implementation) => toolFromRow(row, implementation),
985
1038
  }, options);
986
1039
  }
@@ -1018,7 +1071,7 @@ export class EmergentCapabilityEngine {
1018
1071
  setBy: 'library',
1019
1072
  at: Date.now(),
1020
1073
  request: null,
1021
- });
1074
+ }, options.readAt);
1022
1075
  await this.unregisterIfLive(toolId);
1023
1076
  return { toolId, name, state: 'suspended', reason: 'contended' };
1024
1077
  }
@@ -1027,6 +1080,23 @@ export class EmergentCapabilityEngine {
1027
1080
  // The point after which a change makes what this admission holds stale:
1028
1081
  // where its row was read, or, for a caller that did not say, now.
1029
1082
  const readAt = options.readAt ?? this.registry.generation(toolId);
1083
+ // A stored session tool's session, recorded before any state is held for
1084
+ // it here: the session's cleanup lets go of that state before it returns.
1085
+ if (candidate.tier === 'session' && candidate.session) {
1086
+ this.registry.noteStoredSession(toolId, candidate.session);
1087
+ }
1088
+ // 0. A restriction the host set in this process that the row this
1089
+ // admission read may not show (its write is under way, landed after
1090
+ // the read, or failed) stays in force until the host reactivates the
1091
+ // tool, whatever the row reads, the library's own suspension included:
1092
+ // nothing is written, and the executable goes.
1093
+ if (!options.force) {
1094
+ const hostHeld = this.unreadHostRestriction(toolId, readAt);
1095
+ if (hostHeld) {
1096
+ await this.unregisterIfLive(toolId);
1097
+ return { toolId, name, state: hostHeld.state, reason: hostHeld.reason };
1098
+ }
1099
+ }
1030
1100
  let legacyActive = candidate.legacyActive;
1031
1101
  // A row whose last state write did not finish its flag write: finish it
1032
1102
  // first, so the flag reads what the state row says before anything is
@@ -1050,7 +1120,7 @@ export class EmergentCapabilityEngine {
1050
1120
  if ((stored?.state === 'demoted' || hostTurnedOff) && !options.force) {
1051
1121
  const reason = stored?.state === 'demoted' ? stored.reason : 'legacy_inactive';
1052
1122
  if (stored?.state === 'demoted') {
1053
- this.holdStored(toolId, stored);
1123
+ this.holdStored(toolId, stored, readAt);
1054
1124
  }
1055
1125
  else {
1056
1126
  // Written only while the row is as it was read: a host that
@@ -1072,7 +1142,7 @@ export class EmergentCapabilityEngine {
1072
1142
  if (stored?.state === 'suspended' && !options.force && stored.setBy === 'host') {
1073
1143
  // Another process may have set it: this one takes it in and lets go of
1074
1144
  // the executable, so the suspension holds wherever the tool is loaded.
1075
- this.holdStored(toolId, stored);
1145
+ this.holdStored(toolId, stored, readAt);
1076
1146
  await this.unregisterIfLive(toolId);
1077
1147
  return { toolId, name, state: 'suspended', reason: stored.reason };
1078
1148
  }
@@ -1153,7 +1223,7 @@ export class EmergentCapabilityEngine {
1153
1223
  // The row already says so; this process holds it too. A row that
1154
1224
  // holds no request it can read is held with the one derived from its
1155
1225
  // source, so a registration of a step tool it names finds it.
1156
- this.holdStored(toolId, stored.request ? stored : { ...stored, request });
1226
+ this.holdStored(toolId, stored.request ? stored : { ...stored, request }, readAt);
1157
1227
  }
1158
1228
  await this.unregisterIfLive(toolId);
1159
1229
  return { toolId, name, state: 'suspended', reason };
@@ -1198,7 +1268,7 @@ export class EmergentCapabilityEngine {
1198
1268
  // row and gives way to it.
1199
1269
  const held = written && written.state !== 'active' ? written : this.newerRestrictionHeld(toolId, readAt);
1200
1270
  if (held && held.state !== 'active') {
1201
- this.holdStored(toolId, held);
1271
+ this.holdStored(toolId, held, readAt);
1202
1272
  await this.unregisterIfLive(toolId);
1203
1273
  return { toolId, name, state: held.state, reason: held.reason };
1204
1274
  }
@@ -1325,6 +1395,34 @@ export class EmergentCapabilityEngine {
1325
1395
  console.warn(`[agentos:emergent] could not take out the executable of "${tool.name}" (${tool.id}):`, error instanceof Error ? error.message : error);
1326
1396
  }
1327
1397
  }
1398
+ /**
1399
+ * Register again the tool a forge's executable took the name from, after
1400
+ * the forge took its own executable out: only while nothing holds the name.
1401
+ * A host's tool goes back through `onToolRestored`; another forged tool of
1402
+ * the name, when this process still holds it active, through
1403
+ * `onToolForged`. Best-effort.
1404
+ */
1405
+ async restoreDisplaced(name, displaced, ownToolId) {
1406
+ if (!displaced ||
1407
+ displaced.id === `emergent-tool:${ownToolId}` ||
1408
+ this.composableBuilder.resolve(name) !== undefined) {
1409
+ return;
1410
+ }
1411
+ try {
1412
+ if (displaced.id.startsWith('emergent-tool:')) {
1413
+ const forgedId = displaced.id.slice('emergent-tool:'.length);
1414
+ const forged = this.registry.get(forgedId);
1415
+ if (forged && forged.name === name && this.registry.isActive(forgedId) && this.onToolForged) {
1416
+ await this.onToolForged(forged, this.createExecutableTool(forged));
1417
+ }
1418
+ return;
1419
+ }
1420
+ await this.onToolRestored?.(displaced);
1421
+ }
1422
+ catch (error) {
1423
+ console.warn(`[agentos:emergent] could not register "${name}" again after the forge that took the name gave it up:`, error instanceof Error ? error.message : error);
1424
+ }
1425
+ }
1328
1426
  /**
1329
1427
  * The forge's refusal of a composition under what is registered now: a step
1330
1428
  * that may not be chained, or a chain that reaches the composition itself,
@@ -1410,9 +1508,11 @@ export class EmergentCapabilityEngine {
1410
1508
  * the library's (so a later load, or a registration of the missing step
1411
1509
  * tool, re-checks it), held here, and the executable taken out. It gives
1412
1510
  * way to the host's word: when this process holds a host's suspension or a
1413
- * demotion nothing is written, and a row another process restricted that
1414
- * way is left as it is and held here (`yieldToHost`), so the library never
1415
- * turns a host's restriction into one of its own that a re-check lifts.
1511
+ * demotion nothing is written, a row another process restricted that way
1512
+ * is left as it is and held here (`yieldToHost`), and a row the host turned
1513
+ * off with its own SQL (active, its flag lowered, the mark clear) is
1514
+ * recorded as the host's demotion, so the library never turns a host's
1515
+ * restriction into one of its own that a re-check lifts.
1416
1516
  *
1417
1517
  * It takes its turn with the tool's admissions (`serializeAdmission`): a
1418
1518
  * re-check that a registration starts while the suspension is written runs
@@ -1429,22 +1529,58 @@ export class EmergentCapabilityEngine {
1429
1529
  const held = this.registry.getState(toolId);
1430
1530
  let suspended = false;
1431
1531
  if (!held || !isHostRestriction(held)) {
1532
+ let refusedOverActive = false;
1432
1533
  try {
1433
1534
  const inForce = await this.registry.setState(toolId, 'suspended', reason, {
1434
1535
  setBy: 'library',
1435
1536
  yieldToHost: true,
1436
1537
  });
1437
1538
  suspended = inForce.state === 'suspended' && inForce.setBy === 'library';
1539
+ refusedOverActive = inForce.state === 'active';
1438
1540
  }
1439
1541
  catch (error) {
1440
1542
  // Held here even though the row did not take it.
1441
1543
  suspended = true;
1442
1544
  console.warn(`[agentos:emergent] could not store the suspension of "${toolId}" (${reason}):`, error instanceof Error ? error.message : error);
1443
1545
  }
1546
+ if (refusedOverActive) {
1547
+ // The row reads active and did not take the suspension: when the host
1548
+ // turned the tool row off with its own SQL, that is recorded now as
1549
+ // the host's demotion, as a load records it, so no re-check of the
1550
+ // library's raises the flag again.
1551
+ try {
1552
+ await this.demoteIfHostTurnedOff(toolId);
1553
+ }
1554
+ catch (error) {
1555
+ console.warn(`[agentos:emergent] could not record the host's disable of "${toolId}":`, error instanceof Error ? error.message : error);
1556
+ }
1557
+ }
1444
1558
  }
1445
1559
  await this.unregisterIfLive(toolId);
1446
1560
  return suspended;
1447
1561
  }
1562
+ /**
1563
+ * A row that reads active, its mark clear, with its tool row's flag
1564
+ * lowered: the host turned the tool off with its own SQL. Recorded as the
1565
+ * host's demotion (`legacy_inactive`), as a load records it, only while the
1566
+ * state row is still the one read here, so a host that reactivated the
1567
+ * tool meanwhile is not written over. Only `reactivateTool` lifts it.
1568
+ */
1569
+ async demoteIfHostTurnedOff(toolId) {
1570
+ const row = await this.registry.loadRow(toolId);
1571
+ if (!row || row.state !== 'active') {
1572
+ return;
1573
+ }
1574
+ const markClear = !(row.flag_synced === 0 || row.flag_synced === false);
1575
+ const flagLowered = row.is_active === 0 || row.is_active === false;
1576
+ if (!markClear || !flagLowered) {
1577
+ return;
1578
+ }
1579
+ await this.registry.setState(toolId, 'demoted', 'legacy_inactive', {
1580
+ setBy: 'host',
1581
+ ifRow: { at: Number(row.state_at ?? 0), state: 'active', setBy: stateSetterFromColumn(row.set_by) },
1582
+ });
1583
+ }
1448
1584
  async unregisterIfLive(toolId) {
1449
1585
  const live = this.registry.get(toolId);
1450
1586
  if (live && this.onToolRemoved) {
@@ -1468,8 +1604,27 @@ export class EmergentCapabilityEngine {
1468
1604
  }
1469
1605
  return this.registry.restrictionUnread(toolId, readAt) ? memory : undefined;
1470
1606
  }
1471
- /** A stored restriction, held in this process too when the tool is live here. */
1472
- holdStored(toolId, record) {
1607
+ /**
1608
+ * A host's restriction (its suspension, or a demotion) this process holds
1609
+ * that the row read from `readAt` on may not show: its write is still under
1610
+ * way, landed after the read began, or failed. Only `reactivateTool` lifts
1611
+ * it; nothing read from that row replaces it.
1612
+ */
1613
+ unreadHostRestriction(toolId, readAt) {
1614
+ const memory = this.registry.getState(toolId);
1615
+ return memory && isHostRestriction(memory) && this.registry.restrictionUnread(toolId, readAt) ? memory : undefined;
1616
+ }
1617
+ /**
1618
+ * A stored restriction, held in this process too when the tool is live
1619
+ * here. With `readAt`, the point the record's row was read at, a host's
1620
+ * restriction this process holds that the row may not show stays instead
1621
+ * (see {@link unreadHostRestriction}).
1622
+ */
1623
+ holdStored(toolId, record, readAt) {
1624
+ const kept = readAt === undefined ? undefined : this.unreadHostRestriction(toolId, readAt);
1625
+ if (kept && kept !== record) {
1626
+ return;
1627
+ }
1473
1628
  const live = this.registry.get(toolId);
1474
1629
  if (live) {
1475
1630
  this.registry.adopt(live, record);