@ours.network/fleet 1.2.0-nightly.5 → 1.2.0-nightly.51
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 +263 -53
- package/dist/account-origin.d.ts +2 -0
- package/dist/account-origin.js +6 -0
- package/dist/agent-ours/bridge.js +9 -0
- package/dist/agent-ours/correspondence.d.ts +10 -0
- package/dist/agent-ours/correspondence.js +1 -0
- package/dist/agent-ours/harness.js +8 -0
- package/dist/agent-ours/runtime.d.ts +6 -0
- package/dist/agent-ours/runtime.js +36 -0
- package/dist/agent-ours/service.js +33 -13
- package/dist/application/codex-models.d.ts +15 -0
- package/dist/application/codex-models.js +56 -0
- package/dist/application/conversation-history.d.ts +25 -0
- package/dist/application/conversation-history.js +189 -0
- package/dist/application/fleet-query-service.d.ts +1 -1
- package/dist/application/fleet-query-service.js +2 -2
- package/dist/application/legacy-supervisor-identity.d.ts +7 -0
- package/dist/application/legacy-supervisor-identity.js +43 -0
- package/dist/application/model-catalog.d.ts +1 -1
- package/dist/application/model-catalog.js +5 -2
- package/dist/application/preset-provenance.d.ts +19 -0
- package/dist/application/preset-provenance.js +59 -0
- package/dist/application/role-creation-service.js +1 -1
- package/dist/application/role-removal-service.js +2 -0
- package/dist/application/role-repository.js +2 -2
- package/dist/application/room-layout-definitions.d.ts +45 -0
- package/dist/application/room-layout-definitions.js +130 -0
- package/dist/application/session-control.d.ts +30 -0
- package/dist/application/session-control.js +72 -3
- package/dist/application/supervisor-ours-tools.d.ts +159 -0
- package/dist/application/supervisor-ours-tools.js +113 -0
- package/dist/application/task-layouts.d.ts +91 -0
- package/dist/application/task-layouts.js +249 -0
- package/dist/application/task-room-service.d.ts +99 -3
- package/dist/application/task-room-service.js +296 -31
- package/dist/atomic-file.d.ts +5 -0
- package/dist/atomic-file.js +62 -1
- package/dist/briefing.d.ts +2 -0
- package/dist/briefing.js +8 -1
- package/dist/build-info.json +7 -4
- package/dist/capabilities.d.ts +6 -1
- package/dist/capabilities.js +8 -0
- package/dist/cli.js +376 -34
- package/dist/client-profile.d.ts +5 -17
- package/dist/client-profile.js +4 -127
- package/dist/config.d.ts +28 -0
- package/dist/config.js +41 -6
- package/dist/creation.js +2 -2
- package/dist/daemon-recovery.d.ts +1 -8
- package/dist/daemon-recovery.js +8 -113
- package/dist/docs.d.ts +3 -3
- package/dist/docs.js +126 -22
- package/dist/doctor.d.ts +1 -1
- package/dist/doctor.js +55 -60
- package/dist/erased-resources.d.ts +9 -0
- package/dist/erased-resources.js +87 -0
- package/dist/fleet-command-audit.d.ts +7 -0
- package/dist/fleet-command-audit.js +26 -9
- package/dist/harness/claude-code.js +9 -1
- package/dist/harness/claude-runtime.d.ts +12 -0
- package/dist/harness/claude-runtime.js +43 -0
- package/dist/harness/codex-app-server-proxy.d.ts +4 -1
- package/dist/harness/codex-app-server-proxy.js +41 -5
- package/dist/harness/codex-reasoning.d.ts +5 -0
- package/dist/harness/codex-reasoning.js +12 -0
- package/dist/harness/codex-runtime.d.ts +11 -1
- package/dist/harness/codex-runtime.js +31 -4
- package/dist/harness/codex.d.ts +3 -2
- package/dist/harness/codex.js +20 -11
- package/dist/init-wizard.d.ts +2 -0
- package/dist/init-wizard.js +38 -19
- package/dist/isolation/policy.js +2 -0
- package/dist/isolation/types.d.ts +5 -0
- package/dist/managed-cli.d.ts +253 -0
- package/dist/managed-cli.js +923 -0
- package/dist/minimal-setup.d.ts +2 -0
- package/dist/minimal-setup.js +44 -0
- package/dist/monitor.d.ts +1 -34
- package/dist/monitor.js +24 -151
- package/dist/notifications/fleet-producer.d.ts +19 -0
- package/dist/notifications/fleet-producer.js +208 -0
- package/dist/notifications/outbox.d.ts +46 -0
- package/dist/notifications/outbox.js +158 -0
- package/dist/notifications/target-cleanup.d.ts +8 -0
- package/dist/notifications/target-cleanup.js +41 -0
- package/dist/ops.js +5 -1
- package/dist/owner-channel/channel.d.ts +3 -0
- package/dist/owner-channel/channel.js +34 -6
- package/dist/owner-channel/commands.d.ts +4 -0
- package/dist/owner-channel/commands.js +8 -0
- package/dist/owner-channel/lifecycle-outbox.js +4 -3
- package/dist/owner-channel/ours-client.js +2 -17
- package/dist/paths.d.ts +2 -0
- package/dist/paths.js +2 -0
- package/dist/preset-migration.js +25 -0
- package/dist/resolved-plan.js +1 -0
- package/dist/rooms-tasks/add-member.d.ts +48 -0
- package/dist/rooms-tasks/add-member.js +83 -0
- package/dist/rooms-tasks/archived-absence.d.ts +8 -0
- package/dist/rooms-tasks/archived-absence.js +48 -0
- package/dist/rooms-tasks/cli.js +34 -5
- package/dist/rooms-tasks/close.d.ts +5 -2
- package/dist/rooms-tasks/close.js +208 -28
- package/dist/rooms-tasks/config.d.ts +1 -1
- package/dist/rooms-tasks/config.js +11 -4
- package/dist/rooms-tasks/cowork-adapter.d.ts +6 -4
- package/dist/rooms-tasks/cowork-adapter.js +8 -121
- package/dist/rooms-tasks/deletion.d.ts +1 -1
- package/dist/rooms-tasks/deletion.js +74 -5
- package/dist/rooms-tasks/erasure.d.ts +6 -0
- package/dist/rooms-tasks/erasure.js +169 -0
- package/dist/rooms-tasks/external-worker.d.ts +1 -1
- package/dist/rooms-tasks/external-worker.js +3 -4
- package/dist/rooms-tasks/layout-binding-client.d.ts +11 -0
- package/dist/rooms-tasks/layout-binding-client.js +56 -0
- package/dist/rooms-tasks/layout-binding-grants.d.ts +21 -0
- package/dist/rooms-tasks/layout-binding-grants.js +128 -0
- package/dist/rooms-tasks/layout-cli.d.ts +4 -0
- package/dist/rooms-tasks/layout-cli.js +107 -0
- package/dist/rooms-tasks/layout-config.d.ts +11 -0
- package/dist/rooms-tasks/layout-config.js +89 -0
- package/dist/rooms-tasks/layout-control.d.ts +21 -0
- package/dist/rooms-tasks/layout-control.js +52 -0
- package/dist/rooms-tasks/layout-service.d.ts +42 -0
- package/dist/rooms-tasks/layout-service.js +185 -0
- package/dist/rooms-tasks/layout.d.ts +114 -0
- package/dist/rooms-tasks/layout.js +250 -0
- package/dist/rooms-tasks/live-readiness.d.ts +18 -0
- package/dist/rooms-tasks/live-readiness.js +85 -0
- package/dist/rooms-tasks/member-startup.d.ts +1 -0
- package/dist/rooms-tasks/member-startup.js +2 -0
- package/dist/rooms-tasks/provision.d.ts +14 -0
- package/dist/rooms-tasks/provision.js +173 -46
- package/dist/rooms-tasks/room-state.d.ts +4 -2
- package/dist/rooms-tasks/room-state.js +53 -8
- package/dist/rooms-tasks/task-state.d.ts +42 -7
- package/dist/rooms-tasks/task-state.js +153 -23
- package/dist/rooms-tasks/types.d.ts +28 -0
- package/dist/rooms-tasks/workspace-artifacts.d.ts +6 -0
- package/dist/rooms-tasks/workspace-artifacts.js +93 -0
- package/dist/rooms-tasks/workspace.d.ts +26 -0
- package/dist/rooms-tasks/workspace.js +195 -0
- package/dist/runner.d.ts +19 -3
- package/dist/runner.js +128 -45
- package/dist/session/acp.d.ts +9 -1
- package/dist/session/acp.js +31 -6
- package/dist/session/arbiter.d.ts +5 -0
- package/dist/session/arbiter.js +28 -2
- package/dist/session/codex-app-server.d.ts +5 -0
- package/dist/session/codex-app-server.js +36 -3
- package/dist/session/control.d.ts +12 -1
- package/dist/session/control.js +68 -3
- package/dist/session/conversation-normalizer.d.ts +2 -1
- package/dist/session/conversation-normalizer.js +1 -1
- package/dist/session/conversation-store.d.ts +1 -1
- package/dist/session/conversation-store.js +7 -11
- package/dist/session/conversation-types.d.ts +7 -3
- package/dist/session/task-notice.d.ts +14 -0
- package/dist/session/task-notice.js +13 -0
- package/dist/session/types.d.ts +6 -0
- package/dist/setup-tunnel-preflight.d.ts +34 -0
- package/dist/setup-tunnel-preflight.js +62 -0
- package/dist/socket-path.d.ts +2 -0
- package/dist/socket-path.js +22 -0
- package/dist/spawn.js +8 -1
- package/dist/startup-readiness.d.ts +13 -0
- package/dist/startup-readiness.js +38 -0
- package/dist/subscriptions/cli.d.ts +91 -0
- package/dist/subscriptions/cli.js +223 -0
- package/dist/subscriptions/launch.d.ts +37 -0
- package/dist/subscriptions/launch.js +93 -0
- package/dist/subscriptions/login.d.ts +75 -0
- package/dist/subscriptions/login.js +182 -0
- package/dist/subscriptions/observed.d.ts +7 -0
- package/dist/subscriptions/observed.js +44 -0
- package/dist/subscriptions/probe.d.ts +10 -0
- package/dist/subscriptions/probe.js +73 -0
- package/dist/subscriptions/service.d.ts +102 -0
- package/dist/subscriptions/service.js +364 -0
- package/dist/subscriptions/store.d.ts +71 -0
- package/dist/subscriptions/store.js +140 -0
- package/dist/supervisor/launchd.js +2 -1
- package/dist/supervisor/systemd.js +9 -23
- package/dist/temp-idle.d.ts +17 -0
- package/dist/temp-idle.js +42 -0
- package/dist/temp-lifecycle.d.ts +6 -1
- package/dist/temp-lifecycle.js +29 -13
- package/dist/tunnel-setup-completion.d.ts +7 -0
- package/dist/tunnel-setup-completion.js +13 -0
- package/dist/tunnel-setup-input.d.ts +19 -0
- package/dist/tunnel-setup-input.js +124 -0
- package/dist/web/agent-attachments.d.ts +29 -0
- package/dist/web/agent-attachments.js +162 -0
- package/dist/web/auth.d.ts +29 -1
- package/dist/web/auth.js +82 -7
- package/dist/web/available-port.d.ts +2 -0
- package/dist/web/available-port.js +23 -0
- package/dist/web/control.d.ts +3 -3
- package/dist/web/control.js +10 -8
- package/dist/web/fleet-config-service.d.ts +4 -1
- package/dist/web/fleet-config-service.js +46 -15
- package/dist/web/prefix-gateway.d.ts +32 -0
- package/dist/web/prefix-gateway.js +234 -0
- package/dist/web/runtime.d.ts +3 -1
- package/dist/web/runtime.js +116 -31
- package/dist/web/server.d.ts +16 -0
- package/dist/web/server.js +592 -53
- package/dist/web/service.d.ts +11 -2
- package/dist/web/service.js +30 -4
- package/dist/web/workspace-devices.d.ts +36 -0
- package/dist/web/workspace-devices.js +101 -0
- package/dist/web/workspace-tunnel.d.ts +1 -0
- package/dist/web/workspace-tunnel.js +34 -0
- package/dist/workspace-enrollment.d.ts +82 -0
- package/dist/workspace-enrollment.js +566 -0
- package/dist/workspace-replacement.d.ts +66 -0
- package/dist/workspace-replacement.js +220 -0
- package/docs/live-voice.md +13 -0
- package/docs/room-layouts.md +227 -0
- package/docs/task-workspaces.md +130 -0
- package/docs/validation/managed-cli-permissions.md +421 -0
- package/examples/room-layouts/fresh.yaml +27 -0
- package/examples/room-layouts/scoped.yaml +21 -0
- package/examples/room-layouts/shared.yaml +19 -0
- package/package.json +15 -18
- package/presets/README.md +78 -0
- package/presets/brain-catalog.json +8 -2
- package/presets/fleet/agent_templates/Critic.yaml +1 -1
- package/presets/fleet/agent_templates/Developer.yaml +1 -1
- package/presets/fleet/agent_templates/Engineer.yaml +5 -0
- package/presets/fleet/agent_templates/LocalCoordinator.yaml +1 -1
- package/presets/fleet/agents/FleetCoordinator.yaml +1 -1
- package/presets/fleet/brains/claude-fable-5-1-high.yaml +5 -0
- package/presets/fleet/brains/claude-fable-5-1-low.yaml +5 -0
- package/presets/fleet/brains/claude-fable-5-1-max.yaml +5 -0
- package/presets/fleet/brains/claude-fable-5-1-medium.yaml +5 -0
- package/presets/fleet/brains/claude-fable-5-1-xhigh.yaml +5 -0
- package/presets/fleet/brains/claude-fable-5-high.yaml +1 -1
- package/presets/fleet/brains/claude-fable-5-low.yaml +1 -1
- package/presets/fleet/brains/claude-fable-5-max.yaml +1 -1
- package/presets/fleet/brains/claude-fable-5-medium.yaml +1 -1
- package/presets/fleet/brains/claude-fable-5-xhigh.yaml +1 -1
- package/presets/fleet/brains/claude-haiku-4-5-20251001-default.yaml +4 -0
- package/presets/fleet/brains/claude-opus-5-5-high.yaml +5 -0
- package/presets/fleet/brains/claude-opus-5-5-low.yaml +5 -0
- package/presets/fleet/brains/claude-opus-5-5-max.yaml +5 -0
- package/presets/fleet/brains/claude-opus-5-5-medium.yaml +5 -0
- package/presets/fleet/brains/claude-opus-5-5-xhigh.yaml +5 -0
- package/presets/fleet/brains/claude-opus-5-high.yaml +1 -1
- package/presets/fleet/brains/claude-opus-5-low.yaml +1 -1
- package/presets/fleet/brains/claude-opus-5-max.yaml +1 -1
- package/presets/fleet/brains/claude-opus-5-medium.yaml +1 -1
- package/presets/fleet/brains/claude-opus-5-xhigh.yaml +1 -1
- package/presets/fleet/brains/claude-sonnet-5-high.yaml +1 -1
- package/presets/fleet/brains/claude-sonnet-5-low.yaml +1 -1
- package/presets/fleet/brains/claude-sonnet-5-max.yaml +1 -1
- package/presets/fleet/brains/claude-sonnet-5-medium.yaml +1 -1
- package/presets/fleet/brains/claude-sonnet-5-xhigh.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-3-codex-spark-high.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-3-codex-spark-low.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-3-codex-spark-medium.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-3-codex-spark-xhigh.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-4-high.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-4-low.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-4-medium.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-4-mini-high.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-4-mini-low.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-4-mini-medium.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-4-mini-xhigh.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-4-xhigh.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-5-high.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-5-low.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-5-medium.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-5-xhigh.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-6-luna-high.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-6-luna-low.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-6-luna-max.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-6-luna-medium.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-6-luna-xhigh.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-6-sol-high.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-6-sol-low.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-6-sol-max.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-6-sol-medium.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-6-sol-ultra.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-6-sol-xhigh.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-6-terra-high.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-6-terra-low.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-6-terra-max.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-6-terra-medium.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-6-terra-ultra.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-5-6-terra-xhigh.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-6-1-sol-high.yaml +5 -0
- package/presets/fleet/brains/codex-gpt-6-1-sol-low.yaml +5 -0
- package/presets/fleet/brains/codex-gpt-6-1-sol-max.yaml +5 -0
- package/presets/fleet/brains/codex-gpt-6-1-sol-medium.yaml +5 -0
- package/presets/fleet/brains/codex-gpt-6-1-sol-ultra.yaml +5 -0
- package/presets/fleet/brains/codex-gpt-6-1-sol-xhigh.yaml +5 -0
- package/presets/fleet/brains/codex-gpt-6-astra-high.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-6-astra-low.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-6-astra-max.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-6-astra-medium.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-6-astra-ultra.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-6-astra-xhigh.yaml +1 -1
- package/presets/fleet/brains/codex-gpt-6-luna-high.yaml +5 -0
- package/presets/fleet/brains/codex-gpt-6-luna-low.yaml +5 -0
- package/presets/fleet/brains/codex-gpt-6-luna-max.yaml +5 -0
- package/presets/fleet/brains/codex-gpt-6-luna-medium.yaml +5 -0
- package/presets/fleet/brains/codex-gpt-6-luna-xhigh.yaml +5 -0
- package/presets/fleet/brains/codex-gpt-6-sol-high.yaml +5 -0
- package/presets/fleet/brains/codex-gpt-6-sol-low.yaml +5 -0
- package/presets/fleet/brains/codex-gpt-6-sol-max.yaml +5 -0
- package/presets/fleet/brains/codex-gpt-6-sol-medium.yaml +5 -0
- package/presets/fleet/brains/codex-gpt-6-sol-ultra.yaml +5 -0
- package/presets/fleet/brains/codex-gpt-6-sol-xhigh.yaml +5 -0
- package/presets/fleet/roles/Coordinator.yaml +34 -11
- package/presets/fleet/roles/Engineer.yaml +40 -0
- package/presets/fleet/room_layouts/engineering.yaml +25 -0
- package/presets/fleet/room_layouts/pair.yaml +24 -0
- package/presets/fleet/room_layouts/single.yaml +17 -0
- package/presets/fleet/room_layouts/team.yaml +30 -0
- package/presets/fleet/room_templates/engineering.yaml +19 -0
- package/presets/manifest.json +2 -2
- package/dist/web-app/assets/index-59GF-gsZ.css +0 -1
- package/dist/web-app/assets/index-C0h3ALvs.js +0 -10
- package/dist/web-app/icons/ours-fleet-maskable.svg +0 -4
- package/dist/web-app/icons/ours-fleet.svg +0 -4
- package/dist/web-app/index.html +0 -17
- package/dist/web-app/manifest.webmanifest +0 -15
- package/dist/web-app/offline.html +0 -18
- package/dist/web-app/sw.js +0 -51
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { existsSync, linkSync, mkdirSync, mkdtempSync, renameSync, rmSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { basename, join } from 'node:path';
|
|
3
|
+
import { withFileLock } from './atomic-file.js';
|
|
4
|
+
import { loadConfig, splitRootFor } from './config.js';
|
|
5
|
+
import { preflightInitPaths } from './init-wizard.js';
|
|
6
|
+
import { workspaceOwnerInvite } from './paths.js';
|
|
7
|
+
/** Prepare only the web configuration; App onboarding chooses agents and brains later. */
|
|
8
|
+
export async function ensureMinimalSetup(configuration) {
|
|
9
|
+
const initial = preflightInitPaths(configuration);
|
|
10
|
+
await withFileLock(join(initial.parent, `.${basename(initial.splitRoot)}.init.lock`), async () => {
|
|
11
|
+
const selected = preflightInitPaths(configuration);
|
|
12
|
+
if (selected.manifestExisted) {
|
|
13
|
+
loadConfig(selected.configPath, { yamlMode: 'strict', deferredOwnerInviteFile: workspaceOwnerInvite() });
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
if (selected.rootExisted)
|
|
17
|
+
throw new Error('Fleet split configuration exists without its manifest; retain it and recover the existing setup before setting up a tunnel');
|
|
18
|
+
const stage = mkdtempSync(join(selected.parent, '.fleet-web-setup-'));
|
|
19
|
+
const manifest = join(stage, 'fleet.yaml');
|
|
20
|
+
const root = splitRootFor(manifest);
|
|
21
|
+
let publishedRoot = false;
|
|
22
|
+
try {
|
|
23
|
+
mkdirSync(join(root, 'agents'), { recursive: true, mode: 0o700 });
|
|
24
|
+
writeFileSync(manifest, 'api_version: ours.network/fleet/v2\n', { mode: 0o600, flag: 'wx' });
|
|
25
|
+
loadConfig(manifest, { yamlMode: 'strict' });
|
|
26
|
+
if (existsSync(selected.splitRoot) || existsSync(selected.configPath))
|
|
27
|
+
throw new Error('Fleet setup targets changed; refusing replacement');
|
|
28
|
+
renameSync(root, selected.splitRoot);
|
|
29
|
+
publishedRoot = true;
|
|
30
|
+
// Same-filesystem link publishes without replacing an unexpected manifest.
|
|
31
|
+
linkSync(manifest, selected.configPath);
|
|
32
|
+
unlinkSync(manifest);
|
|
33
|
+
loadConfig(selected.configPath, { yamlMode: 'strict' });
|
|
34
|
+
}
|
|
35
|
+
catch (cause) {
|
|
36
|
+
if (publishedRoot)
|
|
37
|
+
throw new Error('Minimal Fleet setup stopped after publishing its empty split directory; existing files were retained for recovery', { cause });
|
|
38
|
+
throw cause;
|
|
39
|
+
}
|
|
40
|
+
finally {
|
|
41
|
+
rmSync(stage, { recursive: true, force: true });
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
package/dist/monitor.d.ts
CHANGED
|
@@ -88,33 +88,6 @@ export interface MonitorDeps {
|
|
|
88
88
|
* turns they trigger keep dying.
|
|
89
89
|
*/
|
|
90
90
|
export type StatusCause = 'connectivity' | 'delivery' | 'modal' | 'offline' | 'turns-failing' | 'safe-boundary' | 'auth';
|
|
91
|
-
/** Best-effort daemon config (issue #17): the fields the MCP client reads. */
|
|
92
|
-
interface DaemonConfig {
|
|
93
|
-
apiToken?: string;
|
|
94
|
-
port?: number;
|
|
95
|
-
stateDir?: string;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Read the daemon config the way the MCP client does — best-effort. Any missing,
|
|
99
|
-
* malformed, or unreadable config yields `{}` so token resolution falls through
|
|
100
|
-
* (issue #17). Only the well-typed fields we consume are surfaced.
|
|
101
|
-
*/
|
|
102
|
-
export declare function readDaemonConfig(env: NodeJS.ProcessEnv): DaemonConfig;
|
|
103
|
-
/**
|
|
104
|
-
* Resolve the daemon API token exactly like the MCP client (issue #17), a 3-step
|
|
105
|
-
* chain: `OURS_API_TOKEN` (trimmed) → config `apiToken` (trimmed) → the 0600 owner
|
|
106
|
-
* token at `<stateDir>/daemon-token`. Never generates a token; a failed read of
|
|
107
|
-
* any source (missing/unreadable) silently falls through to the next.
|
|
108
|
-
*/
|
|
109
|
-
export declare function resolveApiToken(env: NodeJS.ProcessEnv, file?: DaemonConfig): string | undefined;
|
|
110
|
-
export interface DaemonEndpoint {
|
|
111
|
-
origin: string;
|
|
112
|
-
port: number;
|
|
113
|
-
configPath: string;
|
|
114
|
-
stateDir: string;
|
|
115
|
-
url(name: string): string;
|
|
116
|
-
headers: Record<string, string>;
|
|
117
|
-
}
|
|
118
91
|
export type IdentityPresence = {
|
|
119
92
|
state: 'present';
|
|
120
93
|
temporary: boolean;
|
|
@@ -125,16 +98,12 @@ export type IdentityPresence = {
|
|
|
125
98
|
state: 'unknown';
|
|
126
99
|
detail: string;
|
|
127
100
|
};
|
|
128
|
-
/** Resolve the daemon endpoint + auth header from env → config → defaults. */
|
|
129
|
-
export declare function resolveEndpoint(env: NodeJS.ProcessEnv, includeToken?: boolean): DaemonEndpoint;
|
|
130
101
|
/**
|
|
131
102
|
* Ask the daemon's authoritative identity index. The notifications endpoint is
|
|
132
103
|
* intentionally unsuitable for lifecycle: it serves an empty 200 page for a
|
|
133
104
|
* valid but missing identity, which made a closed temp identity look healthy.
|
|
134
105
|
*/
|
|
135
106
|
export declare function probeIdentityPresence(name: string, fetch: FetchLike, env: NodeJS.ProcessEnv, deps?: IdentityProbeDeps): Promise<IdentityPresence>;
|
|
136
|
-
/** Actionable, secret-free description of every token source for this profile. */
|
|
137
|
-
export declare function authResolutionHint(ep: DaemonEndpoint): string;
|
|
138
107
|
/** Keep only the events whose type the role asked to wake on. */
|
|
139
108
|
export declare function filterEvents(events: NotifyEvent[], wakeSources: string[]): NotifyEvent[];
|
|
140
109
|
/**
|
|
@@ -196,8 +165,7 @@ export declare class Monitor {
|
|
|
196
165
|
private readonly identity;
|
|
197
166
|
private readonly cfg;
|
|
198
167
|
private readonly deps;
|
|
199
|
-
private readonly
|
|
200
|
-
private readonly profile?;
|
|
168
|
+
private readonly profile;
|
|
201
169
|
private readonly profileKey;
|
|
202
170
|
private readonly monitorLeaseToken;
|
|
203
171
|
private profileClientPromise?;
|
|
@@ -263,4 +231,3 @@ export declare class Monitor {
|
|
|
263
231
|
private writeStatus;
|
|
264
232
|
}
|
|
265
233
|
export declare function createMonitor(o: MonitorOpts): Monitor;
|
|
266
|
-
export {};
|
package/dist/monitor.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { existsSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { randomUUID } from 'node:crypto';
|
|
3
|
-
import { homedir } from 'node:os';
|
|
4
3
|
import { join } from 'node:path';
|
|
5
4
|
import { attachOursClient } from '@ours.network/sdk/client';
|
|
6
5
|
import { clientProfileKey, readClientProfile, } from './client-profile.js';
|
|
@@ -42,124 +41,28 @@ const TURN_OBSERVE_INTERVAL_MS = 1_500;
|
|
|
42
41
|
const DEFAULT_TURN_FAIL_THRESHOLD = 3; // fallback when the resolved config omits it
|
|
43
42
|
class AuthError extends Error {
|
|
44
43
|
}
|
|
45
|
-
/** Path to the daemon config the MCP client uses: OURS_CONFIG ?? real ~/.ours/config.json. */
|
|
46
|
-
const daemonConfigPath = (env) => env.OURS_CONFIG ?? join(homedir(), '.ours', 'config.json');
|
|
47
|
-
/** Preserve the daemon's legacy env integer semantics: parseInt, invalid → absent. */
|
|
48
|
-
function envInt(env, name) {
|
|
49
|
-
const raw = env[name];
|
|
50
|
-
if (raw === undefined)
|
|
51
|
-
return undefined;
|
|
52
|
-
const n = parseInt(raw, 10);
|
|
53
|
-
return Number.isNaN(n) ? undefined : n;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Read the daemon config the way the MCP client does — best-effort. Any missing,
|
|
57
|
-
* malformed, or unreadable config yields `{}` so token resolution falls through
|
|
58
|
-
* (issue #17). Only the well-typed fields we consume are surfaced.
|
|
59
|
-
*/
|
|
60
|
-
export function readDaemonConfig(env) {
|
|
61
|
-
try {
|
|
62
|
-
const p = JSON.parse(readFileSync(daemonConfigPath(env), 'utf8'));
|
|
63
|
-
const o = {};
|
|
64
|
-
if (typeof p.apiToken === 'string' && p.apiToken.trim())
|
|
65
|
-
o.apiToken = p.apiToken.trim();
|
|
66
|
-
if (typeof p.port === 'number' && Number.isFinite(p.port))
|
|
67
|
-
o.port = p.port;
|
|
68
|
-
if (typeof p.stateDir === 'string')
|
|
69
|
-
o.stateDir = p.stateDir;
|
|
70
|
-
return o;
|
|
71
|
-
}
|
|
72
|
-
catch {
|
|
73
|
-
return {};
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Resolve the daemon API token exactly like the MCP client (issue #17), a 3-step
|
|
78
|
-
* chain: `OURS_API_TOKEN` (trimmed) → config `apiToken` (trimmed) → the 0600 owner
|
|
79
|
-
* token at `<stateDir>/daemon-token`. Never generates a token; a failed read of
|
|
80
|
-
* any source (missing/unreadable) silently falls through to the next.
|
|
81
|
-
*/
|
|
82
|
-
export function resolveApiToken(env, file = readDaemonConfig(env)) {
|
|
83
|
-
const e = env.OURS_API_TOKEN?.trim();
|
|
84
|
-
if (e)
|
|
85
|
-
return e;
|
|
86
|
-
if (file.apiToken)
|
|
87
|
-
return file.apiToken;
|
|
88
|
-
const sd = env.OURS_STATE_DIR ?? file.stateDir ?? join(homedir(), '.ours');
|
|
89
|
-
try {
|
|
90
|
-
const t = readFileSync(join(sd, 'daemon-token'), 'utf8').trim();
|
|
91
|
-
if (t)
|
|
92
|
-
return t;
|
|
93
|
-
}
|
|
94
|
-
catch { /* missing/unreadable (e.g. cross-user 0600) → fall through */ }
|
|
95
|
-
return undefined;
|
|
96
|
-
}
|
|
97
|
-
/** Resolve the daemon endpoint + auth header from env → config → defaults. */
|
|
98
|
-
export function resolveEndpoint(env, includeToken = true) {
|
|
99
|
-
const file = readDaemonConfig(env);
|
|
100
|
-
const port = envInt(env, 'OURS_PORT') ?? file.port ?? DEFAULT_PORT;
|
|
101
|
-
const configPath = daemonConfigPath(env);
|
|
102
|
-
const stateDir = env.OURS_STATE_DIR ?? file.stateDir ?? join(homedir(), '.ours');
|
|
103
|
-
const token = includeToken ? resolveApiToken(env, file) : undefined;
|
|
104
|
-
const origin = `http://127.0.0.1:${port}`;
|
|
105
|
-
return {
|
|
106
|
-
origin,
|
|
107
|
-
port,
|
|
108
|
-
configPath,
|
|
109
|
-
stateDir,
|
|
110
|
-
url: (name) => `${origin}/identities/${encodeURIComponent(name)}/notifications`,
|
|
111
|
-
headers: token ? { 'x-ours-api-token': token } : {},
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
44
|
/**
|
|
115
45
|
* Ask the daemon's authoritative identity index. The notifications endpoint is
|
|
116
46
|
* intentionally unsuitable for lifecycle: it serves an empty 200 page for a
|
|
117
47
|
* valid but missing identity, which made a closed temp identity look healthy.
|
|
118
48
|
*/
|
|
119
49
|
export async function probeIdentityPresence(name, fetch, env, deps = {}) {
|
|
120
|
-
|
|
121
|
-
if (profile) {
|
|
122
|
-
let client;
|
|
123
|
-
try {
|
|
124
|
-
client = await (deps.attachClient?.({
|
|
125
|
-
endpoint: profile.endpoint, expectedInstanceId: profile.expectedInstanceId,
|
|
126
|
-
credentialPath: profile.credentialPath,
|
|
127
|
-
sessionMode: 'external', leaseToken: randomUUID(), env: {},
|
|
128
|
-
}) ?? attachOursClient({
|
|
129
|
-
endpoint: profile.endpoint, expectedInstanceId: profile.expectedInstanceId,
|
|
130
|
-
credentialPath: profile.credentialPath,
|
|
131
|
-
sessionMode: 'external', leaseToken: randomUUID(), env: {},
|
|
132
|
-
}));
|
|
133
|
-
return classifyIdentityPresence(name, await client.identities());
|
|
134
|
-
}
|
|
135
|
-
catch {
|
|
136
|
-
return { state: 'unknown', detail: 'selected identity index is unavailable' };
|
|
137
|
-
}
|
|
138
|
-
finally {
|
|
139
|
-
await client?.close().catch(() => undefined);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
const ep = resolveEndpoint(env);
|
|
143
|
-
let response;
|
|
50
|
+
let client;
|
|
144
51
|
try {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
if (!response.ok)
|
|
151
|
-
return {
|
|
152
|
-
state: 'unknown',
|
|
153
|
-
detail: response.status === 401
|
|
154
|
-
? `daemon rejected the API token (401) — ${authResolutionHint(ep)}`
|
|
155
|
-
: `identity index returned HTTP ${response.status}`,
|
|
52
|
+
const profile = readClientProfile(env);
|
|
53
|
+
const options = {
|
|
54
|
+
endpoint: profile.endpoint, expectedInstanceId: profile.expectedInstanceId,
|
|
55
|
+
credentialPath: profile.credentialPath,
|
|
56
|
+
sessionMode: 'external', leaseToken: randomUUID(), env: {},
|
|
156
57
|
};
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
return classifyIdentityPresence(name, body.identities);
|
|
58
|
+
client = await (deps.attachClient?.(options) ?? attachOursClient(options));
|
|
59
|
+
return classifyIdentityPresence(name, await client.identities());
|
|
160
60
|
}
|
|
161
|
-
catch
|
|
162
|
-
return { state: 'unknown', detail:
|
|
61
|
+
catch {
|
|
62
|
+
return { state: 'unknown', detail: 'gateway identity index unavailable; check the shared client profile and issued credential' };
|
|
63
|
+
}
|
|
64
|
+
finally {
|
|
65
|
+
await client?.close().catch(() => undefined);
|
|
163
66
|
}
|
|
164
67
|
}
|
|
165
68
|
function classifyIdentityPresence(name, identities) {
|
|
@@ -186,12 +89,6 @@ function classifyIdentityPresence(name, identities) {
|
|
|
186
89
|
stale: found.stale === true,
|
|
187
90
|
};
|
|
188
91
|
}
|
|
189
|
-
/** Actionable, secret-free description of every token source for this profile. */
|
|
190
|
-
export function authResolutionHint(ep) {
|
|
191
|
-
const tokenPath = join(ep.stateDir, 'daemon-token');
|
|
192
|
-
return `set OURS_API_TOKEN, set apiToken in ${JSON.stringify(ep.configPath)}, or ensure ` +
|
|
193
|
-
`${JSON.stringify(tokenPath)} is readable by the fleet supervisor`;
|
|
194
|
-
}
|
|
195
92
|
/** Keep only the events whose type the role asked to wake on. */
|
|
196
93
|
export function filterEvents(events, wakeSources) {
|
|
197
94
|
const set = new Set(wakeSources);
|
|
@@ -414,7 +311,6 @@ export class Monitor {
|
|
|
414
311
|
identity;
|
|
415
312
|
cfg;
|
|
416
313
|
deps;
|
|
417
|
-
ep;
|
|
418
314
|
profile;
|
|
419
315
|
profileKey;
|
|
420
316
|
monitorLeaseToken = `ours-fleet-monitor-${process.pid}-${randomUUID()}`;
|
|
@@ -441,8 +337,7 @@ export class Monitor {
|
|
|
441
337
|
this.cfg = o.cfg;
|
|
442
338
|
this.deps = o.deps;
|
|
443
339
|
this.profile = readClientProfile(o.deps.env);
|
|
444
|
-
this.
|
|
445
|
-
this.profileKey = this.profile ? clientProfileKey(this.profile) : this.ep.origin;
|
|
340
|
+
this.profileKey = clientProfileKey(this.profile);
|
|
446
341
|
this.statusPath = join(o.agentDir, '.monitor-status');
|
|
447
342
|
this.cursorPath = join(o.agentDir, '.notify-cursor');
|
|
448
343
|
this.statePath = join(o.agentDir, '.monitor-state.json');
|
|
@@ -470,14 +365,8 @@ export class Monitor {
|
|
|
470
365
|
}
|
|
471
366
|
catch (e) {
|
|
472
367
|
if (e instanceof AuthError) {
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
this.degrade('auth', e.message);
|
|
476
|
-
}
|
|
477
|
-
else {
|
|
478
|
-
this.fatal = true;
|
|
479
|
-
this.degrade('auth', e.message, 'failed');
|
|
480
|
-
}
|
|
368
|
+
this.cursor = null;
|
|
369
|
+
this.degrade('auth', e.message);
|
|
481
370
|
}
|
|
482
371
|
else {
|
|
483
372
|
this.cursor = null;
|
|
@@ -510,11 +399,6 @@ export class Monitor {
|
|
|
510
399
|
catch (e) {
|
|
511
400
|
if (this.stopped)
|
|
512
401
|
return;
|
|
513
|
-
if (e instanceof AuthError && !this.profile) {
|
|
514
|
-
this.fatal = true;
|
|
515
|
-
this.degrade('auth', e.message, 'failed');
|
|
516
|
-
return;
|
|
517
|
-
}
|
|
518
402
|
backoff = Math.min(backoff + BACKOFF_STEP_MS, BACKOFF_MAX_MS);
|
|
519
403
|
if (e instanceof AuthError)
|
|
520
404
|
this.degrade('auth', e.message);
|
|
@@ -630,23 +514,19 @@ export class Monitor {
|
|
|
630
514
|
this.currentAbort = ctrl;
|
|
631
515
|
let timedOut = false;
|
|
632
516
|
const timer = this.deps.timers.set(() => { timedOut = true; ctrl.abort(); }, timeoutMs);
|
|
633
|
-
let resp;
|
|
634
517
|
try {
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
return { cursor: page.cursor, events: page.events };
|
|
643
|
-
}
|
|
644
|
-
resp = await this.deps.fetch(`${this.ep.url(this.identity)}?since=${since}`, { headers: this.ep.headers, signal: ctrl.signal });
|
|
518
|
+
const client = await this.profileClient();
|
|
519
|
+
const page = await client.readNotificationPage(this.identity, {
|
|
520
|
+
since: since === 'tip' ? 'tip' : Number.parseInt(since, 10),
|
|
521
|
+
signal: ctrl.signal,
|
|
522
|
+
requestTimeoutMs: timeoutMs,
|
|
523
|
+
});
|
|
524
|
+
return { cursor: page.cursor, events: page.events };
|
|
645
525
|
}
|
|
646
526
|
catch (error) {
|
|
647
527
|
if (timedOut && timeoutKind === 'stall')
|
|
648
528
|
throw new Error(`notification stream stalled for ${Math.round(timeoutMs / 1000)}s`);
|
|
649
|
-
if (
|
|
529
|
+
if (/(?:HTTP\s*401|unauthori[sz]ed|API token)/i.test(msg(error)))
|
|
650
530
|
throw new AuthError(`daemon rejected the API token (401) — verify the credential file `
|
|
651
531
|
+ `${JSON.stringify(this.profile.credentialPath)} selected by `
|
|
652
532
|
+ `${JSON.stringify(this.profile.configPath)}`);
|
|
@@ -656,15 +536,8 @@ export class Monitor {
|
|
|
656
536
|
this.deps.timers.clear(timer);
|
|
657
537
|
this.currentAbort = null;
|
|
658
538
|
}
|
|
659
|
-
if (resp.status === 401)
|
|
660
|
-
throw new AuthError(`daemon rejected the API token (401) — ${authResolutionHint(this.ep)}`);
|
|
661
|
-
if (!resp.ok)
|
|
662
|
-
throw new Error(`daemon returned HTTP ${resp.status}`);
|
|
663
|
-
return resp.json();
|
|
664
539
|
}
|
|
665
540
|
profileClient() {
|
|
666
|
-
if (!this.profile)
|
|
667
|
-
throw new Error('explicit client profile is not selected');
|
|
668
541
|
if (!this.profileClientPromise) {
|
|
669
542
|
const { endpoint, expectedInstanceId, credentialPath } = this.profile;
|
|
670
543
|
const options = {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type ProducerConfig } from './outbox.js';
|
|
2
|
+
/** Read durable supervisor ledgers without restarting agents or attaching a
|
|
3
|
+
* conversation controller. Each tick reads at most 256 KiB per role, from its
|
|
4
|
+
* checkpoint; it never loads a complete transcript or requests model history. */
|
|
5
|
+
export declare class FleetNotificationProducer {
|
|
6
|
+
private readonly roots;
|
|
7
|
+
private readonly stateDir;
|
|
8
|
+
private readonly config;
|
|
9
|
+
private readonly warn;
|
|
10
|
+
private readonly queues;
|
|
11
|
+
private readonly timer;
|
|
12
|
+
private readonly existing;
|
|
13
|
+
private cleanup?;
|
|
14
|
+
constructor(roots: string[], stateDir: string, config: ProducerConfig, warn?: (line: string) => void);
|
|
15
|
+
private names;
|
|
16
|
+
poll(): void;
|
|
17
|
+
drain(): Promise<void>;
|
|
18
|
+
close(): Promise<void>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { roomsDir } from '../rooms-tasks/room-state.js';
|
|
2
|
+
import { drainNotificationTargetCleanup } from './target-cleanup.js';
|
|
3
|
+
import { closeSync, existsSync, lstatSync, openSync, readSync, readFileSync, readdirSync, statSync } from 'node:fs';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { createHash } from 'node:crypto';
|
|
6
|
+
import { NotificationOutbox } from './outbox.js';
|
|
7
|
+
/** Unlike a UI inventory, unread classification must not treat unreadable records as absence. */
|
|
8
|
+
function taskRoleAssociations() {
|
|
9
|
+
const dir = roomsDir(), result = new Map();
|
|
10
|
+
let files;
|
|
11
|
+
try {
|
|
12
|
+
files = readdirSync(dir);
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
if (error.code === 'ENOENT')
|
|
16
|
+
return result;
|
|
17
|
+
throw error;
|
|
18
|
+
}
|
|
19
|
+
for (const name of files.filter(name => name.endsWith('.json'))) {
|
|
20
|
+
const file = join(dir, name), stat = lstatSync(file);
|
|
21
|
+
if (!stat.isFile() || stat.isSymbolicLink() || stat.size > 1024 * 1024)
|
|
22
|
+
throw Error('Unreadable room association');
|
|
23
|
+
const room = JSON.parse(readFileSync(file, 'utf8'));
|
|
24
|
+
if (!room || typeof room.room_id !== 'string' || !Array.isArray(room.member_seats))
|
|
25
|
+
throw Error('Invalid room association');
|
|
26
|
+
if (room.task_id === undefined)
|
|
27
|
+
continue;
|
|
28
|
+
if (typeof room.task_id !== 'string' || !/^[A-Za-z0-9_-]{1,120}$/.test(room.task_id))
|
|
29
|
+
throw Error('Invalid task association');
|
|
30
|
+
for (const seat of room.member_seats) {
|
|
31
|
+
if (typeof seat.role_name !== 'string')
|
|
32
|
+
throw Error('Invalid member association');
|
|
33
|
+
if (result.has(seat.role_name) && result.get(seat.role_name) !== room.task_id)
|
|
34
|
+
throw Error('Ambiguous task association');
|
|
35
|
+
result.set(seat.role_name, room.task_id);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
/** Read durable supervisor ledgers without restarting agents or attaching a
|
|
41
|
+
* conversation controller. Each tick reads at most 256 KiB per role, from its
|
|
42
|
+
* checkpoint; it never loads a complete transcript or requests model history. */
|
|
43
|
+
export class FleetNotificationProducer {
|
|
44
|
+
roots;
|
|
45
|
+
stateDir;
|
|
46
|
+
config;
|
|
47
|
+
warn;
|
|
48
|
+
queues = new Map();
|
|
49
|
+
timer;
|
|
50
|
+
existing = new Set();
|
|
51
|
+
cleanup;
|
|
52
|
+
constructor(roots, stateDir, config, warn = () => { }) {
|
|
53
|
+
this.roots = roots;
|
|
54
|
+
this.stateDir = stateDir;
|
|
55
|
+
this.config = config;
|
|
56
|
+
this.warn = warn;
|
|
57
|
+
for (const root of roots)
|
|
58
|
+
for (const name of this.names(root))
|
|
59
|
+
this.existing.add(join(root, name));
|
|
60
|
+
this.poll();
|
|
61
|
+
this.timer = setInterval(() => this.poll(), 1000);
|
|
62
|
+
this.timer.unref();
|
|
63
|
+
}
|
|
64
|
+
names(root) {
|
|
65
|
+
try {
|
|
66
|
+
return readdirSync(root, { withFileTypes: true }).filter(d => d.isDirectory() && /^[a-zA-Z0-9_-]+$/.test(d.name)).map(d => d.name);
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return [];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
poll() {
|
|
73
|
+
this.cleanup ??= drainNotificationTargetCleanup(this.config, undefined, undefined, { beforeDelete: async (url) => {
|
|
74
|
+
const name = new URL(url, 'https://ours.invalid').searchParams.get('chat');
|
|
75
|
+
if (!name || !/^[A-Za-z0-9_-]+$/.test(name))
|
|
76
|
+
return false;
|
|
77
|
+
// A recreated or retained role still has a valid target. Filesystem errors cannot prove removal.
|
|
78
|
+
for (const root of this.roots) {
|
|
79
|
+
try {
|
|
80
|
+
lstatSync(join(root, name));
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
if (error.code !== 'ENOENT')
|
|
85
|
+
throw error;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
for (const root of this.roots) {
|
|
89
|
+
const roleDir = join(root, name), queue = this.queues.get(roleDir);
|
|
90
|
+
if (queue) {
|
|
91
|
+
await queue.retire();
|
|
92
|
+
this.queues.delete(roleDir);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
const file = join(this.stateDir, createHash('sha256').update(roleDir).digest('hex') + '.json');
|
|
96
|
+
if (existsSync(file)) {
|
|
97
|
+
const queue = new NotificationOutbox(file, this.config, async () => { throw Error('retired target'); });
|
|
98
|
+
try {
|
|
99
|
+
await queue.retire();
|
|
100
|
+
}
|
|
101
|
+
finally {
|
|
102
|
+
await queue.close();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return true;
|
|
108
|
+
} }).catch(() => { }).finally(() => { this.cleanup = undefined; });
|
|
109
|
+
let taskRoles;
|
|
110
|
+
try {
|
|
111
|
+
taskRoles = taskRoleAssociations();
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
this.warn('Notification task association unavailable; delivering unclassified events');
|
|
115
|
+
}
|
|
116
|
+
for (const root of this.roots)
|
|
117
|
+
for (const roleId of this.names(root)) {
|
|
118
|
+
const roleDir = join(root, roleId), dir = join(roleDir, '.conversation');
|
|
119
|
+
try {
|
|
120
|
+
if (!existsSync(dir) || lstatSync(dir).isSymbolicLink())
|
|
121
|
+
continue;
|
|
122
|
+
const segments = readdirSync(dir).filter(n => /^events-\d{6}\.jsonl$/.test(n) && !lstatSync(join(dir, n)).isSymbolicLink()).sort();
|
|
123
|
+
if (!segments.length)
|
|
124
|
+
continue;
|
|
125
|
+
let outbox = this.queues.get(roleDir);
|
|
126
|
+
if (!outbox) {
|
|
127
|
+
const key = createHash('sha256').update(roleDir).digest('hex');
|
|
128
|
+
outbox = new NotificationOutbox(join(this.stateDir, key + '.json'), this.config, async (value, eventId) => ({ eventId, title: `${roleId}: agent completed`, body: 'Your agent finished responding. Open the chat to view the result.',
|
|
129
|
+
url: `/fleet/chats?chat=${encodeURIComponent(roleId)}&detail=1`, ...value }), this.warn);
|
|
130
|
+
if (!outbox.checkpoint) {
|
|
131
|
+
const segment = this.existing.has(roleDir) ? segments.at(-1) : segments[0];
|
|
132
|
+
outbox.saveCheckpoint({ segment, offset: this.existing.has(roleDir) ? statSync(join(dir, segment)).size : 0, prompts: [] });
|
|
133
|
+
}
|
|
134
|
+
this.queues.set(roleDir, outbox);
|
|
135
|
+
}
|
|
136
|
+
const saved = outbox.checkpoint;
|
|
137
|
+
const current = { ...saved, prompts: [...saved.prompts], messages: { ...saved.messages } };
|
|
138
|
+
let index = segments.indexOf(current.segment);
|
|
139
|
+
if (index < 0) {
|
|
140
|
+
this.warn('Notification ledger segment unavailable; checkpoint retained');
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
const file = join(dir, current.segment), size = statSync(file).size;
|
|
144
|
+
if (size < current.offset) {
|
|
145
|
+
this.warn('Notification ledger truncated; checkpoint retained');
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
if (size === current.offset && index < segments.length - 1) {
|
|
149
|
+
current.segment = segments[++index];
|
|
150
|
+
current.offset = 0;
|
|
151
|
+
}
|
|
152
|
+
const fd = openSync(join(dir, current.segment), 'r'), buffer = Buffer.alloc(256 * 1024);
|
|
153
|
+
let count;
|
|
154
|
+
try {
|
|
155
|
+
count = readSync(fd, buffer, 0, buffer.length, current.offset);
|
|
156
|
+
}
|
|
157
|
+
finally {
|
|
158
|
+
closeSync(fd);
|
|
159
|
+
}
|
|
160
|
+
let position = 0;
|
|
161
|
+
while (position < count) {
|
|
162
|
+
const end = buffer.indexOf(10, position);
|
|
163
|
+
if (end < 0 || end >= count) {
|
|
164
|
+
// Oversized model/media events are irrelevant to prompt/completion
|
|
165
|
+
// correlation. Skip in bounded chunks; retain partial small lines.
|
|
166
|
+
if (current.discarding || (position === 0 && count === buffer.length)) {
|
|
167
|
+
current.offset += count - position;
|
|
168
|
+
current.discarding = true;
|
|
169
|
+
this.warn('Notification observer skipping oversized ledger record');
|
|
170
|
+
}
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
if (current.discarding) {
|
|
174
|
+
current.offset += end - position + 1;
|
|
175
|
+
position = end + 1;
|
|
176
|
+
current.discarding = false;
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
const event = JSON.parse(buffer.subarray(position, end).toString('utf8'));
|
|
180
|
+
if (event.schemaVersion !== 1 || event.roleId !== roleId)
|
|
181
|
+
throw new Error('invalid ledger event');
|
|
182
|
+
const prompt = `${event.sessionGeneration}:${event.promptId}`;
|
|
183
|
+
if (event.kind === 'prompt.admitted' && event.promptId && ['browser', 'owner_admin_console', 'owner_channel'].includes(event.source ?? '')) {
|
|
184
|
+
if (!current.prompts.includes(prompt))
|
|
185
|
+
current.prompts.push(prompt);
|
|
186
|
+
}
|
|
187
|
+
if (['message.chunk', 'message.replace'].includes(event.kind) && event.promptId && event.messageId && current.prompts.includes(prompt))
|
|
188
|
+
current.messages[prompt] = event.messageId;
|
|
189
|
+
if (event.kind === 'turn.completed' && event.promptId && current.prompts.includes(prompt)) {
|
|
190
|
+
if (!outbox.enqueue(`${roleId}:${event.sessionGeneration}:${event.seq}`, { ...(taskRoles ? { taskId: taskRoles.get(roleId) ?? null } : {}), url: `/fleet/chats?chat=${encodeURIComponent(roleId)}&detail=1#fleet-message-${encodeURIComponent(current.messages[prompt] ?? event.promptId)}` }))
|
|
191
|
+
break;
|
|
192
|
+
current.prompts = current.prompts.filter(p => p !== prompt);
|
|
193
|
+
delete current.messages[prompt];
|
|
194
|
+
}
|
|
195
|
+
current.offset += end - position + 1;
|
|
196
|
+
position = end + 1;
|
|
197
|
+
}
|
|
198
|
+
if (current.segment !== saved.segment || current.offset !== saved.offset)
|
|
199
|
+
outbox.saveCheckpoint(current);
|
|
200
|
+
}
|
|
201
|
+
catch {
|
|
202
|
+
this.warn('Notification ledger admission pending; checkpoint will replay');
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
async drain() { await Promise.all([...this.queues.values()].map(q => q.drain())); }
|
|
207
|
+
async close() { clearInterval(this.timer); await this.cleanup; await Promise.all([...this.queues.values()].map(q => q.close())); }
|
|
208
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export interface NotificationInput {
|
|
2
|
+
eventId: string;
|
|
3
|
+
title: string;
|
|
4
|
+
body: string;
|
|
5
|
+
url: string;
|
|
6
|
+
taskId?: string | null;
|
|
7
|
+
}
|
|
8
|
+
export interface ProducerConfig {
|
|
9
|
+
/** Service base URL. With a gateway credential it is the server gateway's notifications route. */
|
|
10
|
+
origin: string;
|
|
11
|
+
token: string;
|
|
12
|
+
/** Daemon API credential that authenticates this client to the server gateway. */
|
|
13
|
+
gatewayCredential?: string;
|
|
14
|
+
}
|
|
15
|
+
type ProfileLocation = {
|
|
16
|
+
serverUrl: string;
|
|
17
|
+
expectedInstanceId: string;
|
|
18
|
+
credentialPath: string;
|
|
19
|
+
};
|
|
20
|
+
/** The installer delivers the producer credential beside the profile credential, bound to that server installation. */
|
|
21
|
+
export declare const PRODUCER_CREDENTIAL_FILE = "notifications-producer.json";
|
|
22
|
+
export declare function producerConfig(env?: NodeJS.ProcessEnv, profile?: () => ProfileLocation | undefined, warn?: (message: string) => void): ProducerConfig | undefined;
|
|
23
|
+
/** Durable producer queue. Service dedupe makes crash-after-acceptance replay safe. */
|
|
24
|
+
export declare class NotificationOutbox {
|
|
25
|
+
private readonly file;
|
|
26
|
+
private readonly config;
|
|
27
|
+
private readonly project;
|
|
28
|
+
private readonly warn;
|
|
29
|
+
private entries;
|
|
30
|
+
cursor?: number;
|
|
31
|
+
checkpoint?: unknown;
|
|
32
|
+
private running?;
|
|
33
|
+
private retired;
|
|
34
|
+
private timer;
|
|
35
|
+
constructor(file: string, config: ProducerConfig, project: (value: unknown, id: string) => Promise<NotificationInput>, warn?: (message: string) => void);
|
|
36
|
+
private persist;
|
|
37
|
+
advance(cursor: number): void;
|
|
38
|
+
saveCheckpoint(checkpoint: unknown): void;
|
|
39
|
+
enqueue(id: string, value: unknown, cursor?: number | undefined): boolean;
|
|
40
|
+
drain(): Promise<void>;
|
|
41
|
+
private drainOnce;
|
|
42
|
+
/** Wait for the current send before clearing queued sends and retiring its target. */
|
|
43
|
+
retire(): Promise<void>;
|
|
44
|
+
close(): Promise<void>;
|
|
45
|
+
}
|
|
46
|
+
export {};
|