dsh-run2skill 0.3.1 → 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.
package/lib/index.js CHANGED
@@ -1,8 +1,11 @@
1
+ import { r as routeRun2skillEndpoint } from "./contract-vZz7H2_H.js";
1
2
  import { createHash, randomBytes, randomUUID } from "node:crypto";
2
3
  import { z } from "zod";
3
4
  import { basename, dirname, isAbsolute, join, normalize, posix, relative, resolve, sep, win32 } from "node:path";
5
+ import { RemoteError, TypertRemoteService } from "@deepseek-ai/dsh-typert-protocol";
4
6
  import { access, link, lstat, mkdir, open, opendir, readFile, readdir, realpath, rename, rmdir, stat, unlink } from "node:fs/promises";
5
7
  import { homedir } from "node:os";
8
+ import { livePresetMounts, standingMountFor } from "@deepseek-ai/dsh-agent-preset-registry";
6
9
  import z$1 from "@deepseek-ai/schemastery";
7
10
  import { createReadStream } from "node:fs";
8
11
  //#region src/adapters/dsh-session/gap-reader.ts
@@ -40,7 +43,7 @@ var DshSessionGapReader = class {
40
43
  }
41
44
  async listSnapshots(signal) {
42
45
  try {
43
- 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);
44
47
  if (!Array.isArray(snapshots) || snapshots.some((snapshot) => !validSnapshot(snapshot))) return {
45
48
  status: "UNAVAILABLE",
46
49
  healthCode: "SESSION_SNAPSHOTS_UNAVAILABLE"
@@ -67,17 +70,55 @@ var DshSessionGapReader = class {
67
70
  fromSeq
68
71
  };
69
72
  if (!Number.isSafeInteger(fromSeq) || fromSeq < 0) return unavailable;
73
+ let handle;
74
+ let result = unavailable;
70
75
  try {
71
- const result = await this.persistence.readFrom(sessionId, fromSeq, signal);
72
- if (!isRecord$5(result) || !validHeader(result["meta"]) || result.meta.id !== sessionId || !validEvents(result.events)) return unavailable;
73
- 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 = {
74
89
  status: "AVAILABLE",
75
- header: cloneHeader(result.meta),
76
- events: cloneEvents(result.events)
90
+ header: cloneHeader(handle.header),
91
+ events: cloneEvents(read.events)
77
92
  };
93
+ } catch {
94
+ result = unavailable;
95
+ }
96
+ if (handle !== void 0) try {
97
+ await handle.close();
78
98
  } catch {
79
99
  return unavailable;
80
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
+ };
81
122
  }
82
123
  };
83
124
  //#endregion
@@ -3637,9 +3678,6 @@ const ObserveSummaryV1Schema = z.object({
3637
3678
  lastRecoveryProgressAt: z.string().datetime({ offset: true }).optional(),
3638
3679
  lastHealthCode: z.string().regex(/^[A-Z][A-Z0-9_]{0,63}$/).optional()
3639
3680
  }).strict();
3640
- //#endregion
3641
- //#region src/adapters/dsh-connection/observe-summary-rpc.ts
3642
- const RUN2SKILL_RPC_CHANNEL = "/run2skill";
3643
3681
  const ObserveSummaryRequestV1Schema = z.object({ apiVersion: z.literal(1) }).strict();
3644
3682
  function badRequest() {
3645
3683
  return {
@@ -3651,8 +3689,8 @@ function badRequest() {
3651
3689
  }
3652
3690
  };
3653
3691
  }
3654
- function registerObserveSummaryRpc(connection, readSummary, fallback) {
3655
- return connection.rpc.handle(RUN2SKILL_RPC_CHANNEL, async (endpoint, payload, signal) => {
3692
+ function createObserveSummaryRpcHandler(readSummary, fallback) {
3693
+ return async (endpoint, payload, signal) => {
3656
3694
  if (endpoint !== "observe-summary") return fallback === void 0 ? badRequest() : await fallback(endpoint, payload, signal);
3657
3695
  if (!ObserveSummaryRequestV1Schema.safeParse(payload).success) return badRequest();
3658
3696
  if (signal.aborted) return {
@@ -3678,8 +3716,34 @@ function registerObserveSummaryRpc(connection, readSummary, fallback) {
3678
3716
  }
3679
3717
  };
3680
3718
  }
3681
- }, { authority: "loopback" });
3719
+ };
3720
+ }
3721
+ //#endregion
3722
+ //#region src/adapters/dsh-remote/service.ts
3723
+ function assertRoute(endpoint, expected) {
3724
+ let actual;
3725
+ try {
3726
+ actual = routeRun2skillEndpoint(endpoint);
3727
+ } catch (cause) {
3728
+ throw new RemoteError("gateway/bad-request", `unknown run2skill endpoint: ${endpoint}`, {}, { cause });
3729
+ }
3730
+ if (actual !== expected) throw new RemoteError("gateway/bad-request", `run2skill endpoint ${endpoint} must use ${actual}`, {});
3682
3731
  }
3732
+ var Run2skillRemoteService = class extends TypertRemoteService {
3733
+ handler;
3734
+ constructor(ctx, handler) {
3735
+ super(ctx, "run2skillRemote", { namespace: "run2skill" });
3736
+ this.handler = handler;
3737
+ }
3738
+ async query(request, signal) {
3739
+ assertRoute(request.endpoint, "query");
3740
+ return await this.handler(request.endpoint, request.payload, signal);
3741
+ }
3742
+ async command(request, signal) {
3743
+ assertRoute(request.endpoint, "command");
3744
+ return await this.handler(request.endpoint, request.payload, signal);
3745
+ }
3746
+ };
3683
3747
  //#endregion
3684
3748
  //#region src/adapters/dsh-storage/global-store.ts
3685
3749
  var Run2skillGlobalStore = class Run2skillGlobalStore {
@@ -15693,42 +15757,26 @@ var DshPublicationReadbackAdapter = class {
15693
15757
  };
15694
15758
  //#endregion
15695
15759
  //#region src/adapters/dsh-skills/stock-root-contract.ts
15696
- const STOCK_DSH_BASELINE_COMMIT = "b150a551b8d465e31e418e1b2eaf5e79bbb7d28e";
15760
+ const STOCK_DSH_BASELINE_COMMIT = "477b4f420553e8a52c2fbccc464d7561b239c443";
15697
15761
  const STOCK_ROOT_CONTRACT_VERSION = ROOT_CONTRACT_VERSION_V2;
15698
15762
  const STOCK_ROOT_RESOLVER_VERSION = ROOT_RESOLVER_VERSION_V2;
15699
- const SUPPORTED_PRESETS = /* @__PURE__ */ new Set(["standard", "code"]);
15700
- const STOCK_PRESET_COMPOSITION_DIGESTS = Object.freeze({
15701
- standard: Object.freeze(["fa14feb98daef20b810fef30bb7239a89a786de3c45c602b37743f7100d9a5af"]),
15702
- code: Object.freeze(["bdecfe0b26a9d56a2ffcb79694fc123bc395247969e135c62945a1ec8fb92e87"])
15703
- });
15704
- function contextUsesFileSystem(context) {
15705
- if (!("get" in context) || typeof context.get !== "function") return false;
15763
+ const SUPPORTED_PRESETS = /* @__PURE__ */ new Set(["standard"]);
15764
+ const STOCK_PRESET_COMPOSITION_DIGESTS = Object.freeze({ standard: Object.freeze(["ad344050d18ed7bc2582c1ce691b5f56334b84a85ee67a928895f7b0e0b3b5ff"]) });
15765
+ function hasStockPresetComposition(mount, expectedDigest) {
15766
+ if (mount.presetId !== "standard") return false;
15706
15767
  try {
15707
- 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;
15708
15770
  } catch {
15709
- return true;
15771
+ return false;
15710
15772
  }
15711
15773
  }
15712
- async function resolvePinnedStockPresetConfiguration(presets, agent, expectedDigests = STOCK_PRESET_COMPOSITION_DIGESTS) {
15713
- return resolvePinnedStockPresetConfigurationById(presets, presets.composedPreset(agent.ctx), contextUsesFileSystem(agent.ctx), expectedDigests);
15714
- }
15715
- async function resolvePinnedStockPresetConfigurationById(presets, presetId, usesContextFileSystem, expectedDigests = STOCK_PRESET_COMPOSITION_DIGESTS) {
15716
- if (presetId !== "standard" && presetId !== "code") return void 0;
15774
+ function contextUsesFileSystem(context) {
15775
+ if (!("get" in context) || typeof context.get !== "function") return false;
15717
15776
  try {
15718
- const preset = await presets.resolve(presetId);
15719
- if (preset.id !== presetId || preset.trust !== "system") return void 0;
15720
- const content = await presets.read(presetId);
15721
- if (!expectedDigests[presetId].includes(sha256Utf8(content))) return void 0;
15722
- return {
15723
- profile: "web",
15724
- presetId,
15725
- providerName: "filesystem",
15726
- includeDefaultRoots: true,
15727
- customSkillDirs: [],
15728
- ...usesContextFileSystem ? { usesContextFileSystem: true } : {}
15729
- };
15777
+ return context.get("fs") !== void 0;
15730
15778
  } catch {
15731
- return;
15779
+ return true;
15732
15780
  }
15733
15781
  }
15734
15782
  var StockSkillRuntimeConfigurationCache = class {
@@ -15770,9 +15818,12 @@ function isWithinFiber(candidate, root) {
15770
15818
  }
15771
15819
  }
15772
15820
  /** Reads the exact stock filesystem fiber mounted for one Agent's joined generation. */
15773
- async function resolveStockSkillRuntimeConfiguration(mounts, agent) {
15821
+ async function resolveStockSkillRuntimeConfiguration(mounts, agent, expectedDigest) {
15774
15822
  const mount = await mounts.standingMountFor(agent.ctx);
15775
- 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) {
15776
15827
  const fibers = [...agent.ctx.registry.values()].filter((runtime) => runtime.name === "skill-filesystem").flatMap((runtime) => [...runtime.fibers]).filter((fiber) => isWithinFiber(fiber, mount.fiber));
15777
15828
  if (fibers.length !== 1) return void 0;
15778
15829
  const raw = fibers[0].config;
@@ -15899,22 +15950,71 @@ function deriveStockResolutionContractDigest(resolution, scopeIdentity) {
15899
15950
  //#endregion
15900
15951
  //#region src/adapters/dsh-skills/stock-preset-mount.ts
15901
15952
  /** Stock DSH's exact mounted-generation locator, kept behind a narrow production port. */
15902
- const stockPresetMounts = { async standingMountFor(agentContext) {
15903
- const { standingMountFor } = await import("@deepseek-ai/dsh-agent-presets");
15953
+ const stockPresetMounts = { standingMountFor(agentContext) {
15904
15954
  return standingMountFor(agentContext);
15905
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
+ } };
15906
15961
  //#endregion
15907
- //#region src/adapters/dsh-settings/automatic-learning.ts
15908
- const RUN2SKILL_SETTINGS_NAMESPACE = "run2skill";
15909
- const AutomaticLearningSettingsSchema = z$1.object({ automaticLearning: z$1.boolean().default(true) });
15910
- function registerAutomaticLearningSettings(settings) {
15911
- const scope = settings.register(RUN2SKILL_SETTINGS_NAMESPACE, AutomaticLearningSettingsSchema, { applies: "live" });
15912
- 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
+ });
15913
16010
  return {
15914
- snapshot: () => freeze(scope.get()),
15915
- watch: (callback) => scope.watch(async (next, previous) => {
15916
- await callback(freeze(next), freeze(previous));
15917
- })
16011
+ snapshot: () => freeze(context.config.automaticLearning.get()),
16012
+ watch: (callback) => {
16013
+ listeners.add(callback);
16014
+ return () => {
16015
+ listeners.delete(callback);
16016
+ };
16017
+ }
15918
16018
  };
15919
16019
  }
15920
16020
  //#endregion
@@ -15991,6 +16091,7 @@ const SUPPORTED_TURN_EVENT_TYPES = /* @__PURE__ */ new Set([
15991
16091
  "step/end",
15992
16092
  "user/message",
15993
16093
  "assistant/chunk",
16094
+ "assistant/attempt",
15994
16095
  "assistant/message",
15995
16096
  "tool/call",
15996
16097
  "tool/result",
@@ -16157,12 +16258,24 @@ function parseToolCall(event, turn) {
16157
16258
  function parseToolResult(event, turn) {
16158
16259
  if (!isRecord$1(event.data) || event.data["turn"] !== turn || !isSafeCoordinate(event.data["step"])) return void 0;
16159
16260
  const message = event.data["message"];
16160
- 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;
16161
16262
  const callId = message["source"]["callId"];
16162
- const content = message["content"];
16163
- if (!isCoordinateIdentity(callId) || !Array.isArray(content) || content.length !== 1 || !isRecord$1(content[0])) return void 0;
16164
- const block = content[0];
16165
- 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;
16166
16279
  const error = event.data["error"];
16167
16280
  if (error !== void 0 && (!isRecord$1(error) || !isIdentity(error["name"]) || !isIdentity(error["code"]))) return void 0;
16168
16281
  try {
@@ -16170,10 +16283,10 @@ function parseToolResult(event, turn) {
16170
16283
  seq: event.seq,
16171
16284
  step: event.data["step"],
16172
16285
  callId,
16173
- failed: block["isError"] === true || error !== void 0,
16286
+ failed: isError === true || error !== void 0,
16174
16287
  contentDigest: sha256Utf8(canonicalJson({
16175
- content: block["content"],
16176
- isError: block["isError"] === true,
16288
+ content,
16289
+ isError: isError === true,
16177
16290
  error: error ?? null
16178
16291
  }))
16179
16292
  };
@@ -16913,12 +17026,13 @@ var DshSessionActivityAdapter = class {
16913
17026
  }
16914
17027
  #sampleLive(sessionId, sessionLifecycleKey, durableEvents) {
16915
17028
  const live = this.#sessions.get(sessionId);
16916
- if (live !== void 0 && (lifecycleKey(live.header) !== sessionLifecycleKey || !sameSessionPrefix(live.events, durableEvents))) return void 0;
17029
+ const liveEvents = live?.snapshotEvents();
17030
+ if (live !== void 0 && (lifecycleKey(live.header) !== sessionLifecycleKey || liveEvents === void 0 || !sameSessionPrefix(liveEvents, durableEvents))) return void 0;
16917
17031
  const agent = this.#agents.get(sessionId);
16918
17032
  if (agent !== void 0 && (live === void 0 || agent.id !== sessionId || agent.session !== live || lifecycleKey(agent.session.header) !== sessionLifecycleKey || agent.status !== "idle" && agent.status !== "running" || typeof agent.whenIdle !== "function")) return void 0;
16919
17033
  return {
16920
17034
  live,
16921
- liveCoordinates: canonicalJson(eventCoordinates(live?.events ?? [])),
17035
+ liveCoordinates: canonicalJson(eventCoordinates(liveEvents ?? [])),
16922
17036
  agent,
16923
17037
  agentStatus: agent?.status ?? "absent"
16924
17038
  };
@@ -18629,6 +18743,7 @@ const SUPPORTED_TURN_EVENTS = /* @__PURE__ */ new Set([
18629
18743
  "step/end",
18630
18744
  "user/message",
18631
18745
  "assistant/chunk",
18746
+ "assistant/attempt",
18632
18747
  "assistant/message",
18633
18748
  "tool/call",
18634
18749
  "tool/result",
@@ -19449,7 +19564,7 @@ var DshV2RootManifestAdapter = class {
19449
19564
  }
19450
19565
  }
19451
19566
  async #rootManifest(cwd, configuration, budget, filesystem) {
19452
- if (configuration.profile !== "web" || configuration.presetId !== "standard" && configuration.presetId !== "code" || configuration.providerName.trim().length === 0 || configuration.usesContextFileSystem === true && filesystem === void 0) return void 0;
19567
+ if (configuration.profile !== "web" || configuration.presetId !== "standard" || configuration.providerName.trim().length === 0 || configuration.usesContextFileSystem === true && filesystem === void 0) return void 0;
19453
19568
  const home = this.#homeDirectory();
19454
19569
  const current = this.#currentEnvironment();
19455
19570
  if (configuration.configuredDshHome === void 0 && resolveDshHomeCompatible(void 0, current.DSH_HOME, home) !== resolveDshHomeCompatible(void 0, this.#initialEnvironment.DSH_HOME, home)) return void 0;
@@ -25351,16 +25466,15 @@ var DshV2ProductionRuntime = class {
25351
25466
  //#endregion
25352
25467
  //#region src/host/index.ts
25353
25468
  const name = "run2skill";
25469
+ const Config = AutomaticLearningSettingsSchema;
25354
25470
  const inject = [
25355
25471
  "agents",
25356
25472
  "sessions",
25357
25473
  "sessionPersistence",
25358
25474
  "storageDomain",
25359
25475
  "workspaceRegistry",
25360
- "connection",
25361
25476
  "llm",
25362
25477
  "skills",
25363
- "settings",
25364
25478
  "agentPresets",
25365
25479
  "fs"
25366
25480
  ];
@@ -25399,7 +25513,7 @@ var Run2skillRuntimeFactory = class {
25399
25513
  this.scopes = scopes;
25400
25514
  this.automaticLearning = automaticLearning;
25401
25515
  this.mutationGate = mutationGate;
25402
- 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]));
25403
25517
  }
25404
25518
  wakeLearning() {
25405
25519
  this.currentScheduler?.wake();
@@ -25785,7 +25899,7 @@ var Run2skillV2RuntimeFactory = class {
25785
25899
  this.notices = notices;
25786
25900
  this.scopes = scopes;
25787
25901
  this.automaticLearning = automaticLearning;
25788
- 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]));
25789
25903
  }
25790
25904
  wakeLearning() {
25791
25905
  this.currentV2Runtime?.pipeline.wake();
@@ -25801,8 +25915,14 @@ var Run2skillV2RuntimeFactory = class {
25801
25915
  else this.#workspaceBindings.set(agent, workspaceBinding);
25802
25916
  const presetId = configuration.presetId ?? header.agentPreset;
25803
25917
  if (presetId === void 0) throw new Error("V2_SESSION_PRESET_UNAVAILABLE");
25804
- const scope = await this.context.agentPresets.standingKeyFor(presetId);
25805
- 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
+ }
25806
25926
  }
25807
25927
  releaseRootConfiguration(agent) {
25808
25928
  this.#workspaceBindings.delete(agent);
@@ -25838,27 +25958,35 @@ var Run2skillV2RuntimeFactory = class {
25838
25958
  ...workspaceBinding === void 0 ? {} : { workspaceBinding }
25839
25959
  });
25840
25960
  }
25961
+ #currentDormant(session) {
25962
+ return currentStockPresetMount(stockColdPresetMounts, this.context, session.scope) !== void 0;
25963
+ }
25841
25964
  async #hydrateDormantSessions() {
25842
25965
  let snapshots;
25843
25966
  try {
25844
- 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;
25845
25970
  } catch {
25846
25971
  return;
25847
25972
  }
25848
25973
  for (const { header } of snapshots) {
25849
25974
  if (classifySessionRoot(header).status !== "ROOT") continue;
25850
25975
  try {
25851
- const configuration = await resolvePinnedStockPresetConfigurationById(this.context.agentPresets, header.agentPreset, true);
25852
- if (configuration === void 0) continue;
25853
- const scope = await this.context.agentPresets.standingKeyFor(configuration.presetId);
25854
- const workspaceBinding = await this.#workspaceBinding(header.cwd);
25855
- 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
+ }
25856
25984
  } catch {}
25857
25985
  }
25858
25986
  }
25859
25987
  #dormantForView(view) {
25860
25988
  const cwdDigest = deriveSessionCwdDigest(view.cwd);
25861
- 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);
25862
25990
  }
25863
25991
  async open() {
25864
25992
  let domain;
@@ -25889,7 +26017,7 @@ var Run2skillV2RuntimeFactory = class {
25889
26017
  }
25890
26018
  }
25891
26019
  const dormant = this.#dormantSessions.get(lifecycleKey);
25892
- if (dormant === void 0) return void 0;
26020
+ if (dormant === void 0 || !this.#currentDormant(dormant)) return void 0;
25893
26021
  return {
25894
26022
  header: dormant.header,
25895
26023
  view: {
@@ -25906,6 +26034,7 @@ var Run2skillV2RuntimeFactory = class {
25906
26034
  const dormant = this.#dormantForView(view);
25907
26035
  const configuration = this.#stockConfigurations.get(view.scope) ?? dormant?.configuration;
25908
26036
  if (configuration === void 0) return void 0;
26037
+ if (dormant === void 0 && !("session" in view.scope)) return void 0;
25909
26038
  const workspaceBinding = this.#workspaceBindings.get(view.scope) ?? dormant?.workspaceBinding;
25910
26039
  const filesystem = exactAgentFileSystem(view.scope) ?? dormant?.filesystem;
25911
26040
  return {
@@ -25919,7 +26048,7 @@ var Run2skillV2RuntimeFactory = class {
25919
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 };
25920
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 };
25921
26050
  runtime = new DshV2ProductionRuntime(domain, {
25922
- persistence: this.context.sessionPersistence,
26051
+ persistence: new DshSessionPersistenceAdapter(this.context.sessionPersistence),
25923
26052
  sessions,
25924
26053
  agents,
25925
26054
  llm: this.context.llm,
@@ -25955,12 +26084,17 @@ var Run2skillV2RuntimeFactory = class {
25955
26084
  publicationAbort.abort();
25956
26085
  if (this.currentV2Runtime === activeRuntime) this.currentV2Runtime = void 0;
25957
26086
  if (this.currentV2Domain === domain) this.currentV2Domain = void 0;
25958
- await activeRuntime.close();
26087
+ try {
26088
+ await activeRuntime.close();
26089
+ } finally {
26090
+ this.#dormantSessions.clear();
26091
+ }
25959
26092
  }
25960
26093
  };
25961
26094
  } catch (error) {
25962
26095
  if (runtime !== void 0) await runtime.close().catch(() => void 0);
25963
26096
  else if (domain !== void 0) await domain.close().catch(() => void 0);
26097
+ this.#dormantSessions.clear();
25964
26098
  throw error;
25965
26099
  }
25966
26100
  }
@@ -26009,8 +26143,11 @@ function v2Summary(domain, lifecycle, notices) {
26009
26143
  ...latest === void 0 ? {} : { lastHealthCode: latest.healthCode }
26010
26144
  });
26011
26145
  }
26012
- async function apply(context) {
26013
- const automaticLearning = registerAutomaticLearningSettings(context.settings);
26146
+ async function apply(context, config) {
26147
+ const automaticLearning = createAutomaticLearningSettings({
26148
+ config,
26149
+ on: context.on.bind(context)
26150
+ });
26014
26151
  const notices = new RuntimeNotices();
26015
26152
  const scopes = new ExactAgentScopeRegistry();
26016
26153
  const scopeDisposers = /* @__PURE__ */ new WeakMap();
@@ -26117,7 +26254,7 @@ async function apply(context) {
26117
26254
  runtimeAttention: (sessionId) => projectRuntimeAttention(notices, sessionId),
26118
26255
  learningActions: async (currentScope) => await (factory.currentV2Runtime?.attention.project(currentScope) ?? [])
26119
26256
  }, v2LearningRpc);
26120
- const v2Rpc = createV2RecentSkillActivityRpcHandler(() => factory.currentV2Domain, resolveCurrentWorkspace, createV2LearningStatusRpcHandler(() => factory.currentV2Domain, {
26257
+ new Run2skillRemoteService(context, createObserveSummaryRpcHandler(readSummary, createV2RecentSkillActivityRpcHandler(() => factory.currentV2Domain, resolveCurrentWorkspace, createV2LearningStatusRpcHandler(() => factory.currentV2Domain, {
26121
26258
  resolveSession: (lifecycleKey) => factory.currentV2Runtime?.learningStatusSession(lifecycleKey),
26122
26259
  resolveWorkspace: resolveCurrentWorkspace,
26123
26260
  requestSynthesis: async (lifecycleKey) => {
@@ -26125,8 +26262,7 @@ async function apply(context) {
26125
26262
  if (runtime === void 0) throw new Error("V2_RUNTIME_UNAVAILABLE");
26126
26263
  return await runtime.requestSynthesis(lifecycleKey);
26127
26264
  }
26128
- }, createPurgeRpcHandler(() => factory.currentV2Runtime?.purge, v2ProposalRpc, { runMutation: (operation) => mutationGate.run(operation) })));
26129
- const disposeRpc = registerObserveSummaryRpc(context.connection, readSummary, v2Rpc);
26265
+ }, createPurgeRpcHandler(() => factory.currentV2Runtime?.purge, v2ProposalRpc, { runMutation: (operation) => mutationGate.run(operation) })))));
26130
26266
  try {
26131
26267
  await lifecycle.start();
26132
26268
  } catch (error) {
@@ -26137,15 +26273,11 @@ async function apply(context) {
26137
26273
  accepting = false;
26138
26274
  stopWatchingSettings();
26139
26275
  try {
26140
- await disposeRpc();
26276
+ await lifecycle.dispose();
26141
26277
  } finally {
26142
- try {
26143
- await lifecycle.dispose();
26144
- } finally {
26145
- scopes.clear();
26146
- }
26278
+ scopes.clear();
26147
26279
  }
26148
26280
  };
26149
26281
  }
26150
26282
  //#endregion
26151
- 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 };
@@ -0,0 +1,25 @@
1
+ //#region src/adapters/dsh-remote/typert.d.ts
2
+ declare const TYPERT: Readonly<{
3
+ package: "dsh-run2skill";
4
+ face: "host";
5
+ schemas: never[];
6
+ invocations: readonly import("@deepseek-ai/dsh-typert-protocol").InvocationDescriptor[];
7
+ model: {
8
+ services: {
9
+ key: string;
10
+ exportName: string;
11
+ summary: string;
12
+ tags: never[];
13
+ members: {
14
+ kind: string;
15
+ name: string;
16
+ signature: string;
17
+ }[];
18
+ types: never[];
19
+ }[];
20
+ events: never[];
21
+ objects: never[];
22
+ };
23
+ }>;
24
+ //#endregion
25
+ export { TYPERT, TYPERT as default };
@@ -0,0 +1,30 @@
1
+ import { n as RUN2SKILL_REMOTE_DESCRIPTORS } from "./contract-vZz7H2_H.js";
2
+ //#region src/adapters/dsh-remote/typert.ts
3
+ const TYPERT = Object.freeze({
4
+ package: "dsh-run2skill",
5
+ face: "host",
6
+ schemas: [],
7
+ invocations: RUN2SKILL_REMOTE_DESCRIPTORS,
8
+ model: {
9
+ services: [{
10
+ key: "run2skillRemote",
11
+ exportName: "Run2skillRemoteService",
12
+ summary: "Run2Skill read and mutation boundary for the DSH Web client.",
13
+ tags: [],
14
+ members: [{
15
+ kind: "method",
16
+ name: "query",
17
+ signature: "query(request: Run2skillQueryRequest, signal: AbortSignal): Promise<Run2skillRpcResult>"
18
+ }, {
19
+ kind: "method",
20
+ name: "command",
21
+ signature: "command(request: Run2skillCommandRequest, signal: AbortSignal): Promise<Run2skillRpcResult>"
22
+ }],
23
+ types: []
24
+ }],
25
+ events: [],
26
+ objects: []
27
+ }
28
+ });
29
+ //#endregion
30
+ export { TYPERT, TYPERT as default };
@@ -0,0 +1,38 @@
1
+ import { z } from "zod";
2
+ import { RemoteResult, TypertRemoteContribution } from "@deepseek-ai/dsh-typert-protocol";
3
+ //#region src/adapters/dsh-connection/observe-summary-rpc.d.ts
4
+ type ObserveRpcError = {
5
+ readonly code: string;
6
+ readonly message: string;
7
+ readonly details: Record<string, unknown>;
8
+ };
9
+ type ObserveRpcResult<T> = {
10
+ readonly ok: true;
11
+ readonly value: T;
12
+ } | {
13
+ readonly ok: false;
14
+ readonly error: ObserveRpcError;
15
+ };
16
+ //#endregion
17
+ //#region src/adapters/dsh-remote/contract.d.ts
18
+ declare const RUN2SKILL_QUERY_ENDPOINTS: readonly ["observe-summary", "attention", "proposals/list", "summary", "proposals/get", "recent-activity/list", "learning/status", "learning/issues/list", "purge/preview", "purge/status"];
19
+ declare const RUN2SKILL_COMMAND_ENDPOINTS: readonly ["proposals/approve", "proposals/reject", "proposals/retry", "proposals/refresh", "proposals/revise", "coverage/confirm-discard", "learning/request", "learning/issues/retry", "learning/issues/dismiss", "purge/confirm", "purge/retry"];
20
+ type Run2skillQueryEndpoint = typeof RUN2SKILL_QUERY_ENDPOINTS[number];
21
+ type Run2skillCommandEndpoint = typeof RUN2SKILL_COMMAND_ENDPOINTS[number];
22
+ type Run2skillEndpoint = Run2skillQueryEndpoint | Run2skillCommandEndpoint;
23
+ declare const RUN2SKILL_REMOTE: TypertRemoteContribution;
24
+ interface Run2skillRemoteRequest<Endpoint extends Run2skillEndpoint = Run2skillEndpoint> {
25
+ readonly endpoint: Endpoint;
26
+ readonly payload: unknown;
27
+ }
28
+ interface Run2skillRemoteNamespace {
29
+ query(request: Run2skillRemoteRequest<Run2skillQueryEndpoint>, signal?: AbortSignal): Promise<RemoteResult<ObserveRpcResult<unknown>>>;
30
+ command(request: Run2skillRemoteRequest<Run2skillCommandEndpoint>, signal?: AbortSignal): Promise<RemoteResult<ObserveRpcResult<unknown>>>;
31
+ }
32
+ declare module '@deepseek-ai/dsh-typert-protocol' {
33
+ interface TypertRemoteNamespaceMap {
34
+ run2skill: Run2skillRemoteNamespace;
35
+ }
36
+ }
37
+ //#endregion
38
+ export { RUN2SKILL_REMOTE as TYPERT_REMOTE, RUN2SKILL_REMOTE as default };