@oyasmi/pipiclaw 0.9.4 → 0.9.5-beta.3
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.en.md +35 -31
- package/README.md +34 -30
- package/dist/agent/builtin-commands.d.ts +7 -2
- package/dist/agent/builtin-commands.js +19 -23
- package/dist/agent/channel-runner.d.ts +23 -35
- package/dist/agent/channel-runner.js +150 -89
- package/dist/agent/maintenance-context.d.ts +8 -5
- package/dist/agent/maintenance-context.js +30 -15
- package/dist/agent/prompt/manifest.js +1 -1
- package/dist/agent/prompt/resources.d.ts +1 -1
- package/dist/agent/prompt/resources.js +1 -1
- package/dist/agent/prompt/sections.js +11 -9
- package/dist/agent/prompt/types.d.ts +1 -1
- package/dist/agent/runner-factory.d.ts +6 -6
- package/dist/agent/runner-factory.js +7 -8
- package/dist/agent/session/command-extension.js +11 -0
- package/dist/agent/session/compaction-input.d.ts +6 -0
- package/dist/agent/session/compaction-input.js +75 -0
- package/dist/agent/session/compaction-snapshot.d.ts +30 -0
- package/dist/agent/session/compaction-snapshot.js +154 -0
- package/dist/agent/session/compaction-summary.d.ts +39 -0
- package/dist/agent/session/compaction-summary.js +162 -0
- package/dist/agent/session/compaction.d.ts +35 -0
- package/dist/agent/session/compaction.js +294 -0
- package/dist/agent/session/context-input.d.ts +15 -0
- package/dist/agent/session/context-input.js +82 -0
- package/dist/agent/session/context-snapshot.d.ts +11 -0
- package/dist/agent/session/context-snapshot.js +72 -0
- package/dist/agent/session/event-guards.d.ts +2 -0
- package/dist/agent/session/event-guards.js +4 -0
- package/dist/agent/session/execution-trace.d.ts +14 -0
- package/dist/agent/session/execution-trace.js +57 -0
- package/dist/agent/session/request-tools.d.ts +3 -0
- package/dist/agent/session/request-tools.js +20 -0
- package/dist/agent/session/session-adapter.d.ts +2 -1
- package/dist/agent/session/session-adapter.js +6 -3
- package/dist/agent/session/session-events.d.ts +4 -8
- package/dist/agent/session/session-events.js +80 -70
- package/dist/agent/session/session-host.d.ts +39 -61
- package/dist/agent/session/session-host.js +122 -124
- package/dist/agent/session/settings-diagnostics.d.ts +5 -0
- package/dist/agent/session/settings-diagnostics.js +21 -0
- package/dist/agent/status-render.js +5 -2
- package/dist/{runtime → agent}/stop-watchdog.d.ts +3 -1
- package/dist/{runtime → agent}/stop-watchdog.js +7 -3
- package/dist/agent/turn/progress-formatter.d.ts +1 -3
- package/dist/agent/turn/progress-formatter.js +3 -22
- package/dist/agent/turn/task-digest.d.ts +5 -4
- package/dist/agent/turn/task-digest.js +37 -34
- package/dist/agent/turn/turn-context.d.ts +12 -8
- package/dist/agent/turn/turn-context.js +27 -19
- package/dist/agent/turn/turn-finish.d.ts +18 -6
- package/dist/agent/turn/turn-finish.js +52 -77
- package/dist/agent/turn/turn-input.d.ts +2 -2
- package/dist/agent/turn/turn-input.js +4 -3
- package/dist/agent/turn/turn-output.d.ts +19 -0
- package/dist/agent/turn/turn-output.js +41 -0
- package/dist/agent/turn/turn-pipeline.d.ts +15 -10
- package/dist/agent/turn/turn-pipeline.js +86 -59
- package/dist/agent/turn/turn-prompt.d.ts +1 -1
- package/dist/agent/turn/turn-recovery.d.ts +11 -10
- package/dist/agent/turn/turn-recovery.js +14 -29
- package/dist/agent/types.d.ts +93 -24
- package/dist/agent/types.js +5 -1
- package/dist/app/auth-command.js +1 -1
- package/dist/app/home.js +34 -19
- package/dist/channel/active-session-store.d.ts +14 -12
- package/dist/channel/active-session-store.js +29 -25
- package/dist/channel/attachments.d.ts +25 -0
- package/dist/channel/attachments.js +56 -0
- package/dist/channel/channel-context.d.ts +87 -96
- package/dist/channel/channel-context.js +1 -66
- package/dist/channel/channel-event.d.ts +49 -47
- package/dist/channel/channel-event.js +6 -11
- package/dist/channel/channel-id.d.ts +22 -0
- package/dist/channel/channel-id.js +13 -0
- package/dist/channel/channel-index.d.ts +17 -34
- package/dist/channel/channel-index.js +41 -80
- package/dist/channel/config.d.ts +10 -0
- package/dist/channel/config.js +55 -0
- package/dist/channel/ingress.d.ts +93 -0
- package/dist/channel/ingress.js +5 -0
- package/dist/channel/store.d.ts +14 -16
- package/dist/channel/store.js +21 -25
- package/dist/channel/transport.d.ts +99 -0
- package/dist/channel/turn-context.d.ts +23 -0
- package/dist/channel/turn-context.js +1 -0
- package/dist/commands/catalog.d.ts +4 -7
- package/dist/commands/catalog.js +48 -49
- package/dist/commands/router.d.ts +28 -14
- package/dist/commands/router.js +30 -27
- package/dist/config/settings.d.ts +8 -14
- package/dist/config/settings.js +0 -7
- package/dist/config/tools.d.ts +2 -2
- package/dist/config/tools.js +2 -2
- package/dist/desk/bindings.d.ts +6 -0
- package/dist/desk/bindings.js +105 -0
- package/dist/desk/commands.d.ts +81 -0
- package/dist/desk/commands.js +145 -0
- package/dist/desk/default.d.ts +4 -0
- package/dist/desk/default.js +11 -0
- package/dist/desk/paths.d.ts +41 -0
- package/dist/desk/paths.js +81 -0
- package/dist/desk/registry.d.ts +17 -0
- package/dist/desk/registry.js +191 -0
- package/dist/desk/startup-error.d.ts +4 -0
- package/dist/desk/startup-error.js +7 -0
- package/dist/desk/types.d.ts +72 -0
- package/dist/desk/types.js +7 -0
- package/dist/dingtalk/bot.d.ts +20 -35
- package/dist/dingtalk/bot.js +25 -204
- package/dist/dingtalk/cards.d.ts +7 -0
- package/dist/dingtalk/cards.js +32 -2
- package/dist/dingtalk/channel-ids.d.ts +15 -0
- package/dist/dingtalk/channel-ids.js +39 -0
- package/dist/dingtalk/config.d.ts +6 -3
- package/dist/dingtalk/config.js +13 -25
- package/dist/dingtalk/connection.d.ts +1 -0
- package/dist/dingtalk/connection.js +5 -4
- package/dist/dingtalk/conversation-meta.d.ts +10 -5
- package/dist/dingtalk/conversation-meta.js +72 -50
- package/dist/dingtalk/delivery.d.ts +34 -14
- package/dist/dingtalk/delivery.js +332 -190
- package/dist/dingtalk/inbound-media.d.ts +2 -18
- package/dist/dingtalk/inbound-media.js +0 -53
- package/dist/dingtalk/inbound.d.ts +10 -11
- package/dist/dingtalk/inbound.js +12 -19
- package/dist/dingtalk/media.d.ts +9 -11
- package/dist/dingtalk/media.js +18 -31
- package/dist/dingtalk/progress.d.ts +57 -0
- package/dist/dingtalk/progress.js +199 -0
- package/dist/dingtalk/response-mode.d.ts +13 -0
- package/dist/dingtalk/response-mode.js +31 -0
- package/dist/dingtalk/transport.d.ts +47 -0
- package/dist/dingtalk/transport.js +71 -0
- package/dist/events/commands.d.ts +7 -2
- package/dist/events/commands.js +40 -22
- package/dist/events/pre-action-error.d.ts +10 -0
- package/dist/events/pre-action-error.js +10 -0
- package/dist/events/types.d.ts +20 -2
- package/dist/events/watcher.d.ts +14 -7
- package/dist/events/watcher.js +49 -26
- package/dist/file-store.d.ts +4 -0
- package/dist/file-store.js +6 -1
- package/dist/index.d.ts +4 -2
- package/dist/jobs/completion-observer.d.ts +20 -0
- package/dist/jobs/completion-observer.js +107 -0
- package/dist/jobs/completion-signal.d.ts +9 -0
- package/dist/jobs/completion-signal.js +32 -0
- package/dist/jobs/completion-wake.d.ts +14 -0
- package/dist/jobs/completion-wake.js +25 -0
- package/dist/jobs/manager.d.ts +29 -42
- package/dist/jobs/manager.js +130 -236
- package/dist/jobs/probe.d.ts +3 -0
- package/dist/jobs/probe.js +42 -0
- package/dist/jobs/record.d.ts +5 -6
- package/dist/jobs/record.js +2 -0
- package/dist/jobs/runtime.d.ts +28 -0
- package/dist/jobs/runtime.js +69 -0
- package/dist/log.d.ts +0 -1
- package/dist/log.js +1 -1
- package/dist/main.js +10 -3
- package/dist/memory/boundary-work.d.ts +19 -0
- package/dist/memory/boundary-work.js +204 -0
- package/dist/memory/commands.d.ts +4 -3
- package/dist/memory/commands.js +20 -17
- package/dist/memory/desk-memory-queue.d.ts +18 -0
- package/dist/memory/desk-memory-queue.js +33 -0
- package/dist/memory/index-budget.d.ts +3 -3
- package/dist/memory/index-budget.js +21 -18
- package/dist/memory/journal.d.ts +6 -6
- package/dist/memory/journal.js +16 -15
- package/dist/memory/lifecycle.d.ts +17 -28
- package/dist/memory/lifecycle.js +87 -147
- package/dist/memory/maintenance-state.d.ts +14 -15
- package/dist/memory/maintenance-state.js +43 -42
- package/dist/memory/reflect-job.d.ts +5 -10
- package/dist/memory/reflect-job.js +29 -44
- package/dist/memory/reflect.d.ts +6 -1
- package/dist/memory/reflect.js +44 -16
- package/dist/memory/render.d.ts +1 -1
- package/dist/memory/render.js +2 -2
- package/dist/memory/review-log.d.ts +17 -4
- package/dist/memory/review-log.js +54 -5
- package/dist/memory/scheduler.d.ts +12 -19
- package/dist/memory/scheduler.js +28 -64
- package/dist/memory/search.js +7 -4
- package/dist/memory/session-corpus.d.ts +4 -1
- package/dist/memory/session-corpus.js +70 -29
- package/dist/memory/session-search.d.ts +11 -3
- package/dist/memory/session-search.js +14 -11
- package/dist/memory/sidecar-worker.d.ts +1 -0
- package/dist/memory/sidecar-worker.js +57 -76
- package/dist/memory/source-window.d.ts +18 -7
- package/dist/memory/source-window.js +59 -29
- package/dist/memory/store.d.ts +14 -12
- package/dist/memory/store.js +89 -57
- package/dist/paths.d.ts +2 -0
- package/dist/paths.js +2 -0
- package/dist/playbooks/agent-delegation.md +23 -17
- package/dist/playbooks/background-jobs.md +7 -5
- package/dist/playbooks/event-scheduling.md +9 -7
- package/dist/playbooks/memory-and-learning.md +18 -14
- package/dist/playbooks/outbound-media.md +3 -3
- package/dist/playbooks/runtime-orientation.md +39 -23
- package/dist/playbooks/task-lead.md +57 -34
- package/dist/runtime/bootstrap.d.ts +45 -35
- package/dist/runtime/bootstrap.js +372 -167
- package/dist/runtime/channel-queue.d.ts +25 -0
- package/dist/{dingtalk → runtime}/channel-queue.js +25 -10
- package/dist/runtime/daemon-lock.d.ts +12 -0
- package/dist/runtime/daemon-lock.js +28 -0
- package/dist/runtime/desk-runtime.d.ts +131 -0
- package/dist/runtime/desk-runtime.js +402 -0
- package/dist/runtime/durable-dispatch.d.ts +18 -5
- package/dist/runtime/durable-dispatch.js +85 -14
- package/dist/runtime/inbound-images.d.ts +32 -10
- package/dist/runtime/inbound-images.js +95 -21
- package/dist/runtime/ingress-busy.d.ts +25 -0
- package/dist/runtime/ingress-busy.js +178 -0
- package/dist/runtime/ingress-commands.d.ts +7 -0
- package/dist/runtime/ingress-commands.js +170 -0
- package/dist/runtime/ingress-deps.d.ts +59 -0
- package/dist/runtime/ingress-deps.js +1 -0
- package/dist/runtime/ingress.d.ts +22 -0
- package/dist/runtime/ingress.js +386 -0
- package/dist/runtime/request-execution.d.ts +19 -0
- package/dist/runtime/request-execution.js +88 -0
- package/dist/runtime/shutdown.d.ts +14 -6
- package/dist/runtime/shutdown.js +11 -5
- package/dist/runtime/task-close.d.ts +4 -0
- package/dist/runtime/task-close.js +102 -0
- package/dist/runtime/task-control.d.ts +34 -0
- package/dist/runtime/task-control.js +225 -0
- package/dist/runtime/task-input.d.ts +13 -0
- package/dist/runtime/task-input.js +129 -0
- package/dist/runtime/task-lane-types.d.ts +123 -0
- package/dist/runtime/task-lane-types.js +14 -0
- package/dist/runtime/task-lane.d.ts +99 -0
- package/dist/runtime/task-lane.js +703 -0
- package/dist/runtime/task-pending.d.ts +8 -0
- package/dist/runtime/task-pending.js +40 -0
- package/dist/runtime/task-spawn.d.ts +8 -8
- package/dist/runtime/task-spawn.js +10 -9
- package/dist/runtime/task-step.d.ts +32 -0
- package/dist/runtime/task-step.js +276 -0
- package/dist/runtime/transports.d.ts +32 -0
- package/dist/runtime/transports.js +101 -0
- package/dist/runtime/turn-run.d.ts +20 -23
- package/dist/runtime/turn-run.js +252 -159
- package/dist/runtime/wake-coalescing.d.ts +12 -6
- package/dist/runtime/wake-coalescing.js +12 -4
- package/dist/security/config.js +5 -10
- package/dist/security/logger.js +1 -1
- package/dist/security/path-guard.js +7 -63
- package/dist/security/types.d.ts +27 -30
- package/dist/security/types.js +0 -1
- package/dist/shared/atomic-file.d.ts +2 -0
- package/dist/shared/atomic-file.js +14 -1
- package/dist/shared/file-lock.d.ts +35 -0
- package/dist/shared/file-lock.js +195 -0
- package/dist/shared/format.d.ts +0 -6
- package/dist/shared/format.js +0 -17
- package/dist/shared/host-process.d.ts +2 -0
- package/dist/shared/host-process.js +16 -1
- package/dist/shared/jsonl-appender.d.ts +5 -0
- package/dist/shared/jsonl-appender.js +25 -2
- package/dist/shared/with-timeout.d.ts +2 -0
- package/dist/shared/with-timeout.js +21 -0
- package/dist/skills/catalog.d.ts +9 -0
- package/dist/skills/catalog.js +34 -0
- package/dist/skills/commands.d.ts +3 -12
- package/dist/skills/commands.js +36 -22
- package/dist/skills/loader.d.ts +2 -31
- package/dist/skills/loader.js +101 -68
- package/dist/skills/roots.d.ts +12 -0
- package/dist/skills/roots.js +18 -0
- package/dist/skills/types.d.ts +24 -0
- package/dist/skills/types.js +1 -0
- package/dist/subagents/completion-wake.d.ts +11 -2
- package/dist/subagents/completion-wake.js +21 -18
- package/dist/subagents/discovery.d.ts +1 -1
- package/dist/subagents/discovery.js +10 -16
- package/dist/subagents/dispatch.d.ts +0 -10
- package/dist/subagents/dispatch.js +18 -44
- package/dist/subagents/external/cursor-cli.d.ts +2 -0
- package/dist/subagents/external/cursor-cli.js +256 -0
- package/dist/subagents/external/dispatch.js +1 -1
- package/dist/subagents/external/harness.d.ts +5 -5
- package/dist/subagents/external/reconciliation.d.ts +7 -0
- package/dist/subagents/external/reconciliation.js +105 -0
- package/dist/subagents/external/recovery.d.ts +20 -0
- package/dist/subagents/external/recovery.js +71 -0
- package/dist/subagents/external/registry.js +2 -0
- package/dist/subagents/external/role-warnings.d.ts +17 -0
- package/dist/subagents/external/role-warnings.js +42 -0
- package/dist/subagents/external/run.d.ts +1 -1
- package/dist/subagents/external/run.js +21 -25
- package/dist/subagents/format.d.ts +1 -1
- package/dist/subagents/format.js +1 -1
- package/dist/subagents/grace.d.ts +2 -2
- package/dist/subagents/grace.js +3 -3
- package/dist/subagents/internal/run.js +8 -6
- package/dist/subagents/internal/worker.js +37 -16
- package/dist/subagents/result.js +2 -3
- package/dist/subagents/run-archive.d.ts +11 -0
- package/dist/subagents/run-archive.js +49 -0
- package/dist/subagents/run-record.d.ts +13 -15
- package/dist/subagents/run-record.js +5 -5
- package/dist/subagents/run-registry.d.ts +5 -3
- package/dist/subagents/run-registry.js +22 -45
- package/dist/subagents/runs.d.ts +51 -54
- package/dist/subagents/runs.js +178 -304
- package/dist/subagents/task-envelope.js +9 -11
- package/dist/subagents/task-settlement.d.ts +3 -0
- package/dist/subagents/task-settlement.js +20 -0
- package/dist/subagents/types.d.ts +7 -7
- package/dist/subagents/workspace-summary.js +5 -1
- package/dist/tasks/archive.d.ts +11 -0
- package/dist/tasks/archive.js +141 -0
- package/dist/tasks/board.d.ts +5 -12
- package/dist/tasks/board.js +4 -30
- package/dist/tasks/bound-work.d.ts +13 -7
- package/dist/tasks/bound-work.js +41 -28
- package/dist/tasks/brief.d.ts +39 -15
- package/dist/tasks/brief.js +131 -73
- package/dist/tasks/budget.d.ts +3 -3
- package/dist/tasks/budget.js +9 -4
- package/dist/tasks/commands.d.ts +24 -10
- package/dist/tasks/commands.js +225 -131
- package/dist/tasks/completion.d.ts +12 -0
- package/dist/tasks/completion.js +35 -0
- package/dist/tasks/contract.d.ts +8 -19
- package/dist/tasks/contract.js +41 -45
- package/dist/tasks/control.d.ts +138 -0
- package/dist/tasks/control.js +1 -0
- package/dist/tasks/create.d.ts +4 -2
- package/dist/tasks/create.js +13 -7
- package/dist/tasks/delivery.d.ts +24 -0
- package/dist/tasks/delivery.js +221 -0
- package/dist/tasks/file-mutation.d.ts +5 -0
- package/dist/tasks/file-mutation.js +38 -0
- package/dist/tasks/frontmatter.d.ts +46 -27
- package/dist/tasks/frontmatter.js +90 -47
- package/dist/tasks/input-receipts.d.ts +7 -0
- package/dist/tasks/input-receipts.js +60 -0
- package/dist/tasks/loop-log.d.ts +150 -37
- package/dist/tasks/loop-log.js +250 -42
- package/dist/tasks/mutation-lock.d.ts +7 -5
- package/dist/tasks/mutation-lock.js +32 -9
- package/dist/tasks/receipts.d.ts +19 -0
- package/dist/tasks/receipts.js +48 -0
- package/dist/tasks/session-path.d.ts +3 -3
- package/dist/tasks/session-path.js +5 -5
- package/dist/tasks/state.d.ts +93 -0
- package/dist/tasks/state.js +156 -0
- package/dist/tasks/store.d.ts +86 -54
- package/dist/tasks/store.js +256 -156
- package/dist/tools/bash.d.ts +8 -10
- package/dist/tools/bash.js +27 -40
- package/dist/tools/contract/details.d.ts +6 -6
- package/dist/tools/contract/details.js +6 -6
- package/dist/tools/contract/execution-trace.d.ts +4 -0
- package/dist/tools/contract/execution-trace.js +23 -0
- package/dist/tools/contract/names.d.ts +7 -0
- package/dist/tools/contract/names.js +22 -0
- package/dist/tools/contract/presentation.js +6 -2
- package/dist/tools/edit.d.ts +1 -0
- package/dist/tools/edit.js +46 -43
- package/dist/tools/event-manage.d.ts +3 -1
- package/dist/tools/event-manage.js +34 -33
- package/dist/tools/glob.js +5 -5
- package/dist/tools/grep.js +2 -2
- package/dist/tools/index.d.ts +17 -20
- package/dist/tools/index.js +28 -22
- package/dist/tools/job.d.ts +4 -2
- package/dist/tools/job.js +11 -8
- package/dist/tools/memory-manage.d.ts +5 -3
- package/dist/tools/memory-manage.js +32 -25
- package/dist/tools/read.js +1 -1
- package/dist/tools/registry.d.ts +19 -19
- package/dist/tools/registry.js +65 -34
- package/dist/tools/send-media.d.ts +2 -2
- package/dist/tools/send-media.js +3 -3
- package/dist/tools/session-search.d.ts +3 -1
- package/dist/tools/session-search.js +8 -6
- package/dist/tools/skill.d.ts +2 -2
- package/dist/tools/skill.js +24 -10
- package/dist/tools/subagent-manage.d.ts +2 -8
- package/dist/tools/subagent-manage.js +26 -19
- package/dist/tools/subagent.d.ts +0 -2
- package/dist/tools/subagent.js +3 -8
- package/dist/tools/task-manage/control-tools.d.ts +4 -0
- package/dist/tools/task-manage/control-tools.js +65 -0
- package/dist/tools/task-manage/create.js +3 -2
- package/dist/tools/task-manage/factory.d.ts +12 -6
- package/dist/tools/task-manage/factory.js +73 -58
- package/dist/tools/task-manage/lifecycle.d.ts +7 -12
- package/dist/tools/task-manage/lifecycle.js +119 -65
- package/dist/tools/task-manage/log-view.js +10 -7
- package/dist/tools/task-manage/schema.d.ts +21 -26
- package/dist/tools/task-manage/schema.js +29 -35
- package/dist/tools/task-manage/shared.d.ts +8 -39
- package/dist/tools/task-manage/shared.js +20 -69
- package/dist/tools/task-manage/step-tools.d.ts +5 -0
- package/dist/tools/task-manage/step-tools.js +103 -0
- package/dist/tools/task-manage/types.d.ts +33 -21
- package/dist/tools/web-cache.d.ts +3 -3
- package/dist/tools/web-cache.js +12 -12
- package/dist/tools/web-fetch.d.ts +2 -2
- package/dist/tools/web-fetch.js +7 -7
- package/dist/tools/write-content.d.ts +1 -0
- package/dist/tools/write-content.js +7 -2
- package/dist/tools/write.d.ts +1 -0
- package/dist/tools/write.js +1 -0
- package/dist/tui/cli.d.ts +17 -5
- package/dist/tui/cli.js +90 -27
- package/dist/tui/client.d.ts +26 -0
- package/dist/tui/client.js +157 -0
- package/dist/tui/colors.d.ts +0 -1
- package/dist/tui/colors.js +0 -1
- package/dist/tui/commands.d.ts +10 -51
- package/dist/tui/commands.js +16 -39
- package/dist/tui/frontend.d.ts +2 -2
- package/dist/tui/frontend.js +2 -2
- package/dist/tui/pitui-frontend.d.ts +0 -2
- package/dist/tui/pitui-frontend.js +1 -6
- package/dist/tui/render.d.ts +62 -0
- package/dist/tui/render.js +123 -0
- package/dist/tui/session.d.ts +92 -0
- package/dist/tui/session.js +317 -0
- package/dist/usage/ledger.d.ts +9 -4
- package/dist/usage/ledger.js +2 -0
- package/dist/usage/render.d.ts +6 -1
- package/dist/usage/render.js +20 -15
- package/dist/web/search-providers.js +0 -33
- package/dist/webapi/auth.d.ts +13 -0
- package/dist/webapi/auth.js +29 -0
- package/dist/webapi/config.d.ts +29 -0
- package/dist/webapi/config.js +100 -0
- package/dist/webapi/errors.d.ts +39 -0
- package/dist/webapi/errors.js +32 -0
- package/dist/webapi/http.d.ts +25 -0
- package/dist/webapi/http.js +4 -0
- package/dist/webapi/ids.d.ts +9 -0
- package/dist/webapi/ids.js +20 -0
- package/dist/webapi/input.d.ts +17 -0
- package/dist/webapi/input.js +229 -0
- package/dist/webapi/items.d.ts +37 -0
- package/dist/webapi/items.js +48 -0
- package/dist/webapi/key-command.d.ts +2 -0
- package/dist/webapi/key-command.js +110 -0
- package/dist/webapi/limits.d.ts +47 -0
- package/dist/webapi/limits.js +48 -0
- package/dist/webapi/request-policy.d.ts +17 -0
- package/dist/webapi/request-policy.js +160 -0
- package/dist/webapi/response-record.d.ts +68 -0
- package/dist/webapi/response-record.js +58 -0
- package/dist/webapi/response-state.d.ts +90 -0
- package/dist/webapi/response-state.js +347 -0
- package/dist/webapi/routes/conversations.d.ts +8 -0
- package/dist/webapi/routes/conversations.js +80 -0
- package/dist/webapi/routes/models.d.ts +3 -0
- package/dist/webapi/routes/models.js +12 -0
- package/dist/webapi/routes/responses.d.ts +8 -0
- package/dist/webapi/routes/responses.js +118 -0
- package/dist/webapi/routes/websocket.d.ts +9 -0
- package/dist/webapi/routes/websocket.js +328 -0
- package/dist/webapi/server.d.ts +24 -0
- package/dist/webapi/server.js +229 -0
- package/dist/webapi/service.d.ts +130 -0
- package/dist/webapi/service.js +588 -0
- package/dist/webapi/store.d.ts +46 -0
- package/dist/webapi/store.js +245 -0
- package/dist/webapi/stream.d.ts +13 -0
- package/dist/webapi/stream.js +76 -0
- package/dist/webapi/transport.d.ts +43 -0
- package/dist/webapi/transport.js +100 -0
- package/examples/sub-agents/README.md +23 -16
- package/examples/sub-agents/agents/claude-high.md +1 -1
- package/examples/sub-agents/agents/claude-main.md +1 -1
- package/examples/sub-agents/agents/codex-flash.md +1 -1
- package/examples/sub-agents/agents/codex-high.md +1 -1
- package/examples/sub-agents/agents/codex-main.md +4 -4
- package/examples/sub-agents/agents/cursor-high.md +22 -0
- package/examples/sub-agents/agents/cursor-main.md +22 -0
- package/examples/sub-agents/agents/glm-flash.md +1 -1
- package/examples/sub-agents/agents/glm-high.md +2 -2
- package/examples/sub-agents/agents/scout.md +30 -0
- package/package.json +13 -7
- package/dist/channel/channel-paths.d.ts +0 -16
- package/dist/channel/channel-paths.js +0 -53
- package/dist/channel/commands.d.ts +0 -32
- package/dist/channel/commands.js +0 -109
- package/dist/channel/project-scope-store.d.ts +0 -51
- package/dist/channel/project-scope-store.js +0 -112
- package/dist/dingtalk/channel-queue.d.ts +0 -19
- package/dist/dingtalk/handler.d.ts +0 -90
- package/dist/memory/channel-maintenance-queue.d.ts +0 -5
- package/dist/memory/channel-maintenance-queue.js +0 -8
- package/dist/runtime/task-driver.d.ts +0 -100
- package/dist/runtime/task-driver.js +0 -417
- package/dist/runtime/task-migration.d.ts +0 -30
- package/dist/runtime/task-migration.js +0 -465
- package/dist/runtime/task-wake.d.ts +0 -46
- package/dist/runtime/task-wake.js +0 -32
- package/dist/runtime/turn-handler.d.ts +0 -47
- package/dist/runtime/turn-handler.js +0 -318
- package/dist/security/project-scope.d.ts +0 -45
- package/dist/security/project-scope.js +0 -105
- package/dist/shared/wake-claim.d.ts +0 -23
- package/dist/shared/wake-claim.js +0 -26
- package/dist/skills/validation.d.ts +0 -8
- package/dist/skills/validation.js +0 -91
- package/dist/skills/workspace.d.ts +0 -33
- package/dist/skills/workspace.js +0 -116
- package/dist/tasks/steer.d.ts +0 -8
- package/dist/tasks/steer.js +0 -79
- package/dist/tasks/ticket.d.ts +0 -71
- package/dist/tasks/ticket.js +0 -138
- package/dist/tools/task-manage/step-end.d.ts +0 -11
- package/dist/tools/task-manage/step-end.js +0 -117
- package/dist/tui/app.d.ts +0 -16
- package/dist/tui/app.js +0 -166
- package/dist/tui/terminal-context.d.ts +0 -27
- package/dist/tui/terminal-context.js +0 -84
- package/dist/tui/terminal-media-sender.d.ts +0 -9
- package/dist/tui/terminal-media-sender.js +0 -15
- package/dist/tui/turn-controller.d.ts +0 -64
- package/dist/tui/turn-controller.js +0 -311
- /package/dist/{dingtalk/handler.js → channel/transport.js} +0 -0
|
@@ -1,17 +1,31 @@
|
|
|
1
1
|
import { appendFile, mkdir, readFile, stat } from "node:fs/promises";
|
|
2
2
|
import { dirname, join } from "node:path";
|
|
3
|
+
import * as log from "../log.js";
|
|
3
4
|
import { writeFileAtomically } from "../shared/atomic-file.js";
|
|
4
5
|
import { createSerialQueue } from "../shared/serial-queue.js";
|
|
6
|
+
import { errorMessage } from "../shared/text-utils.js";
|
|
7
|
+
/** An audit failure must not replay an already committed reflection. */
|
|
8
|
+
export async function tryAppendMemoryReviewLog(deskDir, entry) {
|
|
9
|
+
try {
|
|
10
|
+
await appendMemoryReviewLog(deskDir, entry);
|
|
11
|
+
}
|
|
12
|
+
catch (error) {
|
|
13
|
+
log.logWarn("memory.review_log.write_failed", "Memory review log write failed", {
|
|
14
|
+
channelId: entry.channelId,
|
|
15
|
+
reason: errorMessage(error),
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
5
19
|
const REVIEW_LOG_MAX_BYTES = 1_024 * 1_024; // 1 MB
|
|
6
|
-
// Three job kinds share a log per
|
|
20
|
+
// Three job kinds share a log per desk (path), so the key space is path x reason.
|
|
7
21
|
const MAX_GATE_SKIP_KEYS = 768;
|
|
8
22
|
const writeQueue = createSerialQueue();
|
|
9
23
|
const lastGateSkipByKey = new Map();
|
|
10
24
|
function gateSkipKey(path, reason) {
|
|
11
25
|
return `${path}\u0000${reason}`;
|
|
12
26
|
}
|
|
13
|
-
export function getMemoryReviewLogPath(
|
|
14
|
-
return join(
|
|
27
|
+
export function getMemoryReviewLogPath(deskDir) {
|
|
28
|
+
return join(deskDir, "memory-review.jsonl");
|
|
15
29
|
}
|
|
16
30
|
async function rotateIfNeeded(path, incomingBytes) {
|
|
17
31
|
try {
|
|
@@ -33,8 +47,8 @@ async function rotateIfNeeded(path, incomingBytes) {
|
|
|
33
47
|
// Rotation failure is non-fatal
|
|
34
48
|
}
|
|
35
49
|
}
|
|
36
|
-
export async function appendMemoryReviewLog(
|
|
37
|
-
const path = getMemoryReviewLogPath(
|
|
50
|
+
export async function appendMemoryReviewLog(deskDir, entry) {
|
|
51
|
+
const path = getMemoryReviewLogPath(deskDir);
|
|
38
52
|
const gateSkipOnly = (entry.skipped?.length ?? 0) > 0 && (entry.actions?.length ?? 0) === 0 && !entry.error;
|
|
39
53
|
const key = gateSkipKey(path, entry.reason);
|
|
40
54
|
if (gateSkipOnly) {
|
|
@@ -59,3 +73,38 @@ export async function appendMemoryReviewLog(channelDir, entry) {
|
|
|
59
73
|
await appendFile(path, line, "utf-8");
|
|
60
74
|
});
|
|
61
75
|
}
|
|
76
|
+
/** Shared by the idle job and `lifecycle.ts`'s boundary calls, so both write the same shape. */
|
|
77
|
+
export function reviewLogEntryFor(result, source) {
|
|
78
|
+
const actions = [...(result.decisions ?? [])];
|
|
79
|
+
if (source?.hasMore || source?.sampledChars) {
|
|
80
|
+
actions.push({
|
|
81
|
+
target: "source",
|
|
82
|
+
action: source.sampledChars ? "sample" : "batch",
|
|
83
|
+
fromEntryId: source.fromEntryId,
|
|
84
|
+
throughEntryId: source.throughEntryId,
|
|
85
|
+
hasMore: source.hasMore,
|
|
86
|
+
sampledChars: source.sampledChars,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
if (result.added.length || result.updated.length || result.deleted.length || result.touched.length) {
|
|
90
|
+
actions.push({
|
|
91
|
+
target: "memory",
|
|
92
|
+
action: "reflect",
|
|
93
|
+
added: result.added,
|
|
94
|
+
updated: result.updated,
|
|
95
|
+
deleted: result.deleted,
|
|
96
|
+
touched: result.touched,
|
|
97
|
+
condensed: result.condensed,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
if (result.journalAppended > 0) {
|
|
101
|
+
actions.push({ target: "journal", action: "append", count: result.journalAppended });
|
|
102
|
+
}
|
|
103
|
+
if (result.expiredProbation.length > 0) {
|
|
104
|
+
actions.push({ target: "memory", action: "expire", entries: result.expiredProbation });
|
|
105
|
+
}
|
|
106
|
+
const skipped = result.rejected.map((item) => ({ target: "memory", ...item }));
|
|
107
|
+
if (result.skipped)
|
|
108
|
+
skipped.push({ target: "reflect", reason: "no meaningful exchange" });
|
|
109
|
+
return { actions, skipped: skipped.length > 0 ? skipped : undefined };
|
|
110
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { AgentMessage } from "@earendil-works/pi-agent-core";
|
|
2
2
|
import type { Api, Model } from "@earendil-works/pi-ai";
|
|
3
3
|
import type { SessionEntry } from "@earendil-works/pi-coding-agent";
|
|
4
|
+
import type { DeskConversation } from "../desk/types.js";
|
|
4
5
|
import { type MemoryMaintenanceInput } from "./maintenance-tuning.js";
|
|
5
6
|
export interface MemoryMaintenanceRuntimeContext {
|
|
6
|
-
|
|
7
|
-
channelDir: string;
|
|
7
|
+
conversation: DeskConversation;
|
|
8
8
|
workspaceDir: string;
|
|
9
9
|
/**
|
|
10
|
-
* Transcript accessors, not arrays: the scheduler visits a
|
|
10
|
+
* Transcript accessors, not arrays: the scheduler visits a conversation every tick but almost
|
|
11
11
|
* every tick is denied by a cheap schedule gate. Copying (and then scanning) the whole
|
|
12
12
|
* transcript before that verdict was the entire steady-state cost of an idle daemon.
|
|
13
13
|
*/
|
|
@@ -21,34 +21,27 @@ export interface MemoryMaintenanceRuntimeContext {
|
|
|
21
21
|
}
|
|
22
22
|
export interface MemoryMaintenanceSchedulerOptions {
|
|
23
23
|
appHomeDir: string;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
/**
|
|
25
|
+
* The candidates (spec 058, D12): every conversation that is currently bound, in an active
|
|
26
|
+
* desk. An unbound conversation already got its last reflect when its runner was disposed at
|
|
27
|
+
* rebind, and a dormant desk does no background work.
|
|
28
|
+
*/
|
|
29
|
+
getConversations: () => DeskConversation[];
|
|
30
|
+
getRuntimeContext: (conversation: DeskConversation) => Promise<MemoryMaintenanceRuntimeContext | null>;
|
|
27
31
|
isChannelActive: (channelId: string) => boolean;
|
|
28
32
|
getSettings: () => {
|
|
29
33
|
memoryMaintenance: MemoryMaintenanceInput;
|
|
30
34
|
};
|
|
31
35
|
intervalMs?: number;
|
|
32
36
|
}
|
|
33
|
-
/**
|
|
34
|
-
* Every channel maintenance should visit, most authoritative source first: the live runner map
|
|
35
|
-
* holds real ids, `CHANNELS.md` does too, and the two directory listings can only offer escaped
|
|
36
|
-
* names. Deduplicating by directory keeps one entry per channel, so a group whose id contains
|
|
37
|
-
* `/` is maintained once — under an id the rest of the runtime can act on — rather than twice.
|
|
38
|
-
*/
|
|
39
|
-
export declare function discoverMemoryMaintenanceChannels(input: {
|
|
40
|
-
appHomeDir: string;
|
|
41
|
-
workspaceDir: string;
|
|
42
|
-
knownChannelIds?: Iterable<string>;
|
|
43
|
-
}): Promise<string[]>;
|
|
44
37
|
export declare class MemoryMaintenanceScheduler {
|
|
45
38
|
private readonly options;
|
|
46
39
|
private timer;
|
|
47
40
|
private running;
|
|
48
|
-
private
|
|
41
|
+
private nextIndex;
|
|
49
42
|
constructor(options: MemoryMaintenanceSchedulerOptions);
|
|
50
43
|
start(): void;
|
|
51
44
|
stop(): void;
|
|
52
45
|
runOnce(now?: Date): Promise<void>;
|
|
53
|
-
private
|
|
46
|
+
private runConversationOnce;
|
|
54
47
|
}
|
package/dist/memory/scheduler.js
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import { readdir } from "node:fs/promises";
|
|
2
|
-
import { basename } from "node:path";
|
|
3
|
-
// The channel index is a runtime-owned workspace artifact; the scheduler is one of its two
|
|
4
|
-
// read-only consumers (see `discoverWorkspaceChannelIds`).
|
|
5
|
-
import { discoverWorkspaceChannelIds } from "../channel/channel-index.js";
|
|
6
|
-
import { dedupeChannelIdsByDirectory, isChannelId } from "../channel/channel-paths.js";
|
|
7
1
|
import * as log from "../log.js";
|
|
8
2
|
import { errorMessage } from "../shared/text-utils.js";
|
|
3
|
+
import { hasBoundaryReflectWork } from "./boundary-work.js";
|
|
9
4
|
import { shouldRunReflect } from "./maintenance-gates.js";
|
|
10
|
-
import {
|
|
5
|
+
import { readMemoryMaintenanceState } from "./maintenance-state.js";
|
|
11
6
|
import { resolveMemoryMaintenanceSettings } from "./maintenance-tuning.js";
|
|
12
7
|
import { runReflectJob } from "./reflect-job.js";
|
|
13
8
|
const DEFAULT_TICK_INTERVAL_MS = 60_000;
|
|
@@ -22,7 +17,11 @@ const DEFAULT_TICK_INTERVAL_MS = 60_000;
|
|
|
22
17
|
* be — it never wrongly skips a channel the job would actually run for.
|
|
23
18
|
*/
|
|
24
19
|
async function mightReflectBeDue(input) {
|
|
25
|
-
|
|
20
|
+
if (await hasBoundaryReflectWork(input.conversation))
|
|
21
|
+
return true;
|
|
22
|
+
if (!input.settings.memoryMaintenance.enabled)
|
|
23
|
+
return false;
|
|
24
|
+
const state = await readMemoryMaintenanceState(input.appHomeDir, input.conversation);
|
|
26
25
|
return shouldRunReflect({
|
|
27
26
|
now: input.now,
|
|
28
27
|
state,
|
|
@@ -31,42 +30,12 @@ async function mightReflectBeDue(input) {
|
|
|
31
30
|
material: () => ({ hasNewEntry: true, hasMeaningfulExchange: true }),
|
|
32
31
|
}).allowed;
|
|
33
32
|
}
|
|
34
|
-
/**
|
|
35
|
-
* Channels with a maintenance state file — the ones nobody has spoken to since this process
|
|
36
|
-
* started and which have no workspace directory yet. Like a directory listing, these names are
|
|
37
|
-
* the escaped form of the id, so they are the least authoritative of the three sources below.
|
|
38
|
-
*/
|
|
39
|
-
async function listStateChannels(appHomeDir) {
|
|
40
|
-
try {
|
|
41
|
-
const entries = await readdir(getMemoryMaintenanceStateDir(appHomeDir), { withFileTypes: true });
|
|
42
|
-
return entries
|
|
43
|
-
.filter((entry) => entry.isFile() && entry.name.endsWith(".json"))
|
|
44
|
-
.map((entry) => basename(entry.name, ".json"))
|
|
45
|
-
.filter(isChannelId);
|
|
46
|
-
}
|
|
47
|
-
catch {
|
|
48
|
-
return [];
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Every channel maintenance should visit, most authoritative source first: the live runner map
|
|
53
|
-
* holds real ids, `CHANNELS.md` does too, and the two directory listings can only offer escaped
|
|
54
|
-
* names. Deduplicating by directory keeps one entry per channel, so a group whose id contains
|
|
55
|
-
* `/` is maintained once — under an id the rest of the runtime can act on — rather than twice.
|
|
56
|
-
*/
|
|
57
|
-
export async function discoverMemoryMaintenanceChannels(input) {
|
|
58
|
-
return dedupeChannelIdsByDirectory([
|
|
59
|
-
...[...(input.knownChannelIds ?? [])].filter(isChannelId),
|
|
60
|
-
...(await discoverWorkspaceChannelIds(input.workspaceDir)),
|
|
61
|
-
...(await listStateChannels(input.appHomeDir)),
|
|
62
|
-
]);
|
|
63
|
-
}
|
|
64
33
|
export class MemoryMaintenanceScheduler {
|
|
65
34
|
constructor(options) {
|
|
66
35
|
this.options = options;
|
|
67
36
|
this.timer = null;
|
|
68
37
|
this.running = false;
|
|
69
|
-
this.
|
|
38
|
+
this.nextIndex = 0;
|
|
70
39
|
}
|
|
71
40
|
start() {
|
|
72
41
|
if (this.timer) {
|
|
@@ -93,54 +62,49 @@ export class MemoryMaintenanceScheduler {
|
|
|
93
62
|
}
|
|
94
63
|
async runOnce(now = new Date()) {
|
|
95
64
|
const settings = this.options.getSettings();
|
|
96
|
-
if (
|
|
65
|
+
if (this.running) {
|
|
97
66
|
return;
|
|
98
67
|
}
|
|
99
68
|
this.running = true;
|
|
100
69
|
try {
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
workspaceDir: this.options.workspaceDir,
|
|
104
|
-
knownChannelIds: this.options.getKnownChannelIds?.(),
|
|
105
|
-
});
|
|
106
|
-
if (channelIds.length === 0) {
|
|
70
|
+
const conversations = this.options.getConversations();
|
|
71
|
+
if (conversations.length === 0) {
|
|
107
72
|
return;
|
|
108
73
|
}
|
|
109
|
-
// One
|
|
110
|
-
//
|
|
74
|
+
// One conversation per tick, round-robin: a reflect pass is an LLM call, and the first
|
|
75
|
+
// due conversation is as good a place to spend it as any.
|
|
111
76
|
let selected;
|
|
112
|
-
let index = this.
|
|
113
|
-
for (let scanned = 0; scanned <
|
|
114
|
-
const
|
|
115
|
-
if (
|
|
116
|
-
!this.options.isChannelActive(channelId) &&
|
|
117
|
-
(await mightReflectBeDue({ appHomeDir: this.options.appHomeDir,
|
|
118
|
-
selected =
|
|
77
|
+
let index = this.nextIndex % conversations.length;
|
|
78
|
+
for (let scanned = 0; scanned < conversations.length && !selected; scanned++) {
|
|
79
|
+
const conversation = conversations[index];
|
|
80
|
+
if (conversation &&
|
|
81
|
+
!this.options.isChannelActive(conversation.channelId) &&
|
|
82
|
+
(await mightReflectBeDue({ appHomeDir: this.options.appHomeDir, conversation, settings, now }))) {
|
|
83
|
+
selected = conversation;
|
|
119
84
|
}
|
|
120
|
-
index = (index + 1) %
|
|
85
|
+
index = (index + 1) % conversations.length;
|
|
121
86
|
}
|
|
122
|
-
this.
|
|
87
|
+
this.nextIndex = index;
|
|
123
88
|
if (selected)
|
|
124
|
-
await this.
|
|
89
|
+
await this.runConversationOnce(selected, now);
|
|
125
90
|
}
|
|
126
91
|
finally {
|
|
127
92
|
this.running = false;
|
|
128
93
|
}
|
|
129
94
|
}
|
|
130
|
-
async
|
|
131
|
-
if (this.options.isChannelActive(channelId)) {
|
|
95
|
+
async runConversationOnce(conversation, now) {
|
|
96
|
+
if (this.options.isChannelActive(conversation.channelId)) {
|
|
132
97
|
return;
|
|
133
98
|
}
|
|
134
|
-
const context = await this.options.getRuntimeContext(
|
|
99
|
+
const context = await this.options.getRuntimeContext(conversation);
|
|
135
100
|
if (!context) {
|
|
136
101
|
return;
|
|
137
102
|
}
|
|
138
103
|
await runReflectJob({
|
|
139
104
|
appHomeDir: this.options.appHomeDir,
|
|
140
|
-
|
|
141
|
-
channelDir: context.channelDir,
|
|
105
|
+
conversation: context.conversation,
|
|
142
106
|
workspaceDir: context.workspaceDir,
|
|
143
|
-
channelActive: this.options.isChannelActive(channelId),
|
|
107
|
+
channelActive: this.options.isChannelActive(conversation.channelId),
|
|
144
108
|
now,
|
|
145
109
|
settings: context.settings,
|
|
146
110
|
model: context.model,
|
package/dist/memory/search.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { parseLocalTime } from "../shared/local-time.js";
|
|
2
|
-
import { splitH2Sections } from "../shared/markdown-sections.js";
|
|
3
2
|
import { HAN_REGEX } from "../shared/text-utils.js";
|
|
4
3
|
import { COMMON_CHINESE_WORDS } from "./chinese-words.js";
|
|
5
4
|
/**
|
|
@@ -289,10 +288,14 @@ export function searchMemory(input) {
|
|
|
289
288
|
}
|
|
290
289
|
}
|
|
291
290
|
if (input.workspaceMemory) {
|
|
292
|
-
|
|
293
|
-
|
|
291
|
+
// Keep the preamble and empty headings searchable without changing the shared parser.
|
|
292
|
+
for (const block of input.workspaceMemory.split(/(?=^## )/m)) {
|
|
293
|
+
if (!block.trim())
|
|
294
|
+
continue;
|
|
295
|
+
const heading = /^## ([^\n]+)/.exec(block)?.[1]?.trim() ?? "Background";
|
|
296
|
+
const { score, line } = scoreText(queryTokens, block);
|
|
294
297
|
if (score > 0) {
|
|
295
|
-
hits.push({ kind: "workspace", label:
|
|
298
|
+
hits.push({ kind: "workspace", label: heading, line, score });
|
|
296
299
|
}
|
|
297
300
|
}
|
|
298
301
|
}
|
|
@@ -12,6 +12,8 @@ export interface SessionSearchDocument {
|
|
|
12
12
|
/** True when even the scan text was clipped: a keyword past this point cannot be found here. */
|
|
13
13
|
scanTruncated?: boolean;
|
|
14
14
|
sessionId?: string;
|
|
15
|
+
/** The conversation directory the document came from (`dm-1`, `group-2`, …). */
|
|
16
|
+
conversation?: string;
|
|
15
17
|
}
|
|
16
18
|
/**
|
|
17
19
|
* Ceiling on how much of one message is kept for *matching*. The old code clipped each message to
|
|
@@ -21,7 +23,8 @@ export interface SessionSearchDocument {
|
|
|
21
23
|
*/
|
|
22
24
|
export declare const SESSION_SCAN_MAX_CHARS = 20000;
|
|
23
25
|
export interface BuildSessionCorpusOptions {
|
|
24
|
-
|
|
26
|
+
/** The desk whose conversations — every channel that has talked to it — form the corpus (spec 058, D12). */
|
|
27
|
+
deskDir: string;
|
|
25
28
|
maxFiles: number;
|
|
26
29
|
maxCharsPerDocument?: number;
|
|
27
30
|
maxDocumentsTotal?: number;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { readdir, stat } from "node:fs/promises";
|
|
2
2
|
import { basename, join } from "node:path";
|
|
3
|
+
import { getConversationsDir, SUBAGENT_RUNS_LOG_FILENAME } from "../desk/paths.js";
|
|
3
4
|
import { isNodeError, readOptionalTextFile } from "../shared/os.js";
|
|
4
5
|
import { isRecord } from "../shared/type-guards.js";
|
|
5
6
|
/**
|
|
@@ -15,7 +16,7 @@ const IGNORED_JSONL_FILES = new Set([
|
|
|
15
16
|
"context.jsonl",
|
|
16
17
|
"log.jsonl",
|
|
17
18
|
"log.jsonl.1",
|
|
18
|
-
|
|
19
|
+
SUBAGENT_RUNS_LOG_FILENAME,
|
|
19
20
|
"memory-review.jsonl",
|
|
20
21
|
]);
|
|
21
22
|
function parseJsonLine(line) {
|
|
@@ -203,10 +204,13 @@ async function parseJsonlFile(path, source, maxChars) {
|
|
|
203
204
|
}
|
|
204
205
|
return docs;
|
|
205
206
|
}
|
|
206
|
-
async function
|
|
207
|
-
let names;
|
|
207
|
+
async function listConversations(deskDir) {
|
|
208
208
|
try {
|
|
209
|
-
|
|
209
|
+
const entries = await readdir(getConversationsDir(deskDir), { withFileTypes: true });
|
|
210
|
+
return entries
|
|
211
|
+
.filter((entry) => entry.isDirectory())
|
|
212
|
+
.map((entry) => entry.name)
|
|
213
|
+
.sort();
|
|
210
214
|
}
|
|
211
215
|
catch (error) {
|
|
212
216
|
if (isNodeError(error) && error.code === "ENOENT") {
|
|
@@ -214,46 +218,68 @@ async function listChannelSessionJsonlFiles(channelDir, maxFiles) {
|
|
|
214
218
|
}
|
|
215
219
|
throw error;
|
|
216
220
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
//
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
221
|
+
}
|
|
222
|
+
async function listSessionJsonlFiles(conversationDirs, maxFiles) {
|
|
223
|
+
// Stat in parallel: one round trip per session file, and awaiting them one at a time made the
|
|
224
|
+
// corpus build scale with the file count rather than with the slowest stat.
|
|
225
|
+
const listed = await Promise.all(conversationDirs.map(async ({ conversation, dir }) => {
|
|
226
|
+
try {
|
|
227
|
+
return (await readdir(dir))
|
|
228
|
+
.filter((name) => name.endsWith(".jsonl") && !IGNORED_JSONL_FILES.has(name))
|
|
229
|
+
.map((name) => ({ conversation, path: join(dir, name) }));
|
|
230
|
+
}
|
|
231
|
+
catch {
|
|
232
|
+
return [];
|
|
233
|
+
}
|
|
234
|
+
}));
|
|
235
|
+
const stated = await Promise.all(listed.flat().map(async (entry) => {
|
|
224
236
|
try {
|
|
225
|
-
const stats = await stat(path);
|
|
226
|
-
return stats.isFile() ? {
|
|
237
|
+
const stats = await stat(entry.path);
|
|
238
|
+
return stats.isFile() ? { ...entry, mtimeMs: stats.mtimeMs } : null;
|
|
227
239
|
}
|
|
228
240
|
catch {
|
|
229
241
|
return null;
|
|
230
242
|
}
|
|
231
243
|
}));
|
|
232
|
-
|
|
233
|
-
|
|
244
|
+
return stated
|
|
245
|
+
.filter((entry) => entry !== null)
|
|
234
246
|
.sort((a, b) => b.mtimeMs - a.mtimeMs)
|
|
235
247
|
.slice(0, Math.max(0, maxFiles))
|
|
236
|
-
.map((
|
|
248
|
+
.map(({ conversation, path }) => ({ conversation, path }));
|
|
237
249
|
}
|
|
238
250
|
export async function buildSessionCorpus(options) {
|
|
239
251
|
const maxFiles = Math.max(1, Math.floor(options.maxFiles));
|
|
240
252
|
const maxChars = options.maxCharsPerDocument ?? DEFAULT_MAX_CHARS_PER_DOCUMENT;
|
|
241
253
|
const maxDocuments = options.maxDocumentsTotal ?? DEFAULT_MAX_DOCUMENTS_TOTAL;
|
|
242
|
-
const
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
254
|
+
const conversationDirs = (await listConversations(options.deskDir)).map((conversation) => ({
|
|
255
|
+
conversation,
|
|
256
|
+
dir: join(getConversationsDir(options.deskDir), conversation),
|
|
257
|
+
}));
|
|
258
|
+
const readPlan = [];
|
|
259
|
+
for (const { conversation, dir } of conversationDirs) {
|
|
260
|
+
readPlan.push({ path: join(dir, "context.jsonl"), source: "context", conversation }, { path: join(dir, "log.jsonl"), source: "log", conversation }, { path: join(dir, "log.jsonl.1"), source: "log", conversation });
|
|
261
|
+
}
|
|
262
|
+
for (const entry of await listSessionJsonlFiles(conversationDirs, maxFiles)) {
|
|
263
|
+
readPlan.push({ ...entry, source: "session" });
|
|
250
264
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
265
|
+
// Every conversation is read, each keeping at most its newest `maxDocuments`; the total is then
|
|
266
|
+
// shared out by `shareBudget`. Stopping in directory order once the total ran over let one
|
|
267
|
+
// long-lived channel fill the budget before later channels were read at all (spec 058, D12:
|
|
268
|
+
// `session_search` covers the whole desk).
|
|
269
|
+
const byConversation = new Map();
|
|
270
|
+
for (const item of readPlan) {
|
|
271
|
+
let docs = byConversation.get(item.conversation) ?? [];
|
|
272
|
+
for (const document of await parseJsonlFile(item.path, item.source, maxChars)) {
|
|
273
|
+
// Ids are `<file>:<line>`, and every conversation has its own `context.jsonl`.
|
|
274
|
+
docs.push({ ...document, id: `${item.conversation}/${document.id}`, conversation: item.conversation });
|
|
255
275
|
}
|
|
276
|
+
if (docs.length > maxDocuments * 2)
|
|
277
|
+
docs = docs.slice(-maxDocuments);
|
|
278
|
+
byConversation.set(item.conversation, docs);
|
|
256
279
|
}
|
|
280
|
+
return shareBudget([...byConversation.values()].map(deduplicate), maxDocuments);
|
|
281
|
+
}
|
|
282
|
+
function deduplicate(docs) {
|
|
257
283
|
const deduplicated = [];
|
|
258
284
|
const seen = new Set();
|
|
259
285
|
for (const document of docs) {
|
|
@@ -265,5 +291,20 @@ export async function buildSessionCorpus(options) {
|
|
|
265
291
|
seen.add(identity);
|
|
266
292
|
deduplicated.push(document);
|
|
267
293
|
}
|
|
268
|
-
return deduplicated
|
|
294
|
+
return deduplicated;
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Fair shares of `budget`, smallest conversation first: one that needs less than an equal share
|
|
298
|
+
* keeps everything and leaves the rest to the others; a larger one keeps its newest documents.
|
|
299
|
+
*/
|
|
300
|
+
function shareBudget(groups, budget) {
|
|
301
|
+
const kept = new Map();
|
|
302
|
+
let remaining = budget;
|
|
303
|
+
const bySize = [...groups].sort((a, b) => a.length - b.length);
|
|
304
|
+
bySize.forEach((group, index) => {
|
|
305
|
+
const take = Math.min(group.length, Math.floor(remaining / (bySize.length - index)));
|
|
306
|
+
kept.set(group, take === 0 ? [] : group.slice(-take));
|
|
307
|
+
remaining -= take;
|
|
308
|
+
});
|
|
309
|
+
return groups.flatMap((group) => kept.get(group) ?? []);
|
|
269
310
|
}
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import type { Api, Model } from "@earendil-works/pi-ai";
|
|
2
2
|
import { type SessionSearchRole } from "./session-corpus.js";
|
|
3
|
-
export interface
|
|
3
|
+
export interface SearchDeskSessionsRequest {
|
|
4
4
|
channelId?: string;
|
|
5
|
-
|
|
5
|
+
/** Attributes the optional summarization's spend to the desk. */
|
|
6
|
+
desk?: string;
|
|
7
|
+
/** Every conversation in this desk is searched (spec 058, D12). */
|
|
8
|
+
deskDir: string;
|
|
9
|
+
/** A human name for a conversation directory (the channel's name), for labelling results. */
|
|
10
|
+
describeConversation?: (conversation: string) => string | undefined;
|
|
6
11
|
query: string;
|
|
7
12
|
roleFilter?: string[];
|
|
8
13
|
limit: number;
|
|
@@ -17,6 +22,9 @@ export interface SearchChannelSessionsRequest {
|
|
|
17
22
|
export interface SessionSearchResult {
|
|
18
23
|
source: string;
|
|
19
24
|
path: string;
|
|
25
|
+
/** Which conversation of the desk the hit came from, and that channel's name when known. */
|
|
26
|
+
conversation?: string;
|
|
27
|
+
channel?: string;
|
|
20
28
|
when?: string;
|
|
21
29
|
role: SessionSearchRole;
|
|
22
30
|
score: number;
|
|
@@ -31,4 +39,4 @@ export interface SessionSearchResponse {
|
|
|
31
39
|
* findable in this corpus, so "no match" there is not proof it was never said. */
|
|
32
40
|
partialDocuments: number;
|
|
33
41
|
}
|
|
34
|
-
export declare function
|
|
42
|
+
export declare function searchDeskSessions(request: SearchDeskSessionsRequest): Promise<SessionSearchResponse>;
|
|
@@ -3,7 +3,7 @@ import { parseLocalTime } from "../shared/local-time.js";
|
|
|
3
3
|
import { recencyBoostByAge, tokenizeRecallText } from "./search.js";
|
|
4
4
|
import { buildSessionCorpus } from "./session-corpus.js";
|
|
5
5
|
import { runSidecarTask } from "./sidecar-worker.js";
|
|
6
|
-
const SESSION_SEARCH_SUMMARY_SYSTEM_PROMPT = `You summarize
|
|
6
|
+
const SESSION_SEARCH_SUMMARY_SYSTEM_PROMPT = `You summarize transcript search hits from one Pipiclaw desk's conversations.
|
|
7
7
|
|
|
8
8
|
Return plain text only.
|
|
9
9
|
|
|
@@ -116,7 +116,7 @@ ${query}
|
|
|
116
116
|
Transcript hit:
|
|
117
117
|
${fallback}`,
|
|
118
118
|
timeoutMs: request.timeoutMs,
|
|
119
|
-
usageContext: request.channelId ? { channelId: request.channelId } : undefined,
|
|
119
|
+
usageContext: request.channelId ? { channelId: request.channelId, desk: request.desk } : undefined,
|
|
120
120
|
parse: (text) => text.trim(),
|
|
121
121
|
});
|
|
122
122
|
return result.output || fallback;
|
|
@@ -128,7 +128,10 @@ ${fallback}`,
|
|
|
128
128
|
function toResult(request, document, score, matches, summary) {
|
|
129
129
|
return {
|
|
130
130
|
source: document.source,
|
|
131
|
-
path: relative(request.
|
|
131
|
+
path: relative(request.deskDir, document.path) || document.path,
|
|
132
|
+
...(document.conversation
|
|
133
|
+
? { conversation: document.conversation, channel: request.describeConversation?.(document.conversation) }
|
|
134
|
+
: {}),
|
|
132
135
|
when: document.timestamp,
|
|
133
136
|
role: document.role,
|
|
134
137
|
score: Number(score.toFixed(3)),
|
|
@@ -139,11 +142,11 @@ function toResult(request, document, score, matches, summary) {
|
|
|
139
142
|
const CORPUS_CACHE_TTL_MS = 30_000;
|
|
140
143
|
const CORPUS_CACHE_MAX_CHANNELS = 8;
|
|
141
144
|
const corpusCache = new Map();
|
|
142
|
-
function corpusCacheKey(
|
|
143
|
-
return JSON.stringify([
|
|
145
|
+
function corpusCacheKey(deskDir, maxFiles, maxCharsPerChunk) {
|
|
146
|
+
return JSON.stringify([deskDir, maxFiles, maxCharsPerChunk]);
|
|
144
147
|
}
|
|
145
|
-
async function getCachedCorpus(
|
|
146
|
-
const key = corpusCacheKey(
|
|
148
|
+
async function getCachedCorpus(deskDir, maxFiles, maxCharsPerChunk) {
|
|
149
|
+
const key = corpusCacheKey(deskDir, maxFiles, maxCharsPerChunk);
|
|
147
150
|
const cached = corpusCache.get(key);
|
|
148
151
|
if (cached && Date.now() - cached.timestamp < CORPUS_CACHE_TTL_MS) {
|
|
149
152
|
corpusCache.delete(key);
|
|
@@ -151,12 +154,12 @@ async function getCachedCorpus(channelDir, maxFiles, maxCharsPerChunk) {
|
|
|
151
154
|
return cached.documents;
|
|
152
155
|
}
|
|
153
156
|
const documents = await buildSessionCorpus({
|
|
154
|
-
|
|
157
|
+
deskDir,
|
|
155
158
|
maxFiles,
|
|
156
159
|
maxCharsPerDocument: maxCharsPerChunk,
|
|
157
160
|
});
|
|
158
161
|
corpusCache.delete(key);
|
|
159
|
-
corpusCache.set(key, {
|
|
162
|
+
corpusCache.set(key, { deskDir, maxFiles, maxCharsPerChunk, documents, timestamp: Date.now() });
|
|
160
163
|
if (corpusCache.size > CORPUS_CACHE_MAX_CHANNELS) {
|
|
161
164
|
const oldestKey = corpusCache.keys().next().value;
|
|
162
165
|
if (oldestKey)
|
|
@@ -164,12 +167,12 @@ async function getCachedCorpus(channelDir, maxFiles, maxCharsPerChunk) {
|
|
|
164
167
|
}
|
|
165
168
|
return documents;
|
|
166
169
|
}
|
|
167
|
-
export async function
|
|
170
|
+
export async function searchDeskSessions(request) {
|
|
168
171
|
const limit = clampInteger(request.limit, 1, 5);
|
|
169
172
|
const maxChunks = clampInteger(request.maxChunks, 1, 500);
|
|
170
173
|
const query = request.query.trim();
|
|
171
174
|
const roleFilter = normalizeRoleFilter(request.roleFilter);
|
|
172
|
-
const documents = (await getCachedCorpus(request.
|
|
175
|
+
const documents = (await getCachedCorpus(request.deskDir, request.maxFiles, request.maxCharsPerChunk))
|
|
173
176
|
.filter((document) => roleFilter.size === 0 || roleFilter.has(document.role))
|
|
174
177
|
.sort(sortRecentDocuments)
|
|
175
178
|
.slice(0, maxChunks);
|