@ouro.bot/cli 0.1.0-alpha.5 → 0.1.0-alpha.500
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 +226 -183
- package/SerpentGuide.ouro/agent.json +82 -0
- package/SerpentGuide.ouro/psyche/SOUL.md +25 -0
- package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/monty.md +2 -2
- package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/the-serpent.md +1 -1
- package/assets/ouroboros.png +0 -0
- package/changelog.json +3418 -0
- package/dist/arc/attention-types.js +8 -0
- package/dist/arc/cares.js +140 -0
- package/dist/arc/episodes.js +117 -0
- package/dist/arc/intentions.js +133 -0
- package/dist/arc/json-store.js +117 -0
- package/dist/arc/obligations.js +237 -0
- package/dist/arc/packets.js +193 -0
- package/dist/arc/presence.js +185 -0
- package/dist/arc/task-lifecycle.js +65 -0
- package/dist/heart/active-work.js +989 -0
- package/dist/heart/agent-entry.js +58 -3
- package/dist/heart/attachments/image-normalize.js +194 -0
- package/dist/heart/attachments/materialize.js +97 -0
- package/dist/heart/attachments/originals.js +88 -0
- package/dist/heart/attachments/render.js +29 -0
- package/dist/heart/attachments/sources/adapter.js +2 -0
- package/dist/heart/attachments/sources/bluebubbles.js +156 -0
- package/dist/heart/attachments/sources/cli-local-file.js +78 -0
- package/dist/heart/attachments/sources/index.js +16 -0
- package/dist/heart/attachments/store.js +103 -0
- package/dist/heart/attachments/types.js +93 -0
- package/dist/heart/auth/auth-flow.js +426 -0
- package/dist/heart/background-operations.js +281 -0
- package/dist/heart/bridges/manager.js +358 -0
- package/dist/heart/bridges/state-machine.js +135 -0
- package/dist/heart/bridges/store.js +123 -0
- package/dist/heart/bundle-state.js +168 -0
- package/dist/heart/commitments.js +111 -0
- package/dist/heart/config-registry.js +304 -0
- package/dist/heart/config.js +193 -130
- package/dist/heart/core.js +1010 -261
- package/dist/heart/cross-chat-delivery.js +131 -0
- package/dist/heart/daemon/agent-config-check.js +490 -0
- package/dist/heart/daemon/agent-discovery.js +157 -0
- package/dist/heart/daemon/agent-service.js +360 -0
- package/dist/heart/daemon/agentic-repair.js +216 -0
- package/dist/heart/daemon/bluebubbles-health-diagnostics.js +122 -0
- package/dist/heart/daemon/cadence.js +70 -0
- package/dist/heart/daemon/cli-defaults.js +640 -0
- package/dist/heart/daemon/cli-exec.js +7239 -0
- package/dist/heart/daemon/cli-help.js +493 -0
- package/dist/heart/daemon/cli-parse.js +1533 -0
- package/dist/heart/daemon/cli-render-doctor.js +57 -0
- package/dist/heart/daemon/cli-render.js +561 -0
- package/dist/heart/daemon/cli-types.js +8 -0
- package/dist/heart/daemon/connect-bay.js +323 -0
- package/dist/heart/daemon/daemon-cli.js +30 -697
- package/dist/heart/daemon/daemon-entry.js +359 -8
- package/dist/heart/daemon/daemon-health.js +141 -0
- package/dist/heart/daemon/daemon-runtime-sync.js +268 -0
- package/dist/heart/daemon/daemon-tombstone.js +236 -0
- package/dist/heart/daemon/daemon.js +813 -19
- package/dist/heart/daemon/dns-workflow.js +394 -0
- package/dist/heart/daemon/doctor-types.js +8 -0
- package/dist/heart/daemon/doctor.js +615 -0
- package/dist/heart/daemon/health-monitor.js +92 -1
- package/dist/heart/daemon/hooks/agent-config-v2.js +33 -0
- package/dist/heart/daemon/hooks/bundle-meta.js +206 -0
- package/dist/heart/daemon/http-health-probe.js +80 -0
- package/dist/heart/daemon/human-command-screens.js +234 -0
- package/dist/heart/daemon/human-readiness.js +114 -0
- package/dist/heart/daemon/inner-status.js +89 -0
- package/dist/heart/daemon/interactive-repair.js +394 -0
- package/dist/heart/daemon/launchd.js +171 -0
- package/dist/heart/daemon/log-tailer.js +82 -12
- package/dist/heart/daemon/logs-prune.js +110 -0
- package/dist/heart/daemon/message-router.js +17 -8
- package/dist/heart/daemon/os-cron-deps.js +134 -0
- package/dist/heart/daemon/ouro-bot-entry.js +4 -2
- package/dist/heart/daemon/ouro-entry.js +3 -1
- package/dist/heart/daemon/process-manager.js +215 -1
- package/dist/heart/daemon/provider-discovery.js +137 -0
- package/dist/heart/daemon/provider-ping-progress.js +83 -0
- package/dist/heart/daemon/pulse.js +475 -0
- package/dist/heart/daemon/readiness-repair.js +365 -0
- package/dist/heart/daemon/run-hooks.js +39 -0
- package/dist/heart/daemon/runtime-logging.js +67 -16
- package/dist/heart/daemon/runtime-metadata.js +191 -0
- package/dist/heart/daemon/runtime-mode.js +67 -0
- package/dist/heart/daemon/safe-mode.js +161 -0
- package/dist/heart/daemon/sense-manager.js +431 -0
- package/dist/heart/daemon/session-id-resolver.js +131 -0
- package/dist/heart/daemon/skill-management-installer.js +94 -0
- package/dist/heart/daemon/socket-client.js +307 -0
- package/dist/heart/daemon/stale-bundle-prune.js +96 -0
- package/dist/heart/daemon/startup-tui.js +264 -0
- package/dist/heart/daemon/task-scheduler.js +3 -25
- package/dist/heart/daemon/terminal-ui.js +499 -0
- package/dist/heart/daemon/thoughts.js +524 -0
- package/dist/heart/daemon/up-progress.js +366 -0
- package/dist/heart/daemon/vault-items.js +56 -0
- package/dist/heart/delegation.js +62 -0
- package/dist/heart/habits/habit-migration.js +189 -0
- package/dist/heart/habits/habit-parser.js +140 -0
- package/dist/heart/habits/habit-runtime-state.js +100 -0
- package/dist/heart/habits/habit-scheduler.js +372 -0
- package/dist/heart/{daemon → hatch}/hatch-animation.js +10 -3
- package/dist/heart/{daemon → hatch}/hatch-flow.js +54 -136
- package/dist/heart/{daemon → hatch}/hatch-specialist.js +3 -3
- package/dist/heart/hatch/specialist-orchestrator.js +129 -0
- package/dist/heart/hatch/specialist-prompt.js +102 -0
- package/dist/heart/hatch/specialist-tools.js +306 -0
- package/dist/heart/identity.js +274 -61
- package/dist/heart/kept-notes.js +357 -0
- package/dist/heart/kicks.js +2 -20
- package/dist/heart/machine-identity.js +161 -0
- package/dist/heart/mail-import-discovery.js +353 -0
- package/dist/heart/mcp/mcp-server.js +653 -0
- package/dist/heart/migrate-config.js +100 -0
- package/dist/heart/model-capabilities.js +59 -0
- package/dist/heart/outlook/outlook-http-hooks.js +66 -0
- package/dist/heart/outlook/outlook-http-response.js +7 -0
- package/dist/heart/outlook/outlook-http-routes.js +244 -0
- package/dist/heart/outlook/outlook-http-static.js +103 -0
- package/dist/heart/outlook/outlook-http-transport.js +116 -0
- package/dist/heart/outlook/outlook-http.js +99 -0
- package/dist/heart/outlook/outlook-read.js +31 -0
- package/dist/heart/outlook/outlook-types.js +27 -0
- package/dist/heart/outlook/outlook-view.js +195 -0
- package/dist/heart/outlook/readers/agent-machine.js +382 -0
- package/dist/heart/outlook/readers/continuity-readers.js +336 -0
- package/dist/heart/outlook/readers/mail.js +362 -0
- package/dist/heart/outlook/readers/runtime-readers.js +644 -0
- package/dist/heart/outlook/readers/sessions.js +232 -0
- package/dist/heart/outlook/readers/shared.js +111 -0
- package/dist/heart/platform.js +81 -0
- package/dist/heart/progress-story.js +42 -0
- package/dist/heart/provider-attempt.js +134 -0
- package/dist/heart/provider-binding-resolver.js +255 -0
- package/dist/heart/provider-credentials.js +424 -0
- package/dist/heart/provider-failover.js +301 -0
- package/dist/heart/provider-models.js +81 -0
- package/dist/heart/provider-ping.js +262 -0
- package/dist/heart/provider-state.js +216 -0
- package/dist/heart/provider-visibility.js +188 -0
- package/dist/heart/providers/anthropic-token.js +131 -0
- package/dist/heart/providers/anthropic.js +202 -50
- package/dist/heart/providers/azure.js +104 -13
- package/dist/heart/providers/error-classification.js +63 -0
- package/dist/heart/providers/github-copilot.js +145 -0
- package/dist/heart/providers/minimax-vlm.js +189 -0
- package/dist/heart/providers/minimax.js +29 -7
- package/dist/heart/providers/openai-codex.js +63 -39
- package/dist/heart/runtime-capability-check.js +170 -0
- package/dist/heart/runtime-credentials.js +260 -0
- package/dist/heart/sense-truth.js +68 -0
- package/dist/heart/session-activity.js +190 -0
- package/dist/heart/session-events.js +1089 -0
- package/dist/heart/session-playback-cli-main.js +5 -0
- package/dist/heart/session-playback-cli.js +36 -0
- package/dist/heart/session-playback.js +231 -0
- package/dist/heart/session-transcript.js +167 -0
- package/dist/heart/start-of-turn-packet.js +345 -0
- package/dist/heart/streaming.js +129 -34
- package/dist/heart/sync.js +332 -0
- package/dist/heart/target-resolution.js +127 -0
- package/dist/heart/tempo.js +93 -0
- package/dist/heart/temporal-view.js +41 -0
- package/dist/heart/tool-activity-callbacks.js +36 -0
- package/dist/heart/tool-description.js +135 -0
- package/dist/heart/tool-friction.js +55 -0
- package/dist/heart/tool-loop.js +200 -0
- package/dist/heart/turn-context.js +372 -0
- package/dist/heart/turn-coordinator.js +28 -0
- package/dist/heart/versioning/ouro-bot-global-installer.js +128 -0
- package/dist/heart/{daemon → versioning}/ouro-bot-wrapper.js +1 -1
- package/dist/heart/versioning/ouro-path-installer.js +425 -0
- package/dist/heart/{daemon → versioning}/ouro-uti.js +11 -2
- package/dist/heart/versioning/ouro-version-manager.js +295 -0
- package/dist/heart/versioning/staged-restart.js +146 -0
- package/dist/heart/versioning/update-checker.js +115 -0
- package/dist/heart/versioning/update-hooks.js +142 -0
- package/dist/heart/versioning/wrapper-publish-guard.js +86 -0
- package/dist/mailroom/attention.js +167 -0
- package/dist/mailroom/autonomy.js +209 -0
- package/dist/mailroom/blob-store.js +606 -0
- package/dist/mailroom/core.js +672 -0
- package/dist/mailroom/entry.js +160 -0
- package/dist/mailroom/file-store.js +426 -0
- package/dist/mailroom/mbox-import.js +382 -0
- package/dist/mailroom/outbound.js +380 -0
- package/dist/mailroom/policy.js +263 -0
- package/dist/mailroom/reader.js +219 -0
- package/dist/mailroom/search-cache.js +182 -0
- package/dist/mailroom/search-relevance.js +319 -0
- package/dist/mailroom/smtp-ingress.js +176 -0
- package/dist/mailroom/source-state.js +176 -0
- package/dist/mailroom/thread.js +109 -0
- package/dist/mailroom/travel-extract.js +89 -0
- package/dist/mind/bundle-manifest.js +77 -1
- package/dist/mind/context.js +173 -94
- package/dist/mind/diary-integrity.js +60 -0
- package/dist/mind/{memory.js → diary.js} +84 -96
- package/dist/mind/embedding-provider.js +60 -0
- package/dist/mind/file-state.js +179 -0
- package/dist/mind/first-impressions.js +16 -2
- package/dist/mind/friends/channel.js +73 -0
- package/dist/mind/friends/group-context.js +144 -0
- package/dist/mind/friends/resolver.js +54 -2
- package/dist/mind/friends/store-file.js +58 -3
- package/dist/mind/friends/trust-explanation.js +74 -0
- package/dist/mind/friends/types.js +10 -2
- package/dist/mind/journal-index.js +161 -0
- package/dist/mind/note-search.js +268 -0
- package/dist/mind/obligation-steering.js +221 -0
- package/dist/mind/pending.js +76 -9
- package/dist/mind/phrases.js +1 -0
- package/dist/mind/prompt-refresh.js +3 -2
- package/dist/mind/prompt.js +1144 -117
- package/dist/mind/provenance-trust.js +26 -0
- package/dist/mind/scrutiny.js +173 -0
- package/dist/mind/token-estimate.js +8 -12
- package/dist/nerves/cli-logging.js +22 -3
- package/dist/nerves/coverage/audit-rules.js +15 -6
- package/dist/nerves/coverage/audit.js +28 -2
- package/dist/nerves/coverage/cli.js +1 -1
- package/dist/nerves/coverage/contract.js +5 -5
- package/dist/nerves/coverage/file-completeness.js +101 -5
- package/dist/nerves/coverage/run-artifacts.js +1 -1
- package/dist/nerves/event-buffer.js +111 -0
- package/dist/nerves/index.js +224 -4
- package/dist/nerves/observation.js +20 -0
- package/dist/nerves/redact.js +79 -0
- package/dist/nerves/runtime.js +5 -1
- package/dist/outlook-ui/assets/index-BPr5vNuM.css +1 -0
- package/dist/outlook-ui/assets/index-Cm51CY9W.js +61 -0
- package/dist/outlook-ui/index.html +15 -0
- package/dist/repertoire/ado-client.js +17 -56
- package/dist/repertoire/ado-semantic.js +11 -10
- package/dist/repertoire/api-client.js +97 -0
- package/dist/repertoire/bitwarden-store.js +774 -0
- package/dist/repertoire/bundle-templates.js +72 -0
- package/dist/repertoire/bw-installer.js +180 -0
- package/dist/repertoire/coding/codex-jsonl.js +64 -0
- package/dist/repertoire/coding/context-pack.js +330 -0
- package/dist/repertoire/coding/feedback.js +301 -0
- package/dist/repertoire/coding/index.js +4 -1
- package/dist/repertoire/coding/manager.js +220 -13
- package/dist/repertoire/coding/spawner.js +58 -12
- package/dist/repertoire/coding/tools.js +209 -7
- package/dist/repertoire/commerce-errors.js +109 -0
- package/dist/repertoire/commerce-self-test.js +156 -0
- package/dist/repertoire/credential-access.js +111 -0
- package/dist/repertoire/data/ado-endpoints.json +188 -0
- package/dist/repertoire/duffel-client.js +185 -0
- package/dist/repertoire/github-client.js +14 -55
- package/dist/repertoire/graph-client.js +11 -52
- package/dist/repertoire/guardrails.js +396 -0
- package/dist/repertoire/mcp-client.js +255 -0
- package/dist/repertoire/mcp-manager.js +305 -0
- package/dist/repertoire/mcp-tools.js +63 -0
- package/dist/repertoire/shell-sessions.js +133 -0
- package/dist/repertoire/skills.js +15 -24
- package/dist/repertoire/stripe-client.js +131 -0
- package/dist/repertoire/tasks/board.js +43 -5
- package/dist/repertoire/tasks/fix.js +182 -0
- package/dist/repertoire/tasks/index.js +39 -13
- package/dist/repertoire/tasks/lifecycle.js +2 -2
- package/dist/repertoire/tasks/parser.js +3 -2
- package/dist/repertoire/tasks/scanner.js +194 -37
- package/dist/repertoire/tasks/transitions.js +16 -79
- package/dist/repertoire/tool-results.js +29 -0
- package/dist/repertoire/tools-attachments.js +317 -0
- package/dist/repertoire/tools-base.js +49 -707
- package/dist/repertoire/tools-bluebubbles.js +94 -0
- package/dist/repertoire/tools-bridge.js +141 -0
- package/dist/repertoire/tools-bundle.js +984 -0
- package/dist/repertoire/tools-config.js +185 -0
- package/dist/repertoire/tools-continuity.js +248 -0
- package/dist/repertoire/tools-credential.js +381 -0
- package/dist/repertoire/tools-files.js +342 -0
- package/dist/repertoire/tools-flight.js +224 -0
- package/dist/repertoire/tools-flow.js +105 -0
- package/dist/repertoire/tools-github.js +1 -7
- package/dist/repertoire/tools-mail.js +1377 -0
- package/dist/repertoire/tools-notes.js +376 -0
- package/dist/repertoire/tools-session.js +749 -0
- package/dist/repertoire/tools-shell.js +120 -0
- package/dist/repertoire/tools-stripe.js +180 -0
- package/dist/repertoire/tools-surface.js +243 -0
- package/dist/repertoire/tools-teams.js +64 -61
- package/dist/repertoire/tools-travel.js +125 -0
- package/dist/repertoire/tools-trip.js +356 -0
- package/dist/repertoire/tools-user-profile.js +144 -0
- package/dist/repertoire/tools-vault.js +40 -0
- package/dist/repertoire/tools.js +149 -98
- package/dist/repertoire/travel-api-client.js +360 -0
- package/dist/repertoire/user-profile.js +131 -0
- package/dist/repertoire/vault-setup.js +246 -0
- package/dist/repertoire/vault-unlock.js +561 -0
- package/dist/scripts/claude-code-hook.js +41 -0
- package/dist/scripts/claude-code-stop-hook.js +47 -0
- package/dist/senses/attention-queue.js +116 -0
- package/dist/senses/bluebubbles/attachment-cache.js +53 -0
- package/dist/senses/bluebubbles/attachment-download.js +137 -0
- package/dist/senses/bluebubbles/client.js +685 -0
- package/dist/senses/bluebubbles/entry.js +73 -0
- package/dist/senses/bluebubbles/inbound-log.js +126 -0
- package/dist/senses/bluebubbles/index.js +1881 -0
- package/dist/senses/bluebubbles/media.js +389 -0
- package/dist/senses/bluebubbles/model.js +282 -0
- package/dist/senses/bluebubbles/mutation-log.js +116 -0
- package/dist/senses/bluebubbles/processed-log.js +111 -0
- package/dist/senses/bluebubbles/replay.js +129 -0
- package/dist/senses/bluebubbles/runtime-state.js +109 -0
- package/dist/senses/bluebubbles/session-cleanup.js +72 -0
- package/dist/senses/cli/bracketed-paste.js +82 -0
- package/dist/senses/cli/image-paste.js +287 -0
- package/dist/senses/cli/image-ref-navigation.js +75 -0
- package/dist/senses/cli/ink-app.js +156 -0
- package/dist/senses/cli/inline-diff.js +64 -0
- package/dist/senses/cli/input-keys.js +174 -0
- package/dist/senses/cli/kill-ring.js +86 -0
- package/dist/senses/cli/message-list.js +51 -0
- package/dist/senses/cli/ouro-tui.js +605 -0
- package/dist/senses/cli/spinner-imperative.js +135 -0
- package/dist/senses/cli/spinner.js +101 -0
- package/dist/senses/cli/status-line.js +60 -0
- package/dist/senses/cli/streaming-markdown.js +526 -0
- package/dist/senses/cli/tool-display.js +83 -0
- package/dist/senses/cli/tool-render.js +85 -0
- package/dist/senses/cli/tui-store.js +240 -0
- package/dist/senses/cli/virtual-list.js +35 -0
- package/dist/senses/cli-entry.js +60 -8
- package/dist/senses/cli-layout.js +187 -0
- package/dist/senses/cli.js +768 -264
- package/dist/senses/commands.js +66 -3
- package/dist/senses/continuity.js +94 -0
- package/dist/senses/habit-turn-message.js +108 -0
- package/dist/senses/inner-dialog-worker.js +199 -16
- package/dist/senses/inner-dialog.js +640 -91
- package/dist/senses/mail-entry.js +66 -0
- package/dist/senses/mail.js +379 -0
- package/dist/senses/pipeline.js +665 -0
- package/dist/senses/proactive-content-guard.js +51 -0
- package/dist/senses/shared-turn.js +248 -0
- package/dist/senses/surface-tool.js +68 -0
- package/dist/senses/teams-entry.js +60 -8
- package/dist/senses/teams.js +844 -197
- package/dist/senses/trust-gate.js +207 -2
- package/dist/trips/core.js +138 -0
- package/dist/trips/store.js +146 -0
- package/package.json +47 -6
- package/skills/agent-commerce.md +106 -0
- package/skills/browser-navigation.md +117 -0
- package/skills/commerce-setup-guide.md +116 -0
- package/skills/commerce-setup.md +84 -0
- package/skills/configure-dev-tools.md +101 -0
- package/skills/travel-planning.md +138 -0
- package/AdoptionSpecialist.ouro/agent.json +0 -20
- package/AdoptionSpecialist.ouro/psyche/SOUL.md +0 -22
- package/dist/heart/daemon/specialist-orchestrator.js +0 -160
- package/dist/heart/daemon/specialist-prompt.js +0 -40
- package/dist/heart/daemon/specialist-session.js +0 -142
- package/dist/heart/daemon/specialist-tools.js +0 -128
- package/dist/heart/daemon/subagent-installer.js +0 -125
- package/dist/inner-worker-entry.js +0 -4
- package/dist/mind/associative-recall.js +0 -197
- package/subagents/README.md +0 -73
- package/subagents/work-doer.md +0 -233
- package/subagents/work-merger.md +0 -624
- package/subagents/work-planner.md +0 -373
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/basilisk.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/jafar.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/jormungandr.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/kaa.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/medusa.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/nagini.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/ouroboros.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/python.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/quetzalcoatl.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/sir-hiss.md +0 -0
- /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/the-snake.md +0 -0
|
@@ -0,0 +1,524 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Formats inner dialog session turns for human consumption.
|
|
3
|
+
// Used by `ouro thoughts` CLI command to show what the agent has been thinking.
|
|
4
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
5
|
+
if (k2 === undefined) k2 = k;
|
|
6
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
7
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
8
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
9
|
+
}
|
|
10
|
+
Object.defineProperty(o, k2, desc);
|
|
11
|
+
}) : (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
o[k2] = m[k];
|
|
14
|
+
}));
|
|
15
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
16
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
17
|
+
}) : function(o, v) {
|
|
18
|
+
o["default"] = v;
|
|
19
|
+
});
|
|
20
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
21
|
+
var ownKeys = function(o) {
|
|
22
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
23
|
+
var ar = [];
|
|
24
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
25
|
+
return ar;
|
|
26
|
+
};
|
|
27
|
+
return ownKeys(o);
|
|
28
|
+
};
|
|
29
|
+
return function (mod) {
|
|
30
|
+
if (mod && mod.__esModule) return mod;
|
|
31
|
+
var result = {};
|
|
32
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
33
|
+
__setModuleDefault(result, mod);
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
})();
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.formatSurfacedValue = formatSurfacedValue;
|
|
39
|
+
exports.deriveInnerDialogStatus = deriveInnerDialogStatus;
|
|
40
|
+
exports.deriveInnerJob = deriveInnerJob;
|
|
41
|
+
exports.formatInnerDialogStatus = formatInnerDialogStatus;
|
|
42
|
+
exports.extractThoughtResponseFromMessages = extractThoughtResponseFromMessages;
|
|
43
|
+
exports.parseInnerDialogSession = parseInnerDialogSession;
|
|
44
|
+
exports.formatThoughtTurns = formatThoughtTurns;
|
|
45
|
+
exports.getInnerDialogSessionPath = getInnerDialogSessionPath;
|
|
46
|
+
exports.readInnerDialogStatus = readInnerDialogStatus;
|
|
47
|
+
exports.readInnerDialogRawData = readInnerDialogRawData;
|
|
48
|
+
exports.followThoughts = followThoughts;
|
|
49
|
+
const fs = __importStar(require("fs"));
|
|
50
|
+
const path = __importStar(require("path"));
|
|
51
|
+
const session_events_1 = require("../session-events");
|
|
52
|
+
const runtime_1 = require("../../nerves/runtime");
|
|
53
|
+
function contentToText(content) {
|
|
54
|
+
if (typeof content === "string")
|
|
55
|
+
return content;
|
|
56
|
+
if (!Array.isArray(content))
|
|
57
|
+
return "";
|
|
58
|
+
return content
|
|
59
|
+
.map((part) => {
|
|
60
|
+
if (typeof part === "string")
|
|
61
|
+
return part;
|
|
62
|
+
if (part && typeof part === "object" && "text" in part && typeof part.text === "string") {
|
|
63
|
+
return part.text;
|
|
64
|
+
}
|
|
65
|
+
return "";
|
|
66
|
+
})
|
|
67
|
+
.join("\n");
|
|
68
|
+
}
|
|
69
|
+
function extractToolFunction(toolCall) {
|
|
70
|
+
if (!toolCall || typeof toolCall !== "object" || !("function" in toolCall))
|
|
71
|
+
return null;
|
|
72
|
+
const maybeFunction = toolCall.function;
|
|
73
|
+
if (!maybeFunction || typeof maybeFunction !== "object")
|
|
74
|
+
return null;
|
|
75
|
+
const name = "name" in maybeFunction && typeof maybeFunction.name === "string"
|
|
76
|
+
? maybeFunction.name
|
|
77
|
+
: undefined;
|
|
78
|
+
const argumentsValue = "arguments" in maybeFunction && typeof maybeFunction.arguments === "string"
|
|
79
|
+
? maybeFunction.arguments
|
|
80
|
+
: undefined;
|
|
81
|
+
return { name, arguments: argumentsValue };
|
|
82
|
+
}
|
|
83
|
+
function classifyTurn(userText) {
|
|
84
|
+
if (userText.includes("waking up."))
|
|
85
|
+
return { type: "boot" };
|
|
86
|
+
const taskMatch = /## task: (.+)$/m.exec(userText);
|
|
87
|
+
if (taskMatch)
|
|
88
|
+
return { type: "task", taskId: taskMatch[1] };
|
|
89
|
+
return { type: "heartbeat" };
|
|
90
|
+
}
|
|
91
|
+
function extractToolNames(messages) {
|
|
92
|
+
const names = [];
|
|
93
|
+
for (const msg of messages) {
|
|
94
|
+
if (msg.role === "assistant" && Array.isArray(msg.tool_calls)) {
|
|
95
|
+
for (const tc of msg.tool_calls) {
|
|
96
|
+
const toolFunction = extractToolFunction(tc);
|
|
97
|
+
if (toolFunction?.name && toolFunction.name !== "settle")
|
|
98
|
+
names.push(toolFunction.name);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return names;
|
|
103
|
+
}
|
|
104
|
+
function extractPendingPromptMessages(prompt) {
|
|
105
|
+
return prompt
|
|
106
|
+
.split("\n")
|
|
107
|
+
.map((line) => line.trim())
|
|
108
|
+
.filter((line) => line.startsWith("[pending from "))
|
|
109
|
+
.map((line) => {
|
|
110
|
+
const separator = line.indexOf("]: ");
|
|
111
|
+
return separator >= 0 ? line.slice(separator + 3).trim() : "";
|
|
112
|
+
})
|
|
113
|
+
.filter((line) => line.length > 0);
|
|
114
|
+
}
|
|
115
|
+
function readPendingMessagesForStatus(pendingDir) {
|
|
116
|
+
if (!fs.existsSync(pendingDir))
|
|
117
|
+
return [];
|
|
118
|
+
let entries;
|
|
119
|
+
try {
|
|
120
|
+
entries = fs.readdirSync(pendingDir);
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
return [];
|
|
124
|
+
}
|
|
125
|
+
const files = [
|
|
126
|
+
...entries.filter((entry) => entry.endsWith(".json.processing")),
|
|
127
|
+
...entries.filter((entry) => entry.endsWith(".json") && !entry.endsWith(".json.processing")),
|
|
128
|
+
].sort((a, b) => a.localeCompare(b));
|
|
129
|
+
const messages = [];
|
|
130
|
+
for (const file of files) {
|
|
131
|
+
try {
|
|
132
|
+
const raw = fs.readFileSync(path.join(pendingDir, file), "utf-8");
|
|
133
|
+
const parsed = JSON.parse(raw);
|
|
134
|
+
if (typeof parsed.content === "string") {
|
|
135
|
+
messages.push(parsed);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
catch {
|
|
139
|
+
// unreadable pending files should not break status queries
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return messages;
|
|
143
|
+
}
|
|
144
|
+
function formatSurfacedValue(text, maxLength = 120) {
|
|
145
|
+
const firstLine = text
|
|
146
|
+
.split("\n")
|
|
147
|
+
.map((line) => line.trim())
|
|
148
|
+
.find((line) => line.length > 0);
|
|
149
|
+
if (!firstLine)
|
|
150
|
+
return "no outward result";
|
|
151
|
+
if (firstLine.length <= maxLength)
|
|
152
|
+
return `"${firstLine}"`;
|
|
153
|
+
return `"${firstLine.slice(0, maxLength - 3)}..."`;
|
|
154
|
+
}
|
|
155
|
+
function extractEnrichedFields(pendingMessages) {
|
|
156
|
+
const delegated = pendingMessages.find((msg) => msg.delegatedFrom);
|
|
157
|
+
if (!delegated?.delegatedFrom)
|
|
158
|
+
return {};
|
|
159
|
+
const snippet = delegated.content.length > 80 ? delegated.content.slice(0, 77) + "..." : delegated.content;
|
|
160
|
+
return {
|
|
161
|
+
origin: {
|
|
162
|
+
friendId: delegated.delegatedFrom.friendId,
|
|
163
|
+
channel: delegated.delegatedFrom.channel,
|
|
164
|
+
key: delegated.delegatedFrom.key,
|
|
165
|
+
},
|
|
166
|
+
contentSnippet: snippet,
|
|
167
|
+
...(delegated.obligationStatus === "pending" ? { obligationPending: true } : {}),
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
function deriveInnerDialogStatus(pendingMessages, turns, runtimeState) {
|
|
171
|
+
if (runtimeState?.status === "running") {
|
|
172
|
+
if (pendingMessages.length > 0) {
|
|
173
|
+
return {
|
|
174
|
+
queue: "queued to inner/dialog",
|
|
175
|
+
wake: "queued behind active turn",
|
|
176
|
+
processing: "pending",
|
|
177
|
+
surfaced: "nothing yet",
|
|
178
|
+
...extractEnrichedFields(pendingMessages),
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
return {
|
|
182
|
+
queue: "clear",
|
|
183
|
+
wake: "in progress",
|
|
184
|
+
processing: "started",
|
|
185
|
+
surfaced: "nothing yet",
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
if (pendingMessages.length > 0) {
|
|
189
|
+
return {
|
|
190
|
+
queue: "queued to inner/dialog",
|
|
191
|
+
wake: "awaiting inner session",
|
|
192
|
+
processing: "pending",
|
|
193
|
+
surfaced: "nothing yet",
|
|
194
|
+
...extractEnrichedFields(pendingMessages),
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
const latestProcessedPendingTurn = [...turns]
|
|
198
|
+
.reverse()
|
|
199
|
+
.find((turn) => extractPendingPromptMessages(turn.prompt).length > 0);
|
|
200
|
+
if (!latestProcessedPendingTurn) {
|
|
201
|
+
return {
|
|
202
|
+
queue: "clear",
|
|
203
|
+
wake: "idle",
|
|
204
|
+
processing: "idle",
|
|
205
|
+
surfaced: "nothing recent",
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
return {
|
|
209
|
+
queue: "clear",
|
|
210
|
+
wake: "completed",
|
|
211
|
+
processing: "processed",
|
|
212
|
+
surfaced: formatSurfacedValue(latestProcessedPendingTurn.response),
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
function deriveInnerJob(pendingMessages, turns, runtimeState) {
|
|
216
|
+
const isRunning = runtimeState?.status === "running";
|
|
217
|
+
const delegated = pendingMessages.find((msg) => msg.delegatedFrom);
|
|
218
|
+
const enriched = extractEnrichedFields(pendingMessages);
|
|
219
|
+
const pendingMode = delegated && "mode" in delegated && delegated.mode ? delegated.mode : "reflect";
|
|
220
|
+
const origin = enriched.origin ?? null;
|
|
221
|
+
const content = delegated?.content ?? null;
|
|
222
|
+
const obligationStatus = delegated?.obligationStatus ?? null;
|
|
223
|
+
const queuedAt = delegated?.timestamp ?? null;
|
|
224
|
+
if (isRunning) {
|
|
225
|
+
(0, runtime_1.emitNervesEvent)({
|
|
226
|
+
component: "engine",
|
|
227
|
+
event: "engine.inner_job_derive",
|
|
228
|
+
message: "derived inner job state",
|
|
229
|
+
meta: { status: "running", mode: pendingMode, hasOrigin: origin !== null, hasObligation: obligationStatus !== null },
|
|
230
|
+
});
|
|
231
|
+
return {
|
|
232
|
+
status: "running",
|
|
233
|
+
content,
|
|
234
|
+
origin,
|
|
235
|
+
mode: pendingMode,
|
|
236
|
+
obligationStatus,
|
|
237
|
+
surfacedResult: null,
|
|
238
|
+
queuedAt,
|
|
239
|
+
startedAt: runtimeState?.startedAt ?? null,
|
|
240
|
+
surfacedAt: null,
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
if (pendingMessages.length > 0) {
|
|
244
|
+
(0, runtime_1.emitNervesEvent)({
|
|
245
|
+
component: "engine",
|
|
246
|
+
event: "engine.inner_job_derive",
|
|
247
|
+
message: "derived inner job state",
|
|
248
|
+
meta: { status: "queued", mode: pendingMode, hasOrigin: origin !== null, hasObligation: obligationStatus !== null },
|
|
249
|
+
});
|
|
250
|
+
return {
|
|
251
|
+
status: "queued",
|
|
252
|
+
content,
|
|
253
|
+
origin,
|
|
254
|
+
mode: pendingMode,
|
|
255
|
+
obligationStatus,
|
|
256
|
+
surfacedResult: null,
|
|
257
|
+
queuedAt,
|
|
258
|
+
startedAt: null,
|
|
259
|
+
surfacedAt: null,
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
// No pending, not running -- check for surfaced result
|
|
263
|
+
const latestProcessedPendingTurn = [...turns]
|
|
264
|
+
.reverse()
|
|
265
|
+
.find((turn) => extractPendingPromptMessages(turn.prompt).length > 0);
|
|
266
|
+
if (latestProcessedPendingTurn) {
|
|
267
|
+
const surfacedResult = extractThoughtResponseFromMessages([
|
|
268
|
+
{ role: "assistant", content: latestProcessedPendingTurn.response },
|
|
269
|
+
]);
|
|
270
|
+
(0, runtime_1.emitNervesEvent)({
|
|
271
|
+
component: "engine",
|
|
272
|
+
event: "engine.inner_job_derive",
|
|
273
|
+
message: "derived inner job state",
|
|
274
|
+
meta: { status: "surfaced", mode: "reflect", hasOrigin: false, hasObligation: false },
|
|
275
|
+
});
|
|
276
|
+
return {
|
|
277
|
+
status: "surfaced",
|
|
278
|
+
content: null,
|
|
279
|
+
origin: null,
|
|
280
|
+
mode: "reflect",
|
|
281
|
+
obligationStatus: null,
|
|
282
|
+
/* v8 ignore next -- defensive: surfacedResult fallback @preserve */
|
|
283
|
+
surfacedResult: surfacedResult || null,
|
|
284
|
+
queuedAt: null,
|
|
285
|
+
startedAt: null,
|
|
286
|
+
surfacedAt: null,
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
(0, runtime_1.emitNervesEvent)({
|
|
290
|
+
component: "engine",
|
|
291
|
+
event: "engine.inner_job_derive",
|
|
292
|
+
message: "derived inner job state",
|
|
293
|
+
meta: { status: "idle", mode: "reflect", hasOrigin: false, hasObligation: false },
|
|
294
|
+
});
|
|
295
|
+
return {
|
|
296
|
+
status: "idle",
|
|
297
|
+
content: null,
|
|
298
|
+
origin: null,
|
|
299
|
+
mode: "reflect",
|
|
300
|
+
obligationStatus: null,
|
|
301
|
+
surfacedResult: null,
|
|
302
|
+
queuedAt: null,
|
|
303
|
+
startedAt: null,
|
|
304
|
+
surfacedAt: null,
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
function formatInnerDialogStatus(status) {
|
|
308
|
+
const lines = [
|
|
309
|
+
`queue: ${status.queue}`,
|
|
310
|
+
`wake: ${status.wake}`,
|
|
311
|
+
`processing: ${status.processing}`,
|
|
312
|
+
`surfaced: ${status.surfaced}`,
|
|
313
|
+
];
|
|
314
|
+
if (status.origin) {
|
|
315
|
+
lines.push(`origin: ${status.origin.friendId}/${status.origin.channel}/${status.origin.key}`);
|
|
316
|
+
}
|
|
317
|
+
if (status.contentSnippet) {
|
|
318
|
+
lines.push(`asked: ${status.contentSnippet}`);
|
|
319
|
+
}
|
|
320
|
+
if (status.obligationPending) {
|
|
321
|
+
lines.push("obligation: pending");
|
|
322
|
+
}
|
|
323
|
+
return lines.join("\n");
|
|
324
|
+
}
|
|
325
|
+
/** Extract text from a settle tool call's arguments. */
|
|
326
|
+
function extractSettleAnswer(messages) {
|
|
327
|
+
for (let k = messages.length - 1; k >= 0; k--) {
|
|
328
|
+
const msg = messages[k];
|
|
329
|
+
if (msg.role !== "assistant" || !Array.isArray(msg.tool_calls))
|
|
330
|
+
continue;
|
|
331
|
+
for (const tc of msg.tool_calls) {
|
|
332
|
+
const toolFunction = extractToolFunction(tc);
|
|
333
|
+
if (toolFunction?.name !== "settle")
|
|
334
|
+
continue;
|
|
335
|
+
try {
|
|
336
|
+
const parsed = JSON.parse(toolFunction.arguments ?? "{}");
|
|
337
|
+
if (typeof parsed.answer === "string" && parsed.answer.trim())
|
|
338
|
+
return parsed.answer.trim();
|
|
339
|
+
}
|
|
340
|
+
catch {
|
|
341
|
+
// malformed arguments — skip
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
return "";
|
|
346
|
+
}
|
|
347
|
+
function extractThoughtResponseFromMessages(messages) {
|
|
348
|
+
const assistantMsgs = messages.filter((message) => message.role === "assistant");
|
|
349
|
+
const lastAssistant = assistantMsgs.reverse().find((message) => contentToText(message.content).trim().length > 0);
|
|
350
|
+
return lastAssistant
|
|
351
|
+
? contentToText(lastAssistant.content).trim()
|
|
352
|
+
: extractSettleAnswer(messages);
|
|
353
|
+
}
|
|
354
|
+
function parseInnerDialogSession(sessionPath) {
|
|
355
|
+
(0, runtime_1.emitNervesEvent)({
|
|
356
|
+
component: "daemon",
|
|
357
|
+
event: "daemon.thoughts_parse",
|
|
358
|
+
message: "parsing inner dialog session",
|
|
359
|
+
meta: { sessionPath },
|
|
360
|
+
});
|
|
361
|
+
let raw;
|
|
362
|
+
try {
|
|
363
|
+
raw = fs.readFileSync(sessionPath, "utf-8");
|
|
364
|
+
}
|
|
365
|
+
catch {
|
|
366
|
+
return [];
|
|
367
|
+
}
|
|
368
|
+
let parsedRaw;
|
|
369
|
+
try {
|
|
370
|
+
parsedRaw = JSON.parse(raw);
|
|
371
|
+
}
|
|
372
|
+
catch {
|
|
373
|
+
return [];
|
|
374
|
+
}
|
|
375
|
+
const legacyRecord = parsedRaw && typeof parsedRaw === "object"
|
|
376
|
+
? parsedRaw
|
|
377
|
+
: null;
|
|
378
|
+
const messages = legacyRecord?.version === 1 && Array.isArray(legacyRecord.messages)
|
|
379
|
+
? legacyRecord.messages
|
|
380
|
+
: (() => {
|
|
381
|
+
const envelope = (0, session_events_1.parseSessionEnvelope)(parsedRaw, {
|
|
382
|
+
recordedAt: new Date().toISOString(),
|
|
383
|
+
});
|
|
384
|
+
if (!envelope)
|
|
385
|
+
return null;
|
|
386
|
+
return (0, session_events_1.projectProviderMessages)(envelope);
|
|
387
|
+
})();
|
|
388
|
+
if (!messages)
|
|
389
|
+
return [];
|
|
390
|
+
const normalizedMessages = messages;
|
|
391
|
+
const turns = [];
|
|
392
|
+
// Walk messages, pairing user → (tool calls) → assistant sequences
|
|
393
|
+
let i = 0;
|
|
394
|
+
while (i < normalizedMessages.length) {
|
|
395
|
+
const msg = normalizedMessages[i];
|
|
396
|
+
if (msg.role === "system") {
|
|
397
|
+
i++;
|
|
398
|
+
continue;
|
|
399
|
+
}
|
|
400
|
+
if (msg.role !== "user") {
|
|
401
|
+
i++;
|
|
402
|
+
continue;
|
|
403
|
+
}
|
|
404
|
+
const userText = contentToText(msg.content);
|
|
405
|
+
const classification = classifyTurn(userText);
|
|
406
|
+
// Collect all messages until the next user message (or end)
|
|
407
|
+
const turnMessages = [];
|
|
408
|
+
let j = i + 1;
|
|
409
|
+
while (j < normalizedMessages.length && normalizedMessages[j].role !== "user") {
|
|
410
|
+
turnMessages.push(normalizedMessages[j]);
|
|
411
|
+
j++;
|
|
412
|
+
}
|
|
413
|
+
// Find the last assistant text response in this turn.
|
|
414
|
+
// With tool_choice="required", the response may be inside a settle tool call.
|
|
415
|
+
const response = extractThoughtResponseFromMessages(turnMessages);
|
|
416
|
+
const tools = extractToolNames(turnMessages);
|
|
417
|
+
turns.push({
|
|
418
|
+
type: classification.type,
|
|
419
|
+
prompt: userText.trim(),
|
|
420
|
+
response,
|
|
421
|
+
tools,
|
|
422
|
+
...(classification.taskId ? { taskId: classification.taskId } : {}),
|
|
423
|
+
});
|
|
424
|
+
i = j;
|
|
425
|
+
}
|
|
426
|
+
return turns;
|
|
427
|
+
}
|
|
428
|
+
function formatThoughtTurns(turns, lastN) {
|
|
429
|
+
if (turns.length === 0)
|
|
430
|
+
return "no inner dialog activity";
|
|
431
|
+
const selected = lastN > 0 ? turns.slice(-lastN) : turns;
|
|
432
|
+
/* v8 ignore next -- unreachable: turns.length > 0 checked above, slice always returns ≥1 @preserve */
|
|
433
|
+
if (selected.length === 0)
|
|
434
|
+
return "no inner dialog activity";
|
|
435
|
+
const lines = [];
|
|
436
|
+
for (const turn of selected) {
|
|
437
|
+
const typeLabel = turn.type === "task" && turn.taskId
|
|
438
|
+
? `task: ${turn.taskId}`
|
|
439
|
+
: turn.type;
|
|
440
|
+
lines.push(`--- ${typeLabel} ---`);
|
|
441
|
+
if (turn.tools.length > 0) {
|
|
442
|
+
lines.push(`tools: ${turn.tools.join(", ")}`);
|
|
443
|
+
}
|
|
444
|
+
if (turn.response) {
|
|
445
|
+
lines.push(turn.response);
|
|
446
|
+
}
|
|
447
|
+
else {
|
|
448
|
+
lines.push("(no response)");
|
|
449
|
+
}
|
|
450
|
+
lines.push("");
|
|
451
|
+
}
|
|
452
|
+
return lines.join("\n").trim();
|
|
453
|
+
}
|
|
454
|
+
function getInnerDialogSessionPath(agentRoot) {
|
|
455
|
+
return path.join(agentRoot, "state", "sessions", "self", "inner", "dialog.json");
|
|
456
|
+
}
|
|
457
|
+
function getInnerDialogRuntimeStatePath(sessionPath) {
|
|
458
|
+
return path.join(path.dirname(sessionPath), "runtime.json");
|
|
459
|
+
}
|
|
460
|
+
function readInnerDialogRuntimeState(runtimePath) {
|
|
461
|
+
try {
|
|
462
|
+
const raw = fs.readFileSync(runtimePath, "utf-8");
|
|
463
|
+
const parsed = JSON.parse(raw);
|
|
464
|
+
if (parsed.status !== "running" && parsed.status !== "idle")
|
|
465
|
+
return null;
|
|
466
|
+
return {
|
|
467
|
+
status: parsed.status,
|
|
468
|
+
reason: parsed.reason === "boot" || parsed.reason === "heartbeat" || parsed.reason === "instinct"
|
|
469
|
+
? parsed.reason
|
|
470
|
+
: undefined,
|
|
471
|
+
startedAt: typeof parsed.startedAt === "string" ? parsed.startedAt : undefined,
|
|
472
|
+
lastCompletedAt: typeof parsed.lastCompletedAt === "string" ? parsed.lastCompletedAt : undefined,
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
catch {
|
|
476
|
+
return null;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
function readInnerDialogStatus(sessionPath, pendingDir, runtimePath = getInnerDialogRuntimeStatePath(sessionPath)) {
|
|
480
|
+
const pendingMessages = readPendingMessagesForStatus(pendingDir);
|
|
481
|
+
const turns = parseInnerDialogSession(sessionPath);
|
|
482
|
+
const runtimeState = readInnerDialogRuntimeState(runtimePath);
|
|
483
|
+
return deriveInnerDialogStatus(pendingMessages, turns, runtimeState);
|
|
484
|
+
}
|
|
485
|
+
function readInnerDialogRawData(sessionPath, pendingDir) {
|
|
486
|
+
const runtimePath = getInnerDialogRuntimeStatePath(sessionPath);
|
|
487
|
+
const pendingMessages = readPendingMessagesForStatus(pendingDir);
|
|
488
|
+
const turns = parseInnerDialogSession(sessionPath);
|
|
489
|
+
const runtimeState = readInnerDialogRuntimeState(runtimePath);
|
|
490
|
+
return { pendingMessages, turns, runtimeState };
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* Watch a session file and emit new turns as they appear.
|
|
494
|
+
* Returns a cleanup function that stops the watcher.
|
|
495
|
+
*/
|
|
496
|
+
function followThoughts(sessionPath, onNewTurns, pollIntervalMs = 1000) {
|
|
497
|
+
let displayedCount = parseInnerDialogSession(sessionPath).length;
|
|
498
|
+
(0, runtime_1.emitNervesEvent)({
|
|
499
|
+
component: "daemon",
|
|
500
|
+
event: "daemon.thoughts_follow_start",
|
|
501
|
+
message: "started following inner dialog session",
|
|
502
|
+
meta: { sessionPath, initialTurns: displayedCount },
|
|
503
|
+
});
|
|
504
|
+
fs.watchFile(sessionPath, { interval: pollIntervalMs }, () => {
|
|
505
|
+
const turns = parseInnerDialogSession(sessionPath);
|
|
506
|
+
if (turns.length > displayedCount) {
|
|
507
|
+
const newTurns = turns.slice(displayedCount);
|
|
508
|
+
onNewTurns(formatThoughtTurns(newTurns, 0));
|
|
509
|
+
displayedCount = turns.length;
|
|
510
|
+
}
|
|
511
|
+
});
|
|
512
|
+
return () => {
|
|
513
|
+
fs.unwatchFile(sessionPath);
|
|
514
|
+
// Must be named `_end` (not `_stop`) to satisfy the nerves audit's
|
|
515
|
+
// start/end pairing rule — see src/nerves/coverage/audit-rules.ts which
|
|
516
|
+
// pairs `<prefix>_start` with `<prefix>_end` or `<prefix>_error`.
|
|
517
|
+
(0, runtime_1.emitNervesEvent)({
|
|
518
|
+
component: "daemon",
|
|
519
|
+
event: "daemon.thoughts_follow_end",
|
|
520
|
+
message: "stopped following inner dialog session",
|
|
521
|
+
meta: { sessionPath, totalTurns: displayedCount },
|
|
522
|
+
});
|
|
523
|
+
};
|
|
524
|
+
}
|