@jungjaehoon/mama-os 0.51.2 → 0.52.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.
Files changed (204) hide show
  1. package/dist/agent/agent-loop.d.ts +50 -0
  2. package/dist/agent/agent-loop.d.ts.map +1 -1
  3. package/dist/agent/agent-loop.js +480 -138
  4. package/dist/agent/agent-loop.js.map +1 -1
  5. package/dist/agent/code-act/constants.d.ts +1 -1
  6. package/dist/agent/code-act/constants.d.ts.map +1 -1
  7. package/dist/agent/code-act/constants.js +5 -2
  8. package/dist/agent/code-act/constants.js.map +1 -1
  9. package/dist/agent/code-act/host-bridge.d.ts.map +1 -1
  10. package/dist/agent/code-act/host-bridge.js +102 -4
  11. package/dist/agent/code-act/host-bridge.js.map +1 -1
  12. package/dist/agent/code-act/tool-catalog.d.ts +2 -0
  13. package/dist/agent/code-act/tool-catalog.d.ts.map +1 -1
  14. package/dist/agent/code-act/tool-catalog.js +20 -7
  15. package/dist/agent/code-act/tool-catalog.js.map +1 -1
  16. package/dist/agent/codex-app-server-process.d.ts +112 -0
  17. package/dist/agent/codex-app-server-process.d.ts.map +1 -1
  18. package/dist/agent/codex-app-server-process.js +518 -1
  19. package/dist/agent/codex-app-server-process.js.map +1 -1
  20. package/dist/agent/gateway-tool-executor.d.ts +17 -0
  21. package/dist/agent/gateway-tool-executor.d.ts.map +1 -1
  22. package/dist/agent/gateway-tool-executor.js +236 -53
  23. package/dist/agent/gateway-tool-executor.js.map +1 -1
  24. package/dist/agent/gateway-tools.md +9 -3
  25. package/dist/agent/model-runner.d.ts +5 -0
  26. package/dist/agent/model-runner.d.ts.map +1 -1
  27. package/dist/agent/model-runner.js.map +1 -1
  28. package/dist/agent/skill-loader.d.ts +7 -2
  29. package/dist/agent/skill-loader.d.ts.map +1 -1
  30. package/dist/agent/skill-loader.js +29 -8
  31. package/dist/agent/skill-loader.js.map +1 -1
  32. package/dist/agent/subagent-run-reconcile.d.ts +23 -0
  33. package/dist/agent/subagent-run-reconcile.d.ts.map +1 -0
  34. package/dist/agent/subagent-run-reconcile.js +56 -0
  35. package/dist/agent/subagent-run-reconcile.js.map +1 -0
  36. package/dist/agent/tool-registry.d.ts.map +1 -1
  37. package/dist/agent/tool-registry.js +126 -3
  38. package/dist/agent/tool-registry.js.map +1 -1
  39. package/dist/agent/types.d.ts +52 -2
  40. package/dist/agent/types.d.ts.map +1 -1
  41. package/dist/agent/types.js.map +1 -1
  42. package/dist/api/graph-api.d.ts.map +1 -1
  43. package/dist/api/graph-api.js +0 -22
  44. package/dist/api/graph-api.js.map +1 -1
  45. package/dist/cli/commands/start.d.ts +8 -7
  46. package/dist/cli/commands/start.d.ts.map +1 -1
  47. package/dist/cli/commands/start.js +148 -74
  48. package/dist/cli/commands/start.js.map +1 -1
  49. package/dist/cli/config/types.d.ts.map +1 -1
  50. package/dist/cli/config/types.js +2 -1
  51. package/dist/cli/config/types.js.map +1 -1
  52. package/dist/cli/runtime/api-routes-init.d.ts +1 -0
  53. package/dist/cli/runtime/api-routes-init.d.ts.map +1 -1
  54. package/dist/cli/runtime/api-routes-init.js +76 -32
  55. package/dist/cli/runtime/api-routes-init.js.map +1 -1
  56. package/dist/db/migrations/operator-procedures.d.ts +4 -0
  57. package/dist/db/migrations/operator-procedures.d.ts.map +1 -0
  58. package/dist/db/migrations/operator-procedures.js +63 -0
  59. package/dist/db/migrations/operator-procedures.js.map +1 -0
  60. package/dist/gateways/message-router.d.ts +4 -3
  61. package/dist/gateways/message-router.d.ts.map +1 -1
  62. package/dist/gateways/message-router.js +43 -131
  63. package/dist/gateways/message-router.js.map +1 -1
  64. package/dist/gateways/telegram-format.d.ts.map +1 -1
  65. package/dist/gateways/telegram-format.js +2 -0
  66. package/dist/gateways/telegram-format.js.map +1 -1
  67. package/dist/multi-agent/runtime-process.d.ts +8 -0
  68. package/dist/multi-agent/runtime-process.d.ts.map +1 -1
  69. package/dist/multi-agent/runtime-process.js +6 -0
  70. package/dist/multi-agent/runtime-process.js.map +1 -1
  71. package/dist/operator/board-delta-gate.d.ts +34 -10
  72. package/dist/operator/board-delta-gate.d.ts.map +1 -1
  73. package/dist/operator/board-delta-gate.js +68 -24
  74. package/dist/operator/board-delta-gate.js.map +1 -1
  75. package/dist/operator/board-refresh-gate.d.ts +11 -6
  76. package/dist/operator/board-refresh-gate.d.ts.map +1 -1
  77. package/dist/operator/board-refresh-gate.js +12 -11
  78. package/dist/operator/board-refresh-gate.js.map +1 -1
  79. package/dist/operator/board-slot-instructions.d.ts +30 -0
  80. package/dist/operator/board-slot-instructions.d.ts.map +1 -1
  81. package/dist/operator/board-slot-instructions.js +110 -6
  82. package/dist/operator/board-slot-instructions.js.map +1 -1
  83. package/dist/operator/console-brief.d.ts +26 -13
  84. package/dist/operator/console-brief.d.ts.map +1 -1
  85. package/dist/operator/console-brief.js +159 -83
  86. package/dist/operator/console-brief.js.map +1 -1
  87. package/dist/operator/experience-evidence.d.ts +18 -0
  88. package/dist/operator/experience-evidence.d.ts.map +1 -0
  89. package/dist/operator/experience-evidence.js +82 -0
  90. package/dist/operator/experience-evidence.js.map +1 -0
  91. package/dist/operator/experience-hints.d.ts +44 -0
  92. package/dist/operator/experience-hints.d.ts.map +1 -0
  93. package/dist/operator/experience-hints.js +98 -0
  94. package/dist/operator/experience-hints.js.map +1 -0
  95. package/dist/operator/mama-memory-port.js +1 -3
  96. package/dist/operator/mama-memory-port.js.map +1 -1
  97. package/dist/operator/operator-trigger-loop.d.ts.map +1 -1
  98. package/dist/operator/operator-trigger-loop.js +3 -2
  99. package/dist/operator/operator-trigger-loop.js.map +1 -1
  100. package/dist/operator/owner-action-effects.d.ts +13 -1
  101. package/dist/operator/owner-action-effects.d.ts.map +1 -1
  102. package/dist/operator/owner-action-effects.js +17 -4
  103. package/dist/operator/owner-action-effects.js.map +1 -1
  104. package/dist/operator/owner-event-inbox.d.ts +7 -1
  105. package/dist/operator/owner-event-inbox.d.ts.map +1 -1
  106. package/dist/operator/owner-event-inbox.js +8 -0
  107. package/dist/operator/owner-event-inbox.js.map +1 -1
  108. package/dist/operator/owner-event-loop.d.ts +28 -2
  109. package/dist/operator/owner-event-loop.d.ts.map +1 -1
  110. package/dist/operator/owner-event-loop.js +60 -2
  111. package/dist/operator/owner-event-loop.js.map +1 -1
  112. package/dist/operator/owner-event-policy.d.ts +20 -0
  113. package/dist/operator/owner-event-policy.d.ts.map +1 -1
  114. package/dist/operator/owner-event-policy.js +34 -5
  115. package/dist/operator/owner-event-policy.js.map +1 -1
  116. package/dist/operator/owner-event-prompt.d.ts +13 -4
  117. package/dist/operator/owner-event-prompt.d.ts.map +1 -1
  118. package/dist/operator/owner-event-prompt.js +31 -38
  119. package/dist/operator/owner-event-prompt.js.map +1 -1
  120. package/dist/operator/owner-runtime-journal.d.ts.map +1 -1
  121. package/dist/operator/owner-runtime-journal.js +7 -3
  122. package/dist/operator/owner-runtime-journal.js.map +1 -1
  123. package/dist/operator/owner-runtime.d.ts +6 -0
  124. package/dist/operator/owner-runtime.d.ts.map +1 -1
  125. package/dist/operator/owner-runtime.js +48 -5
  126. package/dist/operator/owner-runtime.js.map +1 -1
  127. package/dist/operator/procedure-activation.d.ts +7 -0
  128. package/dist/operator/procedure-activation.d.ts.map +1 -0
  129. package/dist/operator/procedure-activation.js +132 -0
  130. package/dist/operator/procedure-activation.js.map +1 -0
  131. package/dist/operator/procedure-projection.d.ts +25 -0
  132. package/dist/operator/procedure-projection.d.ts.map +1 -0
  133. package/dist/operator/procedure-projection.js +80 -0
  134. package/dist/operator/procedure-projection.js.map +1 -0
  135. package/dist/operator/procedure-runtime.d.ts +45 -0
  136. package/dist/operator/procedure-runtime.d.ts.map +1 -0
  137. package/dist/operator/procedure-runtime.js +496 -0
  138. package/dist/operator/procedure-runtime.js.map +1 -0
  139. package/dist/operator/procedure-store.d.ts +97 -0
  140. package/dist/operator/procedure-store.d.ts.map +1 -0
  141. package/dist/operator/procedure-store.js +368 -0
  142. package/dist/operator/procedure-store.js.map +1 -0
  143. package/dist/operator/subagent-stimulus.d.ts +34 -0
  144. package/dist/operator/subagent-stimulus.d.ts.map +1 -0
  145. package/dist/operator/subagent-stimulus.js +145 -0
  146. package/dist/operator/subagent-stimulus.js.map +1 -0
  147. package/dist/operator/task-ledger.d.ts +40 -3
  148. package/dist/operator/task-ledger.d.ts.map +1 -1
  149. package/dist/operator/task-ledger.js +63 -10
  150. package/dist/operator/task-ledger.js.map +1 -1
  151. package/dist/operator/thread-brief-memory.d.ts +29 -0
  152. package/dist/operator/thread-brief-memory.d.ts.map +1 -0
  153. package/dist/operator/thread-brief-memory.js +61 -0
  154. package/dist/operator/thread-brief-memory.js.map +1 -0
  155. package/dist/operator/trigger-author.d.ts +2 -1
  156. package/dist/operator/trigger-author.d.ts.map +1 -1
  157. package/dist/operator/trigger-author.js +23 -0
  158. package/dist/operator/trigger-author.js.map +1 -1
  159. package/dist/operator/trigger-matcher.js +1 -0
  160. package/dist/operator/trigger-matcher.js.map +1 -1
  161. package/dist/operator/trigger-registry.d.ts +5 -4
  162. package/dist/operator/trigger-registry.d.ts.map +1 -1
  163. package/dist/operator/trigger-registry.js +78 -24
  164. package/dist/operator/trigger-registry.js.map +1 -1
  165. package/dist/operator/trigger-review.d.ts +1 -1
  166. package/dist/operator/trigger-review.d.ts.map +1 -1
  167. package/dist/operator/trigger-review.js +24 -4
  168. package/dist/operator/trigger-review.js.map +1 -1
  169. package/dist/operator/trigger-types.d.ts +10 -1
  170. package/dist/operator/trigger-types.d.ts.map +1 -1
  171. package/dist/operator/worker-run.d.ts +7 -1
  172. package/dist/operator/worker-run.d.ts.map +1 -1
  173. package/dist/operator/worker-run.js +5 -2
  174. package/dist/operator/worker-run.js.map +1 -1
  175. package/dist/operator/workorder-consumer.d.ts +91 -14
  176. package/dist/operator/workorder-consumer.d.ts.map +1 -1
  177. package/dist/operator/workorder-consumer.js +272 -93
  178. package/dist/operator/workorder-consumer.js.map +1 -1
  179. package/dist/operator/workorder-hooks.d.ts +42 -9
  180. package/dist/operator/workorder-hooks.d.ts.map +1 -1
  181. package/dist/operator/workorder-hooks.js +52 -13
  182. package/dist/operator/workorder-hooks.js.map +1 -1
  183. package/dist/operator/workorder-publishers.d.ts +9 -1
  184. package/dist/operator/workorder-publishers.d.ts.map +1 -1
  185. package/dist/operator/workorder-publishers.js +21 -2
  186. package/dist/operator/workorder-publishers.js.map +1 -1
  187. package/package.json +2 -2
  188. package/dist/operator/learning-context.d.ts +0 -49
  189. package/dist/operator/learning-context.d.ts.map +0 -1
  190. package/dist/operator/learning-context.js +0 -129
  191. package/dist/operator/learning-context.js.map +0 -1
  192. package/dist/operator/learning-markers.d.ts +0 -19
  193. package/dist/operator/learning-markers.d.ts.map +0 -1
  194. package/dist/operator/learning-markers.js +0 -147
  195. package/dist/operator/learning-markers.js.map +0 -1
  196. package/dist/operator/learning-read.d.ts +0 -16
  197. package/dist/operator/learning-read.d.ts.map +0 -1
  198. package/dist/operator/learning-read.js +0 -18
  199. package/dist/operator/learning-read.js.map +0 -1
  200. package/dist/operator/turn-observer.d.ts +0 -34
  201. package/dist/operator/turn-observer.d.ts.map +0 -1
  202. package/dist/operator/turn-observer.js +0 -79
  203. package/dist/operator/turn-observer.js.map +0 -1
  204. package/templates/skills/heartbeat-report.md +0 -75
@@ -0,0 +1,496 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProcedureRuntime = void 0;
4
+ exports.deriveProcedureAccess = deriveProcedureAccess;
5
+ const node_crypto_1 = require("node:crypto");
6
+ const node_os_1 = require("node:os");
7
+ const procedure_store_js_1 = require("./procedure-store.js");
8
+ const console_brief_js_1 = require("./console-brief.js");
9
+ const procedure_projection_js_1 = require("./procedure-projection.js");
10
+ const experience_hints_js_1 = require("./experience-hints.js");
11
+ const BRIEF_ID = 'owner-console-brief';
12
+ /** Kagemusha keeps the same bound on remembered session ids; older threads are forgotten first. */
13
+ const MAX_TRACKED_THREADS = 100;
14
+ /** TG-03/TG-04: metadata and body use the same host authority; never model-selected scope. */
15
+ function deriveProcedureAccess(state) {
16
+ const context = state?.agentContext;
17
+ const envelope = state?.envelope;
18
+ if (!context ||
19
+ !envelope ||
20
+ !Number.isFinite(Date.parse(envelope.expires_at)) ||
21
+ Date.parse(envelope.expires_at) <= Date.now()) {
22
+ return null;
23
+ }
24
+ const projects = envelope.scope.project_refs.filter((ref) => ref.kind === 'project');
25
+ if (projects.length !== 1 || !projects[0].id) {
26
+ return null;
27
+ }
28
+ const owner = context.roleName === 'owner_console' && !state.memberScopeRequired;
29
+ if (!owner && !context.principalId) {
30
+ return null;
31
+ }
32
+ return {
33
+ ownerScope: owner ? 'owner:runtime' : context.principalId,
34
+ projectId: projects[0].id,
35
+ channelId: envelope.scope.memory_scopes.find((scope) => scope.kind === 'channel')?.id ??
36
+ state.channelId ??
37
+ envelope.channel_id,
38
+ };
39
+ }
40
+ function object(input) {
41
+ if (!input || typeof input !== 'object' || Array.isArray(input)) {
42
+ throw new Error('procedure input object required');
43
+ }
44
+ return input;
45
+ }
46
+ function text(input, name, optional = false) {
47
+ const value = input[name];
48
+ if (optional && value === undefined) {
49
+ return '';
50
+ }
51
+ if (typeof value !== 'string' || !value.trim()) {
52
+ throw new Error(`procedure ${name} required`);
53
+ }
54
+ return value;
55
+ }
56
+ function strings(input, name, optional = false) {
57
+ const value = input[name];
58
+ if (optional && value === undefined) {
59
+ return [];
60
+ }
61
+ if (!Array.isArray(value) || value.some((item) => typeof item !== 'string' || !item.trim())) {
62
+ throw new Error(`procedure ${name} must be a string array`);
63
+ }
64
+ return value;
65
+ }
66
+ function revision(input, name) {
67
+ const value = input[name];
68
+ if (typeof value !== 'number' || !Number.isSafeInteger(value) || value < 0) {
69
+ throw new Error(`procedure ${name} must be a nonnegative integer`);
70
+ }
71
+ return value;
72
+ }
73
+ function metadata(record) {
74
+ return {
75
+ id: record.id,
76
+ revision: record.revision,
77
+ scopeKey: record.scopeKey,
78
+ title: record.title,
79
+ description: record.description,
80
+ whenToUse: record.whenToUse,
81
+ whenNotToUse: record.whenNotToUse,
82
+ };
83
+ }
84
+ function digest(value) {
85
+ return (0, node_crypto_1.createHash)('sha256').update(value).digest('hex');
86
+ }
87
+ /** TG-05/TG-06: selection is a run snapshot; observations do not certify learning. */
88
+ class ProcedureRuntime {
89
+ store;
90
+ homeDir;
91
+ pinned = new Map();
92
+ threads = new Map();
93
+ constructor(store, homeDir = (0, node_os_1.homedir)()) {
94
+ this.store = store;
95
+ this.homeDir = homeDir;
96
+ }
97
+ requireAccess(state) {
98
+ const access = deriveProcedureAccess(state);
99
+ if (!access) {
100
+ throw new Error('procedure host scope unavailable');
101
+ }
102
+ return access;
103
+ }
104
+ runKey(state) {
105
+ const key = state.modelRunId || state.sourceMessageRef;
106
+ if (!key) {
107
+ throw new Error('procedure host run identity unavailable');
108
+ }
109
+ return key;
110
+ }
111
+ correctionId(tool, id, expected, state) {
112
+ const source = state.sourceMessageRef || state.modelRunId;
113
+ if (!source) {
114
+ throw new Error('procedure host correction source unavailable');
115
+ }
116
+ return `correction:${digest(JSON.stringify([source, tool, id, expected]))}`;
117
+ }
118
+ original(state) {
119
+ if (!state.procedureStimulus?.trim()) {
120
+ throw new Error('procedure host original instruction unavailable');
121
+ }
122
+ return state.procedureStimulus;
123
+ }
124
+ sources(input, state) {
125
+ return [
126
+ ...new Set([
127
+ state.sourceMessageRef || state.modelRunId || '',
128
+ ...strings(input, 'source_refs', true),
129
+ ].filter(Boolean)),
130
+ ];
131
+ }
132
+ /**
133
+ * Hints for one prompt. A fresh (or untracked) thread is told the procedures most related
134
+ * to the current stimulus once, with the catalog size; a live thread only what it has not
135
+ * been told: new ids, revisions, or a counted procedure that now looks relevant. Reading
136
+ * a hint proves nothing about learning; the agent still judges and reads the body.
137
+ */
138
+ prepareContext(state, turn) {
139
+ const access = deriveProcedureAccess(state);
140
+ if (!access) {
141
+ return { text: '', hints: [] };
142
+ }
143
+ const projections = this.recoverProjections(access);
144
+ const candidates = this.store.list(access).filter((record) => record.id !== BRIEF_ID);
145
+ const key = `${(0, procedure_store_js_1.procedureScopeKey)(access)}|${turn.threadId}`;
146
+ const fresh = turn.fresh || !this.threads.has(key);
147
+ const memory = this.threadMemory(key, fresh);
148
+ const hits = (0, experience_hints_js_1.selectProcedureHints)({
149
+ stimulus: state?.procedureStimulus ?? '',
150
+ candidates,
151
+ ...(fresh ? {} : { seen: memory }),
152
+ });
153
+ const rendered = (0, experience_hints_js_1.renderProcedureHints)({
154
+ hits,
155
+ total: candidates.length,
156
+ maxChars: fresh ? experience_hints_js_1.FRESH_HINT_CHARS : experience_hints_js_1.CONTINUE_HINT_CHARS,
157
+ fresh,
158
+ });
159
+ if (fresh) {
160
+ for (const candidate of candidates)
161
+ memory.set(candidate.id, null);
162
+ }
163
+ for (const hit of rendered.rendered)
164
+ memory.set(hit.id, hit.revision);
165
+ const projectionText = projections.length
166
+ ? `<procedure_projections>${JSON.stringify(projections)
167
+ .replace(/</g, '\\u003c')
168
+ .replace(/>/g, '\\u003e')
169
+ .replace(/&/g, '\\u0026')}</procedure_projections>`
170
+ : '';
171
+ return {
172
+ text: [rendered.text, projectionText].filter(Boolean).join('\n'),
173
+ hints: rendered.rendered.map((hit) => `${hit.id}@${hit.revision}`),
174
+ };
175
+ }
176
+ threadMemory(key, fresh) {
177
+ const memory = (fresh ? undefined : this.threads.get(key)) ?? new Map();
178
+ this.threads.delete(key);
179
+ this.threads.set(key, memory);
180
+ if (this.threads.size > MAX_TRACKED_THREADS) {
181
+ const oldest = this.threads.keys().next().value;
182
+ if (oldest !== undefined)
183
+ this.threads.delete(oldest);
184
+ }
185
+ return memory;
186
+ }
187
+ canonicalBrief(state) {
188
+ const access = deriveProcedureAccess(state);
189
+ return access ? (this.store.read(BRIEF_ID, access)?.body ?? null) : null;
190
+ }
191
+ releaseRun(state) {
192
+ const key = state?.modelRunId || state?.sourceMessageRef;
193
+ if (key) {
194
+ this.pinned.delete(key);
195
+ }
196
+ }
197
+ assertWritable(state) {
198
+ const key = state.modelRunId || state.sourceMessageRef;
199
+ if (!state.procedureRefs?.length && (!key || !this.pinned.get(key)?.size)) {
200
+ return;
201
+ }
202
+ const access = this.requireAccess(state);
203
+ const scopeKey = (0, procedure_store_js_1.procedureScopeKey)(access);
204
+ const selected = new Map(state.procedureRefs?.map((ref) => [
205
+ ref.id,
206
+ { revision: ref.revision, scopeKey: ref.scopeKey ?? scopeKey },
207
+ ]) ?? []);
208
+ if (key) {
209
+ for (const [id, reference] of this.pinned.get(key) ?? []) {
210
+ selected.set(id, reference);
211
+ }
212
+ }
213
+ for (const [id, reference] of selected) {
214
+ if (reference.scopeKey !== scopeKey || !this.store.read(id, access, reference.revision)) {
215
+ throw new Error('selected procedure unavailable: retired or access revoked');
216
+ }
217
+ }
218
+ }
219
+ publish(record, access) {
220
+ if (!record.projection) {
221
+ throw new Error('procedure projection missing');
222
+ }
223
+ return (0, procedure_projection_js_1.publishProcedureProjection)({
224
+ path: record.projection.path,
225
+ text: record.projection.desiredText,
226
+ expectedFileHash: record.projection.expectedFileHash,
227
+ serialize: (publish) => this.store.withWriteTransaction(() => {
228
+ const current = this.store.read(record.id, access);
229
+ if (current?.revision !== record.revision) {
230
+ throw new Error('procedure projection revision conflict');
231
+ }
232
+ return publish();
233
+ }),
234
+ onPublished: (hash) => this.store.markProjected(record.id, record.revision, hash, access),
235
+ });
236
+ }
237
+ recoverProjections(access) {
238
+ return this.store.pendingProjections(access).map((record) => {
239
+ const result = this.publish(record, access);
240
+ return {
241
+ id: record.id,
242
+ status: result.status,
243
+ ...(result.reason ? { reason: result.reason } : {}),
244
+ };
245
+ });
246
+ }
247
+ execute(tool, raw, state) {
248
+ const access = this.requireAccess(state);
249
+ const input = object(raw);
250
+ for (const key of [
251
+ 'scope',
252
+ 'ownerScope',
253
+ 'owner_scope',
254
+ 'projectId',
255
+ 'project_id',
256
+ 'channelIds',
257
+ 'channel_ids',
258
+ 'originalInstruction',
259
+ 'original_instruction',
260
+ 'correctionId',
261
+ 'correction_id',
262
+ 'projection',
263
+ ]) {
264
+ if (key in input) {
265
+ throw new Error(`procedure ${key} is host-owned`);
266
+ }
267
+ }
268
+ if (tool === 'procedure_list') {
269
+ return { success: true, procedures: this.store.list(access).map(metadata) };
270
+ }
271
+ if (tool === 'console_brief_update') {
272
+ return this.updateBrief(input, state, access);
273
+ }
274
+ const id = text(input, 'id');
275
+ if (tool === 'procedure_read') {
276
+ if (id === BRIEF_ID) {
277
+ if (access.ownerScope !== 'owner:runtime' || state.memberScopeRequired) {
278
+ throw new Error('console brief owner scope required');
279
+ }
280
+ // The first edit needs the exact legacy text/hash without importing on a read.
281
+ // This snapshot is not a persisted revision; updateBrief checks its hash at commit.
282
+ if (this.store.history(id, access).length === 0) {
283
+ if (input.revision !== undefined && revision(input, 'revision') !== 0) {
284
+ throw new Error('procedure unavailable');
285
+ }
286
+ const snapshot = (0, console_brief_js_1.readConsoleBriefSnapshot)(this.homeDir);
287
+ return {
288
+ success: true,
289
+ procedure: {
290
+ id,
291
+ revision: 0,
292
+ title: 'Owner console operating brief',
293
+ body: snapshot.text,
294
+ scopeKey: (0, procedure_store_js_1.procedureScopeKey)(access),
295
+ },
296
+ hash: (0, procedure_projection_js_1.hashProcedureDocument)(snapshot.text),
297
+ status: 'legacy_snapshot',
298
+ behaviorVerified: false,
299
+ };
300
+ }
301
+ }
302
+ const key = this.runKey(state);
303
+ const pinned = this.pinned.get(key) ??
304
+ new Map(state.procedureRefs?.map((ref) => [
305
+ ref.id,
306
+ { revision: ref.revision, scopeKey: ref.scopeKey ?? (0, procedure_store_js_1.procedureScopeKey)(access) },
307
+ ]) ?? []);
308
+ if (pinned.has(id) && pinned.get(id).scopeKey !== (0, procedure_store_js_1.procedureScopeKey)(access)) {
309
+ throw new Error('procedure scope unavailable');
310
+ }
311
+ const explicit = input.revision === undefined ? undefined : revision(input, 'revision');
312
+ if (pinned.has(id) && explicit !== undefined && pinned.get(id)?.revision !== explicit) {
313
+ throw new Error('procedure running revision is pinned');
314
+ }
315
+ const record = this.store.read(id, access, pinned.get(id)?.revision ?? explicit);
316
+ if (!record) {
317
+ throw new Error('procedure unavailable');
318
+ }
319
+ pinned.set(id, { revision: record.revision, scopeKey: record.scopeKey });
320
+ this.pinned.set(key, pinned);
321
+ return {
322
+ success: true,
323
+ procedure: record,
324
+ hash: (0, procedure_projection_js_1.hashProcedureDocument)(record.body),
325
+ observations: this.store.getOutcomes(id, access).slice(-20),
326
+ behaviorVerified: false,
327
+ };
328
+ }
329
+ if ([
330
+ 'procedure_update',
331
+ 'procedure_retire',
332
+ 'procedure_observe',
333
+ 'console_brief_update',
334
+ ].includes(tool) &&
335
+ state.envelope?.tier === 3) {
336
+ throw new Error('procedure write denied at read-only tier');
337
+ }
338
+ if (id === BRIEF_ID && (tool === 'procedure_update' || tool === 'procedure_retire')) {
339
+ throw new Error('Use console_brief_update for operating brief corrections');
340
+ }
341
+ if (tool === 'procedure_update') {
342
+ const expected = revision(input, 'expected_revision');
343
+ const existing = expected > 0 ? this.store.read(id, access) : null;
344
+ if (expected > 0 && !existing) {
345
+ throw new Error('procedure unavailable');
346
+ }
347
+ const record = this.store.save({
348
+ id,
349
+ expectedRevision: expected,
350
+ correctionId: this.correctionId(tool, id, expected, state),
351
+ title: text(input, 'title'),
352
+ description: text(input, 'description'),
353
+ whenToUse: text(input, 'when_to_use'),
354
+ whenNotToUse: text(input, 'when_not_to_use'),
355
+ body: text(input, 'body'),
356
+ expectedResults: strings(input, 'expected_results'),
357
+ reason: text(input, 'reason'),
358
+ originalInstruction: this.original(state),
359
+ sourceRefs: this.sources(input, state),
360
+ supersededMemoryIds: strings(input, 'superseded_memory_ids', true),
361
+ scope: existing?.scope ?? {
362
+ ownerScope: access.ownerScope,
363
+ projectId: access.projectId,
364
+ ...(state.memberScopeRequired ? { channelIds: [access.channelId] } : {}),
365
+ },
366
+ }, access);
367
+ return {
368
+ success: true,
369
+ status: 'stored',
370
+ procedure: metadata(record),
371
+ behaviorVerified: false,
372
+ };
373
+ }
374
+ if (tool === 'procedure_retire') {
375
+ const expected = revision(input, 'expected_revision');
376
+ const record = this.store.retire(id, expected, this.correctionId(tool, id, expected, state), text(input, 'reason'), access);
377
+ return {
378
+ success: true,
379
+ status: 'retired',
380
+ procedure: metadata(record),
381
+ behaviorVerified: false,
382
+ };
383
+ }
384
+ if (tool === 'procedure_observe') {
385
+ const status = text(input, 'status');
386
+ if (!['selected', 'satisfied', 'failed', 'noop', 'not_performed', 'unknown'].includes(status)) {
387
+ throw new Error('procedure observation status invalid');
388
+ }
389
+ const observation = this.store.recordOutcome({
390
+ procedureId: id,
391
+ revision: revision(input, 'revision'),
392
+ receiptId: text(input, 'receipt_id'),
393
+ status: status,
394
+ evidenceRefs: strings(input, 'evidence_refs'),
395
+ }, access);
396
+ return {
397
+ success: true,
398
+ observation,
399
+ behaviorVerified: false,
400
+ message: 'Observation stored; satisfaction is an agent assessment, not independently verified learning.',
401
+ };
402
+ }
403
+ throw new Error('Unknown procedure tool');
404
+ }
405
+ updateBrief(input, state, access) {
406
+ if (access.ownerScope !== 'owner:runtime' || state.memberScopeRequired) {
407
+ throw new Error('console brief owner scope required');
408
+ }
409
+ const operation = input.operation;
410
+ if (operation === 'append') {
411
+ throw new Error('console brief update refused: append is retired; store the correction with procedure_update');
412
+ }
413
+ if (operation !== 'replace' && operation !== 'retire') {
414
+ throw new Error('console brief operation invalid');
415
+ }
416
+ if (state.envelope?.tier === 3) {
417
+ throw new Error('procedure write denied at read-only tier');
418
+ }
419
+ // A committed predecessor must be acknowledged before taking the next file baseline.
420
+ // This covers both crash-before-rename and crash-after-rename-before-ack.
421
+ const pending = this.store.pendingProjections(access).find((record) => record.id === BRIEF_ID);
422
+ if (pending) {
423
+ const recovery = this.publish(pending, access);
424
+ if (recovery.status !== 'projected') {
425
+ throw new Error(`console brief prior projection unresolved: ${recovery.reason ?? recovery.status}`);
426
+ }
427
+ }
428
+ const current = this.store.read(BRIEF_ID, access);
429
+ const snapshot = (0, console_brief_js_1.readConsoleBriefSnapshot)(this.homeDir);
430
+ const correctionId = this.correctionId('console_brief_update', BRIEF_ID, typeof input.expected_hash === 'string' ? input.expected_hash : 'none', state);
431
+ const requestHash = digest(JSON.stringify(Object.fromEntries(Object.entries(input).sort(([a], [b]) => a.localeCompare(b)))));
432
+ const retry = this.store
433
+ .history(BRIEF_ID, access)
434
+ .find((record) => record.correctionId === correctionId);
435
+ if (retry) {
436
+ if (retry.correctionRequestHash !== requestHash) {
437
+ throw new Error('procedure correction conflict');
438
+ }
439
+ const status = current?.revision === retry.revision ? this.publish(retry, access).status : 'stored';
440
+ return {
441
+ success: true,
442
+ status,
443
+ revision: retry.revision,
444
+ hash: (0, procedure_projection_js_1.hashProcedureDocument)(retry.body),
445
+ behaviorVerified: false,
446
+ message: 'Correction already stored; no duplicate change.',
447
+ };
448
+ }
449
+ const base = current?.body ?? snapshot.text;
450
+ const edit = {
451
+ operation,
452
+ lesson: typeof (input.lesson ?? input.content) === 'string'
453
+ ? String(input.lesson ?? input.content)
454
+ : undefined,
455
+ target: typeof input.target === 'string' ? input.target : undefined,
456
+ replacement: typeof input.replacement === 'string' ? input.replacement : undefined,
457
+ expectedHash: typeof input.expected_hash === 'string' ? input.expected_hash : undefined,
458
+ };
459
+ const prepared = (0, console_brief_js_1.prepareConsoleBriefUpdate)(edit, base);
460
+ const record = this.store.save({
461
+ id: BRIEF_ID,
462
+ expectedRevision: current?.revision ?? 0,
463
+ correctionId,
464
+ correctionRequestHash: requestHash,
465
+ previousBody: base,
466
+ title: 'Owner console operating brief',
467
+ description: 'Current owner operating instructions',
468
+ whenToUse: 'Owner work subject to the conditions of each individual rule',
469
+ whenNotToUse: 'Rules whose applicability excludes the current work',
470
+ body: prepared.text,
471
+ expectedResults: ['Preserve each rule applicability and unrelated instructions'],
472
+ originalInstruction: this.original(state),
473
+ sourceRefs: this.sources(input, state),
474
+ reason: text(input, 'reason', true) || `Owner brief ${operation}`,
475
+ supersededMemoryIds: strings(input, 'superseded_memory_ids', true),
476
+ scope: { ownerScope: access.ownerScope, projectId: access.projectId },
477
+ projection: {
478
+ path: snapshot.path,
479
+ expectedFileHash: current ? (0, procedure_projection_js_1.hashProcedureDocument)(current.body) : snapshot.hash,
480
+ desiredText: prepared.text,
481
+ },
482
+ }, access);
483
+ const projected = this.publish(record, access);
484
+ return {
485
+ success: true,
486
+ status: projected.status,
487
+ revision: record.revision,
488
+ hash: prepared.hash,
489
+ ...(projected.reason ? { reason: projected.reason } : {}),
490
+ behaviorVerified: false,
491
+ message: 'Correction stored. Projection status is separate from evidence that future behavior satisfies the instruction.',
492
+ };
493
+ }
494
+ }
495
+ exports.ProcedureRuntime = ProcedureRuntime;
496
+ //# sourceMappingURL=procedure-runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"procedure-runtime.js","sourceRoot":"","sources":["../../src/operator/procedure-runtime.ts"],"names":[],"mappings":";;;AA2CA,sDA2BC;AAtED,6CAAyC;AACzC,qCAAkC;AAElC,6DAM8B;AAC9B,yDAI4B;AAC5B,uEAImC;AACnC,+DAM+B;AAK/B,MAAM,QAAQ,GAAG,qBAAqB,CAAC;AACvC,mGAAmG;AACnG,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAShC,8FAA8F;AAC9F,SAAgB,qBAAqB,CAAC,KAAmC;IACvE,MAAM,OAAO,GAAG,KAAK,EAAE,YAAY,CAAC;IACpC,MAAM,QAAQ,GAAG,KAAK,EAAE,QAAQ,CAAC;IACjC,IACE,CAAC,OAAO;QACR,CAAC,QAAQ;QACT,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;QACjD,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,IAAI,CAAC,GAAG,EAAE,EAC7C,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,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AAU,EAAE,MAAM,CAAC,UAAU,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE;YACrE,UAAU,EAAE;gBACV,IAAI,EAAE,QAAQ,CAAC,IAAI;gBACnB,gBAAgB,EAAE,OAAO,CAAC,CAAC,CAAC,IAAA,+CAAqB,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI;gBAC/E,WAAW,EAAE,QAAQ,CAAC,IAAI;aAC3B;SACF,EACD,MAAM,CACP,CAAC;QACF,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC/C,OAAO;YACL,OAAO,EAAE,IAAI;YACb,MAAM,EAAE,SAAS,CAAC,MAAM;YACxB,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,IAAI,EAAE,QAAQ,CAAC,IAAI;YACnB,GAAG,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACzD,gBAAgB,EAAE,KAAK;YACvB,OAAO,EACL,gHAAgH;SACnH,CAAC;IACJ,CAAC;CACF;AA3cD,4CA2cC"}
@@ -0,0 +1,97 @@
1
+ import type { SQLiteDatabase } from '../sqlite.js';
2
+ /** Host-derived authority only; sourceRefs and model input never confer access. */
3
+ export interface ProcedureAccess {
4
+ ownerScope: string;
5
+ projectId: string;
6
+ channelId?: string;
7
+ }
8
+ export interface ProcedureScope {
9
+ ownerScope: string;
10
+ projectId: string;
11
+ channelIds?: string[];
12
+ }
13
+ export interface ProcedureProjection {
14
+ path: string;
15
+ expectedFileHash: string | null;
16
+ desiredText: string;
17
+ }
18
+ export interface ProcedureSaveInput {
19
+ id: string;
20
+ expectedRevision?: number;
21
+ correctionId: string;
22
+ title: string;
23
+ description: string;
24
+ whenToUse: string;
25
+ whenNotToUse: string;
26
+ body: string;
27
+ expectedResults: string[];
28
+ scope: ProcedureScope;
29
+ sourceRefs: string[];
30
+ originalInstruction: string;
31
+ reason?: string;
32
+ supersededMemoryIds?: string[];
33
+ origin?: {
34
+ id: string;
35
+ hash: string;
36
+ };
37
+ projection?: ProcedureProjection;
38
+ /** Exact imported or replaced text, retained alongside the immutable new version. */
39
+ previousBody?: string;
40
+ /** Host retry comparison for derived document edits. */
41
+ correctionRequestHash?: string;
42
+ }
43
+ export interface ProcedureRecord extends Omit<ProcedureSaveInput, 'expectedRevision'> {
44
+ revision: number;
45
+ scopeKey: string;
46
+ status: 'active' | 'retired';
47
+ createdAt: number;
48
+ updatedAt: number;
49
+ }
50
+ export interface ProcedureOutcomeInput {
51
+ procedureId: string;
52
+ revision: number;
53
+ receiptId: string;
54
+ status: 'selected' | 'satisfied' | 'failed' | 'noop' | 'not_performed' | 'unknown';
55
+ evidenceRefs: string[];
56
+ }
57
+ export interface ProcedureOutcome extends ProcedureOutcomeInput {
58
+ observedAt: number;
59
+ }
60
+ /** Stable scope identity for durable trigger references, independent of logical procedure ID. */
61
+ export declare function procedureScopeKey(scope: Pick<ProcedureAccess, 'ownerScope' | 'projectId'>): string;
62
+ /** TG-03/TG-05/TG-06: authorized heads, immutable instructions and receipt observations. */
63
+ export declare class ProcedureStore {
64
+ private readonly db;
65
+ constructor(db: SQLiteDatabase);
66
+ /** Keep projection file publication serialized with every canonical writer. */
67
+ withWriteTransaction<T>(work: () => T): T;
68
+ private authorized;
69
+ private head;
70
+ private revision;
71
+ list(access: ProcedureAccess): ProcedureRecord[];
72
+ read(id: string, access: ProcedureAccess, revision?: number): ProcedureRecord | null;
73
+ history(id: string, access: ProcedureAccess): ProcedureRecord[];
74
+ private retry;
75
+ private append;
76
+ save(input: ProcedureSaveInput, access: ProcedureAccess): ProcedureRecord;
77
+ /** The mapping records the original queued snapshot; current head is resolved separately. */
78
+ getLegacyTriggerBinding(triggerId: string, access: ProcedureAccess): {
79
+ id: string;
80
+ revision: number;
81
+ scopeKey: string;
82
+ snapshotHash: string;
83
+ } | null;
84
+ /** TG-05: lazy legacy import never binds a global trigger to the first channel's private rule. */
85
+ importLegacyTrigger(input: ProcedureSaveInput, access: ProcedureAccess, binding: {
86
+ triggerId: string;
87
+ snapshotHash: string;
88
+ }): ProcedureRecord;
89
+ retire(id: string, expectedRevision: number, correctionId: string, reason: string, access: ProcedureAccess): ProcedureRecord;
90
+ supersededMemoryIds(access: ProcedureAccess): string[];
91
+ recordOutcome(input: ProcedureOutcomeInput, access: ProcedureAccess): ProcedureOutcome;
92
+ /** Durable intent is part of the immutable revision; publication is a separate receipt. */
93
+ pendingProjections(access: ProcedureAccess): ProcedureRecord[];
94
+ markProjected(id: string, revision: number, publishedHash: string, access: ProcedureAccess): void;
95
+ getOutcomes(id: string, access: ProcedureAccess): ProcedureOutcome[];
96
+ }
97
+ //# sourceMappingURL=procedure-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"procedure-store.d.ts","sourceRoot":"","sources":["../../src/operator/procedure-store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAGnD,mFAAmF;AACnF,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AACD,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;CACvB;AACD,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,WAAW,EAAE,MAAM,CAAC;CACrB;AACD,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,KA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