dsh-run2skill 0.4.0 → 0.5.0-alpha.2

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.
@@ -66,14 +66,14 @@ function descriptor(method, requestSchema) {
66
66
  codec: {
67
67
  mode: "strict",
68
68
  typeSymbol: method === "query" ? "Run2skillQueryRequest" : "Run2skillCommandRequest",
69
- schema: requestSchema
69
+ create: () => requestSchema
70
70
  }
71
71
  }],
72
72
  cancellation: { parameter: "signal" },
73
73
  result: {
74
74
  mode: "strict",
75
75
  typeSymbol: "Run2skillRpcResult",
76
- schema: rpcResult
76
+ create: () => rpcResult
77
77
  }
78
78
  };
79
79
  return Object.freeze(value);
package/lib/index.d.ts CHANGED
@@ -4841,12 +4841,24 @@ interface SessionPersistenceSnapshot {
4841
4841
  readonly header: DshSessionHeader;
4842
4842
  readonly revision: string;
4843
4843
  }
4844
- interface SessionPersistencePort {
4845
- listSnapshots(signal?: AbortSignal): Promise<readonly SessionPersistenceSnapshot[]>;
4846
- readFrom(sessionId: string, fromSeq: number, signal?: AbortSignal): Promise<{
4847
- readonly meta: DshSessionHeader;
4844
+ interface DshSessionReadHandlePort {
4845
+ readonly header: DshSessionHeader;
4846
+ read(offset?: number, length?: number, options?: {
4847
+ readonly signal?: AbortSignal;
4848
+ }): Promise<{
4849
+ readonly eventState: 'detached' | 'shared-frozen';
4848
4850
  readonly events: readonly DshSessionEvent[];
4849
4851
  }>;
4852
+ close(): Promise<void>;
4853
+ }
4854
+ /** DSH 0.1.3-alpha.2 persistence service exposed as ctx.sessionPersistence. */
4855
+ interface DshSessionPersistencePort {
4856
+ list(options?: {
4857
+ readonly signal?: AbortSignal;
4858
+ }): Promise<readonly SessionPersistenceSnapshot[]>;
4859
+ open(sessionId: string, access: 'read', options?: {
4860
+ readonly signal?: AbortSignal;
4861
+ }): Promise<DshSessionReadHandlePort>;
4850
4862
  }
4851
4863
  //#endregion
4852
4864
  //#region src/adapters/dsh-filesystem/context-filesystem.d.ts
@@ -5497,6 +5509,12 @@ interface StockPluginRuntimeProjection {
5497
5509
  interface StockPresetMountProjection {
5498
5510
  readonly presetId: string;
5499
5511
  readonly fiber: StockFiberProjection;
5512
+ readonly key?: object | undefined;
5513
+ readonly tree?: {
5514
+ readonly root: {
5515
+ readonly data: unknown;
5516
+ };
5517
+ } | undefined;
5500
5518
  }
5501
5519
  interface StockPresetMountPort {
5502
5520
  standingMountFor(agentContext: object): StockPresetMountProjection | undefined | Promise<StockPresetMountProjection | undefined>;
@@ -5509,32 +5527,26 @@ interface StockComposedAgentProjection {
5509
5527
  readonly get?: (name: string) => unknown;
5510
5528
  };
5511
5529
  }
5512
- interface StockAgentPresetObservationPort {
5513
- composedPreset(agentContext: object): string | undefined;
5514
- resolve(id: string): Promise<{
5515
- readonly id: string;
5516
- readonly trust: 'system' | 'user';
5517
- }>;
5518
- read(id: string): Promise<string>;
5519
- }
5520
- declare function resolvePinnedStockPresetConfiguration(presets: StockAgentPresetObservationPort, agent: {
5521
- readonly ctx: object;
5522
- }, expectedDigests?: Readonly<Record<'standard', readonly string[]>>): Promise<StockSkillRuntimeConfiguration | undefined>;
5523
5530
  /** Reads the exact stock filesystem fiber mounted for one Agent's joined generation. */
5524
- declare function resolveStockSkillRuntimeConfiguration(mounts: StockPresetMountPort, agent: StockComposedAgentProjection): Promise<StockSkillRuntimeConfiguration | undefined>;
5531
+ declare function resolveStockSkillRuntimeConfiguration(mounts: StockPresetMountPort, agent: StockComposedAgentProjection, expectedDigest?: string): Promise<StockSkillRuntimeConfiguration | undefined>;
5525
5532
  //#endregion
5526
- //#region src/adapters/dsh-settings/automatic-learning.d.ts
5527
- interface DshSettingsScope<T> {
5528
- get(): T;
5529
- watch(callback: (next: T, previous: T) => void | Promise<void>): () => void;
5533
+ //#region src/adapters/dsh-skills/stock-cold-preset.d.ts
5534
+ interface StockPresetLease {
5535
+ readonly key: object;
5536
+ [Symbol.asyncDispose](): Promise<void>;
5537
+ }
5538
+ interface StockColdPresetRegistry {
5539
+ acquireScope(id: string): Promise<StockPresetLease>;
5530
5540
  }
5531
- interface DshSettingsPort {
5532
- register<T>(namespace: string, schema: z$1<T>, options: {
5533
- readonly applies: 'live';
5534
- }): DshSettingsScope<T>;
5541
+ //#endregion
5542
+ //#region src/adapters/dsh-settings/automatic-learning.d.ts
5543
+ interface AutomaticLearningConfig {
5544
+ readonly automaticLearning: {
5545
+ get(): boolean;
5546
+ };
5535
5547
  }
5536
5548
  interface AutomaticLearningSettingsPolicy extends AutomaticLearningPolicyPort {
5537
- watch(callback: (next: AutomaticLearningSnapshot, previous: AutomaticLearningSnapshot) => void | Promise<void>): () => void;
5549
+ watch(callback: (next: AutomaticLearningSnapshot, previous: AutomaticLearningSnapshot) => void): () => void;
5538
5550
  }
5539
5551
  //#endregion
5540
5552
  //#region src/application/purge/purge-service.d.ts
@@ -5694,19 +5706,21 @@ declare class PublicationTargetSingleFlight {
5694
5706
  //#endregion
5695
5707
  //#region src/host/index.d.ts
5696
5708
  declare const name = "run2skill";
5697
- declare const inject: readonly ["agents", "sessions", "sessionPersistence", "storageDomain", "workspaceRegistry", "llm", "skills", "settings", "agentPresets", "fs"];
5709
+ declare const Config: import("@deepseek-ai/schemastery").default<Schemastery.ObjectS<NoInfer<{
5710
+ automaticLearning: import("@deepseek-ai/schemastery").default<boolean, boolean, "volatile-defined">;
5711
+ }>>, Schemastery.ObjectT<NoInfer<{
5712
+ automaticLearning: import("@deepseek-ai/schemastery").default<boolean, boolean, "volatile-defined">;
5713
+ }>>, "plain">;
5714
+ declare const inject: readonly ["agents", "sessions", "sessionPersistence", "storageDomain", "workspaceRegistry", "llm", "skills", "agentPresets", "fs"];
5698
5715
  type Run2skillAgent = object & AgentScopeProjection & Parameters<typeof resolveStockSkillRuntimeConfiguration>[1];
5699
- type Run2skillAgentPresets = Parameters<typeof resolvePinnedStockPresetConfiguration>[0] & {
5700
- standingKeyFor(id?: string): Promise<object>;
5701
- };
5716
+ type Run2skillAgentPresets = StockColdPresetRegistry;
5702
5717
  interface Run2skillHostContext extends Run2skillStorageContext {
5703
5718
  readonly agents: unknown;
5704
5719
  readonly sessions: unknown;
5705
- readonly sessionPersistence: SessionPersistencePort;
5720
+ readonly sessionPersistence: DshSessionPersistencePort;
5706
5721
  readonly workspaceRegistry: DshWorkspaceRegistryPort;
5707
5722
  readonly llm: DshLlmPort;
5708
5723
  readonly skills: DshSkillRegistryPort<LearningSkillView<Run2skillAgent>>;
5709
- readonly settings: DshSettingsPort;
5710
5724
  readonly agentPresets: Run2skillAgentPresets;
5711
5725
  /** Host-plane DSH filesystem used by the supported web presets. */
5712
5726
  readonly fs: unknown;
@@ -5740,6 +5754,6 @@ declare class Run2skillRuntimeFactory implements RecoveryRuntimeFactory {
5740
5754
  resolvePurgeScope(scope: 'PROJECT' | 'USER', workspaceId?: string): Promise<PurgeScopeBindingV1>;
5741
5755
  open(): Promise<RecoveryRuntime>;
5742
5756
  }
5743
- declare function apply(context: Run2skillHostContext): Promise<() => Promise<void>>;
5757
+ declare function apply(context: Run2skillHostContext, config: AutomaticLearningConfig): Promise<() => Promise<void>>;
5744
5758
  //#endregion
5745
- export { ApprovalPublicationSaga, ApprovalPublicationSagaOptions, ApprovedProposalRevalidator, PublicationConflict, PublicationFileSystemPort, PublicationFileSystemResult, PublicationReadbackPort, PublicationReadbackResult, PublicationRevalidationPort, PublicationRevalidationResult, PublicationRootPreparation, PublicationScheduler, PublicationSchedulerOptions, PublicationSingleFlightPort, PublicationTargetSingleFlight, PublicationWorkerPort, Run2skillHostContext, Run2skillRuntimeFactory, V2ProposalPublicationCoordinator, V2ProposalPublicationError, V2ProposalPublicationInput, V2ProposalPublicationOptions, V2ProposalPublicationOutcome, V2ProposalPublicationRecoveryOutcome, V2ProposalPublicationRequest, V2ProposalPublicationResult, apply, createBundle, finalizeTransaction, inject, mergeBundle, name, preparePublicationRoot, recoverTransaction };
5759
+ export { ApprovalPublicationSaga, ApprovalPublicationSagaOptions, ApprovedProposalRevalidator, Config, PublicationConflict, PublicationFileSystemPort, PublicationFileSystemResult, PublicationReadbackPort, PublicationReadbackResult, PublicationRevalidationPort, PublicationRevalidationResult, PublicationRootPreparation, PublicationScheduler, PublicationSchedulerOptions, PublicationSingleFlightPort, PublicationTargetSingleFlight, PublicationWorkerPort, Run2skillHostContext, Run2skillRuntimeFactory, V2ProposalPublicationCoordinator, V2ProposalPublicationError, V2ProposalPublicationInput, V2ProposalPublicationOptions, V2ProposalPublicationOutcome, V2ProposalPublicationRecoveryOutcome, V2ProposalPublicationRequest, V2ProposalPublicationResult, apply, createBundle, finalizeTransaction, inject, mergeBundle, name, preparePublicationRoot, recoverTransaction };
package/lib/index.js CHANGED
@@ -1,10 +1,11 @@
1
- import { r as routeRun2skillEndpoint } from "./contract-W_T3v8Fv.js";
1
+ import { r as routeRun2skillEndpoint } from "./contract-vZz7H2_H.js";
2
2
  import { createHash, randomBytes, randomUUID } from "node:crypto";
3
3
  import { z } from "zod";
4
4
  import { basename, dirname, isAbsolute, join, normalize, posix, relative, resolve, sep, win32 } from "node:path";
5
5
  import { RemoteError, TypertRemoteService } from "@deepseek-ai/dsh-typert-protocol";
6
6
  import { access, link, lstat, mkdir, open, opendir, readFile, readdir, realpath, rename, rmdir, stat, unlink } from "node:fs/promises";
7
7
  import { homedir } from "node:os";
8
+ import { livePresetMounts, standingMountFor } from "@deepseek-ai/dsh-agent-preset-registry";
8
9
  import z$1 from "@deepseek-ai/schemastery";
9
10
  import { createReadStream } from "node:fs";
10
11
  //#region src/adapters/dsh-session/gap-reader.ts
@@ -42,7 +43,7 @@ var DshSessionGapReader = class {
42
43
  }
43
44
  async listSnapshots(signal) {
44
45
  try {
45
- const snapshots = await this.persistence.listSnapshots(signal);
46
+ const snapshots = "list" in this.persistence ? await this.persistence.list(signal === void 0 ? void 0 : { signal }) : await this.persistence.listSnapshots(signal);
46
47
  if (!Array.isArray(snapshots) || snapshots.some((snapshot) => !validSnapshot(snapshot))) return {
47
48
  status: "UNAVAILABLE",
48
49
  healthCode: "SESSION_SNAPSHOTS_UNAVAILABLE"
@@ -69,17 +70,55 @@ var DshSessionGapReader = class {
69
70
  fromSeq
70
71
  };
71
72
  if (!Number.isSafeInteger(fromSeq) || fromSeq < 0) return unavailable;
73
+ let handle;
74
+ let result = unavailable;
72
75
  try {
73
- const result = await this.persistence.readFrom(sessionId, fromSeq, signal);
74
- if (!isRecord$5(result) || !validHeader(result["meta"]) || result.meta.id !== sessionId || !validEvents(result.events)) return unavailable;
75
- return {
76
+ if (!("open" in this.persistence)) {
77
+ const legacy = await this.persistence.readFrom(sessionId, fromSeq, signal);
78
+ if (isRecord$5(legacy) && validHeader(legacy["meta"]) && legacy.meta.id === sessionId && validEvents(legacy.events)) return {
79
+ status: "AVAILABLE",
80
+ header: cloneHeader(legacy.meta),
81
+ events: cloneEvents(legacy.events)
82
+ };
83
+ return unavailable;
84
+ }
85
+ handle = await this.persistence.open(sessionId, "read", signal === void 0 ? void 0 : { signal });
86
+ const read = await handle.read(fromSeq, void 0, signal === void 0 ? void 0 : { signal });
87
+ if (!validHeader(handle.header) || handle.header.id !== sessionId || !isRecord$5(read) || read["eventState"] !== "detached" && read["eventState"] !== "shared-frozen" || !validEvents(read["events"])) result = unavailable;
88
+ else result = {
76
89
  status: "AVAILABLE",
77
- header: cloneHeader(result.meta),
78
- events: cloneEvents(result.events)
90
+ header: cloneHeader(handle.header),
91
+ events: cloneEvents(read.events)
79
92
  };
93
+ } catch {
94
+ result = unavailable;
95
+ }
96
+ if (handle !== void 0) try {
97
+ await handle.close();
80
98
  } catch {
81
99
  return unavailable;
82
100
  }
101
+ return result;
102
+ }
103
+ };
104
+ /** Converts the lifecycle-owned DSH service into run2skill's detached reader port. */
105
+ var DshSessionPersistenceAdapter = class {
106
+ #reader;
107
+ constructor(persistence) {
108
+ this.#reader = new DshSessionGapReader(persistence);
109
+ }
110
+ async listSnapshots(signal) {
111
+ const result = await this.#reader.listSnapshots(signal);
112
+ if (result.status === "UNAVAILABLE") throw new Error(result.healthCode);
113
+ return result.snapshots;
114
+ }
115
+ async readFrom(sessionId, fromSeq, signal) {
116
+ const result = await this.#reader.readFrom(sessionId, fromSeq, signal);
117
+ if (result.status === "UNAVAILABLE") throw new Error(result.healthCode);
118
+ return {
119
+ meta: result.header,
120
+ events: result.events
121
+ };
83
122
  }
84
123
  };
85
124
  //#endregion
@@ -15718,39 +15757,26 @@ var DshPublicationReadbackAdapter = class {
15718
15757
  };
15719
15758
  //#endregion
15720
15759
  //#region src/adapters/dsh-skills/stock-root-contract.ts
15721
- const STOCK_DSH_BASELINE_COMMIT = "a66e4702047846cdaa10c66c9d3df3951f5ea70d";
15760
+ const STOCK_DSH_BASELINE_COMMIT = "477b4f420553e8a52c2fbccc464d7561b239c443";
15722
15761
  const STOCK_ROOT_CONTRACT_VERSION = ROOT_CONTRACT_VERSION_V2;
15723
15762
  const STOCK_ROOT_RESOLVER_VERSION = ROOT_RESOLVER_VERSION_V2;
15724
15763
  const SUPPORTED_PRESETS = /* @__PURE__ */ new Set(["standard"]);
15725
- const STOCK_PRESET_COMPOSITION_DIGESTS = Object.freeze({ standard: Object.freeze(["f18dd942686aa71f43ffc4fd328a712f79af113fb67a35b54cb6de4fc3b84bda"]) });
15726
- function contextUsesFileSystem(context) {
15727
- if (!("get" in context) || typeof context.get !== "function") return false;
15764
+ const STOCK_PRESET_COMPOSITION_DIGESTS = Object.freeze({ standard: Object.freeze(["ad344050d18ed7bc2582c1ce691b5f56334b84a85ee67a928895f7b0e0b3b5ff"]) });
15765
+ function hasStockPresetComposition(mount, expectedDigest) {
15766
+ if (mount.presetId !== "standard") return false;
15728
15767
  try {
15729
- return context.get("fs") !== void 0;
15768
+ const rows = mount.tree?.root.data;
15769
+ return Array.isArray(rows) && sha256Utf8(canonicalJson(JSON.parse(JSON.stringify(rows)))) === expectedDigest;
15730
15770
  } catch {
15731
- return true;
15771
+ return false;
15732
15772
  }
15733
15773
  }
15734
- async function resolvePinnedStockPresetConfiguration(presets, agent, expectedDigests = STOCK_PRESET_COMPOSITION_DIGESTS) {
15735
- return resolvePinnedStockPresetConfigurationById(presets, presets.composedPreset(agent.ctx), contextUsesFileSystem(agent.ctx), expectedDigests);
15736
- }
15737
- async function resolvePinnedStockPresetConfigurationById(presets, presetId, usesContextFileSystem, expectedDigests = STOCK_PRESET_COMPOSITION_DIGESTS) {
15738
- if (presetId !== "standard") return void 0;
15774
+ function contextUsesFileSystem(context) {
15775
+ if (!("get" in context) || typeof context.get !== "function") return false;
15739
15776
  try {
15740
- const preset = await presets.resolve(presetId);
15741
- if (preset.id !== presetId || preset.trust !== "system") return void 0;
15742
- const content = await presets.read(presetId);
15743
- if (!expectedDigests[presetId].includes(sha256Utf8(content))) return void 0;
15744
- return {
15745
- profile: "web",
15746
- presetId,
15747
- providerName: "filesystem",
15748
- includeDefaultRoots: true,
15749
- customSkillDirs: [],
15750
- ...usesContextFileSystem ? { usesContextFileSystem: true } : {}
15751
- };
15777
+ return context.get("fs") !== void 0;
15752
15778
  } catch {
15753
- return;
15779
+ return true;
15754
15780
  }
15755
15781
  }
15756
15782
  var StockSkillRuntimeConfigurationCache = class {
@@ -15792,9 +15818,12 @@ function isWithinFiber(candidate, root) {
15792
15818
  }
15793
15819
  }
15794
15820
  /** Reads the exact stock filesystem fiber mounted for one Agent's joined generation. */
15795
- async function resolveStockSkillRuntimeConfiguration(mounts, agent) {
15821
+ async function resolveStockSkillRuntimeConfiguration(mounts, agent, expectedDigest) {
15796
15822
  const mount = await mounts.standingMountFor(agent.ctx);
15797
- if (mount === void 0) return void 0;
15823
+ if (mount === void 0 || expectedDigest !== void 0 && !hasStockPresetComposition(mount, expectedDigest)) return void 0;
15824
+ return resolveMountedStockSkillRuntimeConfiguration(mount, agent);
15825
+ }
15826
+ function resolveMountedStockSkillRuntimeConfiguration(mount, agent) {
15798
15827
  const fibers = [...agent.ctx.registry.values()].filter((runtime) => runtime.name === "skill-filesystem").flatMap((runtime) => [...runtime.fibers]).filter((fiber) => isWithinFiber(fiber, mount.fiber));
15799
15828
  if (fibers.length !== 1) return void 0;
15800
15829
  const raw = fibers[0].config;
@@ -15921,22 +15950,71 @@ function deriveStockResolutionContractDigest(resolution, scopeIdentity) {
15921
15950
  //#endregion
15922
15951
  //#region src/adapters/dsh-skills/stock-preset-mount.ts
15923
15952
  /** Stock DSH's exact mounted-generation locator, kept behind a narrow production port. */
15924
- const stockPresetMounts = { async standingMountFor(agentContext) {
15925
- const { standingMountFor } = await import("@deepseek-ai/dsh-agent-presets");
15953
+ const stockPresetMounts = { standingMountFor(agentContext) {
15926
15954
  return standingMountFor(agentContext);
15927
15955
  } };
15956
+ const stockColdPresetMounts = { liveMounts(hostContext) {
15957
+ const root = "root" in hostContext ? hostContext.root : void 0;
15958
+ if (typeof root !== "object" || root === null || !("fiber" in root)) return [];
15959
+ return livePresetMounts(root.fiber);
15960
+ } };
15928
15961
  //#endregion
15929
- //#region src/adapters/dsh-settings/automatic-learning.ts
15930
- const RUN2SKILL_SETTINGS_NAMESPACE = "run2skill";
15931
- const AutomaticLearningSettingsSchema = z$1.object({ automaticLearning: z$1.boolean().default(true) });
15932
- function registerAutomaticLearningSettings(settings) {
15933
- const scope = settings.register(RUN2SKILL_SETTINGS_NAMESPACE, AutomaticLearningSettingsSchema, { applies: "live" });
15934
- const freeze = (value) => Object.freeze({ automaticLearning: value.automaticLearning });
15962
+ //#region src/adapters/dsh-skills/stock-cold-preset.ts
15963
+ /** A retained generation remains usable only while it is the sole standard mount in this Host. */
15964
+ function currentStockPresetMount(mounts, hostContext, key, expectedDigest = STOCK_PRESET_COMPOSITION_DIGESTS.standard[0]) {
15965
+ const standard = mounts.liveMounts(hostContext).filter((mount) => mount.presetId === "standard");
15966
+ if (standard.length !== 1 || standard[0]?.key !== key) return void 0;
15967
+ const mount = standard[0];
15968
+ return mount !== void 0 && expectedDigest !== void 0 && hasStockPresetComposition(mount, expectedDigest) ? mount : void 0;
15969
+ }
15970
+ async function acquireStockColdPreset(presets, mounts, hostContext, id, expectedDigest = STOCK_PRESET_COMPOSITION_DIGESTS.standard[0]) {
15971
+ if (id !== "standard") return void 0;
15972
+ let lease;
15973
+ try {
15974
+ lease = await presets.acquireScope(id);
15975
+ } catch {
15976
+ return;
15977
+ }
15978
+ let accepted = false;
15979
+ try {
15980
+ const mount = currentStockPresetMount(mounts, hostContext, lease.key, expectedDigest);
15981
+ if (mount === void 0) return void 0;
15982
+ const configuration = resolveMountedStockSkillRuntimeConfiguration(mount, { ctx: {
15983
+ registry: mount.fiber.ctx.registry,
15984
+ get: (name) => name === "fs" ? hostContext.fs : void 0
15985
+ } });
15986
+ if (configuration === void 0) return void 0;
15987
+ accepted = true;
15988
+ return {
15989
+ lease,
15990
+ configuration
15991
+ };
15992
+ } finally {
15993
+ if (!accepted) await lease[Symbol.asyncDispose]();
15994
+ }
15995
+ }
15996
+ const AutomaticLearningSettingsSchema = z$1.object({ automaticLearning: z$1.boolean().default(true).volatile() });
15997
+ function createAutomaticLearningSettings(context) {
15998
+ const listeners = /* @__PURE__ */ new Set();
15999
+ let previous = context.config.automaticLearning.get();
16000
+ const freeze = (value) => Object.freeze({ automaticLearning: value });
16001
+ context.on("loader/volatile-update", (paths) => {
16002
+ if (!paths.some((path) => path.length === 1 && path[0] === "automaticLearning")) return;
16003
+ const next = context.config.automaticLearning.get();
16004
+ if (next === previous) return;
16005
+ const before = freeze(previous);
16006
+ previous = next;
16007
+ const after = freeze(next);
16008
+ for (const listener of listeners) listener(after, before);
16009
+ });
15935
16010
  return {
15936
- snapshot: () => freeze(scope.get()),
15937
- watch: (callback) => scope.watch(async (next, previous) => {
15938
- await callback(freeze(next), freeze(previous));
15939
- })
16011
+ snapshot: () => freeze(context.config.automaticLearning.get()),
16012
+ watch: (callback) => {
16013
+ listeners.add(callback);
16014
+ return () => {
16015
+ listeners.delete(callback);
16016
+ };
16017
+ }
15940
16018
  };
15941
16019
  }
15942
16020
  //#endregion
@@ -16013,6 +16091,7 @@ const SUPPORTED_TURN_EVENT_TYPES = /* @__PURE__ */ new Set([
16013
16091
  "step/end",
16014
16092
  "user/message",
16015
16093
  "assistant/chunk",
16094
+ "assistant/attempt",
16016
16095
  "assistant/message",
16017
16096
  "tool/call",
16018
16097
  "tool/result",
@@ -16179,12 +16258,24 @@ function parseToolCall(event, turn) {
16179
16258
  function parseToolResult(event, turn) {
16180
16259
  if (!isRecord$1(event.data) || event.data["turn"] !== turn || !isSafeCoordinate(event.data["step"])) return void 0;
16181
16260
  const message = event.data["message"];
16182
- if (!isRecord$1(message) || message["role"] !== "user" || !isRecord$1(message["source"]) || message["source"]["kind"] !== "tool") return void 0;
16261
+ if (!isRecord$1(message) || !isRecord$1(message["source"]) || message["source"]["kind"] !== "tool") return void 0;
16183
16262
  const callId = message["source"]["callId"];
16184
- const content = message["content"];
16185
- if (!isCoordinateIdentity(callId) || !Array.isArray(content) || content.length !== 1 || !isRecord$1(content[0])) return void 0;
16186
- const block = content[0];
16187
- if (block["type"] !== "tool-result" || block["toolCallId"] !== callId || !Array.isArray(block["content"]) || block["isError"] !== void 0 && typeof block["isError"] !== "boolean") return void 0;
16263
+ if (!isCoordinateIdentity(callId)) return void 0;
16264
+ let content;
16265
+ let isError;
16266
+ if (message["role"] === "tool") {
16267
+ if (message["toolCallId"] !== callId || !Array.isArray(message["content"])) return void 0;
16268
+ content = message["content"];
16269
+ isError = message["isError"];
16270
+ } else if (message["role"] === "user") {
16271
+ const blocks = message["content"];
16272
+ if (!Array.isArray(blocks) || blocks.length !== 1 || !isRecord$1(blocks[0])) return void 0;
16273
+ const block = blocks[0];
16274
+ if (block["type"] !== "tool-result" || block["toolCallId"] !== callId || !Array.isArray(block["content"])) return void 0;
16275
+ content = block["content"];
16276
+ isError = block["isError"];
16277
+ } else return void 0;
16278
+ if (isError !== void 0 && typeof isError !== "boolean") return void 0;
16188
16279
  const error = event.data["error"];
16189
16280
  if (error !== void 0 && (!isRecord$1(error) || !isIdentity(error["name"]) || !isIdentity(error["code"]))) return void 0;
16190
16281
  try {
@@ -16192,10 +16283,10 @@ function parseToolResult(event, turn) {
16192
16283
  seq: event.seq,
16193
16284
  step: event.data["step"],
16194
16285
  callId,
16195
- failed: block["isError"] === true || error !== void 0,
16286
+ failed: isError === true || error !== void 0,
16196
16287
  contentDigest: sha256Utf8(canonicalJson({
16197
- content: block["content"],
16198
- isError: block["isError"] === true,
16288
+ content,
16289
+ isError: isError === true,
16199
16290
  error: error ?? null
16200
16291
  }))
16201
16292
  };
@@ -18652,6 +18743,7 @@ const SUPPORTED_TURN_EVENTS = /* @__PURE__ */ new Set([
18652
18743
  "step/end",
18653
18744
  "user/message",
18654
18745
  "assistant/chunk",
18746
+ "assistant/attempt",
18655
18747
  "assistant/message",
18656
18748
  "tool/call",
18657
18749
  "tool/result",
@@ -25374,6 +25466,7 @@ var DshV2ProductionRuntime = class {
25374
25466
  //#endregion
25375
25467
  //#region src/host/index.ts
25376
25468
  const name = "run2skill";
25469
+ const Config = AutomaticLearningSettingsSchema;
25377
25470
  const inject = [
25378
25471
  "agents",
25379
25472
  "sessions",
@@ -25382,7 +25475,6 @@ const inject = [
25382
25475
  "workspaceRegistry",
25383
25476
  "llm",
25384
25477
  "skills",
25385
- "settings",
25386
25478
  "agentPresets",
25387
25479
  "fs"
25388
25480
  ];
@@ -25421,7 +25513,7 @@ var Run2skillRuntimeFactory = class {
25421
25513
  this.scopes = scopes;
25422
25514
  this.automaticLearning = automaticLearning;
25423
25515
  this.mutationGate = mutationGate;
25424
- this.#stockConfigurations = new StockSkillRuntimeConfigurationCache(async (agent) => await resolveStockSkillRuntimeConfiguration(stockPresetMounts, agent) ?? await resolvePinnedStockPresetConfiguration(this.context.agentPresets, agent));
25516
+ this.#stockConfigurations = new StockSkillRuntimeConfigurationCache(async (agent) => await resolveStockSkillRuntimeConfiguration(stockPresetMounts, agent, STOCK_PRESET_COMPOSITION_DIGESTS.standard[0]));
25425
25517
  }
25426
25518
  wakeLearning() {
25427
25519
  this.currentScheduler?.wake();
@@ -25807,7 +25899,7 @@ var Run2skillV2RuntimeFactory = class {
25807
25899
  this.notices = notices;
25808
25900
  this.scopes = scopes;
25809
25901
  this.automaticLearning = automaticLearning;
25810
- this.#stockConfigurations = new StockSkillRuntimeConfigurationCache(async (agent) => await resolveStockSkillRuntimeConfiguration(stockPresetMounts, agent) ?? await resolvePinnedStockPresetConfiguration(this.context.agentPresets, agent));
25902
+ this.#stockConfigurations = new StockSkillRuntimeConfigurationCache(async (agent) => await resolveStockSkillRuntimeConfiguration(stockPresetMounts, agent, STOCK_PRESET_COMPOSITION_DIGESTS.standard[0]));
25811
25903
  }
25812
25904
  wakeLearning() {
25813
25905
  this.currentV2Runtime?.pipeline.wake();
@@ -25823,8 +25915,14 @@ var Run2skillV2RuntimeFactory = class {
25823
25915
  else this.#workspaceBindings.set(agent, workspaceBinding);
25824
25916
  const presetId = configuration.presetId ?? header.agentPreset;
25825
25917
  if (presetId === void 0) throw new Error("V2_SESSION_PRESET_UNAVAILABLE");
25826
- const scope = await this.context.agentPresets.standingKeyFor(presetId);
25827
- this.#rememberDormantSession(header, scope, configuration, workspaceBinding);
25918
+ const retained = await acquireStockColdPreset(this.context.agentPresets, stockColdPresetMounts, this.context, presetId);
25919
+ if (retained === void 0) throw new Error("V2_SESSION_PRESET_GENERATION_UNAVAILABLE");
25920
+ try {
25921
+ if ((await stockPresetMounts.standingMountFor(agent.ctx))?.key !== retained.lease.key) throw new Error("V2_SESSION_PRESET_GENERATION_UNAVAILABLE");
25922
+ this.#rememberDormantSession(header, retained.lease.key, retained.configuration, workspaceBinding);
25923
+ } finally {
25924
+ await retained.lease[Symbol.asyncDispose]();
25925
+ }
25828
25926
  }
25829
25927
  releaseRootConfiguration(agent) {
25830
25928
  this.#workspaceBindings.delete(agent);
@@ -25860,27 +25958,35 @@ var Run2skillV2RuntimeFactory = class {
25860
25958
  ...workspaceBinding === void 0 ? {} : { workspaceBinding }
25861
25959
  });
25862
25960
  }
25961
+ #currentDormant(session) {
25962
+ return currentStockPresetMount(stockColdPresetMounts, this.context, session.scope) !== void 0;
25963
+ }
25863
25964
  async #hydrateDormantSessions() {
25864
25965
  let snapshots;
25865
25966
  try {
25866
- snapshots = await this.context.sessionPersistence.listSnapshots();
25967
+ const listed = await new DshSessionGapReader(this.context.sessionPersistence).listSnapshots();
25968
+ if (listed.status === "UNAVAILABLE") return;
25969
+ snapshots = listed.snapshots;
25867
25970
  } catch {
25868
25971
  return;
25869
25972
  }
25870
25973
  for (const { header } of snapshots) {
25871
25974
  if (classifySessionRoot(header).status !== "ROOT") continue;
25872
25975
  try {
25873
- const configuration = await resolvePinnedStockPresetConfigurationById(this.context.agentPresets, header.agentPreset, true);
25874
- if (configuration === void 0) continue;
25875
- const scope = await this.context.agentPresets.standingKeyFor(configuration.presetId);
25876
- const workspaceBinding = await this.#workspaceBinding(header.cwd);
25877
- this.#rememberDormantSession(header, scope, configuration, workspaceBinding);
25976
+ const retained = await acquireStockColdPreset(this.context.agentPresets, stockColdPresetMounts, this.context, header.agentPreset);
25977
+ if (retained === void 0) continue;
25978
+ try {
25979
+ const workspaceBinding = await this.#workspaceBinding(header.cwd);
25980
+ this.#rememberDormantSession(header, retained.lease.key, retained.configuration, workspaceBinding);
25981
+ } finally {
25982
+ await retained.lease[Symbol.asyncDispose]();
25983
+ }
25878
25984
  } catch {}
25879
25985
  }
25880
25986
  }
25881
25987
  #dormantForView(view) {
25882
25988
  const cwdDigest = deriveSessionCwdDigest(view.cwd);
25883
- return [...this.#dormantSessions.values()].find((session) => session.scope === view.scope && deriveSessionCwdDigest(session.header.cwd) === cwdDigest);
25989
+ return [...this.#dormantSessions.values()].find((session) => this.#currentDormant(session) && session.scope === view.scope && deriveSessionCwdDigest(session.header.cwd) === cwdDigest);
25884
25990
  }
25885
25991
  async open() {
25886
25992
  let domain;
@@ -25911,7 +26017,7 @@ var Run2skillV2RuntimeFactory = class {
25911
26017
  }
25912
26018
  }
25913
26019
  const dormant = this.#dormantSessions.get(lifecycleKey);
25914
- if (dormant === void 0) return void 0;
26020
+ if (dormant === void 0 || !this.#currentDormant(dormant)) return void 0;
25915
26021
  return {
25916
26022
  header: dormant.header,
25917
26023
  view: {
@@ -25928,6 +26034,7 @@ var Run2skillV2RuntimeFactory = class {
25928
26034
  const dormant = this.#dormantForView(view);
25929
26035
  const configuration = this.#stockConfigurations.get(view.scope) ?? dormant?.configuration;
25930
26036
  if (configuration === void 0) return void 0;
26037
+ if (dormant === void 0 && !("session" in view.scope)) return void 0;
25931
26038
  const workspaceBinding = this.#workspaceBindings.get(view.scope) ?? dormant?.workspaceBinding;
25932
26039
  const filesystem = exactAgentFileSystem(view.scope) ?? dormant?.filesystem;
25933
26040
  return {
@@ -25941,7 +26048,7 @@ var Run2skillV2RuntimeFactory = class {
25941
26048
  const sessions = typeof this.context.sessions === "object" && this.context.sessions !== null && "get" in this.context.sessions && typeof this.context.sessions.get === "function" ? this.context.sessions : { get: (_id) => void 0 };
25942
26049
  const agents = typeof this.context.agents === "object" && this.context.agents !== null && "get" in this.context.agents && typeof this.context.agents.get === "function" ? this.context.agents : { get: (_id) => void 0 };
25943
26050
  runtime = new DshV2ProductionRuntime(domain, {
25944
- persistence: this.context.sessionPersistence,
26051
+ persistence: new DshSessionPersistenceAdapter(this.context.sessionPersistence),
25945
26052
  sessions,
25946
26053
  agents,
25947
26054
  llm: this.context.llm,
@@ -25977,12 +26084,17 @@ var Run2skillV2RuntimeFactory = class {
25977
26084
  publicationAbort.abort();
25978
26085
  if (this.currentV2Runtime === activeRuntime) this.currentV2Runtime = void 0;
25979
26086
  if (this.currentV2Domain === domain) this.currentV2Domain = void 0;
25980
- await activeRuntime.close();
26087
+ try {
26088
+ await activeRuntime.close();
26089
+ } finally {
26090
+ this.#dormantSessions.clear();
26091
+ }
25981
26092
  }
25982
26093
  };
25983
26094
  } catch (error) {
25984
26095
  if (runtime !== void 0) await runtime.close().catch(() => void 0);
25985
26096
  else if (domain !== void 0) await domain.close().catch(() => void 0);
26097
+ this.#dormantSessions.clear();
25986
26098
  throw error;
25987
26099
  }
25988
26100
  }
@@ -26031,8 +26143,11 @@ function v2Summary(domain, lifecycle, notices) {
26031
26143
  ...latest === void 0 ? {} : { lastHealthCode: latest.healthCode }
26032
26144
  });
26033
26145
  }
26034
- async function apply(context) {
26035
- const automaticLearning = registerAutomaticLearningSettings(context.settings);
26146
+ async function apply(context, config) {
26147
+ const automaticLearning = createAutomaticLearningSettings({
26148
+ config,
26149
+ on: context.on.bind(context)
26150
+ });
26036
26151
  const notices = new RuntimeNotices();
26037
26152
  const scopes = new ExactAgentScopeRegistry();
26038
26153
  const scopeDisposers = /* @__PURE__ */ new WeakMap();
@@ -26165,4 +26280,4 @@ async function apply(context) {
26165
26280
  };
26166
26281
  }
26167
26282
  //#endregion
26168
- export { ApprovalPublicationSaga, ApprovedProposalRevalidator, PublicationConflict, PublicationScheduler, PublicationTargetSingleFlight, Run2skillRuntimeFactory, V2ProposalPublicationCoordinator, V2ProposalPublicationError, apply, createBundle, finalizeTransaction, inject, mergeBundle, name, preparePublicationRoot, recoverTransaction };
26283
+ export { ApprovalPublicationSaga, ApprovedProposalRevalidator, Config, PublicationConflict, PublicationScheduler, PublicationTargetSingleFlight, Run2skillRuntimeFactory, V2ProposalPublicationCoordinator, V2ProposalPublicationError, apply, createBundle, finalizeTransaction, inject, mergeBundle, name, preparePublicationRoot, recoverTransaction };
@@ -1,4 +1,4 @@
1
- import { n as RUN2SKILL_REMOTE_DESCRIPTORS } from "./contract-W_T3v8Fv.js";
1
+ import { n as RUN2SKILL_REMOTE_DESCRIPTORS } from "./contract-vZz7H2_H.js";
2
2
  //#region src/adapters/dsh-remote/typert.ts
3
3
  const TYPERT = Object.freeze({
4
4
  package: "dsh-run2skill",
@@ -1,2 +1,2 @@
1
- import { t as RUN2SKILL_REMOTE } from "./contract-W_T3v8Fv.js";
1
+ import { t as RUN2SKILL_REMOTE } from "./contract-vZz7H2_H.js";
2
2
  export { RUN2SKILL_REMOTE as TYPERT_REMOTE, RUN2SKILL_REMOTE as default };