@comput/pi-intercom 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -23
- package/dist/core-monitor.js +7 -8
- package/dist/core-monitor.js.map +1 -1
- package/dist/core-pane-close.d.ts +2 -2
- package/dist/core-pane-close.js +5 -5
- package/dist/core-pane-close.js.map +1 -1
- package/dist/herdr-core.d.ts +3 -1
- package/dist/herdr-core.js +27 -13
- package/dist/herdr-core.js.map +1 -1
- package/dist/index.js +4 -5
- package/dist/index.js.map +1 -1
- package/dist/launcher.js +2 -2
- package/dist/launcher.js.map +1 -1
- package/dist/observability.d.ts +1 -1
- package/dist/observability.js +1 -1
- package/dist/observability.js.map +1 -1
- package/dist/runtime.d.ts +6 -7
- package/dist/runtime.js +38 -42
- package/dist/runtime.js.map +1 -1
- package/dist/transport.d.ts +1 -1
- package/dist/transport.js +1 -1
- package/dist/transport.js.map +1 -1
- package/package.json +2 -2
- package/references/herdr-core.md +2 -2
- package/src/core-monitor.ts +5 -6
- package/src/core-pane-close.ts +5 -5
- package/src/herdr-core.ts +29 -13
- package/src/index.ts +4 -5
- package/src/launcher.ts +2 -2
- package/src/observability.ts +1 -1
- package/src/runtime.ts +35 -42
- package/src/transport.ts +2 -2
- package/dist/reminders.d.ts +0 -28
- package/dist/reminders.js +0 -81
- package/dist/reminders.js.map +0 -1
- package/src/reminders.ts +0 -69
package/src/runtime.ts
CHANGED
|
@@ -9,7 +9,6 @@ import { readObservationSnapshot } from './snapshot.js';
|
|
|
9
9
|
import { workerStatusPage } from './worker-status.js';
|
|
10
10
|
import { probeWorker, probeWorkers } from './connections.js';
|
|
11
11
|
import { HandoffWorkflow, HANDOFF_KINDS, fencedClose, type CloseProvider, type HandoffKind } from './handoff.js';
|
|
12
|
-
import { CoordinatorReminders, type ReminderClock } from './reminders.js';
|
|
13
12
|
|
|
14
13
|
export const UNSUPPORTED_CANCELLATION = 'Unsupported Pi host: stop_worker and legacy graceful-close control are disabled. Pi 0.84.4 extension abort does not cancel retry backoff/continuations; graceful shutdown cannot guarantee no queued work restarts. No cancellation or shutdown was performed. close_worker uses a separate supported-provider owned-pane closure contract, not graceful cancellation. See references/implementation-blocker.md. A verified supported host API is required for graceful cancellation (no version-only override).';
|
|
15
14
|
export interface Host {
|
|
@@ -37,7 +36,6 @@ export interface RuntimeOptions {
|
|
|
37
36
|
closeProvider?: CloseProvider;
|
|
38
37
|
/** Test seam; production defaults to 120 seconds, values above that are capped. */
|
|
39
38
|
closeTimeoutMs?: number;
|
|
40
|
-
reminderClock?: ReminderClock;
|
|
41
39
|
monitor?: MonitorOperations;
|
|
42
40
|
/** Explicit launcher-provided root must equal canonical cwd; no parent-root exception. */
|
|
43
41
|
workspaceRoot?: string;
|
|
@@ -60,11 +58,24 @@ export class Intercom {
|
|
|
60
58
|
private probeController = new AbortController();
|
|
61
59
|
private resumeFences = new Map<string, { inFlight: boolean; submitted: boolean; announced: boolean }>();
|
|
62
60
|
private handoff?: HandoffWorkflow;
|
|
63
|
-
|
|
64
|
-
private
|
|
65
|
-
private reminderInvocation = 0;
|
|
61
|
+
/** Worker only: the coordinator sent work and has heard nothing back since. */
|
|
62
|
+
private owesCoordinator = false;
|
|
66
63
|
workerStarted(): void { this.handoff?.workerStarted(); }
|
|
67
|
-
|
|
64
|
+
/** Resolves once any idle notice has been attempted; callers need not await it. */
|
|
65
|
+
workerSettled(successfulToolCallIds: ReadonlySet<string>): Promise<void> {
|
|
66
|
+
this.handoff?.workerSettled(successfulToolCallIds);
|
|
67
|
+
if (!this.owesCoordinator || this.handoff?.workerClosing) return Promise.resolve();
|
|
68
|
+
// One event-driven notice, sent in code: no timer, no model turn here.
|
|
69
|
+
this.owesCoordinator = false;
|
|
70
|
+
return this.notifyIdle().catch(() => { /* Best effort; never retried. */ });
|
|
71
|
+
}
|
|
72
|
+
private async notifyIdle(): Promise<void> {
|
|
73
|
+
const assertValid = this.validity();
|
|
74
|
+
const { config, me } = await this.state();
|
|
75
|
+
assertValid();
|
|
76
|
+
if (!me || me.coordinator || !this.responsibility) return;
|
|
77
|
+
await this.transmit(coordinator(config).name, 'idle');
|
|
78
|
+
}
|
|
68
79
|
private captureObserver(): (event: EventType, metadata?: EventMetadata) => void {
|
|
69
80
|
const observer = this.observer;
|
|
70
81
|
return (event, metadata = {}) => {
|
|
@@ -127,11 +138,6 @@ export class Intercom {
|
|
|
127
138
|
const config = await this.store.read();
|
|
128
139
|
assertValid();
|
|
129
140
|
const me = config.agents.find(a => a.sessionId === this.id());
|
|
130
|
-
this.reminders = new CoordinatorReminders({
|
|
131
|
-
isCoordinator: async () => { const fresh = await this.state(); assertValid(); return fresh.me?.coordinator === true; },
|
|
132
|
-
busy: () => this.host.busy(),
|
|
133
|
-
deliver: message => { assertValid(); this.host.deliver(message, false); },
|
|
134
|
-
}, this.options.reminderClock);
|
|
135
141
|
this.handoff = new HandoffWorkflow({
|
|
136
142
|
state: () => this.state(), assertCurrent: assertValid,
|
|
137
143
|
update: async (mutate, guard) => {
|
|
@@ -189,8 +195,7 @@ export class Intercom {
|
|
|
189
195
|
this.active = false; this.generation++;
|
|
190
196
|
this.probeController.abort();
|
|
191
197
|
this.handoff?.dispose(); this.handoff = undefined;
|
|
192
|
-
this.
|
|
193
|
-
this.reminders?.dispose(); this.reminders = undefined;
|
|
198
|
+
this.owesCoordinator = false;
|
|
194
199
|
const endpoint = this.endpoint; this.endpoint = undefined;
|
|
195
200
|
this.responsibility = undefined;
|
|
196
201
|
const closing = (async () => {
|
|
@@ -374,19 +379,27 @@ export class Intercom {
|
|
|
374
379
|
if (!fresh.config.agents.some(agent => agent.sessionId === message.from && !agent.coordinator)) fail('reporting worker is no longer configured');
|
|
375
380
|
await saveWorkerReport(this.store.root, { version: 1, sessionId: message.from, ...payload, updatedAt: new Date().toISOString() }, assertValid);
|
|
376
381
|
assertValid();
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
382
|
+
// Retiring a report needs no decision: store it without waking the coordinator.
|
|
383
|
+
if (payload.status === 'clear') return;
|
|
384
|
+
try { notify('worker report', `${payload.status}: ${payload.summary}`); }
|
|
385
|
+
catch { fail('Report stored, but coordinator notification failed or became uncertain; do not blindly resend'); }
|
|
380
386
|
});
|
|
381
387
|
this.reportWrites = pending.catch(() => {}).finally(() => { this.pendingReports--; });
|
|
382
388
|
await pending;
|
|
383
389
|
return;
|
|
384
390
|
}
|
|
391
|
+
if (message.kind === 'idle') {
|
|
392
|
+
requireCoordinator(config, id);
|
|
393
|
+
if (!sender || sender.coordinator) fail('idle notices require a configured worker sender');
|
|
394
|
+
notify('worker idle', 'Turn ended without a report or message to you.'); return;
|
|
395
|
+
}
|
|
385
396
|
if (message.kind === 'message') {
|
|
386
397
|
if (!sender || !me) fail('agent messaging requires configured sender and recipient; anonymous permissions TODO');
|
|
387
398
|
if (!this.responsibility) fail('worker must load responsibility before receiving work');
|
|
388
399
|
if (this.handoff?.workerClosing || fencedClose(me.closeJob)) fail('worker close is active or uncertain; new Intercom work is fenced');
|
|
389
|
-
notify('agent message', message.payload.message as string);
|
|
400
|
+
notify('agent message', message.payload.message as string);
|
|
401
|
+
if (sender.coordinator && !me.coordinator) this.owesCoordinator = true;
|
|
402
|
+
return;
|
|
390
403
|
}
|
|
391
404
|
if (!sender?.coordinator) fail('control requires current coordinator sender session ID');
|
|
392
405
|
if (me?.coordinator) fail('worker control cannot target coordinator');
|
|
@@ -408,17 +421,7 @@ export class Intercom {
|
|
|
408
421
|
}
|
|
409
422
|
fail('unsupported control');
|
|
410
423
|
}
|
|
411
|
-
async tool(operation: string, args: Record<string, unknown>, toolCallId?: string
|
|
412
|
-
// Reserve invocation order before state/directory awaits, but only VALID
|
|
413
|
-
// reminder actions advance the accepted revision. Invalid/nonworker calls
|
|
414
|
-
// must not supersede a pending stop or suppress an older valid preflight.
|
|
415
|
-
const invocation = ++this.reminderInvocation;
|
|
416
|
-
const armReminder = () => {
|
|
417
|
-
if (invocation >= this.reminderRevision && !reminderSignal?.aborted) {
|
|
418
|
-
this.reminderRevision = invocation;
|
|
419
|
-
this.reminders?.arm(reminderSignal);
|
|
420
|
-
}
|
|
421
|
-
};
|
|
424
|
+
async tool(operation: string, args: Record<string, unknown>, toolCallId?: string): Promise<unknown> {
|
|
422
425
|
const record = this.captureObserver();
|
|
423
426
|
const assertValid = this.validity();
|
|
424
427
|
const { id, config, me } = await this.state();
|
|
@@ -449,6 +452,7 @@ export class Intercom {
|
|
|
449
452
|
if (!me || me.coordinator || !this.responsibility) fail('report_work requires a configured, responsibility-loaded worker');
|
|
450
453
|
const payload = reportPayload(args);
|
|
451
454
|
await this.transmit(coordinator(config).name, 'report', payload);
|
|
455
|
+
if (payload.status !== 'clear') this.owesCoordinator = false;
|
|
452
456
|
return { accepted: true, coordinatorEvaluation: 'not awaited' };
|
|
453
457
|
}
|
|
454
458
|
if (operation === 'send') {
|
|
@@ -456,8 +460,9 @@ export class Intercom {
|
|
|
456
460
|
const recipient = named(config, args.to as string);
|
|
457
461
|
text(args.message, 'message', 48000);
|
|
458
462
|
if (this.handoff?.workerClosing || fencedClose(me.closeJob) || this.handoff?.isClosing(recipient.sessionId) || fencedClose(recipient.closeJob)) fail('worker close is active or uncertain; new Intercom work is fenced');
|
|
459
|
-
|
|
460
|
-
|
|
463
|
+
await this.transmit(args.to as string, 'message', { message: args.message });
|
|
464
|
+
if (recipient.coordinator) this.owesCoordinator = false;
|
|
465
|
+
return { accepted: true, completion: 'not awaited' };
|
|
461
466
|
}
|
|
462
467
|
requireCoordinator(config, id);
|
|
463
468
|
if (operation === 'configure_models') {
|
|
@@ -491,11 +496,6 @@ export class Intercom {
|
|
|
491
496
|
if (operation === 'open_monitor' || operation === 'close_monitor') {
|
|
492
497
|
return this.operateMonitor(operation, args);
|
|
493
498
|
}
|
|
494
|
-
if (operation === 'stop_reminders') {
|
|
495
|
-
const current = invocation >= this.reminderRevision;
|
|
496
|
-
if (current) { this.reminderRevision = invocation; this.reminders?.stop(); }
|
|
497
|
-
return { stopped: current };
|
|
498
|
-
}
|
|
499
499
|
if (operation === 'stop_worker') fail(UNSUPPORTED_CANCELLATION);
|
|
500
500
|
if (operation === 'configure_worker') {
|
|
501
501
|
const assertConfigurable = () => {
|
|
@@ -503,8 +503,6 @@ export class Intercom {
|
|
|
503
503
|
if (this.handoff?.isClosing(args.sessionId as string) || this.resumeFences.has(args.sessionId as string)) fail('worker lifecycle operation is in flight; configuration is fenced');
|
|
504
504
|
};
|
|
505
505
|
assertConfigurable();
|
|
506
|
-
// Validate the candidate without writing, so invalid input never arms a
|
|
507
|
-
// reminder; persistence failures after valid initiation still do.
|
|
508
506
|
const relative = await directory(this.store.root, args.projectDirectory as string);
|
|
509
507
|
assertConfigurable();
|
|
510
508
|
const candidate: Agent = { sessionId: args.sessionId as string, name: args.name as string, description: args.description as string,
|
|
@@ -513,7 +511,6 @@ export class Intercom {
|
|
|
513
511
|
const previous = config.agents.find(a => a.sessionId === candidate.sessionId);
|
|
514
512
|
if (fencedClose(previous?.closeJob)) fail('worker close is active or uncertain; configuration is fenced');
|
|
515
513
|
validateConfig({ ...config, agents: [...config.agents.filter(a => a.sessionId !== candidate.sessionId), candidate] });
|
|
516
|
-
armReminder();
|
|
517
514
|
await this.store.configure(id, args as unknown as Omit<Agent, 'coordinator'>, assertConfigurable);
|
|
518
515
|
record('config.changed', { operation: 'configure_worker', peerSessionId: args.sessionId as string, peerName: args.name as string, outcome: 'written' });
|
|
519
516
|
return { written: true, reloaded: false };
|
|
@@ -526,7 +523,6 @@ export class Intercom {
|
|
|
526
523
|
const relative = await directory(this.store.root, (args.projectDirectory as string | undefined) ?? '.');
|
|
527
524
|
assertValid();
|
|
528
525
|
if (relative !== '.') fail('worker working directory must equal the config root; subdirectory launches would read a forbidden parent config');
|
|
529
|
-
armReminder();
|
|
530
526
|
return this.launchObserved({ multiplexer: config.multiplexer, cwd: path.resolve(this.store.root, relative), workspaceRoot: this.store.root });
|
|
531
527
|
}
|
|
532
528
|
const target = named(config, args.to as string);
|
|
@@ -535,12 +531,10 @@ export class Intercom {
|
|
|
535
531
|
if (!this.options.closeProvider || !this.handoff || config.multiplexer !== 'herdr') fail('Owned-pane close requires supported Linux Herdr provider; no closure attempted');
|
|
536
532
|
if (this.resumeFences.has(target.sessionId)) fail('resume is in flight; close is fenced');
|
|
537
533
|
if (fencedClose(target.closeJob) && !this.handoff.isClosing(target.sessionId)) fail('worker close is active or uncertain; close is fenced');
|
|
538
|
-
armReminder();
|
|
539
534
|
return { job: await this.handoff.request(target), completion: 'not awaited', contract: 'best-effort owned-pane closure; not all-child-process termination' };
|
|
540
535
|
}
|
|
541
536
|
if (['reload_worker', 'resume_worker', 'remove_worker'].includes(operation) && (this.handoff?.isClosing(target.sessionId) || fencedClose(target.closeJob))) fail('worker close is active or uncertain; operation is fenced');
|
|
542
537
|
if (operation === 'reload_worker' || operation === 'request_status') {
|
|
543
|
-
armReminder();
|
|
544
538
|
await this.transmit(target.name, operation === 'reload_worker' ? 'reload' : 'request_status');
|
|
545
539
|
return { accepted: true, completion: 'not awaited' };
|
|
546
540
|
}
|
|
@@ -556,7 +550,6 @@ export class Intercom {
|
|
|
556
550
|
if (this.handoff?.isClosing(target.sessionId)) fail('worker close is active or uncertain; resume is fenced');
|
|
557
551
|
const fence = { inFlight: true, submitted: false, announced: false };
|
|
558
552
|
this.resumeFences.set(target.sessionId, fence);
|
|
559
|
-
armReminder();
|
|
560
553
|
let completed = false;
|
|
561
554
|
try {
|
|
562
555
|
const connection = await (this.options.probe ?? probeWorker)(target, { signal: this.probeController.signal });
|
package/src/transport.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { HANDOFF_KINDS, validateHandoffPayload, type HandoffKind } from './hando
|
|
|
5
5
|
|
|
6
6
|
export const BODY_LIMIT = 64 * 1024;
|
|
7
7
|
export const RECEIPT_TIMEOUT = 5000;
|
|
8
|
-
export type Kind = 'message' | 'report' | 'registration' | 'status' | 'request_status' | 'reload' | 'stop' | 'close' | HandoffKind;
|
|
8
|
+
export type Kind = 'message' | 'report' | 'registration' | 'status' | 'idle' | 'request_status' | 'reload' | 'stop' | 'close' | HandoffKind;
|
|
9
9
|
export interface Envelope {
|
|
10
10
|
version: 1;
|
|
11
11
|
kind: Kind;
|
|
@@ -24,7 +24,7 @@ export function reportPayload(payload: Record<string, unknown>): { status: Repor
|
|
|
24
24
|
}
|
|
25
25
|
export function envelope(value: unknown): Envelope {
|
|
26
26
|
const m = value as Envelope;
|
|
27
|
-
if (!m || m.version !== 1 || !['message', 'report', 'registration', 'status', 'request_status', 'reload', 'stop', 'close', ...HANDOFF_KINDS].includes(m.kind)) fail('invalid wire schema/version/kind');
|
|
27
|
+
if (!m || m.version !== 1 || !['message', 'report', 'registration', 'status', 'idle', 'request_status', 'reload', 'stop', 'close', ...HANDOFF_KINDS].includes(m.kind)) fail('invalid wire schema/version/kind');
|
|
28
28
|
text(m.from, 'sender sessionId', 256); text(m.to, 'recipient sessionId', 256);
|
|
29
29
|
if (m.correlationId !== undefined && (typeof m.correlationId !== 'string' || !/^[a-zA-Z0-9-]{1,128}$/.test(m.correlationId))) fail('invalid correlation ID');
|
|
30
30
|
if (!m.payload || Array.isArray(m.payload) || typeof m.payload !== 'object') fail('invalid payload');
|
package/dist/reminders.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export declare const REMINDER_INTERVAL_MS: number;
|
|
2
|
-
export declare const REMINDER_TEXT = "Intercom reminder: Review outstanding delegated work and worker reports. If follow-up is needed, take the next appropriate action. Do not assume workers have finished or stopped.\n\nIf there is genuinely nothing to follow up on, call intercom_stop_reminders. Otherwise, reminders continue every five minutes; a new worker call resets the timer.\n\nThis reminder does not authorize new work, retries, worker closure, or publication.";
|
|
3
|
-
export interface ReminderClock {
|
|
4
|
-
schedule(callback: () => void, milliseconds: number): () => void;
|
|
5
|
-
}
|
|
6
|
-
interface ReminderHost {
|
|
7
|
-
isCoordinator(): Promise<boolean>;
|
|
8
|
-
busy(): boolean;
|
|
9
|
-
deliver(text: string): void;
|
|
10
|
-
}
|
|
11
|
-
/** Ephemeral reminder only: never worker actions, network retries or a backlog. */
|
|
12
|
-
export declare class CoordinatorReminders {
|
|
13
|
-
private readonly host;
|
|
14
|
-
private readonly timer;
|
|
15
|
-
private generation;
|
|
16
|
-
private tick;
|
|
17
|
-
private checking;
|
|
18
|
-
private disposed;
|
|
19
|
-
private cancel?;
|
|
20
|
-
private detachOwner?;
|
|
21
|
-
constructor(host: ReminderHost, timer?: ReminderClock);
|
|
22
|
-
arm(signal?: AbortSignal): void;
|
|
23
|
-
stop(): void;
|
|
24
|
-
dispose(): void;
|
|
25
|
-
private current;
|
|
26
|
-
private schedule;
|
|
27
|
-
}
|
|
28
|
-
export {};
|
package/dist/reminders.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
export const REMINDER_INTERVAL_MS = 5 * 60 * 1000;
|
|
2
|
-
export const REMINDER_TEXT = 'Intercom reminder: Review outstanding delegated work and worker reports. If follow-up is needed, take the next appropriate action. Do not assume workers have finished or stopped.\n\nIf there is genuinely nothing to follow up on, call intercom_stop_reminders. Otherwise, reminders continue every five minutes; a new worker call resets the timer.\n\nThis reminder does not authorize new work, retries, worker closure, or publication.';
|
|
3
|
-
const clock = {
|
|
4
|
-
schedule(callback, milliseconds) {
|
|
5
|
-
const timer = setTimeout(callback, milliseconds);
|
|
6
|
-
timer.unref();
|
|
7
|
-
return () => clearTimeout(timer);
|
|
8
|
-
},
|
|
9
|
-
};
|
|
10
|
-
/** Ephemeral reminder only: never worker actions, network retries or a backlog. */
|
|
11
|
-
export class CoordinatorReminders {
|
|
12
|
-
host;
|
|
13
|
-
timer;
|
|
14
|
-
generation = 0;
|
|
15
|
-
tick = 0;
|
|
16
|
-
checking = false;
|
|
17
|
-
disposed = false;
|
|
18
|
-
cancel;
|
|
19
|
-
detachOwner;
|
|
20
|
-
constructor(host, timer = clock) {
|
|
21
|
-
this.host = host;
|
|
22
|
-
this.timer = timer;
|
|
23
|
-
}
|
|
24
|
-
arm(signal) {
|
|
25
|
-
if (this.disposed || signal?.aborted)
|
|
26
|
-
return;
|
|
27
|
-
this.stop();
|
|
28
|
-
const generation = this.generation;
|
|
29
|
-
if (signal) {
|
|
30
|
-
const abort = () => { if (this.generation === generation)
|
|
31
|
-
this.stop(); };
|
|
32
|
-
signal.addEventListener('abort', abort, { once: true });
|
|
33
|
-
this.detachOwner = () => signal.removeEventListener('abort', abort);
|
|
34
|
-
}
|
|
35
|
-
this.schedule(generation);
|
|
36
|
-
}
|
|
37
|
-
stop() {
|
|
38
|
-
this.generation++;
|
|
39
|
-
this.tick++;
|
|
40
|
-
this.cancel?.();
|
|
41
|
-
this.cancel = undefined;
|
|
42
|
-
this.detachOwner?.();
|
|
43
|
-
this.detachOwner = undefined;
|
|
44
|
-
}
|
|
45
|
-
dispose() { this.stop(); this.disposed = true; }
|
|
46
|
-
current(generation, tick) {
|
|
47
|
-
return !this.disposed && this.generation === generation && this.tick === tick;
|
|
48
|
-
}
|
|
49
|
-
schedule(generation) {
|
|
50
|
-
this.cancel = this.timer.schedule(() => {
|
|
51
|
-
if (this.disposed || generation !== this.generation)
|
|
52
|
-
return;
|
|
53
|
-
this.cancel = undefined;
|
|
54
|
-
const tick = ++this.tick;
|
|
55
|
-
this.schedule(generation);
|
|
56
|
-
// A slow role read never creates concurrent reads or a queued reminder.
|
|
57
|
-
// Advancing tick also invalidates any read from the preceding interval.
|
|
58
|
-
if (this.checking)
|
|
59
|
-
return;
|
|
60
|
-
this.checking = true;
|
|
61
|
-
void (async () => {
|
|
62
|
-
try {
|
|
63
|
-
const coordinator = await this.host.isCoordinator();
|
|
64
|
-
if (!this.current(generation, tick))
|
|
65
|
-
return;
|
|
66
|
-
if (!coordinator) {
|
|
67
|
-
this.stop();
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
if (!this.host.busy())
|
|
71
|
-
this.host.deliver(REMINDER_TEXT);
|
|
72
|
-
}
|
|
73
|
-
catch { /* Unknown role/read/delivery outcome: no blind immediate replay. */ }
|
|
74
|
-
finally {
|
|
75
|
-
this.checking = false;
|
|
76
|
-
}
|
|
77
|
-
})();
|
|
78
|
-
}, REMINDER_INTERVAL_MS);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
//# sourceMappingURL=reminders.js.map
|
package/dist/reminders.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"reminders.js","sourceRoot":"","sources":["../src/reminders.ts"],"names":[],"mappings":"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"}
|
package/src/reminders.ts
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
export const REMINDER_INTERVAL_MS = 5 * 60 * 1000;
|
|
2
|
-
export const REMINDER_TEXT = 'Intercom reminder: Review outstanding delegated work and worker reports. If follow-up is needed, take the next appropriate action. Do not assume workers have finished or stopped.\n\nIf there is genuinely nothing to follow up on, call intercom_stop_reminders. Otherwise, reminders continue every five minutes; a new worker call resets the timer.\n\nThis reminder does not authorize new work, retries, worker closure, or publication.';
|
|
3
|
-
|
|
4
|
-
export interface ReminderClock {
|
|
5
|
-
schedule(callback: () => void, milliseconds: number): () => void;
|
|
6
|
-
}
|
|
7
|
-
const clock: ReminderClock = {
|
|
8
|
-
schedule(callback, milliseconds) {
|
|
9
|
-
const timer = setTimeout(callback, milliseconds);
|
|
10
|
-
timer.unref();
|
|
11
|
-
return () => clearTimeout(timer);
|
|
12
|
-
},
|
|
13
|
-
};
|
|
14
|
-
interface ReminderHost {
|
|
15
|
-
isCoordinator(): Promise<boolean>;
|
|
16
|
-
busy(): boolean;
|
|
17
|
-
deliver(text: string): void;
|
|
18
|
-
}
|
|
19
|
-
/** Ephemeral reminder only: never worker actions, network retries or a backlog. */
|
|
20
|
-
export class CoordinatorReminders {
|
|
21
|
-
private generation = 0;
|
|
22
|
-
private tick = 0;
|
|
23
|
-
private checking = false;
|
|
24
|
-
private disposed = false;
|
|
25
|
-
private cancel?: () => void;
|
|
26
|
-
private detachOwner?: () => void;
|
|
27
|
-
constructor(private readonly host: ReminderHost, private readonly timer: ReminderClock = clock) {}
|
|
28
|
-
arm(signal?: AbortSignal): void {
|
|
29
|
-
if (this.disposed || signal?.aborted) return;
|
|
30
|
-
this.stop();
|
|
31
|
-
const generation = this.generation;
|
|
32
|
-
if (signal) {
|
|
33
|
-
const abort = () => { if (this.generation === generation) this.stop(); };
|
|
34
|
-
signal.addEventListener('abort', abort, { once: true });
|
|
35
|
-
this.detachOwner = () => signal.removeEventListener('abort', abort);
|
|
36
|
-
}
|
|
37
|
-
this.schedule(generation);
|
|
38
|
-
}
|
|
39
|
-
stop(): void {
|
|
40
|
-
this.generation++; this.tick++;
|
|
41
|
-
this.cancel?.(); this.cancel = undefined;
|
|
42
|
-
this.detachOwner?.(); this.detachOwner = undefined;
|
|
43
|
-
}
|
|
44
|
-
dispose(): void { this.stop(); this.disposed = true; }
|
|
45
|
-
private current(generation: number, tick: number): boolean {
|
|
46
|
-
return !this.disposed && this.generation === generation && this.tick === tick;
|
|
47
|
-
}
|
|
48
|
-
private schedule(generation: number): void {
|
|
49
|
-
this.cancel = this.timer.schedule(() => {
|
|
50
|
-
if (this.disposed || generation !== this.generation) return;
|
|
51
|
-
this.cancel = undefined;
|
|
52
|
-
const tick = ++this.tick;
|
|
53
|
-
this.schedule(generation);
|
|
54
|
-
// A slow role read never creates concurrent reads or a queued reminder.
|
|
55
|
-
// Advancing tick also invalidates any read from the preceding interval.
|
|
56
|
-
if (this.checking) return;
|
|
57
|
-
this.checking = true;
|
|
58
|
-
void (async () => {
|
|
59
|
-
try {
|
|
60
|
-
const coordinator = await this.host.isCoordinator();
|
|
61
|
-
if (!this.current(generation, tick)) return;
|
|
62
|
-
if (!coordinator) { this.stop(); return; }
|
|
63
|
-
if (!this.host.busy()) this.host.deliver(REMINDER_TEXT);
|
|
64
|
-
} catch { /* Unknown role/read/delivery outcome: no blind immediate replay. */ }
|
|
65
|
-
finally { this.checking = false; }
|
|
66
|
-
})();
|
|
67
|
-
}, REMINDER_INTERVAL_MS);
|
|
68
|
-
}
|
|
69
|
-
}
|