@dsmm/dsmm 0.1.1 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/README.md +24 -13
  2. package/agent-presets/dsmm-builder/agent.cordis.yml +14 -12
  3. package/agent-presets/dsmm-builder/preset.yml +1 -1
  4. package/agent-presets/dsmm-clarifier/agent.cordis.yml +4 -2
  5. package/agent-presets/dsmm-clarifier/preset.yml +1 -1
  6. package/agent-presets/dsmm-code-search/agent.cordis.yml +4 -2
  7. package/agent-presets/dsmm-code-search/preset.yml +1 -1
  8. package/agent-presets/dsmm-creative/agent.cordis.yml +3 -1
  9. package/agent-presets/dsmm-creative/preset.yml +1 -1
  10. package/agent-presets/dsmm-doc-search/agent.cordis.yml +4 -2
  11. package/agent-presets/dsmm-doc-search/preset.yml +1 -1
  12. package/agent-presets/dsmm-media-reader/agent.cordis.yml +4 -2
  13. package/agent-presets/dsmm-media-reader/preset.yml +1 -1
  14. package/agent-presets/dsmm-oracle/agent.cordis.yml +3 -1
  15. package/agent-presets/dsmm-oracle/preset.yml +1 -1
  16. package/agent-presets/dsmm-oracle-2nd/agent.cordis.yml +3 -1
  17. package/agent-presets/dsmm-oracle-2nd/preset.yml +1 -1
  18. package/agent-presets/dsmm-orchestrator/agent.cordis.yml +15 -13
  19. package/agent-presets/dsmm-orchestrator/preset.yml +2 -2
  20. package/agent-presets/dsmm-plan-critic/agent.cordis.yml +4 -2
  21. package/agent-presets/dsmm-plan-critic/preset.yml +1 -1
  22. package/agent-presets/dsmm-planner/agent.cordis.yml +4 -2
  23. package/agent-presets/dsmm-planner/preset.yml +1 -1
  24. package/agent-presets/dsmm-reviewer/agent.cordis.yml +4 -2
  25. package/agent-presets/dsmm-reviewer/preset.yml +1 -1
  26. package/docs/agent-presets.md +15 -5
  27. package/docs/compatibility.md +64 -11
  28. package/docs/model-routing.md +10 -6
  29. package/docs/profiles.md +83 -0
  30. package/docs/releasing.md +58 -19
  31. package/docs/settings-status.md +13 -5
  32. package/lib/client/ProfilesSection.d.ts +11 -0
  33. package/lib/client/ProfilesSection.js +62 -0
  34. package/lib/client/controller.d.ts +77 -0
  35. package/lib/client/controller.js +198 -0
  36. package/lib/client/index.d.ts +11 -0
  37. package/lib/client/index.js +34 -0
  38. package/lib/client/locales.d.ts +56 -0
  39. package/lib/client/locales.js +48 -0
  40. package/lib/client/styles.d.ts +3 -0
  41. package/lib/client/styles.js +25 -0
  42. package/lib/client.js +1930 -0
  43. package/lib/commands.d.ts +3 -3
  44. package/lib/commands.js +4 -4
  45. package/lib/dsh-types.d.ts +4 -0
  46. package/lib/guards.d.ts +2 -2
  47. package/lib/guards.js +3 -2
  48. package/lib/index.d.ts +12 -4
  49. package/lib/index.js +72 -20
  50. package/lib/mode.d.ts +2 -2
  51. package/lib/mode.js +1 -1
  52. package/lib/model-routing.d.ts +2 -2
  53. package/lib/model-routing.js +17 -2
  54. package/lib/preset-registry.js +5 -3
  55. package/lib/profile-remote.d.ts +31 -0
  56. package/lib/profile-remote.js +106 -0
  57. package/lib/profile-rpc.d.ts +27 -0
  58. package/lib/profile-rpc.js +90 -0
  59. package/lib/profile-runtime.d.ts +44 -0
  60. package/lib/profile-runtime.js +159 -0
  61. package/lib/profile-store.d.ts +42 -0
  62. package/lib/profile-store.js +478 -0
  63. package/lib/profile-types.d.ts +40 -0
  64. package/lib/profile-types.js +2 -0
  65. package/lib/profiles.d.ts +26 -0
  66. package/lib/profiles.js +237 -0
  67. package/lib/prompts.d.ts +2 -2
  68. package/lib/prompts.js +4 -4
  69. package/lib/role-providers.d.ts +2 -2
  70. package/lib/role-providers.js +39 -6
  71. package/lib/role-routing.d.ts +2 -2
  72. package/lib/role-routing.js +4 -1
  73. package/lib/role-subagents.d.ts +2 -2
  74. package/lib/role-subagents.js +6 -4
  75. package/lib/roles.d.ts +4 -0
  76. package/lib/roles.js +43 -27
  77. package/lib/runtime-recovery.d.ts +2 -2
  78. package/lib/runtime-recovery.js +3 -3
  79. package/lib/session-metadata.d.ts +13 -0
  80. package/lib/session-metadata.js +34 -0
  81. package/lib/session-persistence.d.ts +35 -0
  82. package/lib/session-persistence.js +304 -0
  83. package/lib/settings.d.ts +8 -1
  84. package/lib/settings.js +4 -0
  85. package/lib/state.d.ts +1 -0
  86. package/lib/state.js +4 -0
  87. package/lib/status.js +6 -5
  88. package/locale/en.json +6 -0
  89. package/locale/zh.json +6 -0
  90. package/package.json +62 -15
  91. package/patches/agent-presets-root.example.cordis.patch.yml +6 -10
  92. package/prompts/deepseek-v4-pro.md +1 -1
  93. package/prompts/deepwork.md +3 -3
  94. package/scripts/repair-session-log.mjs +476 -0
  95. package/scripts/session-repair-native-verifier.mjs +367 -0
@@ -0,0 +1,44 @@
1
+ import type { DshAgent, DshContext } from "./dsh-types.js";
2
+ import type { LoadedProfileSelection } from "./profile-store.js";
3
+ import type { ProfileReadResult, ProfileSaveRequest, ProfileSelectRequest, ProfileSelectionState, ProfileSnapshot } from "./profile-types.js";
4
+ import type { DsmmProfileDocument } from "./profiles.js";
5
+ import type { DsmmSettings, DsmmSettingsGetter } from "./settings.js";
6
+ export interface DsmmProfileRuntimeStore {
7
+ loadSelection(): Promise<LoadedProfileSelection>;
8
+ describe(): Promise<ProfileSnapshot>;
9
+ read(id: string): Promise<ProfileReadResult>;
10
+ save(request: ProfileSaveRequest): Promise<ProfileReadResult>;
11
+ select<T>(request: ProfileSelectRequest, validateCandidate: (document: DsmmProfileDocument | null) => T | Promise<T>): Promise<{
12
+ selection: ProfileSelectionState;
13
+ prepared: T;
14
+ }>;
15
+ }
16
+ export interface DsmmProfileRuntimeOptions {
17
+ /** Trusted test/integration seam, never a wire-supplied path or callback. */
18
+ validateCandidate?: (settings: DsmmSettings) => void | Promise<void>;
19
+ }
20
+ /** Selection admits new roots only; live children inherit exact runtime ownership. */
21
+ export declare class DsmmProfileRuntime {
22
+ private readonly ctx;
23
+ private readonly store;
24
+ private readonly options;
25
+ readonly getSettings: DsmmSettingsGetter;
26
+ private current;
27
+ private readonly baseline;
28
+ private readonly bound;
29
+ private selectionQueue;
30
+ constructor(ctx: DshContext, baseline: DsmmSettings, store: DsmmProfileRuntimeStore, options?: DsmmProfileRuntimeOptions);
31
+ initialize(): Promise<void>;
32
+ admission(agent: DshAgent): ProfileSelectionState;
33
+ describe(): Promise<ProfileSnapshot>;
34
+ read(id: string): Promise<ProfileReadResult>;
35
+ save(request: ProfileSaveRequest): Promise<ProfileReadResult>;
36
+ select(request: ProfileSelectRequest): Promise<ProfileSnapshot>;
37
+ private prepare;
38
+ private agents;
39
+ private bind;
40
+ private validate;
41
+ }
42
+ /** No guessed home fallback: native deployment context owns this directory. */
43
+ export declare function createProfileRuntime(ctx: DshContext, baseline: DsmmSettings): Promise<DsmmProfileRuntime>;
44
+ //# sourceMappingURL=profile-runtime.d.ts.map
@@ -0,0 +1,159 @@
1
+ import { join } from "node:path";
2
+ import { ProfileStore } from "./profile-store.js";
3
+ import { DsmmProfileError, resolveProfileSettings } from "./profiles.js";
4
+ import { DSMM_ROLES, isRootRole } from "./roles.js";
5
+ function immutableSettings(settings) {
6
+ const copy = structuredClone(settings);
7
+ const freeze = (value) => {
8
+ if (typeof value !== "object" || value === null || Object.isFrozen(value))
9
+ return;
10
+ for (const entry of Object.values(value))
11
+ freeze(entry);
12
+ Object.freeze(value);
13
+ };
14
+ freeze(copy);
15
+ return copy;
16
+ }
17
+ /** Selection admits new roots only; live children inherit exact runtime ownership. */
18
+ export class DsmmProfileRuntime {
19
+ ctx;
20
+ store;
21
+ options;
22
+ getSettings = (agent) => agent === undefined ? this.current.settings : this.bind(agent).settings;
23
+ current;
24
+ baseline;
25
+ bound = new WeakMap();
26
+ selectionQueue = Promise.resolve();
27
+ constructor(ctx, baseline, store, options = {}) {
28
+ this.ctx = ctx;
29
+ this.store = store;
30
+ this.options = options;
31
+ this.baseline = immutableSettings(baseline);
32
+ this.current = { selectedId: null, appliedRevision: null, selectionRevision: "absent", settings: this.baseline };
33
+ }
34
+ async initialize() {
35
+ const selection = await this.store.loadSelection();
36
+ // Cold resumes are new runtime Agents: the pinned current selection is the
37
+ // startup authority, not an assertion that a previous process still lives.
38
+ this.current = this.prepare(selection.document, selection);
39
+ this.ctx.on?.("agent/created", ({ agent }) => { this.bind(agent); }, { global: true, prepend: true });
40
+ // Installation into an already-running host treats those Agents as admitted
41
+ // now, while all later profile switches continue to preserve their snapshot.
42
+ for (const agent of this.agents()?.list() ?? [])
43
+ this.bind(agent);
44
+ }
45
+ admission(agent) {
46
+ const { selectedId, appliedRevision, selectionRevision } = this.bind(agent);
47
+ return { selectedId, appliedRevision, selectionRevision };
48
+ }
49
+ async describe() {
50
+ const persisted = await this.store.describe();
51
+ const current = this.current;
52
+ const changedOutsideHost = persisted.selectedId !== current.selectedId
53
+ || persisted.appliedRevision !== current.appliedRevision
54
+ || persisted.selectionRevision !== current.selectionRevision;
55
+ return {
56
+ ...persisted,
57
+ selectedId: current.selectedId,
58
+ appliedRevision: current.appliedRevision,
59
+ // Keep the disk revision for CAS, but never label its unvalidated policy
60
+ // as admitted in this Host. Existing Agent snapshots remain untouched.
61
+ ...(persisted.selectionError === undefined && changedOutsideHost ? {
62
+ selectionError: {
63
+ code: "conflict",
64
+ message: "The persisted selection changed outside this Host. New Agents still use this Host's admitted current policy; reapply the desired profile or restart."
65
+ }
66
+ } : {})
67
+ };
68
+ }
69
+ read(id) { return this.store.read(id); }
70
+ save(request) { return this.store.save(request); }
71
+ select(request) {
72
+ const operation = this.selectionQueue.then(async () => {
73
+ const result = await this.store.select(request, async (document) => {
74
+ const prepared = immutableSettings(resolveProfileSettings(this.baseline, document?.settings ?? {}));
75
+ await this.validate(prepared);
76
+ return prepared;
77
+ });
78
+ // There is no await between successful durable commit and publication of
79
+ // the complete settings value. Draft saves never reach this assignment.
80
+ this.current = { ...result.selection, settings: result.prepared };
81
+ return this.describe();
82
+ });
83
+ this.selectionQueue = operation.catch(() => undefined);
84
+ return operation;
85
+ }
86
+ prepare(document, selection) {
87
+ return { selectedId: selection.selectedId, appliedRevision: selection.appliedRevision, selectionRevision: selection.selectionRevision,
88
+ settings: immutableSettings(resolveProfileSettings(this.baseline, document?.settings ?? {})) };
89
+ }
90
+ agents() { return this.ctx.get?.("agents"); }
91
+ bind(agent) {
92
+ const existing = this.bound.get(agent);
93
+ if (existing !== undefined)
94
+ return existing;
95
+ const agents = this.agents();
96
+ // The native factory enters the exact child/owner pair before announcing
97
+ // creation. Durable lineage and inherited persona never establish ownership.
98
+ const parent = agent.id === undefined ? undefined
99
+ : agents?.list().find((candidate) => candidate !== agent && agents.isOwnedBy(agent.id, candidate));
100
+ const admitted = parent === undefined ? this.current : this.bind(parent);
101
+ this.bound.set(agent, admitted);
102
+ return admitted;
103
+ }
104
+ async validate(settings) {
105
+ if (this.options.validateCandidate !== undefined) {
106
+ await this.options.validateCandidate(settings);
107
+ return;
108
+ }
109
+ const registry = this.ctx.get?.("agentPresets");
110
+ if (registry !== undefined) {
111
+ for (const role of DSMM_ROLES.filter((role) => isRootRole(role) && settings.roles[role.id])) {
112
+ try {
113
+ const preset = await registry.resolve(role.id);
114
+ if (preset.broken !== undefined)
115
+ throw new Error("unusable root preset");
116
+ }
117
+ catch {
118
+ throw new DsmmProfileError("activation", "An enabled DW root preset is unavailable. Resolve the native preset loading error before applying a profile.", role.id);
119
+ }
120
+ }
121
+ }
122
+ const routes = [];
123
+ for (const [role, policy] of Object.entries(settings.roleRouting)) {
124
+ if (!settings.roles[role])
125
+ continue;
126
+ if (policy.primary !== undefined)
127
+ routes.push({ route: policy.primary, field: `settings.roleRouting.${role}.primary` });
128
+ for (const [index, route] of (policy.fallbackRoutes ?? []).entries())
129
+ routes.push({ route, field: `settings.roleRouting.${role}.fallbackRoutes.${index}` });
130
+ }
131
+ for (const [index, route] of settings.runtimeRecovery.fallbackRoutes.entries())
132
+ routes.push({ route, field: `settings.runtimeRecovery.fallbackRoutes.${index}` });
133
+ if (routes.length === 0)
134
+ return;
135
+ const llm = (this.agents()?.list() ?? []).map((agent) => agent.ctx?.get?.("llm")).find((service) => service?.resolveCallConfig !== undefined)
136
+ ?? this.ctx.get?.("llm") ?? (this.ctx.get === undefined ? this.ctx.llm : undefined);
137
+ if (llm?.resolveCallConfig === undefined) {
138
+ throw new DsmmProfileError("activation", "Open a chat so its native model service can validate configured routes before applying this profile.");
139
+ }
140
+ for (const { route, field } of routes) {
141
+ try {
142
+ await llm.resolveCallConfig({ ...route });
143
+ }
144
+ catch {
145
+ throw new DsmmProfileError("activation", "The configured provider, model or exact reasoning effort is unavailable in the native model catalog.", field);
146
+ }
147
+ }
148
+ }
149
+ }
150
+ /** No guessed home fallback: native deployment context owns this directory. */
151
+ export async function createProfileRuntime(ctx, baseline) {
152
+ const profile = ctx.get?.("profileContext");
153
+ if (typeof profile?.dir !== "string" || profile.dir.trim() === "")
154
+ throw new DsmmProfileError("activation", "Deepwork profiles require the native deployment profile directory.");
155
+ const runtime = new DsmmProfileRuntime(ctx, baseline, new ProfileStore(join(profile.dir, "dsmm-profiles")));
156
+ await runtime.initialize();
157
+ return runtime;
158
+ }
159
+ //# sourceMappingURL=profile-runtime.js.map
@@ -0,0 +1,42 @@
1
+ import type { ProfileReadResult, ProfileSaveRequest, ProfileSelectRequest, ProfileSelectionState, ProfileSnapshot } from "./profile-types.js";
2
+ import type { DsmmProfileDocument } from "./profiles.js";
3
+ export type SaveProfileRequest = ProfileSaveRequest;
4
+ export type SelectProfileRequest = ProfileSelectRequest;
5
+ export interface LoadedProfileSelection extends ProfileSelectionState {
6
+ document: DsmmProfileDocument | null;
7
+ content: string | null;
8
+ }
9
+ export interface ProfileStoreOptions {
10
+ lockTimeoutMs?: number;
11
+ lockPollMs?: number;
12
+ /** Narrow test seam for a failed atomic replacement; never delete the old target. */
13
+ rename?: (source: string, destination: string) => void;
14
+ }
15
+ /** This directory is supplied by the Host, never by a remote method parameter. */
16
+ export declare class ProfileStore {
17
+ readonly profileDir: string;
18
+ private readonly timeoutMs;
19
+ private readonly pollMs;
20
+ private readonly rename;
21
+ private rootIdentity?;
22
+ constructor(profileDir: string, options?: ProfileStoreOptions);
23
+ describe(): Promise<ProfileSnapshot>;
24
+ read(id: string): Promise<ProfileReadResult>;
25
+ save(request: ProfileSaveRequest): Promise<ProfileReadResult>;
26
+ loadSelection(): Promise<LoadedProfileSelection>;
27
+ select<T = undefined>(request: ProfileSelectRequest, validateCandidate?: (document: DsmmProfileDocument | null) => T | Promise<T>): Promise<{
28
+ selection: LoadedProfileSelection;
29
+ prepared: T;
30
+ }>;
31
+ private readResult;
32
+ private inventory;
33
+ private draftName;
34
+ private draft;
35
+ private selection;
36
+ private assertSelectionRevision;
37
+ private publishRevision;
38
+ private atomicReplace;
39
+ private validateRoot;
40
+ private locked;
41
+ }
42
+ //# sourceMappingURL=profile-store.d.ts.map