odai-dsh-agent 0.2.5 → 0.2.7

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 (166) hide show
  1. package/README.md +3 -3
  2. package/build/bin/odai-dsh-agent.d.mts +3 -0
  3. package/build/bin/odai-dsh-agent.d.mts.map +1 -0
  4. package/build/bin/odai-dsh-agent.mjs +114 -0
  5. package/build/bin/odai-dsh-agent.mjs.map +1 -0
  6. package/build/src/dsh-version.d.mts +16 -0
  7. package/build/src/dsh-version.d.mts.map +1 -0
  8. package/build/src/dsh-version.mjs +20 -0
  9. package/build/src/dsh-version.mjs.map +1 -0
  10. package/build/src/installer.d.mts +46 -0
  11. package/build/src/installer.d.mts.map +1 -0
  12. package/build/src/installer.mjs +398 -0
  13. package/build/src/installer.mjs.map +1 -0
  14. package/package.json +13 -12
  15. package/preset/odai/runtime/compaction-config.d.mts +66 -0
  16. package/preset/odai/runtime/compaction-config.d.mts.map +1 -0
  17. package/preset/odai/runtime/compaction-config.mjs +320 -342
  18. package/preset/odai/runtime/compaction-config.mjs.map +1 -0
  19. package/preset/odai/runtime/compaction-runtime.d.mts +68 -0
  20. package/preset/odai/runtime/compaction-runtime.d.mts.map +1 -0
  21. package/preset/odai/runtime/compaction-runtime.mjs +157 -0
  22. package/preset/odai/runtime/compaction-runtime.mjs.map +1 -0
  23. package/preset/odai/runtime/context-activation.d.mts +31 -0
  24. package/preset/odai/runtime/context-activation.d.mts.map +1 -0
  25. package/preset/odai/runtime/context-activation.mjs +55 -49
  26. package/preset/odai/runtime/context-activation.mjs.map +1 -0
  27. package/preset/odai/runtime/context-capability.d.mts +16 -0
  28. package/preset/odai/runtime/context-capability.d.mts.map +1 -0
  29. package/preset/odai/runtime/context-capability.mjs +79 -74
  30. package/preset/odai/runtime/context-capability.mjs.map +1 -0
  31. package/preset/odai/runtime/governance.d.mts +30 -0
  32. package/preset/odai/runtime/governance.d.mts.map +1 -0
  33. package/preset/odai/runtime/governance.mjs +126 -113
  34. package/preset/odai/runtime/governance.mjs.map +1 -0
  35. package/preset/odai/runtime/human-care.d.mts +13 -0
  36. package/preset/odai/runtime/human-care.d.mts.map +1 -0
  37. package/preset/odai/runtime/human-care.mjs +45 -42
  38. package/preset/odai/runtime/human-care.mjs.map +1 -0
  39. package/preset/odai/runtime/human-safety-continuity-store.d.mts +43 -0
  40. package/preset/odai/runtime/human-safety-continuity-store.d.mts.map +1 -0
  41. package/preset/odai/runtime/human-safety-continuity-store.mjs +193 -215
  42. package/preset/odai/runtime/human-safety-continuity-store.mjs.map +1 -0
  43. package/preset/odai/runtime/human-safety-continuity.d.mts +27 -0
  44. package/preset/odai/runtime/human-safety-continuity.d.mts.map +1 -0
  45. package/preset/odai/runtime/human-safety-continuity.mjs +205 -216
  46. package/preset/odai/runtime/human-safety-continuity.mjs.map +1 -0
  47. package/preset/odai/runtime/human-safety.d.mts +14 -0
  48. package/preset/odai/runtime/human-safety.d.mts.map +1 -0
  49. package/preset/odai/runtime/human-safety.mjs +50 -47
  50. package/preset/odai/runtime/human-safety.mjs.map +1 -0
  51. package/preset/odai/runtime/index.d.mts +8 -0
  52. package/preset/odai/runtime/index.d.mts.map +1 -0
  53. package/preset/odai/runtime/index.mjs +190 -2473
  54. package/preset/odai/runtime/index.mjs.map +1 -0
  55. package/preset/odai/runtime/lifecycle-runtime.d.mts +83 -0
  56. package/preset/odai/runtime/lifecycle-runtime.d.mts.map +1 -0
  57. package/preset/odai/runtime/lifecycle-runtime.mjs +1140 -0
  58. package/preset/odai/runtime/lifecycle-runtime.mjs.map +1 -0
  59. package/preset/odai/runtime/model-route.d.mts +22 -0
  60. package/preset/odai/runtime/model-route.d.mts.map +1 -0
  61. package/preset/odai/runtime/model-route.mjs +68 -60
  62. package/preset/odai/runtime/model-route.mjs.map +1 -0
  63. package/preset/odai/runtime/output-config.d.mts +54 -0
  64. package/preset/odai/runtime/output-config.d.mts.map +1 -0
  65. package/preset/odai/runtime/output-config.mjs +289 -315
  66. package/preset/odai/runtime/output-config.mjs.map +1 -0
  67. package/preset/odai/runtime/output-policy-state.d.mts +3 -0
  68. package/preset/odai/runtime/output-policy-state.d.mts.map +1 -0
  69. package/preset/odai/runtime/output-policy-state.mjs +41 -29
  70. package/preset/odai/runtime/output-policy-state.mjs.map +1 -0
  71. package/preset/odai/runtime/prompt-runtime.d.mts +55 -0
  72. package/preset/odai/runtime/prompt-runtime.d.mts.map +1 -0
  73. package/preset/odai/runtime/prompt-runtime.mjs +303 -0
  74. package/preset/odai/runtime/prompt-runtime.mjs.map +1 -0
  75. package/preset/odai/runtime/research-packet.d.mts +30 -0
  76. package/preset/odai/runtime/research-packet.d.mts.map +1 -0
  77. package/preset/odai/runtime/research-packet.mjs +116 -117
  78. package/preset/odai/runtime/research-packet.mjs.map +1 -0
  79. package/preset/odai/runtime/responsibility-gap.d.mts +26 -0
  80. package/preset/odai/runtime/responsibility-gap.d.mts.map +1 -0
  81. package/preset/odai/runtime/responsibility-gap.mjs +93 -85
  82. package/preset/odai/runtime/responsibility-gap.mjs.map +1 -0
  83. package/preset/odai/runtime/responsibility-scope.d.mts +69 -0
  84. package/preset/odai/runtime/responsibility-scope.d.mts.map +1 -0
  85. package/preset/odai/runtime/responsibility-scope.mjs +199 -171
  86. package/preset/odai/runtime/responsibility-scope.mjs.map +1 -0
  87. package/preset/odai/runtime/role-overlays.d.mts +5 -0
  88. package/preset/odai/runtime/role-overlays.d.mts.map +1 -0
  89. package/preset/odai/runtime/role-overlays.mjs +15 -14
  90. package/preset/odai/runtime/role-overlays.mjs.map +1 -0
  91. package/preset/odai/runtime/route-card.d.mts +42 -0
  92. package/preset/odai/runtime/route-card.d.mts.map +1 -0
  93. package/preset/odai/runtime/route-card.mjs +158 -146
  94. package/preset/odai/runtime/route-card.mjs.map +1 -0
  95. package/preset/odai/runtime/router.d.mts +80 -0
  96. package/preset/odai/runtime/router.d.mts.map +1 -0
  97. package/preset/odai/runtime/router.mjs +509 -559
  98. package/preset/odai/runtime/router.mjs.map +1 -0
  99. package/preset/odai/runtime/routing-config.d.mts +76 -0
  100. package/preset/odai/runtime/routing-config.d.mts.map +1 -0
  101. package/preset/odai/runtime/routing-config.mjs +373 -438
  102. package/preset/odai/runtime/routing-config.mjs.map +1 -0
  103. package/preset/odai/runtime/routing-context.d.mts +64 -0
  104. package/preset/odai/runtime/routing-context.d.mts.map +1 -0
  105. package/preset/odai/runtime/routing-context.mjs +398 -277
  106. package/preset/odai/runtime/routing-context.mjs.map +1 -0
  107. package/preset/odai/runtime/runtime-config.d.mts +24 -0
  108. package/preset/odai/runtime/runtime-config.d.mts.map +1 -0
  109. package/preset/odai/runtime/runtime-config.mjs +181 -0
  110. package/preset/odai/runtime/runtime-config.mjs.map +1 -0
  111. package/preset/odai/runtime/runtime-support.d.mts +91 -0
  112. package/preset/odai/runtime/runtime-support.d.mts.map +1 -0
  113. package/preset/odai/runtime/runtime-support.mjs +371 -0
  114. package/preset/odai/runtime/runtime-support.mjs.map +1 -0
  115. package/preset/odai/runtime/runtime-types.d.mts +237 -0
  116. package/preset/odai/runtime/runtime-types.d.mts.map +1 -0
  117. package/preset/odai/runtime/runtime-types.mjs +4 -0
  118. package/preset/odai/runtime/runtime-types.mjs.map +1 -0
  119. package/preset/odai/runtime/semantic-memory-store.d.mts +110 -0
  120. package/preset/odai/runtime/semantic-memory-store.d.mts.map +1 -0
  121. package/preset/odai/runtime/semantic-memory-store.mjs +271 -385
  122. package/preset/odai/runtime/semantic-memory-store.mjs.map +1 -0
  123. package/preset/odai/runtime/semantic-memory.d.mts +88 -0
  124. package/preset/odai/runtime/semantic-memory.d.mts.map +1 -0
  125. package/preset/odai/runtime/semantic-memory.mjs +790 -750
  126. package/preset/odai/runtime/semantic-memory.mjs.map +1 -0
  127. package/preset/odai/runtime/session-compat.d.mts +31 -0
  128. package/preset/odai/runtime/session-compat.d.mts.map +1 -0
  129. package/preset/odai/runtime/session-compat.mjs +301 -328
  130. package/preset/odai/runtime/session-compat.mjs.map +1 -0
  131. package/preset/odai/runtime/session-evidence.d.mts +25 -0
  132. package/preset/odai/runtime/session-evidence.d.mts.map +1 -0
  133. package/preset/odai/runtime/session-evidence.mjs +309 -287
  134. package/preset/odai/runtime/session-evidence.mjs.map +1 -0
  135. package/preset/odai/runtime/skill-bundle.d.mts +53 -0
  136. package/preset/odai/runtime/skill-bundle.d.mts.map +1 -0
  137. package/preset/odai/runtime/skill-bundle.mjs +286 -276
  138. package/preset/odai/runtime/skill-bundle.mjs.map +1 -0
  139. package/preset/odai/runtime/skill-evolution.d.mts +112 -0
  140. package/preset/odai/runtime/skill-evolution.d.mts.map +1 -0
  141. package/preset/odai/runtime/skill-evolution.mjs +1287 -1261
  142. package/preset/odai/runtime/skill-evolution.mjs.map +1 -0
  143. package/preset/odai/runtime/skill-selection-state.d.mts +5 -0
  144. package/preset/odai/runtime/skill-selection-state.d.mts.map +1 -0
  145. package/preset/odai/runtime/skill-selection-state.mjs +59 -43
  146. package/preset/odai/runtime/skill-selection-state.mjs.map +1 -0
  147. package/preset/odai/runtime/skill-selector.d.mts +28 -0
  148. package/preset/odai/runtime/skill-selector.d.mts.map +1 -0
  149. package/preset/odai/runtime/skill-selector.mjs +100 -109
  150. package/preset/odai/runtime/skill-selector.mjs.map +1 -0
  151. package/preset/odai/runtime/skill-source-config.d.mts +32 -0
  152. package/preset/odai/runtime/skill-source-config.d.mts.map +1 -0
  153. package/preset/odai/runtime/skill-source-config.mjs +200 -210
  154. package/preset/odai/runtime/skill-source-config.mjs.map +1 -0
  155. package/preset/odai/runtime/store-lock.d.mts +2 -0
  156. package/preset/odai/runtime/store-lock.d.mts.map +1 -0
  157. package/preset/odai/runtime/store-lock.mjs +92 -87
  158. package/preset/odai/runtime/store-lock.mjs.map +1 -0
  159. package/preset/odai/runtime/tool-runtime.d.mts +43 -0
  160. package/preset/odai/runtime/tool-runtime.d.mts.map +1 -0
  161. package/preset/odai/runtime/tool-runtime.mjs +221 -0
  162. package/preset/odai/runtime/tool-runtime.mjs.map +1 -0
  163. package/bin/odai-dsh-agent.mjs +0 -108
  164. package/scripts/verify-agent-load.mjs +0 -260
  165. package/src/dsh-version.mjs +0 -24
  166. package/src/installer.mjs +0 -385
@@ -1,199 +1,227 @@
1
1
  import { randomUUID } from "node:crypto";
2
-
3
2
  const SHORT_SCOPE_ROLES = new Set(["planner", "reviewer"]);
4
3
  const WORK_SCOPE_ROLES = new Set(["executor", "frontend"]);
5
-
6
4
  function routeSnapshot(value) {
7
- if (typeof value?.provider !== "string" || typeof value?.model !== "string") return undefined;
8
- return Object.freeze({
9
- provider: value.provider,
10
- model: value.model,
11
- ...(value.reasoningEffort === undefined ? {} : { reasoningEffort: value.reasoningEffort }),
12
- ...(value.maxTokens === undefined ? {} : { maxTokens: value.maxTokens }),
13
- });
14
- }
15
-
5
+ if (typeof value?.provider !== "string" || typeof value?.model !== "string")
6
+ return undefined;
7
+ return Object.freeze({
8
+ provider: value.provider,
9
+ model: value.model,
10
+ ...(value.reasoningEffort === undefined ? {} : { reasoningEffort: value.reasoningEffort }),
11
+ ...(value.maxTokens === undefined ? {} : { maxTokens: value.maxTokens }),
12
+ });
13
+ }
16
14
  function rolePolicy(role) {
17
- if (SHORT_SCOPE_ROLES.has(role)) return "read-only-tool-chain";
18
- if (WORK_SCOPE_ROLES.has(role)) return "bounded-work-tool-chain";
19
- throw new TypeError(`unsupported in-place responsibility: ${role}`);
20
- }
21
-
22
- export function createResponsibilityScope({
23
- turn,
24
- startStep,
25
- role,
26
- route,
27
- source,
28
- decision,
29
- routeValidated = false,
30
- cardId,
31
- resumeOfScopeId,
32
- }) {
33
- if (!Number.isSafeInteger(turn) || turn < 1) throw new TypeError("scope turn must be a positive integer");
34
- if (!Number.isSafeInteger(startStep) || startStep < 1) throw new TypeError("scope startStep must be a positive integer");
35
- const requestedRoute = routeSnapshot(route);
36
- if (!requestedRoute) throw new TypeError("scope route must contain provider and model");
37
- if (resumeOfScopeId !== undefined && (typeof resumeOfScopeId !== "string" || resumeOfScopeId === "")) {
38
- throw new TypeError("resumeOfScopeId must be a non-empty string");
39
- }
40
- return Object.freeze({
41
- id: randomUUID(),
42
- state: "pending",
43
- turn,
44
- startStep,
45
- role,
46
- route: requestedRoute,
47
- source,
48
- decision,
49
- continuationPolicy: rolePolicy(role),
50
- stopPolicy: "terminal-response-or-ownership-boundary",
51
- routeValidated: routeValidated === true,
52
- ...(cardId ? { cardId } : {}),
53
- ...(resumeOfScopeId ? { resumeOfScopeId } : {}),
54
- });
55
- }
56
-
57
- export function claimResponsibilityScope(scope, { step, baseRoute, temporaryRoute, routeMode }) {
58
- if (scope?.state !== "pending") return scope;
59
- if (step !== scope.startStep) throw new Error("responsibility scope may only be claimed by its start step");
60
- const base = routeSnapshot(baseRoute);
61
- const temporary = routeSnapshot(temporaryRoute);
62
- if (!base || !temporary) throw new TypeError("claimed responsibility scope requires base and temporary routes");
63
- return Object.freeze({
64
- ...scope,
65
- state: "active",
66
- claimedStep: step,
67
- baseRoute: base,
68
- temporaryRoute: temporary,
69
- routeMode,
70
- });
71
- }
72
-
15
+ if (SHORT_SCOPE_ROLES.has(role))
16
+ return "read-only-tool-chain";
17
+ if (WORK_SCOPE_ROLES.has(role))
18
+ return "bounded-work-tool-chain";
19
+ throw new TypeError(`unsupported in-place responsibility: ${role}`);
20
+ }
21
+ export function createResponsibilityScope(options) {
22
+ const { turn, startStep, role, route, source, decision, routeValidated = false, cardId, resumeOfScopeId } = options;
23
+ if (!Number.isSafeInteger(turn) || turn < 1)
24
+ throw new TypeError("scope turn must be a positive integer");
25
+ if (!Number.isSafeInteger(startStep) || startStep < 1)
26
+ throw new TypeError("scope startStep must be a positive integer");
27
+ const requestedRoute = routeSnapshot(route);
28
+ if (!requestedRoute)
29
+ throw new TypeError("scope route must contain provider and model");
30
+ if (resumeOfScopeId !== undefined && (typeof resumeOfScopeId !== "string" || resumeOfScopeId === "")) {
31
+ throw new TypeError("resumeOfScopeId must be a non-empty string");
32
+ }
33
+ return Object.freeze({
34
+ id: randomUUID(),
35
+ state: "pending",
36
+ turn,
37
+ startStep,
38
+ role,
39
+ route: requestedRoute,
40
+ source,
41
+ decision,
42
+ continuationPolicy: rolePolicy(role),
43
+ stopPolicy: "terminal-response-or-ownership-boundary",
44
+ routeValidated: routeValidated === true,
45
+ ...(cardId ? { cardId } : {}),
46
+ ...(resumeOfScopeId ? { resumeOfScopeId } : {}),
47
+ });
48
+ }
49
+ export function claimResponsibilityScope(scope, options) {
50
+ const { step, baseRoute, temporaryRoute, routeMode } = options;
51
+ if (scope?.state !== "pending")
52
+ return scope;
53
+ if (step !== scope.startStep)
54
+ throw new Error("responsibility scope may only be claimed by its start step");
55
+ const base = routeSnapshot(baseRoute);
56
+ const temporary = routeSnapshot(temporaryRoute);
57
+ if (!base || !temporary)
58
+ throw new TypeError("claimed responsibility scope requires base and temporary routes");
59
+ return Object.freeze({
60
+ ...scope,
61
+ state: "active",
62
+ claimedStep: step,
63
+ baseRoute: base,
64
+ temporaryRoute: temporary,
65
+ routeMode,
66
+ });
67
+ }
73
68
  export function responsibilityScopeOwnsRequest(scope, turn, step) {
74
- return Boolean(scope
75
- && ["pending", "active"].includes(scope.state)
76
- && scope.turn === turn
77
- && Number.isSafeInteger(step)
78
- && step >= scope.startStep);
69
+ return Boolean(scope
70
+ && (scope.state === "pending" || scope.state === "active")
71
+ && scope.turn === turn
72
+ && Number.isSafeInteger(step)
73
+ && step >= scope.startStep);
79
74
  }
80
-
81
75
  export function isDirectHumanMessage(message) {
82
- return message?.role === "user" && message?.source?.kind === "user";
76
+ return message?.role === "user" && message?.source?.kind === "user";
83
77
  }
84
-
85
78
  function assistantHasToolCalls(event) {
86
- return Array.isArray(event?.data?.message?.content)
87
- && event.data.message.content.some((block) => block?.type === "tool-call");
79
+ return Array.isArray(event?.data?.message?.content)
80
+ && event.data.message.content.some((block) => block?.type === "tool-call");
88
81
  }
89
-
90
82
  export function responsibilityScopeStopReason(scope, event) {
91
- if (!scope || !event) return undefined;
92
- if (event.type === "agent/inbox/spliced"
93
- && Array.isArray(event.data?.inserted)
94
- && event.data.inserted.some(isDirectHumanMessage)) {
95
- return "direct-user-input";
96
- }
97
- if (event.type === "assistant/message"
98
- && event.data?.turn === scope.turn
99
- && Number.isSafeInteger(event.data?.step)
100
- && event.data.step >= scope.startStep
101
- && !assistantHasToolCalls(event)) {
102
- return "terminal-response";
103
- }
104
- if (event.type === "turn/end" && event.data?.turn === scope.turn) return "turn-ended";
105
- if (scope.cardId && event.type === "odai/route-card-cleared" && event.data?.cardId === scope.cardId) return "route-card-cleared";
106
- if (scope.cardId && event.type === "odai/route-card-claim-released" && event.data?.cardId === scope.cardId) return "route-card-released";
107
- return undefined;
108
- }
109
-
83
+ if (!scope || !event)
84
+ return undefined;
85
+ if (event.type === "agent/inbox/spliced"
86
+ && Array.isArray(event.data?.inserted)
87
+ && event.data.inserted.some(isDirectHumanMessage)) {
88
+ return "direct-user-input";
89
+ }
90
+ if (event.type === "assistant/message"
91
+ && event.data?.turn === scope.turn
92
+ && Number.isSafeInteger(event.data?.step)
93
+ && (event.data.step ?? -1) >= scope.startStep
94
+ && !assistantHasToolCalls(event)) {
95
+ return "terminal-response";
96
+ }
97
+ if (event.type === "turn/end" && event.data?.turn === scope.turn)
98
+ return "turn-ended";
99
+ if (scope.cardId && event.type === "odai/route-card-cleared" && event.data?.cardId === scope.cardId)
100
+ return "route-card-cleared";
101
+ if (scope.cardId && event.type === "odai/route-card-claim-released" && event.data?.cardId === scope.cardId)
102
+ return "route-card-released";
103
+ return undefined;
104
+ }
110
105
  function scopeEventData(scope) {
111
- return Object.freeze({
112
- scopeId: scope.id,
113
- turn: scope.turn,
114
- startStep: scope.startStep,
115
- role: scope.role,
116
- requestedRoute: scope.route,
117
- continuationPolicy: scope.continuationPolicy,
118
- stopPolicy: scope.stopPolicy,
119
- ...(scope.source ? { routeSource: scope.source } : {}),
120
- ...(scope.cardId ? { routeCardId: scope.cardId } : {}),
121
- ...(scope.resumeOfScopeId ? { resumeOfScopeId: scope.resumeOfScopeId } : {}),
122
- ...(scope.baseRoute ? { baseRoute: scope.baseRoute } : {}),
123
- ...(scope.temporaryRoute ? { temporaryRoute: scope.temporaryRoute } : {}),
124
- ...(scope.routeMode ? { routeMode: scope.routeMode } : {}),
125
- });
126
- }
127
-
106
+ return Object.freeze({
107
+ scopeId: scope.id,
108
+ turn: scope.turn,
109
+ startStep: scope.startStep,
110
+ role: scope.role,
111
+ requestedRoute: scope.route,
112
+ continuationPolicy: scope.continuationPolicy,
113
+ stopPolicy: scope.stopPolicy,
114
+ ...(scope.source ? { routeSource: scope.source } : {}),
115
+ ...(scope.cardId ? { routeCardId: scope.cardId } : {}),
116
+ ...(scope.resumeOfScopeId ? { resumeOfScopeId: scope.resumeOfScopeId } : {}),
117
+ ...(scope.baseRoute ? { baseRoute: scope.baseRoute } : {}),
118
+ ...(scope.temporaryRoute ? { temporaryRoute: scope.temporaryRoute } : {}),
119
+ ...(scope.routeMode ? { routeMode: scope.routeMode } : {}),
120
+ });
121
+ }
128
122
  export function responsibilityScopeStartedEvent(scope) {
129
- return scopeEventData(scope);
123
+ return scopeEventData(scope);
130
124
  }
131
-
132
125
  export function responsibilityScopeClaimedEvent(scope) {
133
- if (scope?.state !== "active") throw new TypeError("only an active responsibility scope can be recorded as claimed");
134
- return scopeEventData(scope);
126
+ if (scope?.state !== "active")
127
+ throw new TypeError("only an active responsibility scope can be recorded as claimed");
128
+ return scopeEventData(scope);
135
129
  }
136
-
137
130
  export function responsibilityScopeStoppedEvent(scope, reason, position = {}) {
138
- return Object.freeze({
139
- ...scopeEventData(scope),
140
- ...(Number.isSafeInteger(position.step) ? { stopStep: position.step } : {}),
141
- reason,
142
- });
131
+ return Object.freeze({
132
+ ...scopeEventData(scope),
133
+ ...(Number.isSafeInteger(position.step) ? { stopStep: position.step } : {}),
134
+ reason,
135
+ });
143
136
  }
144
-
145
137
  export function latestDanglingResponsibilityScope(events) {
146
- const states = new Map();
147
- for (const event of Array.isArray(events) ? events : []) {
148
- const scopeId = event?.data?.scopeId;
149
- if (typeof scopeId !== "string") continue;
150
- if (event.type === "odai/responsibility-scope-started") states.set(scopeId, { state: "started", data: event.data });
151
- else if (event.type === "odai/responsibility-scope-claimed") states.set(scopeId, { state: "claimed", data: event.data });
152
- else if (event.type === "odai/responsibility-scope-stopped") states.set(scopeId, { state: "stopped", data: event.data });
153
- }
154
- return [...states.values()].findLast((entry) => entry.state === "claimed")?.data;
155
- }
156
-
138
+ const states = new Map();
139
+ for (const event of Array.isArray(events) ? events : []) {
140
+ const scopeId = event?.data?.scopeId;
141
+ if (typeof scopeId !== "string")
142
+ continue;
143
+ if (event.type === "odai/responsibility-scope-started")
144
+ states.set(scopeId, { state: "started", data: event.data });
145
+ else if (event.type === "odai/responsibility-scope-claimed")
146
+ states.set(scopeId, { state: "claimed", data: event.data });
147
+ else if (event.type === "odai/responsibility-scope-stopped")
148
+ states.set(scopeId, { state: "stopped", data: event.data });
149
+ }
150
+ return [...states.values()].findLast((entry) => entry.state === "claimed")?.data;
151
+ }
157
152
  export function latestStoppedResponsibilityScope(events, turn) {
158
- return (Array.isArray(events) ? events : []).findLast((event) => (
159
- event?.type === "odai/responsibility-scope-stopped"
160
- && event.data?.turn === turn
161
- && typeof event.data?.scopeId === "string"
162
- ))?.data;
153
+ if (turn === undefined)
154
+ return undefined;
155
+ return (Array.isArray(events) ? events : []).findLast((event) => (event?.type === "odai/responsibility-scope-stopped"
156
+ && event.data?.turn === turn
157
+ && typeof event.data?.scopeId === "string"))?.data;
158
+ }
159
+ function isInPlaceResponsibility(value) {
160
+ return value === "planner" || value === "reviewer" || value === "executor" || value === "frontend";
161
+ }
162
+ function isRouteCard(value) {
163
+ if (value === null || typeof value !== "object")
164
+ return false;
165
+ return "id" in value && typeof value.id === "string"
166
+ && "frozen" in value && value.frozen === true
167
+ && "observableBenefit" in value && value.observableBenefit === true
168
+ && "authorization" in value && value.authorization !== null && typeof value.authorization === "object"
169
+ && "target" in value && typeof value.target === "string"
170
+ && "evidence" in value && Array.isArray(value.evidence)
171
+ && "scope" in value && Array.isArray(value.scope)
172
+ && "accept" in value && Array.isArray(value.accept)
173
+ && "stop" in value && typeof value.stop === "string";
174
+ }
175
+ function isResponsibilityInterruption(data) {
176
+ return typeof data.scopeId === "string"
177
+ && isInPlaceResponsibility(data.responsibility)
178
+ && typeof data.reason === "string"
179
+ && (data.routeCard === undefined || isRouteCard(data.routeCard));
163
180
  }
164
-
165
181
  export function pendingResponsibilityInterruption(events) {
166
- const settled = new Set();
167
- for (let index = (Array.isArray(events) ? events.length : 0) - 1; index >= 0; index -= 1) {
168
- const event = events[index];
169
- const scopeId = event?.data?.scopeId;
170
- if (typeof scopeId !== "string") continue;
171
- if (["odai/responsibility-interruption-consumed", "odai/responsibility-interruption-cleared"].includes(event.type)) {
172
- settled.add(scopeId);
173
- continue;
182
+ const settled = new Set();
183
+ for (let index = (Array.isArray(events) ? events.length : 0) - 1; index >= 0; index -= 1) {
184
+ const event = events?.[index];
185
+ const scopeId = event?.data?.scopeId;
186
+ if (!event || typeof scopeId !== "string")
187
+ continue;
188
+ if (["odai/responsibility-interruption-consumed", "odai/responsibility-interruption-cleared"].includes(event.type)) {
189
+ settled.add(scopeId);
190
+ continue;
191
+ }
192
+ if (event.type === "odai/responsibility-interrupted") {
193
+ return event.data?.reason === "max-tokens" && !settled.has(scopeId) && isResponsibilityInterruption(event.data)
194
+ ? event.data
195
+ : undefined;
196
+ }
174
197
  }
175
- if (event.type === "odai/responsibility-interrupted") {
176
- return event.data?.reason === "max-tokens" && !settled.has(scopeId)
177
- ? event.data
178
- : undefined;
179
- }
180
- }
181
- return undefined;
198
+ return undefined;
199
+ }
200
+ function isModelRoute(value) {
201
+ return value !== null && typeof value === "object"
202
+ && "provider" in value && typeof value.provider === "string"
203
+ && "model" in value && typeof value.model === "string";
204
+ }
205
+ function isResponsibilityScopeRestoration(data) {
206
+ return typeof data.scopeId === "string"
207
+ && isInPlaceResponsibility(data.role)
208
+ && isModelRoute(data.baseRoute)
209
+ && isModelRoute(data.temporaryRoute);
182
210
  }
183
-
184
211
  export function pendingResponsibilityScopeRestoration(events) {
185
- let candidate;
186
- for (const event of Array.isArray(events) ? events : []) {
187
- if (event?.type === "odai/responsibility-scope-stopped"
188
- && event.data?.baseRoute
189
- && event.data?.temporaryRoute) {
190
- candidate = event.data;
191
- continue;
212
+ let candidate;
213
+ for (const event of Array.isArray(events) ? events : []) {
214
+ if (event?.type === "odai/responsibility-scope-stopped"
215
+ && isResponsibilityScopeRestoration(event.data)) {
216
+ candidate = event.data;
217
+ continue;
218
+ }
219
+ if (candidate
220
+ && event?.type === "odai/responsibility-scope-restored"
221
+ && event.data?.scopeId === candidate.scopeId
222
+ && event.data?.status === "applied")
223
+ candidate = undefined;
192
224
  }
193
- if (candidate
194
- && event?.type === "odai/responsibility-scope-restored"
195
- && event.data?.scopeId === candidate.scopeId
196
- && event.data?.status === "applied") candidate = undefined;
197
- }
198
- return candidate;
225
+ return candidate;
199
226
  }
227
+ //# sourceMappingURL=responsibility-scope.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"responsibility-scope.mjs","sourceRoot":"","sources":["../src/responsibility-scope.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAUzC,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAwB,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC;AAClF,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAwB,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC;AAuDlF,SAAS,aAAa,CAAC,KAAsC;IAC3D,IAAI,OAAO,KAAK,EAAE,QAAQ,KAAK,QAAQ,IAAI,OAAO,KAAK,EAAE,KAAK,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC;IAC9F,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,GA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S,YAAY,CAAC,KAAc;IAClC,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ;WAC7C,UAAU,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,QAAQ,KAAK,QAAQ;WACzD,OAAO,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,KAAK,KAAK,QAAQ,CAAC;AAC3D,CAAC;AAED,SAAS,gCAAgC,CAAC,IAAsB;IAC9D,OAAO,OAAO,IAAI,CAAC,OAAO,KAAK,QAAQ;WAClC,uBAAuB,CAAC,IAAI,CAAC,IAAI,CAAC;WAClC,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC;WAC5B,YAAY,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;AACzC,CAAC;AAED,MAAM,UAAU,qCAAqC,CAAC,MAAuC;IAC3F,IAAI,SAAqD,CAAC;IAC1D,KAAK,MAAM,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;QACxD,IAAI,KAAK,EAAE,IAAI,KAAK,mCAAmC;eAClD,gCAAgC,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;YAClD,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC;YACvB,SAAS;QACX,CAAC;QACD,IAAI,SAAS;eACR,KAAK,EAAE,IAAI,KAAK,oCAAoC;eACpD,KAAK,CAAC,IAAI,EAAE,OAAO,KAAK,SAAS,CAAC,OAAO;eACzC,KAAK,CAAC,IAAI,EAAE,MAAM,KAAK,SAAS;YAAE,SAAS,GAAG,SAAS,CAAC;IAC/D,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -0,0 +1,5 @@
1
+ export interface RoleReferenceContracts {
2
+ craft?: unknown;
3
+ }
4
+ export declare function dshRoleContract(role: string, canonicalContract: unknown, referenceContracts?: RoleReferenceContracts): string;
5
+ //# sourceMappingURL=role-overlays.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"role-overlays.d.mts","sourceRoot":"","sources":["../src/role-overlays.mts"],"names":[],"mappings":"AAkBA,MAAM,WAAW,sBAAsB;IACrC,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,wBAAgB,eAAe,CAC7B,IAAI,EAAE,MAAM,EACZ,iBAAiB,EAAE,OAAO,EAC1B,kBAAkB,GAAE,sBAA2B,GAC9C,MAAM,CAQR"}
@@ -1,27 +1,28 @@
1
1
  const DSH_ROLE_OVERLAYS = Object.freeze({
2
- researcher: `## DSH researcher execution boundary
2
+ researcher: `## DSH researcher execution boundary
3
3
 
4
4
  This responsibility runs as one read-only child before the primary routing decision. Use only read, glob, grep, and other non-mutating source tools; do not run shell commands, edit, plan, recommend, approve, or delegate. Return JSON only, with no fence and no fields beyond this exact shape: {"schemaVersion":1,"question":"...","facts":[{"claim":"...","excerpt":"exact complete cited line","source":{"path":"repository/relative/path","line":1},"authority":"source role and freshness boundary"}],"conflicts":[],"unknowns":[],"stop":"..."}. Return the smallest useful 2-6 facts from at least two distinct files. DSH validates every cited file, line, and excerpt inside the project root before hashing and exposing this packet to the controller or planner.`,
5
- planner: `## DSH planner execution boundary
5
+ planner: `## DSH planner execution boundary
6
6
 
7
7
  In auto mode this responsibility runs by replacing the controller route only inside one explicit responsibility scope, not by starting a child. The scope may continue through read-only tool calls, but ends on a terminal response, new direct-human input, failure, cancellation, route mismatch, or turn boundary. When the user-persisted planner mapping explicitly includes maxTokens, that responsibility ceiling overrides the controller ceiling only inside this scope. Retain the current conversation and project context, use only read-only evidence, and do not implement or edit. If the result is mode: planned, execute: executor, and separation has a concrete observable benefit, use odai_route_card to freeze exactly one structured card with non-empty evidence, scope, acceptance conditions, and stop condition. When the original current task already authorizes implementation, immediately submit one executor gap through odai_responsibility_gap so the same task continues without another user prompt. For plan-only work, a new task, expanded scope, or missing user-owned authorization, stop for the minimal user decision instead. Otherwise do not create a route card.`,
8
- executor: `## DSH executor execution boundary
8
+ executor: `## DSH executor execution boundary
9
9
 
10
10
  In auto mode this responsibility is reachable when an active frozen route card proves observable separation benefit and either the original current task already authorizes implementation or the user explicitly continues it. It runs in one bounded controller responsibility scope because DSH routed children are read-only. The scope may continue only through its own tool chain and ends on a terminal response, new direct-human input, failure, cancellation, route mismatch, card release, or turn boundary. When the user-persisted executor mapping explicitly includes maxTokens, that responsibility ceiling overrides the controller ceiling only inside this scope. Follow the claimed card exactly; do not reinterpret the request, broaden scope, or claim final acceptance. The card is consumed after the effective executor request route is verified; that route receipt admits one executor attempt but does not keep the responsibility scope alive by itself.`,
11
- reviewer: `## DSH reviewer execution boundary
11
+ reviewer: `## DSH reviewer execution boundary
12
12
 
13
- Start an independent child only from a bounded, hash-addressed packet that contains verified tool evidence. The child's effective request header must match its configured route before its output is accepted. Without such a packet, auto mode keeps the current controller route and may perform only a controller-local read-only check while it gathers project-available acceptance evidence. That local check is not independent acceptance, must not claim reviewer approval, and must not stop the authorized task solely to ask the user for artifacts the project can produce.`,
14
- frontend: `## DSH frontend execution boundary
13
+ Start an independent child only from a bounded, hash-addressed packet that contains verified tool evidence. The child's effective request header must match its configured route before its output is accepted. Without such a packet, auto mode keeps the current controller route while the recorded reviewer gap remains pending for one controlled reassessment after new acceptance, write, diff, test, failure, or host-evidence diagnostics. A controller-local read-only check may guide evidence gathering, but it is not independent acceptance, must not claim reviewer approval, and must not stop the authorized task solely to ask the user for artifacts the project can produce.`,
14
+ frontend: `## DSH frontend execution boundary
15
15
 
16
16
  This responsibility runs in one bounded controller responsibility scope so it retains the active conversation, workspace, dev-server, and browser context. It is not an independent child. The scope may continue only through its own tool chain and ends on a terminal response, new direct-human input, failure, cancellation, route mismatch, or turn boundary. DSH may use a user-persisted frontend provider/model/reasoning route and, only when that mapping explicitly includes maxTokens, apply that responsibility ceiling inside this scope. The runtime compares the effective DSH request header with that mapping and records an applied, mismatch, or unverified receipt; configuration and self-report are not routing evidence.`,
17
17
  });
18
-
19
18
  export function dshRoleContract(role, canonicalContract, referenceContracts = {}) {
20
- const canonical = typeof canonicalContract === "string" ? canonicalContract.trim() : "";
21
- const overlay = DSH_ROLE_OVERLAYS[role];
22
- if (!canonical) throw new Error(`canonical ${role} responsibility contract is unavailable`);
23
- const craft = role === "frontend" && typeof referenceContracts.craft === "string"
24
- ? `## Canonical craft reference\n\n${referenceContracts.craft.trim()}`
25
- : "";
26
- return [canonical, craft, overlay].filter(Boolean).join("\n\n");
19
+ const canonical = typeof canonicalContract === "string" ? canonicalContract.trim() : "";
20
+ const overlay = DSH_ROLE_OVERLAYS[role];
21
+ if (!canonical)
22
+ throw new Error(`canonical ${role} responsibility contract is unavailable`);
23
+ const craft = role === "frontend" && typeof referenceContracts.craft === "string"
24
+ ? `## Canonical craft reference\n\n${referenceContracts.craft.trim()}`
25
+ : "";
26
+ return [canonical, craft, overlay].filter(Boolean).join("\n\n");
27
27
  }
28
+ //# sourceMappingURL=role-overlays.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"role-overlays.mjs","sourceRoot":"","sources":["../src/role-overlays.mts"],"names":[],"mappings":"AAAA,MAAM,iBAAiB,GAAqC,MAAM,CAAC,MAAM,CAAC;IACxE,UAAU,EAAE;;kvBAEouB;IAChvB,OAAO,EAAE;;kpCAEuoC;IAChpC,QAAQ,EAAE;;y7BAE66B;IACv7B,QAAQ,EAAE;;iqBAEqpB;IAC/pB,QAAQ,EAAE;;ktBAEssB;CACjtB,CAAC,CAAC;AAMH,MAAM,UAAU,eAAe,CAC7B,IAAY,EACZ,iBAA0B,EAC1B,kBAAkB,GAA2B,EAAE;IAE/C,MAAM,SAAS,GAAG,OAAO,iBAAiB,KAAK,QAAQ,CAAC,CAAC,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACxF,MAAM,OAAO,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC;IACxC,IAAI,CAAC,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,aAAa,IAAI,yCAAyC,CAAC,CAAC;IAC5F,MAAM,KAAK,GAAG,IAAI,KAAK,UAAU,IAAI,OAAO,kBAAkB,CAAC,KAAK,KAAK,QAAQ;QAC/E,CAAC,CAAC,mCAAmC,kBAAkB,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE;QACtE,CAAC,CAAC,EAAE,CAAC;IACP,OAAO,CAAC,SAAS,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAClE,CAAC"}
@@ -0,0 +1,42 @@
1
+ import type { DshAgent, DshEvent, RuntimeTool } from "./runtime-types.mjs";
2
+ export declare const ROUTE_CARD_PROMPT: string;
3
+ export type RouteAuthorizationStatus = "authorized" | "plan-only" | "unknown";
4
+ export interface RouteAuthorization {
5
+ readonly status: RouteAuthorizationStatus;
6
+ readonly userMessageId?: string;
7
+ }
8
+ export interface RouteCard {
9
+ readonly id: string;
10
+ readonly frozen: true;
11
+ readonly observableBenefit: true;
12
+ readonly authorization: RouteAuthorization;
13
+ readonly target: string;
14
+ readonly evidence: readonly string[];
15
+ readonly scope: readonly string[];
16
+ readonly accept: readonly string[];
17
+ readonly stop: string;
18
+ }
19
+ export type RouteCardToolResult = {
20
+ readonly action: "freeze";
21
+ readonly status: "frozen";
22
+ readonly card: RouteCard;
23
+ } | {
24
+ readonly action: "clear";
25
+ readonly status: "cleared";
26
+ readonly cardId: string;
27
+ } | {
28
+ readonly action: "clear";
29
+ readonly status: "absent";
30
+ };
31
+ export declare function activeRouteCard(events: readonly DshEvent[] | undefined): RouteCard | undefined;
32
+ export declare function unsettledRouteCard(events: readonly DshEvent[] | undefined): RouteCard | undefined;
33
+ export declare function routeCardById(events: readonly DshEvent[] | undefined, cardId: unknown): RouteCard | undefined;
34
+ export interface RouteCardToolOptions {
35
+ onFrozen?(agent: DshAgent, card: RouteCard): void;
36
+ onCleared?(agent: DshAgent, cardId: string): void;
37
+ activeFor?(agent: DshAgent): RouteCard | undefined;
38
+ unsettledFor?(agent: DshAgent): RouteCard | undefined;
39
+ authorizationFor?(agent: DshAgent): RouteAuthorization;
40
+ }
41
+ export declare function createRouteCardTool(options?: RouteCardToolOptions): RuntimeTool<unknown, RouteCardToolResult>;
42
+ //# sourceMappingURL=route-card.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route-card.d.mts","sourceRoot":"","sources":["../src/route-card.mts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAG3E,eAAO,MAAM,iBAAiB,QAOlB,CAAC;AAEb,MAAM,MAAM,wBAAwB,GAAG,YAAY,GAAG,WAAW,GAAG,SAAS,CAAC;AAE9E,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,MAAM,EAAE,wBAAwB,CAAC;IAC1C,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;CACjC;AAED,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC;IACtB,QAAQ,CAAC,iBAAiB,EAAE,IAAI,CAAC;IACjC,QAAQ,CAAC,aAAa,EAAE,kBAAkB,CAAC;IAC3C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAID,MAAM,MAAM,mBAAmB,GAC3B;IAAE,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,SAAS,CA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