@dsh-enhanced/assistant-dreaming 0.0.0-stage → 0.1.68
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +281 -2
- package/cordis.patch.yml +3 -0
- package/lib/config.d.ts +87 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +145 -0
- package/lib/config.js.map +1 -0
- package/lib/dream-agent.d.ts +58 -0
- package/lib/dream-agent.d.ts.map +1 -0
- package/lib/dream-agent.js +188 -0
- package/lib/dream-agent.js.map +1 -0
- package/lib/index.d.ts +20 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +15 -0
- package/lib/index.js.map +1 -0
- package/lib/notify.d.ts +64 -0
- package/lib/notify.d.ts.map +1 -0
- package/lib/notify.js +52 -0
- package/lib/notify.js.map +1 -0
- package/lib/projection.d.ts +32 -0
- package/lib/projection.d.ts.map +1 -0
- package/lib/projection.js +89 -0
- package/lib/projection.js.map +1 -0
- package/lib/runtime.d.ts +43 -0
- package/lib/runtime.d.ts.map +1 -0
- package/lib/runtime.js +500 -0
- package/lib/runtime.js.map +1 -0
- package/lib/store.d.ts +113 -0
- package/lib/store.d.ts.map +1 -0
- package/lib/store.js +367 -0
- package/lib/store.js.map +1 -0
- package/lib/trigger.d.ts +134 -0
- package/lib/trigger.d.ts.map +1 -0
- package/lib/trigger.js +155 -0
- package/lib/trigger.js.map +1 -0
- package/lib/version.d.ts +2 -0
- package/lib/version.d.ts.map +1 -0
- package/lib/version.js +2 -0
- package/lib/version.js.map +1 -0
- package/package.json +95 -3
package/lib/runtime.js
ADDED
|
@@ -0,0 +1,500 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { Context, Service } from '@deepseek-ai/cordis';
|
|
3
|
+
import { acceptanceDigest } from '@dsh-enhanced/task-acceptance-contract';
|
|
4
|
+
import { Config, normalizeConfig } from './config.js';
|
|
5
|
+
import { DreamStore } from './store.js';
|
|
6
|
+
import { decideTrigger, localDayKey, assignTicket, rollLottery, matchTickets } from './trigger.js';
|
|
7
|
+
import { buildDreamMaterial } from './projection.js';
|
|
8
|
+
import { runDreamAgent } from './dream-agent.js';
|
|
9
|
+
import { enqueueDreamNotification } from './notify.js';
|
|
10
|
+
/** Bounds how many recorded ideas may hold recall tickets per wake. */
|
|
11
|
+
const DREAM_RECORDED_TICKET_LIMIT = 100;
|
|
12
|
+
const EXECUTOR = 'assistant-dreaming-v1';
|
|
13
|
+
const OWNER = 'assistant-dreaming';
|
|
14
|
+
const CATALOG = acceptanceDigest({ executor: EXECUTOR, version: 1 });
|
|
15
|
+
/**
|
|
16
|
+
* Terminal outcomes for the Automations Host-executor contract. Success may
|
|
17
|
+
* only carry the literal `none` tuple; a possible side effect must be
|
|
18
|
+
* retryability-unsafe and a pure no-op success must be retryability-safe.
|
|
19
|
+
* Budget reservation/settlement belongs to Automations, never to this
|
|
20
|
+
* executor, so no result here reports a budget settlement.
|
|
21
|
+
*/
|
|
22
|
+
const NO_EFFECT = Object.freeze({
|
|
23
|
+
outcome: 'succeeded', failureClass: 'none', failurePhase: 'none', failureCode: 'none',
|
|
24
|
+
sideEffectState: 'none', retryability: 'safe',
|
|
25
|
+
});
|
|
26
|
+
const EFFECT_OK = Object.freeze({
|
|
27
|
+
outcome: 'succeeded', failureClass: 'none', failurePhase: 'none', failureCode: 'none',
|
|
28
|
+
sideEffectState: 'possible', retryability: 'unsafe',
|
|
29
|
+
});
|
|
30
|
+
function failed(failureClass, failurePhase, failureCode, sideEffectState) {
|
|
31
|
+
const retryability = sideEffectState !== 'none' ? 'unsafe'
|
|
32
|
+
: failureClass === 'configuration' || failureClass === 'policy' || failureClass === 'budget'
|
|
33
|
+
? 'after-intervention' : 'safe';
|
|
34
|
+
return Object.freeze({
|
|
35
|
+
outcome: failureClass === 'cancelled' || failureClass === 'unknown' ? 'unknown' : 'failed',
|
|
36
|
+
failureClass, failurePhase, failureCode, sideEffectState, retryability,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The owner-enabled dreaming runtime. It registers exactly one system-owned
|
|
41
|
+
* `every` automation and, per slot, re-derives the deterministic trigger, then
|
|
42
|
+
* runs one frozen single-tool agent that may only record private ideas. It
|
|
43
|
+
* never notifies unless L1 is explicitly enabled, never adopts, promotes, or
|
|
44
|
+
* writes goals/work-items; with `enabled: false` it opens no database and
|
|
45
|
+
* registers nothing.
|
|
46
|
+
*
|
|
47
|
+
* Scheduling and per-occurrence budget reservation/settlement belong to
|
|
48
|
+
* `assistant-automations`; this executor is a pure consumer of the Host
|
|
49
|
+
* executor contract and never reserves budget itself.
|
|
50
|
+
*/
|
|
51
|
+
export class AssistantDreamingService extends Service {
|
|
52
|
+
static Config = Config;
|
|
53
|
+
static inject = ['assistantAutomations', 'assistantDelivery', 'assistantEvaluation',
|
|
54
|
+
'assistantGoals', 'assistantSkills', 'agents', 'sessions', 'tools'];
|
|
55
|
+
#config;
|
|
56
|
+
#lane;
|
|
57
|
+
#ports;
|
|
58
|
+
#store;
|
|
59
|
+
#flight;
|
|
60
|
+
#active = true;
|
|
61
|
+
#scheduler;
|
|
62
|
+
#lastRunAt = null;
|
|
63
|
+
#lastRunOutcome = null;
|
|
64
|
+
#lastSkipReason = null;
|
|
65
|
+
#unregister;
|
|
66
|
+
/**
|
|
67
|
+
* Fresh per-load reconcile nonce for the active transition. Automations
|
|
68
|
+
* caches `automation_system_reconciles` by idempotency key and replays the
|
|
69
|
+
* old receipt without touching the row, so a deterministic key would silently
|
|
70
|
+
* skip reactivation after a retire/reload. A new key per load converges to
|
|
71
|
+
* one active row (the store CAS is idempotent) and appends one audit receipt.
|
|
72
|
+
*/
|
|
73
|
+
#loadNonce = randomUUID();
|
|
74
|
+
constructor(ctx, input = {}) {
|
|
75
|
+
super(ctx, 'assistantDreaming');
|
|
76
|
+
const config = normalizeConfig(input);
|
|
77
|
+
this.#config = config;
|
|
78
|
+
this.#lane = config.scope === null ? 'inactive'
|
|
79
|
+
: acceptanceDigest({ scope: config.scope, databasePath: config.databasePath }).slice(0, 40);
|
|
80
|
+
if (!config.enabled) {
|
|
81
|
+
this.#scheduler = 'dormant';
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const ports = this.#portsFor(ctx);
|
|
85
|
+
this.#ports = ports;
|
|
86
|
+
this.#store = new DreamStore(config.databasePath, this.#lane);
|
|
87
|
+
try {
|
|
88
|
+
this.#store.interrupt();
|
|
89
|
+
this.#pruneStore(Date.now());
|
|
90
|
+
if (config.retired) {
|
|
91
|
+
// Owner pause: keep the ledger and definition, make sure the system
|
|
92
|
+
// automation is paused, and register no executor. This is the supported
|
|
93
|
+
// way to stop dreaming before disabling/uninstalling the bundle.
|
|
94
|
+
ports.automations.reconcileSystem(this.#reconcileInput('paused'));
|
|
95
|
+
this.#scheduler = 'dormant';
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
this.#unregister = ports.automations.registerHostExecutor(this.#executor(ports));
|
|
99
|
+
ports.automations.reconcileSystem(this.#reconcileInput('active'));
|
|
100
|
+
this.#scheduler = 'active';
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
// Construction must not leak a registered executor or an open ledger:
|
|
105
|
+
// the Loader keeps this process alive and a retry would otherwise fail
|
|
106
|
+
// with a duplicate executor descriptor. This also covers a failed paused
|
|
107
|
+
// reconcile while the owner is trying to retire.
|
|
108
|
+
this.#active = false;
|
|
109
|
+
this.#scheduler = 'unavailable';
|
|
110
|
+
try {
|
|
111
|
+
this.#unregister?.();
|
|
112
|
+
}
|
|
113
|
+
catch { /* best-effort unload */ }
|
|
114
|
+
this.#unregister = undefined;
|
|
115
|
+
try {
|
|
116
|
+
this.#store.interrupt();
|
|
117
|
+
}
|
|
118
|
+
catch { /* store may already be closed */ }
|
|
119
|
+
this.#store.close();
|
|
120
|
+
this.#store = undefined;
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
|
+
ctx.effect(() => () => {
|
|
124
|
+
this.#active = false;
|
|
125
|
+
this.#unregister?.();
|
|
126
|
+
try {
|
|
127
|
+
this.#store?.interrupt();
|
|
128
|
+
}
|
|
129
|
+
catch { /* store may already be closed */ }
|
|
130
|
+
const closing = this.#flight;
|
|
131
|
+
this.#store?.close();
|
|
132
|
+
return closing;
|
|
133
|
+
}, 'assistant-dreaming.runtime');
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Enforce the owner retention policy over the private idea ledger. Runs on
|
|
137
|
+
* plugin load and after every completed dream so a long-lived Host cannot
|
|
138
|
+
* keep expired ideas forever. Failure is observable but never fails a wake.
|
|
139
|
+
*/
|
|
140
|
+
#pruneStore(now) {
|
|
141
|
+
try {
|
|
142
|
+
this.#store?.prune(now, this.#config.retentionDays);
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
this.ctx.logger.warn(`assistant-dreaming: idea retention prune failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Register a stable ticket for every recallable subject derived from the
|
|
150
|
+
* current projected material and for this lane's unresolved recorded ideas.
|
|
151
|
+
* Pure registration: no randomness here, the ticket value comes from the
|
|
152
|
+
* HMAC seed in assignTicket.
|
|
153
|
+
*/
|
|
154
|
+
#registerTickets(store, material, now, seedDigest) {
|
|
155
|
+
for (const item of material.items) {
|
|
156
|
+
const subject = { kind: item.kind, key: item.evidenceRef };
|
|
157
|
+
const ticket = assignTicket({ seedDigest, lane: this.#lane, subject });
|
|
158
|
+
store.upsertTicket({ subjectKind: subject.kind, subjectKey: subject.key,
|
|
159
|
+
value: ticket.value, digest: ticket.digest, now });
|
|
160
|
+
}
|
|
161
|
+
// Recorded-but-unresolved ideas are recall subjects too, so a past dream
|
|
162
|
+
// can be revisited; resolved ones (validated/rejected/withdrawn) stop
|
|
163
|
+
// holding a ticket by never being re-registered.
|
|
164
|
+
store.pruneResolvedIdeaTickets();
|
|
165
|
+
for (const idea of store.listIdeas(DREAM_RECORDED_TICKET_LIMIT)) {
|
|
166
|
+
if (idea.state !== 'recorded')
|
|
167
|
+
continue;
|
|
168
|
+
const subject = { kind: 'recorded-idea', key: idea.id };
|
|
169
|
+
const ticket = assignTicket({ seedDigest, lane: this.#lane, subject });
|
|
170
|
+
store.upsertTicket({ subjectKind: subject.kind, subjectKey: subject.key,
|
|
171
|
+
value: ticket.value, digest: ticket.digest, now });
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* The "无事找事" lottery: roll one code-generated number and return the
|
|
176
|
+
* tickets within the circular window. Runs without a model call; an empty
|
|
177
|
+
* result means no subject is recalled this slot.
|
|
178
|
+
*/
|
|
179
|
+
#drawRecallHits(store, occurrence, seedDigest) {
|
|
180
|
+
const draw = rollLottery({ seedDigest, lane: this.#lane, occurrence });
|
|
181
|
+
const tickets = store.listTickets().map(row => ({
|
|
182
|
+
subject: { kind: row.subjectKind, key: row.subjectKey },
|
|
183
|
+
value: row.value, digest: row.digest,
|
|
184
|
+
}));
|
|
185
|
+
const hits = matchTickets({ draw, tickets, window: this.#config.lotteryWindow });
|
|
186
|
+
return { draw, hits };
|
|
187
|
+
}
|
|
188
|
+
#portsFor(ctx) {
|
|
189
|
+
const automations = ctx.get('assistantAutomations');
|
|
190
|
+
const delivery = ctx.get('assistantDelivery');
|
|
191
|
+
const evaluation = ctx.get('assistantEvaluation');
|
|
192
|
+
const goals = ctx.get('assistantGoals');
|
|
193
|
+
const skills = ctx.get('assistantSkills');
|
|
194
|
+
if (!automations || !delivery || !evaluation || !goals || !skills
|
|
195
|
+
|| !ctx.get('agents') || !ctx.get('sessions') || !ctx.get('tools')) {
|
|
196
|
+
throw new Error('assistant-dreaming: enabled dreaming requires automations, delivery, evaluation, goals, skills, agents, sessions and tools');
|
|
197
|
+
}
|
|
198
|
+
return { automations, delivery, evaluation, goals, skills };
|
|
199
|
+
}
|
|
200
|
+
#automationId() {
|
|
201
|
+
return `dsh-enhanced-assistant-dreaming:${this.#lane}`;
|
|
202
|
+
}
|
|
203
|
+
#configDigest() {
|
|
204
|
+
return acceptanceDigest({ lane: this.#lane, config: this.#config }).slice(0, 40);
|
|
205
|
+
}
|
|
206
|
+
#reconcileInput(desiredStatus) {
|
|
207
|
+
// Both transitions are load-scoped. Automations replays a cached
|
|
208
|
+
// `automation_system_reconciles` receipt for a repeated idempotency key
|
|
209
|
+
// without touching the row, so a deterministic paused key would make a
|
|
210
|
+
// second retire (or retire after resume) silently leave the row active
|
|
211
|
+
// while this plugin is already dormant. Reconcile is a local CAS converge
|
|
212
|
+
// operation: a fresh key per load is safe, and a repeated retire() in the
|
|
213
|
+
// same load still just replays the same paused receipt.
|
|
214
|
+
const key = `${this.#automationId()}:${this.#configDigest()}:${desiredStatus}:${this.#loadNonce}`;
|
|
215
|
+
return {
|
|
216
|
+
owner: OWNER,
|
|
217
|
+
automationId: this.#automationId(),
|
|
218
|
+
idempotencyKey: key,
|
|
219
|
+
desiredStatus,
|
|
220
|
+
definition: this.#definition(),
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
#definition() {
|
|
224
|
+
const scope = this.#config.scope;
|
|
225
|
+
return {
|
|
226
|
+
name: 'Bounded dreaming review',
|
|
227
|
+
schedule: { kind: 'every', anchorAt: new Date(0).toISOString(), intervalMs: this.#config.baseIntervalMs },
|
|
228
|
+
workspace: scope.workspace,
|
|
229
|
+
agentPreset: scope.preset,
|
|
230
|
+
timeoutMs: this.#config.maxDurationMs,
|
|
231
|
+
// A missed slot is skipped, never replayed: dreaming must not catch up
|
|
232
|
+
// with a burst of paid model calls after downtime.
|
|
233
|
+
misfire: { kind: 'skip' },
|
|
234
|
+
overlap: 'skip',
|
|
235
|
+
retrySafety: 'never',
|
|
236
|
+
maxRetries: 0,
|
|
237
|
+
principal: scope.principalId,
|
|
238
|
+
budgetId: this.#config.budgetId,
|
|
239
|
+
budgetAmount: this.#config.budgetAmount,
|
|
240
|
+
execution: {
|
|
241
|
+
kind: 'host', executorId: EXECUTOR, executorContractVersion: 1, runbookId: 'dream', runbookVersion: 1,
|
|
242
|
+
catalogDigest: CATALOG,
|
|
243
|
+
targetScope: { workspace: scope.workspace, preset: scope.preset },
|
|
244
|
+
scopeDigest: acceptanceDigest([scope.workspace, scope.preset]),
|
|
245
|
+
ownerRouteId: scope.ownerRouteId,
|
|
246
|
+
activationNonce: this.#configDigest(),
|
|
247
|
+
},
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
#executor(ports) {
|
|
251
|
+
return {
|
|
252
|
+
descriptor: { executorId: EXECUTOR, contractVersion: 1, catalogDigest: CATALOG },
|
|
253
|
+
accepts: (spec) => spec.executorId === EXECUTOR && spec.executorContractVersion === 1 && spec.catalogDigest === CATALOG
|
|
254
|
+
&& spec.runbookId === 'dream' && spec.runbookVersion === 1,
|
|
255
|
+
execute: (input) => {
|
|
256
|
+
const flight = this.#runSlot(ports, input);
|
|
257
|
+
this.#flight = flight;
|
|
258
|
+
void flight.finally(() => { if (this.#flight === flight)
|
|
259
|
+
this.#flight = undefined; }).catch(() => { });
|
|
260
|
+
return flight;
|
|
261
|
+
},
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
/** Latest trusted activity timestamp from Evaluation projections, or null. */
|
|
265
|
+
#latestActivity(ports, scope) {
|
|
266
|
+
const page = ports.evaluation.listTrustedTaskLearningProjections({ scope, limit: 1 });
|
|
267
|
+
const item = page.items[0];
|
|
268
|
+
const at = item?.receipt.objective?.occurredAt;
|
|
269
|
+
return typeof at === 'number' && Number.isFinite(at) ? at : null;
|
|
270
|
+
}
|
|
271
|
+
async #runSlot(ports, input) {
|
|
272
|
+
if (!this.#active || this.#store === undefined) {
|
|
273
|
+
return failed('cancelled', 'preflight', 'disposed', 'none');
|
|
274
|
+
}
|
|
275
|
+
const store = this.#store;
|
|
276
|
+
const config = this.#config;
|
|
277
|
+
const scopeConfig = config.scope;
|
|
278
|
+
if (input.executionMode !== 'production') {
|
|
279
|
+
// A dry-run/preview occurrence must never spend money or write ideas.
|
|
280
|
+
this.#lastSkipReason = 'preview';
|
|
281
|
+
return NO_EFFECT;
|
|
282
|
+
}
|
|
283
|
+
if (input.targetScope?.workspace !== scopeConfig.workspace
|
|
284
|
+
|| input.targetScope?.preset !== scopeConfig.preset
|
|
285
|
+
|| input.principal !== scopeConfig.principalId
|
|
286
|
+
|| input.ownerRouteId !== scopeConfig.ownerRouteId) {
|
|
287
|
+
this.#lastRunOutcome = 'failed';
|
|
288
|
+
return failed('configuration', 'preflight', 'dream-scope-mismatch', 'none');
|
|
289
|
+
}
|
|
290
|
+
const now = Date.now();
|
|
291
|
+
const timezone = config.activeHours?.timezone ?? 'UTC';
|
|
292
|
+
const dayKey = localDayKey(now, timezone);
|
|
293
|
+
let latestActivityAt = null;
|
|
294
|
+
try {
|
|
295
|
+
latestActivityAt = this.#latestActivity(ports, ports.evaluation.canonicalHostScope({
|
|
296
|
+
workspace: scopeConfig.workspace, preset: scopeConfig.preset
|
|
297
|
+
}));
|
|
298
|
+
}
|
|
299
|
+
catch {
|
|
300
|
+
latestActivityAt = null;
|
|
301
|
+
}
|
|
302
|
+
const occurrence = Number.parseInt(createHash('sha256')
|
|
303
|
+
.update(`${input.definitionHash}\0${input.occurrenceId}`).digest('hex').slice(0, 12), 16);
|
|
304
|
+
const seedDigest = config.seedDigest ?? createHash('sha256').update(`assistant-dreaming\0${this.#lane}`).digest('hex');
|
|
305
|
+
const decision = decideTrigger({
|
|
306
|
+
now,
|
|
307
|
+
occurrence,
|
|
308
|
+
lane: this.#lane,
|
|
309
|
+
seedDigest,
|
|
310
|
+
probabilityPpm: config.runProbabilityPpm,
|
|
311
|
+
activeHours: config.activeHours,
|
|
312
|
+
latestActivityAt,
|
|
313
|
+
idleMinMs: config.idleMinMs,
|
|
314
|
+
dreamsToday: store.countDreams(dayKey),
|
|
315
|
+
maxDreamsPerDay: config.maxDreamsPerDay,
|
|
316
|
+
});
|
|
317
|
+
if (!decision.fire) {
|
|
318
|
+
this.#lastSkipReason = decision.reason;
|
|
319
|
+
return NO_EFFECT;
|
|
320
|
+
}
|
|
321
|
+
// Per-subject lottery ("无事找事"): build material and tickets, then roll
|
|
322
|
+
// one code-generated number. A miss is a normal no-thought slot and skips
|
|
323
|
+
// the model entirely; a hit focuses the wake on the recalled subject.
|
|
324
|
+
let seedMaterial;
|
|
325
|
+
try {
|
|
326
|
+
seedMaterial = buildDreamMaterial({
|
|
327
|
+
evaluation: ports.evaluation, delivery: ports.delivery, goals: ports.goals, skills: ports.skills,
|
|
328
|
+
scope: scopeConfig, maxInputBytes: config.maxInputBytes,
|
|
329
|
+
});
|
|
330
|
+
this.#registerTickets(store, seedMaterial, now, seedDigest);
|
|
331
|
+
}
|
|
332
|
+
catch (error) {
|
|
333
|
+
// A revoked/missing owner route or projection failure is an owner
|
|
334
|
+
// configuration problem, not a dreamed result: fail closed with no
|
|
335
|
+
// model spend and no ledger write.
|
|
336
|
+
this.#lastRunOutcome = 'failed';
|
|
337
|
+
this.ctx.logger.warn(`assistant-dreaming: material unavailable: ${error instanceof Error ? error.message : String(error)}`);
|
|
338
|
+
return failed('configuration', 'preflight', 'dream-material-unavailable', 'none');
|
|
339
|
+
}
|
|
340
|
+
const { draw, hits } = this.#drawRecallHits(store, occurrence, seedDigest);
|
|
341
|
+
if (hits.length === 0) {
|
|
342
|
+
this.#lastSkipReason = 'lottery-no-hit';
|
|
343
|
+
return NO_EFFECT;
|
|
344
|
+
}
|
|
345
|
+
for (const hit of hits) {
|
|
346
|
+
store.recordRecall({ occurrence, drawDigest: draw.drawDigest, drawValue: draw.value,
|
|
347
|
+
subjectKind: hit.subject.kind, subjectKey: hit.subject.key, ticketValue: hit.ticketValue,
|
|
348
|
+
distance: hit.distance, at: now });
|
|
349
|
+
}
|
|
350
|
+
this.#lastSkipReason = null;
|
|
351
|
+
const runId = `dream-${input.occurrenceId}`;
|
|
352
|
+
let submitted = false;
|
|
353
|
+
try {
|
|
354
|
+
const model = this.#resolveModel();
|
|
355
|
+
store.beginDream(runId, occurrence, decision.dayKey, now, decision.drawDigest);
|
|
356
|
+
submitted = true;
|
|
357
|
+
this.#lastRunAt = now;
|
|
358
|
+
const result = await runDreamAgent({
|
|
359
|
+
ctx: this.ctx,
|
|
360
|
+
wakeId: input.occurrenceId,
|
|
361
|
+
config,
|
|
362
|
+
model,
|
|
363
|
+
scope: scopeConfig,
|
|
364
|
+
material: seedMaterial,
|
|
365
|
+
recallHits: hits.map(hit => {
|
|
366
|
+
const focus = { kind: hit.subject.kind, key: hit.subject.key,
|
|
367
|
+
ticketValue: hit.ticketValue, distance: hit.distance };
|
|
368
|
+
// Recorded ideas live outside the projection material; carry their
|
|
369
|
+
// own summary so the recalled subject is not just an opaque id.
|
|
370
|
+
if (hit.subject.kind === 'recorded-idea') {
|
|
371
|
+
const idea = store.idea(hit.subject.key);
|
|
372
|
+
if (idea !== undefined)
|
|
373
|
+
return { ...focus, summary: idea.summary };
|
|
374
|
+
}
|
|
375
|
+
return focus;
|
|
376
|
+
}),
|
|
377
|
+
deadlineAt: Math.min(now + config.maxDurationMs, Date.now() + config.maxDurationMs),
|
|
378
|
+
signal: input.signal,
|
|
379
|
+
onSubmit: ideas => {
|
|
380
|
+
let recorded = 0;
|
|
381
|
+
for (const idea of ideas) {
|
|
382
|
+
store.recordIdea({
|
|
383
|
+
id: createHash('sha256').update(`${runId}\0${recorded}\0${idea.summary}`).digest('hex').slice(0, 32),
|
|
384
|
+
runId, createdAt: Date.now(), dayKey: decision.dayKey,
|
|
385
|
+
summary: idea.summary, detail: idea.detail, evidenceRefs: idea.evidenceRefs,
|
|
386
|
+
});
|
|
387
|
+
recorded += 1;
|
|
388
|
+
}
|
|
389
|
+
return recorded;
|
|
390
|
+
},
|
|
391
|
+
});
|
|
392
|
+
this.#lastRunOutcome = result.outcome;
|
|
393
|
+
if (result.outcome === 'succeeded') {
|
|
394
|
+
store.completeDream(runId, Date.now(), result.ideaCount);
|
|
395
|
+
this.#pruneStore(Date.now());
|
|
396
|
+
this.#notifyOwner(store, runId, decision.dayKey, result.ideaCount, now);
|
|
397
|
+
return EFFECT_OK;
|
|
398
|
+
}
|
|
399
|
+
store.markInterrupted(runId, Date.now());
|
|
400
|
+
return result.outcome === 'cancelled'
|
|
401
|
+
? failed('cancelled', 'host-execution', 'dream-agent-cancelled', 'possible')
|
|
402
|
+
: failed('execution', 'host-execution', 'dream-agent-failed', 'possible');
|
|
403
|
+
}
|
|
404
|
+
catch (error) {
|
|
405
|
+
if (this.#store !== undefined) {
|
|
406
|
+
try {
|
|
407
|
+
store.markInterrupted(runId, Date.now());
|
|
408
|
+
}
|
|
409
|
+
catch { /* closed */ }
|
|
410
|
+
}
|
|
411
|
+
this.#lastRunOutcome = 'failed';
|
|
412
|
+
this.ctx.logger.warn(`assistant-dreaming: dream wake failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
413
|
+
return submitted
|
|
414
|
+
? failed('execution', 'host-execution', 'dream-execution-failed', 'possible')
|
|
415
|
+
: failed('configuration', 'preflight', 'dream-preflight-failed', 'none');
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
#resolveModel() {
|
|
419
|
+
const config = this.#config;
|
|
420
|
+
return { provider: config.provider, model: config.model,
|
|
421
|
+
...(config.reasoningEffort === null ? {} : { reasoningEffort: config.reasoningEffort }) };
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* L1 owner summary notification. Fails closed at every gate: the
|
|
425
|
+
* notification flag, daily count and minimum interval must all allow it,
|
|
426
|
+
* and the live route is re-validated by the enqueue helper. A failed
|
|
427
|
+
* notification never changes the dream outcome.
|
|
428
|
+
*/
|
|
429
|
+
#notifyOwner(store, runId, dayKey, ideaCount, now) {
|
|
430
|
+
const config = this.#config;
|
|
431
|
+
if (!config.notifyOwner || config.maxNotificationsPerDay === 0 || ideaCount === 0)
|
|
432
|
+
return;
|
|
433
|
+
if (store.countNotifications(dayKey) >= config.maxNotificationsPerDay)
|
|
434
|
+
return;
|
|
435
|
+
const lastAt = store.lastNotificationAt();
|
|
436
|
+
if (lastAt !== null && now - lastAt < config.notifyMinIntervalMs)
|
|
437
|
+
return;
|
|
438
|
+
const scope = config.scope;
|
|
439
|
+
const delivery = this.ctx.get('assistantDelivery', false);
|
|
440
|
+
if (delivery === undefined)
|
|
441
|
+
return;
|
|
442
|
+
const sent = enqueueDreamNotification({
|
|
443
|
+
validateOwnerRoute: input => delivery.validateOwnerRoute({ authorityId: scope.ownerRouteId, principalId: input.principalId,
|
|
444
|
+
workspace: input.workspace, agentPreset: input.preset }),
|
|
445
|
+
resolveOwnerRoute: ownerRouteId => delivery.resolveOwnerRoute(ownerRouteId),
|
|
446
|
+
enqueueOwnerNotification: input => delivery.enqueueOwnerNotification(input),
|
|
447
|
+
}, {
|
|
448
|
+
owner: { ownerRouteId: scope.ownerRouteId, principalId: scope.principalId, workspace: scope.workspace, preset: scope.preset },
|
|
449
|
+
runId,
|
|
450
|
+
summaries: store.listIdeas(ideaCount).map(idea => ({ summary: idea.summary, detail: idea.detail })),
|
|
451
|
+
dayKey, now, expiresAt: now + config.maxDurationMs,
|
|
452
|
+
});
|
|
453
|
+
if (sent)
|
|
454
|
+
store.incrementNotifications(dayKey, now);
|
|
455
|
+
}
|
|
456
|
+
// Public surfaces are bound arrow properties: Cordis serves services through
|
|
457
|
+
// a traceable proxy whose method calls would otherwise lose the private-field
|
|
458
|
+
// receiver (the Loader and owner surfaces always read through that proxy).
|
|
459
|
+
health = () => {
|
|
460
|
+
let counts = { runs: 0, ideas: 0, recorded: 0 };
|
|
461
|
+
if (this.#store !== undefined) {
|
|
462
|
+
try {
|
|
463
|
+
counts = this.#store.counts();
|
|
464
|
+
}
|
|
465
|
+
catch { /* read failure keeps zeros */ }
|
|
466
|
+
}
|
|
467
|
+
return Object.freeze({
|
|
468
|
+
enabled: this.#config.enabled,
|
|
469
|
+
scheduler: this.#scheduler,
|
|
470
|
+
lastRunAt: this.#lastRunAt,
|
|
471
|
+
lastRunOutcome: this.#lastRunOutcome,
|
|
472
|
+
lastSkipReason: this.#lastSkipReason,
|
|
473
|
+
counts,
|
|
474
|
+
});
|
|
475
|
+
};
|
|
476
|
+
/** Read-only access to recorded ideas for the owner-facing surfaces. */
|
|
477
|
+
inspectIdeas = (limit = 50) => {
|
|
478
|
+
if (this.#store === undefined)
|
|
479
|
+
return Object.freeze([]);
|
|
480
|
+
return Object.freeze([...this.#store.listIdeas(Math.min(Math.max(1, limit), 200))]);
|
|
481
|
+
};
|
|
482
|
+
/**
|
|
483
|
+
* Owner-visible retirement: pause the system automation and unregister the
|
|
484
|
+
* executor, keeping the private ledger (ideas are never deleted here).
|
|
485
|
+
*/
|
|
486
|
+
retire = () => {
|
|
487
|
+
if (!this.#config.enabled || this.#store === undefined)
|
|
488
|
+
return;
|
|
489
|
+
this.#active = false;
|
|
490
|
+
this.#unregister?.();
|
|
491
|
+
this.#unregister = undefined;
|
|
492
|
+
try {
|
|
493
|
+
this.#ports?.automations.reconcileSystem(this.#reconcileInput('paused'));
|
|
494
|
+
}
|
|
495
|
+
catch { /* ledger stays readable */ }
|
|
496
|
+
this.#scheduler = 'dormant';
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
export { Config };
|
|
500
|
+
//# sourceMappingURL=runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACpD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAOtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAA;AACzE,OAAO,EAAE,MAAM,EAAE,eAAe,EAAsD,MAAM,aAAa,CAAA;AACzG,OAAO,EAAE,UAAU,EAAkB,MAAM,YAAY,CAAA;AACvD,OAAO,EAAE,aAAa,E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F,CAAC,CAAA;IAED;;;OAGG;IACH,MAAM,GAAG,GAAS,EAAE;QAClB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS;YAAE,OAAM;QAC9D,IAAI,CAAC,OAAO,GAAG,KAAK,CAAA;QACpB,IAAI,CAAC,WAAW,EAAE,EAAE,CAAA;QACpB,IAAI,CAAC,WAAW,GAAG,SAAS,CAAA;QAC5B,IAAI,CAAC;YAAC,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC,eAAe,CAAC,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC,CAAA;QAAC,CAAC;QAAC,MAAM,CAAC,CAAC,2BAA2B,CAAC,CAAC;QACtH,IAAI,CAAC,UAAU,GAAG,SAAS,CAAA;IAC7B,CAAC,CAAA;;AAGH,OAAO,EAAE,MAAM,EAAE,CAAA"}
|
package/lib/store.d.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
export type IdeaState = 'recorded' | 'withdrawn' | 'owner-acknowledged' | 'validated' | 'rejected';
|
|
2
|
+
export interface DreamIdea {
|
|
3
|
+
id: string;
|
|
4
|
+
lane: string;
|
|
5
|
+
runId: string;
|
|
6
|
+
createdAt: number;
|
|
7
|
+
dayKey: string;
|
|
8
|
+
state: IdeaState;
|
|
9
|
+
summary: string;
|
|
10
|
+
detail: string;
|
|
11
|
+
/** Digests of the Host projections this idea cites; never raw content. */
|
|
12
|
+
evidenceRefs: readonly string[];
|
|
13
|
+
}
|
|
14
|
+
export interface DreamRunRecord {
|
|
15
|
+
id: string;
|
|
16
|
+
lane: string;
|
|
17
|
+
occurrence: number;
|
|
18
|
+
dayKey: string;
|
|
19
|
+
startedAt: number;
|
|
20
|
+
endedAt: number | null;
|
|
21
|
+
outcome: 'running' | 'completed' | 'interrupted';
|
|
22
|
+
drawDigest: string;
|
|
23
|
+
ideaCount: number;
|
|
24
|
+
}
|
|
25
|
+
export interface IdeaEvent {
|
|
26
|
+
ideaId: string;
|
|
27
|
+
state: IdeaState;
|
|
28
|
+
actor: 'owner' | 'host';
|
|
29
|
+
at: number;
|
|
30
|
+
note?: string;
|
|
31
|
+
}
|
|
32
|
+
export declare function assertLedgerPath(path: string): void;
|
|
33
|
+
/** New idea data must be exact own data: no accessors, proxies or cycles. */
|
|
34
|
+
export declare function ownData<T>(input: T): T;
|
|
35
|
+
export declare class DreamStore {
|
|
36
|
+
private readonly db;
|
|
37
|
+
private readonly lane;
|
|
38
|
+
private closed;
|
|
39
|
+
constructor(databasePath: string, lane: string);
|
|
40
|
+
private migrate;
|
|
41
|
+
get isClosed(): boolean;
|
|
42
|
+
close(): void;
|
|
43
|
+
beginDream(id: string, occurrence: number, dayKey: string, startedAt: number, drawDigest: string): DreamRunRecord;
|
|
44
|
+
completeDream(id: string, endedAt: number, ideaCount: number): void;
|
|
45
|
+
markInterrupted(id: string, endedAt: number): void;
|
|
46
|
+
run(id: string): DreamRunRecord | undefined;
|
|
47
|
+
countDreams(dayKey: string): number;
|
|
48
|
+
/** L1 notification accounting over the existing per-day counters row. */
|
|
49
|
+
countNotifications(dayKey: string): number;
|
|
50
|
+
incrementNotifications(dayKey: string, at: number): number;
|
|
51
|
+
/** Timestamp of the most recent notification, or null when none was sent. */
|
|
52
|
+
lastNotificationAt(): number | null;
|
|
53
|
+
/**
|
|
54
|
+
* Register one subject's lottery ticket. The value is derived by the caller
|
|
55
|
+
* from the plugin seed, so the store never invents randomness; re-registering
|
|
56
|
+
* the same subject keeps its original ticket.
|
|
57
|
+
*/
|
|
58
|
+
upsertTicket(ticket: {
|
|
59
|
+
subjectKind: string;
|
|
60
|
+
subjectKey: string;
|
|
61
|
+
value: number;
|
|
62
|
+
digest: string;
|
|
63
|
+
now: number;
|
|
64
|
+
}): void;
|
|
65
|
+
/** All unsolved lottery tickets for this lane, oldest first. */
|
|
66
|
+
listTickets(): readonly {
|
|
67
|
+
subjectKind: string;
|
|
68
|
+
subjectKey: string;
|
|
69
|
+
value: number;
|
|
70
|
+
digest: string;
|
|
71
|
+
}[];
|
|
72
|
+
/** Record one recall hit; the unique key makes a replayed slot a no-op. */
|
|
73
|
+
recordRecall(input: {
|
|
74
|
+
occurrence: number;
|
|
75
|
+
drawDigest: string;
|
|
76
|
+
drawValue: number;
|
|
77
|
+
subjectKind: string;
|
|
78
|
+
subjectKey: string;
|
|
79
|
+
ticketValue: number;
|
|
80
|
+
distance: number;
|
|
81
|
+
at: number;
|
|
82
|
+
}): boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Drop tickets held by recorded ideas that left the `recorded` state
|
|
85
|
+
* (validated/rejected/withdrawn): a resolved idea must stop being recalled.
|
|
86
|
+
*/
|
|
87
|
+
pruneResolvedIdeaTickets(): number;
|
|
88
|
+
lastRecall(): {
|
|
89
|
+
occurrence: number;
|
|
90
|
+
subjectKind: string;
|
|
91
|
+
subjectKey: string;
|
|
92
|
+
at: number;
|
|
93
|
+
} | undefined;
|
|
94
|
+
recordIdea(idea: Omit<DreamIdea, 'lane' | 'state'>): DreamIdea;
|
|
95
|
+
idea(id: string): DreamIdea | undefined;
|
|
96
|
+
transitionIdea(id: string, state: Exclude<IdeaState, 'recorded'>, actor: 'owner' | 'host', at: number, note?: string): void;
|
|
97
|
+
listIdeas(limit?: number): readonly DreamIdea[];
|
|
98
|
+
counts(): {
|
|
99
|
+
runs: number;
|
|
100
|
+
ideas: number;
|
|
101
|
+
recorded: number;
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Hard-delete expired ideas per retention policy; runs keep audit digests
|
|
105
|
+
* only. Events are removed first in the same transaction because
|
|
106
|
+
* `dream_idea_events.idea_id` is a foreign key without ON DELETE CASCADE:
|
|
107
|
+
* a single event row would otherwise abort the whole prune with
|
|
108
|
+
* FOREIGN KEY constraint failed and silently disable retention.
|
|
109
|
+
*/
|
|
110
|
+
prune(now: number, retentionDays: number): number;
|
|
111
|
+
interrupt(): void;
|
|
112
|
+
}
|
|
113
|
+
//# sour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