@lmzhen/dsh-evolution-adapter 0.58.0 → 0.59.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -13,3 +13,7 @@ It owns:
13
13
  Feature packages must not import `@deepseek-ai/dsh-*`; they import contract
14
14
  types and adapter helpers. The adapter is also the place where a real host API
15
15
  shape difference is normalized; business code never branches on a DSH version.
16
+
17
+ ## Detached review child
18
+
19
+ `@lmzhen/dsh-evolution-adapter/review-child` exports `createReviewChildAgent(parent, taskId, options)`. It creates a live child `Session` through the public Session store, makes the child object the scope key of a real `createScope` context, and assigns that context to the child. When PTC is requested it probes the platform's optional `@deepseek-ai/dsh-tool-executor-ptc` package by export shape and mounts that executor in the child scope; a missing/incompatible package fails with `PTC_UNAVAILABLE`, never a version guess. The child stays detached from the parent lineage, so PTC nested `tool/ptc-dispatch*` frames land on the child and never touch the parent Session. The PTC package is not a family dependency: the platform base bundle ships it disabled and the PTC preset enables it.
package/lib/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { _ as pluginManagerPort, a as toolsPort, b as commandsPort, c as userQuestionsPort, d as connectionPort, f as storageDomainPort, g as pluginInventoryPort, h as configEditorPort, i as registerEvolutionTool, l as subagentsPort, m as workingDirectoryPort, n as llmPort, o as projectionPort, p as skillsPort, r as modelRoute, s as presetsPort, t as EvolutionLlmError, u as systemPromptPort, v as profileContextPort, x as agentsPort, y as settingsPort } from "./llm-C8dh3Tqa.js";
1
+ import { _ as pluginManagerPort, a as toolsPort, b as commandsPort, c as userQuestionsPort, d as connectionPort, f as storageDomainPort, g as pluginInventoryPort, h as configEditorPort, i as registerEvolutionTool, l as subagentsPort, m as workingDirectoryPort, n as llmPort, o as projectionPort, p as skillsPort, r as modelRoute, s as presetsPort, t as EvolutionLlmError, u as systemPromptPort, v as profileContextPort, x as agentsPort, y as settingsPort } from "./llm-9Y3qyl1T.js";
2
2
  import { EvolutionPlatform } from "./service.js";
3
3
  import "./ports.js";
4
4
  import { BlockAssembler, DomainError, SessionId, createToolResultMessage, createUserMessage, defineDomain, defineTool, domainTable, escapeText, scopeOf, withFileLock } from "./values.js";
@@ -227,10 +227,11 @@ function toolsPort(ctx) {
227
227
  const tools = ctx.get("tools");
228
228
  if (tools === void 0) return void 0;
229
229
  return {
230
- register: (definition) => tools.register(definition),
230
+ register: (definition, options) => tools.register(definition, options),
231
231
  guard: (guard) => tools.guard(guard),
232
232
  restrict: (filter) => tools.restrict(filter),
233
233
  get: (name, scope) => tools.get(name, scope),
234
+ ...typeof tools.resolve === "function" ? { resolve: (context) => tools.resolve(context) } : {},
234
235
  ...typeof tools.execute === "function" ? { execute: (input) => tools.execute(input) } : {}
235
236
  };
236
237
  }
package/lib/ports.js CHANGED
@@ -1,2 +1,2 @@
1
- import { _ as pluginManagerPort, a as toolsPort, b as commandsPort, c as userQuestionsPort, d as connectionPort, f as storageDomainPort, g as pluginInventoryPort, h as configEditorPort, i as registerEvolutionTool, l as subagentsPort, m as workingDirectoryPort, n as llmPort, o as projectionPort, p as skillsPort, r as modelRoute, s as presetsPort, t as EvolutionLlmError, u as systemPromptPort, v as profileContextPort, x as agentsPort, y as settingsPort } from "./llm-C8dh3Tqa.js";
1
+ import { _ as pluginManagerPort, a as toolsPort, b as commandsPort, c as userQuestionsPort, d as connectionPort, f as storageDomainPort, g as pluginInventoryPort, h as configEditorPort, i as registerEvolutionTool, l as subagentsPort, m as workingDirectoryPort, n as llmPort, o as projectionPort, p as skillsPort, r as modelRoute, s as presetsPort, t as EvolutionLlmError, u as systemPromptPort, v as profileContextPort, x as agentsPort, y as settingsPort } from "./llm-9Y3qyl1T.js";
2
2
  export { EvolutionLlmError, agentsPort, commandsPort, configEditorPort, connectionPort, llmPort, modelRoute, pluginInventoryPort, pluginManagerPort, presetsPort, profileContextPort, projectionPort, registerEvolutionTool, settingsPort, skillsPort, storageDomainPort, subagentsPort, systemPromptPort, toolsPort, userQuestionsPort, workingDirectoryPort };
@@ -0,0 +1,117 @@
1
+ import { createScope } from "@deepseek-ai/dsh-scope";
2
+ import { Session, SessionId } from "@deepseek-ai/dsh-session";
3
+ //#region lib/types/review-child.js
4
+ /**
5
+ * Detached review child agent.
6
+ *
7
+ * PTC's `run_code` appends its nested `tool/ptc-dispatch*` frames to
8
+ * `exec.agent.session`. A background review must never write those frames to the
9
+ * parent Session, so the review executor calls the model with a child agent whose
10
+ * `session` is a real, live Session created through the public Session store. The
11
+ * child object is also the scope key of a real scoped context, so the platform's
12
+ * executor selection can attach a PTC executor to this child without touching the
13
+ * parent. This Session is detached from the parent lineage, but is live in the
14
+ * SessionStore so platform tools can resolve its working directory and approval
15
+ * context; the parent Session's seq is therefore untouched.
16
+ *
17
+ * The PTC executor is a platform-provided optional capability, not a family
18
+ * dependency. It is loaded through a runtime probe, never through a declared
19
+ * peer, so one family artifact can remain valid across the declared cohort while
20
+ * a host without PTC mode fails with an explicit unavailable error.
21
+ *
22
+ * @module @lmzhen/dsh-evolution-adapter/review-child
23
+ */
24
+ var __rewriteRelativeImportExtension = function(path, preserveJsx) {
25
+ if (typeof path === "string" && /^\.\.?\//.test(path)) return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function(m, tsx, d, ext, cm) {
26
+ return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : d + ext + "." + cm.toLowerCase() + "js";
27
+ });
28
+ return path;
29
+ };
30
+ /** The platform PTC executor is absent or not compatible with this host. */
31
+ var PtcExecutorUnavailableError = class extends Error {
32
+ code = "PTC_UNAVAILABLE";
33
+ constructor(reason) {
34
+ super("PTC executor unavailable: " + reason);
35
+ this.name = "PtcExecutorUnavailableError";
36
+ }
37
+ };
38
+ let nextChild = 0;
39
+ /**
40
+ * Probe the platform's optional PTC executor without declaring a family peer.
41
+ * Shape checks fail closed: a host may ship an older/newer package, but an
42
+ * incompatible export must surface as PTC_UNAVAILABLE, not as a generic startup
43
+ * crash. The version is intentionally not inferred from the package name.
44
+ */
45
+ async function loadPtcExecutor() {
46
+ const specifier = "@deepseek-ai/dsh-tool-executor-ptc";
47
+ let module;
48
+ try {
49
+ module = await import(__rewriteRelativeImportExtension(
50
+ /* @vite-ignore */
51
+ specifier
52
+ ));
53
+ } catch {
54
+ throw new PtcExecutorUnavailableError("platform package @deepseek-ai/dsh-tool-executor-ptc is not installed");
55
+ }
56
+ if (typeof module.apply !== "function") throw new PtcExecutorUnavailableError("@deepseek-ai/dsh-tool-executor-ptc has no apply() export");
57
+ if (module.inject !== void 0 && (!Array.isArray(module.inject) || !module.inject.every((item) => typeof item === "string"))) throw new PtcExecutorUnavailableError("@deepseek-ai/dsh-tool-executor-ptc has an incompatible inject export");
58
+ return module;
59
+ }
60
+ /**
61
+ * Create a detached review child agent.
62
+ * @param parent - the live parent agent; only its `session` is replaced.
63
+ * @param taskId - review task identity used in the child Session id.
64
+ */
65
+ async function createReviewChildAgent(parent, taskId, options = {}) {
66
+ const childId = SessionId(`review-child:${taskId.replace(/[^A-Za-z0-9_.:-]/g, "_")}:${nextChild++}`);
67
+ const parentSession = parent.session;
68
+ const parentCtx = parent.ctx;
69
+ const cwd = typeof parentSession?.header?.cwd === "string" ? parentSession.header.cwd : void 0;
70
+ const agent = Object.create(parent);
71
+ let scope;
72
+ let child;
73
+ try {
74
+ if (parentCtx !== void 0 && typeof parentCtx.plugin === "function") {
75
+ scope = createScope(parentCtx, agent, { parent });
76
+ Object.defineProperty(agent, "ctx", {
77
+ value: scope.ctx,
78
+ enumerable: true,
79
+ configurable: false
80
+ });
81
+ }
82
+ if (scope !== void 0) {
83
+ const capture = Object.assign((inner) => {
84
+ child = inner.sessions.create(childId, cwd === void 0 ? void 0 : { meta: { cwd } });
85
+ }, { inject: ["sessions"] });
86
+ await scope.ctx.plugin(capture, {});
87
+ } else child = parentCtx?.sessions?.create(childId, cwd === void 0 ? void 0 : { meta: { cwd } }) ?? Session.create(childId);
88
+ if (child === void 0) throw new PtcExecutorUnavailableError("the platform has no session store for the child scope");
89
+ Object.defineProperty(agent, "session", {
90
+ value: child,
91
+ enumerable: true,
92
+ configurable: false
93
+ });
94
+ Object.defineProperty(agent, "id", {
95
+ value: child.id,
96
+ enumerable: true,
97
+ configurable: false
98
+ });
99
+ if (options.ptc === true) {
100
+ if (scope === void 0) throw new PtcExecutorUnavailableError("the parent has no scoped context");
101
+ const plugin = await loadPtcExecutor();
102
+ await scope.ctx.plugin(plugin, {});
103
+ }
104
+ return {
105
+ agent,
106
+ session: child,
107
+ async dispose() {
108
+ await scope?.dispose();
109
+ }
110
+ };
111
+ } catch (error) {
112
+ await scope?.dispose().catch(() => {});
113
+ throw error;
114
+ }
115
+ }
116
+ //#endregion
117
+ export { PtcExecutorUnavailableError, createReviewChildAgent };
package/lib/service.js CHANGED
@@ -1,4 +1,4 @@
1
- import { _ as pluginManagerPort, a as toolsPort, b as commandsPort, c as userQuestionsPort, d as connectionPort, f as storageDomainPort, g as pluginInventoryPort, h as configEditorPort, l as subagentsPort, m as workingDirectoryPort, n as llmPort, o as projectionPort, p as skillsPort, s as presetsPort, u as systemPromptPort, v as profileContextPort, x as agentsPort, y as settingsPort } from "./llm-C8dh3Tqa.js";
1
+ import { _ as pluginManagerPort, a as toolsPort, b as commandsPort, c as userQuestionsPort, d as connectionPort, f as storageDomainPort, g as pluginInventoryPort, h as configEditorPort, l as subagentsPort, m as workingDirectoryPort, n as llmPort, o as projectionPort, p as skillsPort, s as presetsPort, u as systemPromptPort, v as profileContextPort, x as agentsPort, y as settingsPort } from "./llm-9Y3qyl1T.js";
2
2
  import { Service } from "@deepseek-ai/cordis";
3
3
  import { CONTRACT } from "@lmzhen/dsh-evolution-platform-contract";
4
4
  //#region lib/types/service.js
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Detached review child agent.
3
+ *
4
+ * PTC's `run_code` appends its nested `tool/ptc-dispatch*` frames to
5
+ * `exec.agent.session`. A background review must never write those frames to the
6
+ * parent Session, so the review executor calls the model with a child agent whose
7
+ * `session` is a real, live Session created through the public Session store. The
8
+ * child object is also the scope key of a real scoped context, so the platform's
9
+ * executor selection can attach a PTC executor to this child without touching the
10
+ * parent. This Session is detached from the parent lineage, but is live in the
11
+ * SessionStore so platform tools can resolve its working directory and approval
12
+ * context; the parent Session's seq is therefore untouched.
13
+ *
14
+ * The PTC executor is a platform-provided optional capability, not a family
15
+ * dependency. It is loaded through a runtime probe, never through a declared
16
+ * peer, so one family artifact can remain valid across the declared cohort while
17
+ * a host without PTC mode fails with an explicit unavailable error.
18
+ *
19
+ * @module @lmzhen/dsh-evolution-adapter/review-child
20
+ */
21
+ import { Session } from '@deepseek-ai/dsh-session';
22
+ /** The platform PTC executor is absent or not compatible with this host. */
23
+ export declare class PtcExecutorUnavailableError extends Error {
24
+ readonly code = "PTC_UNAVAILABLE";
25
+ constructor(reason: string);
26
+ }
27
+ export interface ReviewChildAgent {
28
+ /** Parent-shaped agent whose `session` is the detached child. */
29
+ readonly agent: unknown;
30
+ /** The detached Session; exposed for tests and diagnostics. */
31
+ readonly session: Session;
32
+ /** Drop the review child scope, its executor, and the scope-owned child Session. */
33
+ dispose(): Promise<void>;
34
+ }
35
+ export interface ReviewChildOptions {
36
+ /** Mount the PTC tool executor in the child scope (required for PTC programs). */
37
+ readonly ptc?: boolean;
38
+ }
39
+ /**
40
+ * Create a detached review child agent.
41
+ * @param parent - the live parent agent; only its `session` is replaced.
42
+ * @param taskId - review task identity used in the child Session id.
43
+ */
44
+ export declare function createReviewChildAgent(parent: unknown, taskId: string, options?: ReviewChildOptions): Promise<ReviewChildAgent>;
45
+ //# sourceMappingURL=review-child.d.ts.map
@@ -0,0 +1,117 @@
1
+ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
2
+ if (typeof path === "string" && /^\.\.?\//.test(path)) {
3
+ return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
4
+ return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
5
+ });
6
+ }
7
+ return path;
8
+ };
9
+ /**
10
+ * Detached review child agent.
11
+ *
12
+ * PTC's `run_code` appends its nested `tool/ptc-dispatch*` frames to
13
+ * `exec.agent.session`. A background review must never write those frames to the
14
+ * parent Session, so the review executor calls the model with a child agent whose
15
+ * `session` is a real, live Session created through the public Session store. The
16
+ * child object is also the scope key of a real scoped context, so the platform's
17
+ * executor selection can attach a PTC executor to this child without touching the
18
+ * parent. This Session is detached from the parent lineage, but is live in the
19
+ * SessionStore so platform tools can resolve its working directory and approval
20
+ * context; the parent Session's seq is therefore untouched.
21
+ *
22
+ * The PTC executor is a platform-provided optional capability, not a family
23
+ * dependency. It is loaded through a runtime probe, never through a declared
24
+ * peer, so one family artifact can remain valid across the declared cohort while
25
+ * a host without PTC mode fails with an explicit unavailable error.
26
+ *
27
+ * @module @lmzhen/dsh-evolution-adapter/review-child
28
+ */
29
+ import { Session, SessionId } from '@deepseek-ai/dsh-session';
30
+ import { createScope } from '@deepseek-ai/dsh-scope';
31
+ /** The platform PTC executor is absent or not compatible with this host. */
32
+ export class PtcExecutorUnavailableError extends Error {
33
+ code = 'PTC_UNAVAILABLE';
34
+ constructor(reason) {
35
+ super('PTC executor unavailable: ' + reason);
36
+ this.name = 'PtcExecutorUnavailableError';
37
+ }
38
+ }
39
+ let nextChild = 0;
40
+ /**
41
+ * Probe the platform's optional PTC executor without declaring a family peer.
42
+ * Shape checks fail closed: a host may ship an older/newer package, but an
43
+ * incompatible export must surface as PTC_UNAVAILABLE, not as a generic startup
44
+ * crash. The version is intentionally not inferred from the package name.
45
+ */
46
+ async function loadPtcExecutor() {
47
+ const specifier = '@deepseek-ai/dsh-tool-executor-ptc';
48
+ let module;
49
+ try {
50
+ module = await import(__rewriteRelativeImportExtension(/* @vite-ignore */ specifier));
51
+ }
52
+ catch {
53
+ throw new PtcExecutorUnavailableError('platform package @deepseek-ai/dsh-tool-executor-ptc is not installed');
54
+ }
55
+ if (typeof module.apply !== 'function') {
56
+ throw new PtcExecutorUnavailableError('@deepseek-ai/dsh-tool-executor-ptc has no apply() export');
57
+ }
58
+ if (module.inject !== undefined && (!Array.isArray(module.inject) || !module.inject.every(item => typeof item === 'string'))) {
59
+ throw new PtcExecutorUnavailableError('@deepseek-ai/dsh-tool-executor-ptc has an incompatible inject export');
60
+ }
61
+ return module;
62
+ }
63
+ /**
64
+ * Create a detached review child agent.
65
+ * @param parent - the live parent agent; only its `session` is replaced.
66
+ * @param taskId - review task identity used in the child Session id.
67
+ */
68
+ export async function createReviewChildAgent(parent, taskId, options = {}) {
69
+ const safe = taskId.replace(/[^A-Za-z0-9_.:-]/g, '_');
70
+ const childId = SessionId(`review-child:${safe}:${nextChild++}`);
71
+ const parentSession = parent.session;
72
+ const parentCtx = parent.ctx;
73
+ const cwd = typeof parentSession?.header?.cwd === 'string' ? parentSession.header.cwd : undefined;
74
+ // Object.create keeps the parent's Agent prototype and identity-independent
75
+ // fields while making this object the exact scope key used by tools.execute.
76
+ const agent = Object.create(parent);
77
+ let scope;
78
+ let child;
79
+ try {
80
+ if (parentCtx !== undefined && typeof parentCtx.plugin === 'function') {
81
+ scope = createScope(parentCtx, agent, { parent: parent });
82
+ Object.defineProperty(agent, 'ctx', { value: scope.ctx, enumerable: true, configurable: false });
83
+ }
84
+ // A scope-owned Session is removed with the scope on success or failure.
85
+ // The capture plugin gets `sessions` through Cordis injection; the scope's
86
+ // own ctx is not guaranteed to hold that service without an inject list.
87
+ if (scope !== undefined) {
88
+ const capture = Object.assign((inner) => {
89
+ child = inner.sessions.create(childId, cwd === undefined ? undefined : { meta: { cwd } });
90
+ }, { inject: ['sessions'] });
91
+ await scope.ctx.plugin(capture, {});
92
+ }
93
+ else {
94
+ child = parentCtx?.sessions?.create(childId, cwd === undefined ? undefined : { meta: { cwd } }) ?? Session.create(childId);
95
+ }
96
+ if (child === undefined)
97
+ throw new PtcExecutorUnavailableError('the platform has no session store for the child scope');
98
+ Object.defineProperty(agent, 'session', { value: child, enumerable: true, configurable: false });
99
+ Object.defineProperty(agent, 'id', { value: child.id, enumerable: true, configurable: false });
100
+ if (options.ptc === true) {
101
+ if (scope === undefined)
102
+ throw new PtcExecutorUnavailableError('the parent has no scoped context');
103
+ const plugin = await loadPtcExecutor();
104
+ await scope.ctx.plugin(plugin, {});
105
+ }
106
+ return {
107
+ agent,
108
+ session: child,
109
+ async dispose() { await scope?.dispose(); },
110
+ };
111
+ }
112
+ catch (error) {
113
+ await scope?.dispose().catch(() => { });
114
+ throw error;
115
+ }
116
+ }
117
+ //# sourceMappingURL=review-child.js.map
@@ -9,10 +9,11 @@ export function toolsPort(ctx) {
9
9
  if (tools === undefined)
10
10
  return undefined;
11
11
  return {
12
- register: (definition) => tools.register(definition),
12
+ register: (definition, options) => tools.register(definition, options),
13
13
  guard: (guard) => tools.guard(guard),
14
14
  restrict: (filter) => tools.restrict(filter),
15
15
  get: (name, scope) => tools.get(name, scope),
16
+ ...(typeof tools.resolve === 'function' ? { resolve: (context) => tools.resolve(context) } : {}),
16
17
  ...(typeof tools.execute === 'function' ? { execute: (input) => tools.execute(input) } : {}),
17
18
  };
18
19
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lmzhen/dsh-evolution-adapter",
3
3
  "description": "The only host-facing platform adapter for the dsh-evolution family (community build)",
4
- "version": "0.58.0",
4
+ "version": "0.59.0",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -30,6 +30,10 @@
30
30
  "types": "./lib/types/values.d.ts",
31
31
  "default": "./lib/values.js"
32
32
  },
33
+ "./review-child": {
34
+ "types": "./lib/types/review-child.d.ts",
35
+ "default": "./lib/review-child.js"
36
+ },
33
37
  "./package.json": "./package.json"
34
38
  },
35
39
  "files": [
@@ -40,7 +44,7 @@
40
44
  "license": "MIT",
41
45
  "dependencies": {
42
46
  "@deepseek-ai/dsh-atomic-write": "0.2.2-rc.5",
43
- "@lmzhen/dsh-evolution-platform-contract": "0.58.0"
47
+ "@lmzhen/dsh-evolution-platform-contract": "0.59.0"
44
48
  },
45
49
  "peerDependencies": {
46
50
  "@deepseek-ai/cordis": "^4.0.5",