opensquid 0.5.441 → 0.5.447
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 +1 -0
- package/dist/functions/arm_scope.d.ts +27 -0
- package/dist/functions/arm_scope.d.ts.map +1 -0
- package/dist/functions/arm_scope.js +52 -0
- package/dist/functions/arm_scope.js.map +1 -0
- package/dist/functions/index.d.ts +1 -0
- package/dist/functions/index.d.ts.map +1 -1
- package/dist/functions/index.js +1 -0
- package/dist/functions/index.js.map +1 -1
- package/dist/runtime/bootstrap.d.ts.map +1 -1
- package/dist/runtime/bootstrap.js +2 -0
- package/dist/runtime/bootstrap.js.map +1 -1
- package/dist/runtime/handoff/render.d.ts +5 -4
- package/dist/runtime/handoff/render.d.ts.map +1 -1
- package/dist/runtime/handoff/render.js +7 -7
- package/dist/runtime/handoff/render.js.map +1 -1
- package/dist/runtime/hooks/active_task_mirror.js +0 -0
- package/dist/runtime/hooks/apply_patch.js +0 -0
- package/dist/runtime/hooks/dispatch.js +0 -0
- package/dist/runtime/hooks/hook_output.js +0 -0
- package/dist/runtime/hooks/memory_reconcile.js +0 -0
- package/dist/runtime/hooks/new_project_detect.js +0 -0
- package/dist/runtime/hooks/profession_resolver.js +0 -0
- package/dist/runtime/hooks/scope_intent.js +0 -0
- package/dist/runtime/hooks/session_id.js +0 -0
- package/dist/runtime/hooks/session_liveness.js +0 -0
- package/dist/runtime/hooks/stop_drive.js +0 -0
- package/dist/runtime/hooks/stop_stream.js +0 -0
- package/dist/runtime/hooks/subagent_guard.js +0 -0
- package/dist/runtime/hooks/transcript.js +0 -0
- package/dist/runtime/hooks/transcript_tasks.js +0 -0
- package/dist/runtime/ralph/orchestrator.d.ts.map +1 -1
- package/dist/runtime/ralph/orchestrator.js +2 -1
- package/dist/runtime/ralph/orchestrator.js.map +1 -1
- package/dist/setup/cli/limits_state.d.ts.map +1 -1
- package/dist/setup/cli/limits_state.js +6 -40
- package/dist/setup/cli/limits_state.js.map +1 -1
- package/dist/setup/cli/pack_walk.d.ts +32 -0
- package/dist/setup/cli/pack_walk.d.ts.map +1 -0
- package/dist/setup/cli/pack_walk.js +76 -0
- package/dist/setup/cli/pack_walk.js.map +1 -0
- package/dist/setup/cli/permissions_state.d.ts.map +1 -1
- package/dist/setup/cli/permissions_state.js +6 -37
- package/dist/setup/cli/permissions_state.js.map +1 -1
- package/dist/setup/cli/triggers_state.d.ts.map +1 -1
- package/dist/setup/cli/triggers_state.js +3 -29
- package/dist/setup/cli/triggers_state.js.map +1 -1
- package/dist/workgraph/events.d.ts.map +1 -1
- package/dist/workgraph/events.js +10 -0
- package/dist/workgraph/events.js.map +1 -1
- package/dist/workgraph/store.d.ts.map +1 -1
- package/dist/workgraph/store.js +5 -0
- package/dist/workgraph/store.js.map +1 -1
- package/dist/workgraph/types.d.ts +2 -1
- package/dist/workgraph/types.d.ts.map +1 -1
- package/docs/ARCHITECTURE.md +268 -0
- package/package.json +5 -3
- package/packs/builtin/coding-flow/skills/entry-and-handoffs/skill.yaml +13 -17
- package/dist/anti-drift/evaluator.d.ts +0 -88
- package/dist/anti-drift/evaluator.d.ts.map +0 -1
- package/dist/anti-drift/evaluator.js +0 -417
- package/dist/anti-drift/evaluator.js.map +0 -1
- package/dist/anti-drift/evaluator.test.js +0 -78
- package/dist/anti-drift/rules.d.ts +0 -80
- package/dist/anti-drift/rules.d.ts.map +0 -1
- package/dist/anti-drift/rules.js +0 -368
- package/dist/anti-drift/rules.js.map +0 -1
- package/dist/anti-drift/rules.test.js +0 -213
- package/dist/anti-drift/state.d.ts +0 -107
- package/dist/anti-drift/state.d.ts.map +0 -1
- package/dist/anti-drift/state.js +0 -177
- package/dist/anti-drift/state.js.map +0 -1
- package/dist/anti-drift/state.test.js +0 -120
- package/dist/chat/adapters/discord.d.ts +0 -41
- package/dist/chat/adapters/discord.d.ts.map +0 -1
- package/dist/chat/adapters/discord.js +0 -176
- package/dist/chat/adapters/discord.js.map +0 -1
- package/dist/chat/adapters/discord.test.js +0 -25
- package/dist/chat/adapters/slack.d.ts +0 -43
- package/dist/chat/adapters/slack.d.ts.map +0 -1
- package/dist/chat/adapters/slack.js +0 -172
- package/dist/chat/adapters/slack.js.map +0 -1
- package/dist/chat/adapters/slack.test.js +0 -30
- package/dist/chat/adapters/telegram.d.ts +0 -148
- package/dist/chat/adapters/telegram.d.ts.map +0 -1
- package/dist/chat/adapters/telegram.js +0 -498
- package/dist/chat/adapters/telegram.js.map +0 -1
- package/dist/chat/adapters/telegram.test.js +0 -94
- package/dist/chat/config.d.ts +0 -98
- package/dist/chat/config.d.ts.map +0 -1
- package/dist/chat/config.js +0 -185
- package/dist/chat/config.js.map +0 -1
- package/dist/chat/daemon/active-project.d.ts +0 -17
- package/dist/chat/daemon/active-project.d.ts.map +0 -1
- package/dist/chat/daemon/active-project.js +0 -23
- package/dist/chat/daemon/active-project.js.map +0 -1
- package/dist/chat/daemon/autospawn.d.ts +0 -40
- package/dist/chat/daemon/autospawn.d.ts.map +0 -1
- package/dist/chat/daemon/autospawn.js +0 -129
- package/dist/chat/daemon/autospawn.js.map +0 -1
- package/dist/chat/daemon/autospawn.test.js +0 -112
- package/dist/chat/daemon/cli.d.ts +0 -18
- package/dist/chat/daemon/cli.d.ts.map +0 -1
- package/dist/chat/daemon/cli.js +0 -71
- package/dist/chat/daemon/cli.js.map +0 -1
- package/dist/chat/daemon/collisions.js +0 -384
- package/dist/chat/daemon/health-check.d.ts +0 -69
- package/dist/chat/daemon/health-check.d.ts.map +0 -1
- package/dist/chat/daemon/health-check.js +0 -112
- package/dist/chat/daemon/health-check.js.map +0 -1
- package/dist/chat/daemon/inbox-read.d.ts +0 -35
- package/dist/chat/daemon/inbox-read.d.ts.map +0 -1
- package/dist/chat/daemon/inbox-read.js +0 -75
- package/dist/chat/daemon/inbox-read.js.map +0 -1
- package/dist/chat/daemon/inbox-read.test.js +0 -97
- package/dist/chat/daemon/inbox.d.ts +0 -63
- package/dist/chat/daemon/inbox.d.ts.map +0 -1
- package/dist/chat/daemon/inbox.js +0 -56
- package/dist/chat/daemon/inbox.js.map +0 -1
- package/dist/chat/daemon/inbox.test.js +0 -110
- package/dist/chat/daemon/lifecycle.d.ts +0 -71
- package/dist/chat/daemon/lifecycle.d.ts.map +0 -1
- package/dist/chat/daemon/lifecycle.js +0 -221
- package/dist/chat/daemon/lifecycle.js.map +0 -1
- package/dist/chat/daemon/lifecycle.test.js +0 -163
- package/dist/chat/daemon/protocol.d.ts +0 -107
- package/dist/chat/daemon/protocol.d.ts.map +0 -1
- package/dist/chat/daemon/protocol.js +0 -54
- package/dist/chat/daemon/protocol.js.map +0 -1
- package/dist/chat/daemon/routing.d.ts +0 -140
- package/dist/chat/daemon/routing.d.ts.map +0 -1
- package/dist/chat/daemon/routing.js +0 -198
- package/dist/chat/daemon/routing.js.map +0 -1
- package/dist/chat/daemon/routing.test.js +0 -259
- package/dist/chat/daemon/rpc-client.d.ts +0 -45
- package/dist/chat/daemon/rpc-client.d.ts.map +0 -1
- package/dist/chat/daemon/rpc-client.js +0 -133
- package/dist/chat/daemon/rpc-client.js.map +0 -1
- package/dist/chat/daemon/rpc-server.d.ts +0 -39
- package/dist/chat/daemon/rpc-server.d.ts.map +0 -1
- package/dist/chat/daemon/rpc-server.js +0 -385
- package/dist/chat/daemon/rpc-server.js.map +0 -1
- package/dist/chat/daemon/rpc.test.js +0 -177
- package/dist/chat/daemon/subscribers.js +0 -257
- package/dist/chat/daemon/worker.d.ts +0 -27
- package/dist/chat/daemon/worker.d.ts.map +0 -1
- package/dist/chat/daemon/worker.js +0 -313
- package/dist/chat/daemon/worker.js.map +0 -1
- package/dist/chat/daemon/workspace-topic.js +0 -324
- package/dist/chat/env-token.d.ts +0 -60
- package/dist/chat/env-token.d.ts.map +0 -1
- package/dist/chat/env-token.js +0 -137
- package/dist/chat/env-token.js.map +0 -1
- package/dist/chat/env-token.test.js +0 -160
- package/dist/chat/factory.d.ts +0 -30
- package/dist/chat/factory.d.ts.map +0 -1
- package/dist/chat/factory.js +0 -50
- package/dist/chat/factory.js.map +0 -1
- package/dist/chat/factory.test.js +0 -55
- package/dist/chat/gateway.d.ts +0 -176
- package/dist/chat/gateway.d.ts.map +0 -1
- package/dist/chat/gateway.js +0 -146
- package/dist/chat/gateway.js.map +0 -1
- package/dist/chat/gateway.test.js +0 -192
- package/dist/claude-md.d.ts +0 -39
- package/dist/claude-md.d.ts.map +0 -1
- package/dist/claude-md.js +0 -113
- package/dist/claude-md.js.map +0 -1
- package/dist/claude-md.test.js +0 -91
- package/dist/codex/activate.d.ts +0 -66
- package/dist/codex/activate.d.ts.map +0 -1
- package/dist/codex/activate.js +0 -329
- package/dist/codex/activate.js.map +0 -1
- package/dist/codex/activate.test.js +0 -229
- package/dist/codex/bundled-default/bundled-default.test.js +0 -161
- package/dist/codex/cli-publish.test.js +0 -133
- package/dist/codex/cli.d.ts +0 -35
- package/dist/codex/cli.d.ts.map +0 -1
- package/dist/codex/cli.js +0 -554
- package/dist/codex/cli.js.map +0 -1
- package/dist/codex/cli.test.js +0 -277
- package/dist/codex/import-skill-md.d.ts +0 -53
- package/dist/codex/import-skill-md.d.ts.map +0 -1
- package/dist/codex/import-skill-md.js +0 -236
- package/dist/codex/import-skill-md.js.map +0 -1
- package/dist/codex/import-skill-md.test.js +0 -225
- package/dist/codex/loader.d.ts +0 -27
- package/dist/codex/loader.d.ts.map +0 -1
- package/dist/codex/loader.js +0 -86
- package/dist/codex/loader.js.map +0 -1
- package/dist/codex/loader.test.js +0 -75
- package/dist/codex/parse.d.ts +0 -28
- package/dist/codex/parse.d.ts.map +0 -1
- package/dist/codex/parse.js +0 -309
- package/dist/codex/parse.js.map +0 -1
- package/dist/codex/parse.test.js +0 -241
- package/dist/codex/store.d.ts +0 -87
- package/dist/codex/store.d.ts.map +0 -1
- package/dist/codex/store.js +0 -205
- package/dist/codex/store.js.map +0 -1
- package/dist/codex/store.test.js +0 -242
- package/dist/codex/types.d.ts +0 -398
- package/dist/codex/types.d.ts.map +0 -1
- package/dist/codex/types.js +0 -21
- package/dist/codex/types.js.map +0 -1
- package/dist/config.d.ts +0 -53
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js +0 -202
- package/dist/config.js.map +0 -1
- package/dist/config.test.js +0 -117
- package/dist/engine/cli.d.ts +0 -14
- package/dist/engine/cli.d.ts.map +0 -1
- package/dist/engine/cli.js +0 -171
- package/dist/engine/cli.js.map +0 -1
- package/dist/engine/client.d.ts +0 -219
- package/dist/engine/client.d.ts.map +0 -1
- package/dist/engine/client.js +0 -312
- package/dist/engine/client.js.map +0 -1
- package/dist/engine/config.d.ts +0 -62
- package/dist/engine/config.d.ts.map +0 -1
- package/dist/engine/config.js +0 -223
- package/dist/engine/config.js.map +0 -1
- package/dist/engine/index.d.ts +0 -17
- package/dist/engine/index.d.ts.map +0 -1
- package/dist/engine/index.js +0 -16
- package/dist/engine/index.js.map +0 -1
- package/dist/engine/resolver.d.ts +0 -62
- package/dist/engine/resolver.d.ts.map +0 -1
- package/dist/engine/resolver.js +0 -103
- package/dist/engine/resolver.js.map +0 -1
- package/dist/engine/singleton.d.ts +0 -95
- package/dist/engine/singleton.d.ts.map +0 -1
- package/dist/engine/singleton.js +0 -325
- package/dist/engine/singleton.js.map +0 -1
- package/dist/engine/types.d.ts +0 -402
- package/dist/engine/types.d.ts.map +0 -1
- package/dist/engine/types.js +0 -22
- package/dist/engine/types.js.map +0 -1
- package/dist/engine-binary-resolver.js +0 -110
- package/dist/engine-binary-resolver.test.js +0 -61
- package/dist/engine-cli.js +0 -60
- package/dist/engine-client.js +0 -301
- package/dist/engine-client.test.js +0 -118
- package/dist/functions/chain_state.d.ts +0 -51
- package/dist/functions/chain_state.d.ts.map +0 -1
- package/dist/functions/chain_state.js +0 -59
- package/dist/functions/chain_state.js.map +0 -1
- package/dist/hooks/drift-catalog.d.ts +0 -68
- package/dist/hooks/drift-catalog.d.ts.map +0 -1
- package/dist/hooks/drift-catalog.js +0 -184
- package/dist/hooks/drift-catalog.js.map +0 -1
- package/dist/hooks/drift-catalog.test.js +0 -154
- package/dist/hooks/drift-patterns.d.ts +0 -110
- package/dist/hooks/drift-patterns.d.ts.map +0 -1
- package/dist/hooks/drift-patterns.js +0 -289
- package/dist/hooks/drift-patterns.js.map +0 -1
- package/dist/hooks/drift-patterns.test.js +0 -325
- package/dist/hooks/engine-vocab-gate.d.ts +0 -108
- package/dist/hooks/engine-vocab-gate.d.ts.map +0 -1
- package/dist/hooks/engine-vocab-gate.js +0 -225
- package/dist/hooks/engine-vocab-gate.js.map +0 -1
- package/dist/hooks/engine-vocab-gate.test.js +0 -170
- package/dist/hooks/heartbeat.d.ts +0 -107
- package/dist/hooks/heartbeat.d.ts.map +0 -1
- package/dist/hooks/heartbeat.js +0 -316
- package/dist/hooks/heartbeat.js.map +0 -1
- package/dist/hooks/heartbeat.test.js +0 -393
- package/dist/hooks/honesty-ledger-session-scope.test.js +0 -100
- package/dist/hooks/honesty-ledger.d.ts +0 -123
- package/dist/hooks/honesty-ledger.d.ts.map +0 -1
- package/dist/hooks/honesty-ledger.js +0 -226
- package/dist/hooks/honesty-ledger.js.map +0 -1
- package/dist/hooks/honesty-ledger.test.js +0 -466
- package/dist/hooks/inline-report-check.d.ts +0 -63
- package/dist/hooks/inline-report-check.d.ts.map +0 -1
- package/dist/hooks/inline-report-check.js +0 -88
- package/dist/hooks/inline-report-check.js.map +0 -1
- package/dist/hooks/inline-report-check.test.js +0 -96
- package/dist/hooks/pre-tool-use.d.ts +0 -62
- package/dist/hooks/pre-tool-use.d.ts.map +0 -1
- package/dist/hooks/pre-tool-use.js +0 -342
- package/dist/hooks/pre-tool-use.js.map +0 -1
- package/dist/hooks/pre-tool-use.test.js +0 -134
- package/dist/hooks/session-end.d.ts +0 -15
- package/dist/hooks/session-end.d.ts.map +0 -1
- package/dist/hooks/session-end.js +0 -60
- package/dist/hooks/session-end.js.map +0 -1
- package/dist/hooks/session-end.test.js +0 -52
- package/dist/hooks/stop.d.ts +0 -35
- package/dist/hooks/stop.d.ts.map +0 -1
- package/dist/hooks/stop.js +0 -136
- package/dist/hooks/stop.js.map +0 -1
- package/dist/hooks/transcript-active-task.test.js +0 -342
- package/dist/hooks/transcript.d.ts +0 -26
- package/dist/hooks/transcript.d.ts.map +0 -1
- package/dist/hooks/transcript.js +0 -266
- package/dist/hooks/transcript.js.map +0 -1
- package/dist/hooks/transcript.test.js +0 -103
- package/dist/hooks/user-prompt-submit.d.ts +0 -74
- package/dist/hooks/user-prompt-submit.d.ts.map +0 -1
- package/dist/hooks/user-prompt-submit.js +0 -256
- package/dist/hooks/user-prompt-submit.js.map +0 -1
- package/dist/hooks/user-prompt-submit.test.js +0 -118
- package/dist/hooks/versioning-gate.d.ts +0 -101
- package/dist/hooks/versioning-gate.d.ts.map +0 -1
- package/dist/hooks/versioning-gate.js +0 -245
- package/dist/hooks/versioning-gate.js.map +0 -1
- package/dist/hooks/versioning-gate.test.js +0 -368
- package/dist/hooks/workflow-gate.d.ts +0 -64
- package/dist/hooks/workflow-gate.d.ts.map +0 -1
- package/dist/hooks/workflow-gate.js +0 -152
- package/dist/hooks/workflow-gate.js.map +0 -1
- package/dist/hooks/workflow-gate.test.js +0 -197
- package/dist/hooks-cli.d.ts +0 -25
- package/dist/hooks-cli.d.ts.map +0 -1
- package/dist/hooks-cli.js +0 -286
- package/dist/hooks-cli.js.map +0 -1
- package/dist/hooks-cli.test.js +0 -148
- package/dist/origin.d.ts +0 -16
- package/dist/origin.d.ts.map +0 -1
- package/dist/origin.js +0 -92
- package/dist/origin.js.map +0 -1
- package/dist/packs/seed_lessons_ingest.d.ts +0 -30
- package/dist/packs/seed_lessons_ingest.d.ts.map +0 -1
- package/dist/packs/seed_lessons_ingest.js +0 -107
- package/dist/packs/seed_lessons_ingest.js.map +0 -1
- package/dist/project-cli.d.ts +0 -7
- package/dist/project-cli.d.ts.map +0 -1
- package/dist/project-cli.js +0 -145
- package/dist/project-cli.js.map +0 -1
- package/dist/project.d.ts +0 -127
- package/dist/project.d.ts.map +0 -1
- package/dist/project.js +0 -281
- package/dist/project.js.map +0 -1
- package/dist/project.test.js +0 -287
- package/dist/rag/backends/loop_engine.d.ts +0 -61
- package/dist/rag/backends/loop_engine.d.ts.map +0 -1
- package/dist/rag/backends/loop_engine.js +0 -160
- package/dist/rag/backends/loop_engine.js.map +0 -1
- package/dist/recall.d.ts +0 -82
- package/dist/recall.d.ts.map +0 -1
- package/dist/recall.js +0 -81
- package/dist/recall.js.map +0 -1
- package/dist/runtime/agent_bridge/autospawn.d.ts +0 -131
- package/dist/runtime/agent_bridge/autospawn.d.ts.map +0 -1
- package/dist/runtime/agent_bridge/autospawn.js +0 -251
- package/dist/runtime/agent_bridge/autospawn.js.map +0 -1
- package/dist/runtime/chain_state.d.ts +0 -124
- package/dist/runtime/chain_state.d.ts.map +0 -1
- package/dist/runtime/chain_state.js +0 -189
- package/dist/runtime/chain_state.js.map +0 -1
- package/dist/runtime/hooks/permission_decision.d.ts +0 -34
- package/dist/runtime/hooks/permission_decision.d.ts.map +0 -1
- package/dist/runtime/hooks/permission_decision.js +0 -39
- package/dist/runtime/hooks/permission_decision.js.map +0 -1
- package/dist/runtime/workflow_fsm.d.ts +0 -21
- package/dist/runtime/workflow_fsm.d.ts.map +0 -1
- package/dist/runtime/workflow_fsm.js +0 -25
- package/dist/runtime/workflow_fsm.js.map +0 -1
- package/dist/runtime/workflow_map.d.ts +0 -26
- package/dist/runtime/workflow_map.d.ts.map +0 -1
- package/dist/runtime/workflow_map.js +0 -38
- package/dist/runtime/workflow_map.js.map +0 -1
- package/dist/scope.d.ts +0 -48
- package/dist/scope.d.ts.map +0 -1
- package/dist/scope.js +0 -111
- package/dist/scope.js.map +0 -1
- package/dist/setup/cli/topic_create_step.d.ts +0 -84
- package/dist/setup/cli/topic_create_step.d.ts.map +0 -1
- package/dist/setup/cli/topic_create_step.js +0 -213
- package/dist/setup/cli/topic_create_step.js.map +0 -1
- package/dist/system-export.d.ts +0 -65
- package/dist/system-export.d.ts.map +0 -1
- package/dist/system-export.js +0 -194
- package/dist/system-export.js.map +0 -1
- package/dist/utterance/classifier.d.ts +0 -53
- package/dist/utterance/classifier.d.ts.map +0 -1
- package/dist/utterance/classifier.js +0 -184
- package/dist/utterance/classifier.js.map +0 -1
- package/dist/utterance/classifier.test.js +0 -147
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Loop-engine RAG backend — routes RagBackend through the engine daemon's
|
|
3
|
-
* JSON-RPC API (memory.search + memory.create) via the T.4 UDS singleton.
|
|
4
|
-
*
|
|
5
|
-
* Quality: `mode: 'hybrid'` invokes engine-side RRF fusion (K=60, Cormack
|
|
6
|
-
* et al. 2009) — drop-in equivalent to opensquid's `src/rag/rrf.ts:65`
|
|
7
|
-
* per T.1.JJ. No TS-side fusion needed; engine does it server-side over a
|
|
8
|
-
* larger native vector index than libsql's DiskANN.
|
|
9
|
-
*
|
|
10
|
-
* Critical design locks (T.1.B + T.1.#6):
|
|
11
|
-
*
|
|
12
|
-
* 1. **storeLesson → memory.create is INTENTIONAL, not a bug.** Routing
|
|
13
|
-
* here through `lesson.create` would force every recall-pool write
|
|
14
|
-
* through the wedge gate's 24h + applied_count=3 + external_signal
|
|
15
|
-
* promotion requirements (per T.1.F — unsatisfiable in a single
|
|
16
|
-
* write call, breaks unit tests). RagBackend.storeLesson semantically
|
|
17
|
-
* stores a recallable memory, NOT a wedge-gated lesson; lesson
|
|
18
|
-
* lifecycle is a separate surface added in T.6.
|
|
19
|
-
*
|
|
20
|
-
* 2. **Description synthesis is mandatory.** `memory.create` rejects
|
|
21
|
-
* empty `description` (T.1.B INVALID_PARAMS -32602). Synthesized
|
|
22
|
-
* from first sentence → first 80 chars → ultimate fallback. Lesson
|
|
23
|
-
* shape doesn't carry a description field today, so we derive it.
|
|
24
|
-
*
|
|
25
|
-
* 3. **`include_body: true` on every recall.** memory.search's default
|
|
26
|
-
* `body_preview` is truncated to 240 chars (engine serve.rs); without
|
|
27
|
-
* this flag RecallHit.lesson.content gets cut mid-sentence.
|
|
28
|
-
*
|
|
29
|
-
* 4. **Source vocab mapping at the boundary.** Engine speaks
|
|
30
|
-
* `'semantic' | 'text' | 'both'`; RagBackend's RecallHit speaks
|
|
31
|
-
* `'semantic' | 'lexical' | 'fused'`. The adapter table is the
|
|
32
|
-
* single point of translation — DO NOT leak engine vocab past it.
|
|
33
|
-
*
|
|
34
|
-
* 5. **Engine schema gap.** `memory.create` doesn't preserve tags /
|
|
35
|
-
* source / author / createdAt today (T.8 follow-up filed). For v1
|
|
36
|
-
* we send `description` + `content` only; lesson metadata round-trips
|
|
37
|
-
* via the Lesson defaults applied by `src/functions/rag.ts:122-145`.
|
|
38
|
-
*
|
|
39
|
-
* 6. **No daemon lifecycle here.** `EngineClient` connects via the T.4
|
|
40
|
-
* `acquireOrSpawnEngine()` singleton transparently — zero per-call
|
|
41
|
-
* subprocess cost, cross-session shared engine.
|
|
42
|
-
*
|
|
43
|
-
* Imports from: ../../engine/client.js, ../ollama_client.js, ../types.js.
|
|
44
|
-
* Imported by: src/rag/backend_factory.ts.
|
|
45
|
-
*/
|
|
46
|
-
import { ENGINE_ERROR, EngineClient, RpcError } from '../../engine/client.js';
|
|
47
|
-
import { ollamaEmbed } from '../ollama_client.js';
|
|
48
|
-
import { UserAuthoredImmunityError } from '../types.js';
|
|
49
|
-
export function loopEngineBackend(opts = {}) {
|
|
50
|
-
const client = opts.client ?? new EngineClient();
|
|
51
|
-
const mode = opts.mode ?? 'hybrid';
|
|
52
|
-
const ollamaUrl = opts.ollamaUrl ?? 'http://localhost:11434';
|
|
53
|
-
return {
|
|
54
|
-
async init() {
|
|
55
|
-
// Ensures engine daemon is up + connected before any primitive call.
|
|
56
|
-
// Singleton handles spawn-or-acquire; ping confirms the handshake.
|
|
57
|
-
await client.ping();
|
|
58
|
-
},
|
|
59
|
-
async embed(text) {
|
|
60
|
-
// RagBackend contract says embedder-unavailable returns null, not
|
|
61
|
-
// throws (T.1.T). ollamaEmbed throws on HTTP / malformed response;
|
|
62
|
-
// we translate.
|
|
63
|
-
try {
|
|
64
|
-
return await ollamaEmbed(ollamaUrl, text);
|
|
65
|
-
}
|
|
66
|
-
catch {
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
async recall(query, k) {
|
|
71
|
-
const result = await client.memorySearch({
|
|
72
|
-
query,
|
|
73
|
-
limit: k,
|
|
74
|
-
mode,
|
|
75
|
-
include_body: true,
|
|
76
|
-
});
|
|
77
|
-
return result.results.map((h) => ({
|
|
78
|
-
lesson: {
|
|
79
|
-
id: h.id,
|
|
80
|
-
content: h.body_preview,
|
|
81
|
-
tags: [],
|
|
82
|
-
source: 'unknown',
|
|
83
|
-
author: 'user',
|
|
84
|
-
createdAt: '',
|
|
85
|
-
},
|
|
86
|
-
score: h.similarity,
|
|
87
|
-
source: mapEngineSource(h.source),
|
|
88
|
-
}));
|
|
89
|
-
},
|
|
90
|
-
async storeLesson(lesson) {
|
|
91
|
-
const description = synthesizeDescription(lesson.content);
|
|
92
|
-
await client.memoryCreate({
|
|
93
|
-
description,
|
|
94
|
-
content: lesson.content,
|
|
95
|
-
// Preserve eviction immunity across the write-path cutover: a `user`-authored memory must
|
|
96
|
-
// round-trip `authored_by` so the engine keeps it eviction-immune (else memorize→storeLesson
|
|
97
|
-
// would silently strip immunity). The string collapses to Lesson.author ('user'|'agent').
|
|
98
|
-
authored_by: lesson.author,
|
|
99
|
-
});
|
|
100
|
-
},
|
|
101
|
-
async deleteLesson(id, delOpts) {
|
|
102
|
-
try {
|
|
103
|
-
await client.memoryGet({ id }); // existence pre-check (NOT_FOUND → not-found result)
|
|
104
|
-
}
|
|
105
|
-
catch (e) {
|
|
106
|
-
if (e instanceof RpcError && e.code === ENGINE_ERROR.NOT_FOUND) {
|
|
107
|
-
return { deleted: false, forced: false };
|
|
108
|
-
}
|
|
109
|
-
throw e;
|
|
110
|
-
}
|
|
111
|
-
try {
|
|
112
|
-
const result = await client.memoryDelete({
|
|
113
|
-
id,
|
|
114
|
-
...(delOpts?.force === undefined ? {} : { force: delOpts.force }),
|
|
115
|
-
});
|
|
116
|
-
return { deleted: true, forced: result.forced };
|
|
117
|
-
}
|
|
118
|
-
catch (e) {
|
|
119
|
-
if (e instanceof RpcError && e.code === ENGINE_ERROR.USER_MEMORY_IMMUNE) {
|
|
120
|
-
throw new UserAuthoredImmunityError(id);
|
|
121
|
-
}
|
|
122
|
-
throw e;
|
|
123
|
-
}
|
|
124
|
-
},
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Derive a non-empty description from lesson content. Engine rejects
|
|
129
|
-
* empty descriptions with INVALID_PARAMS -32602 (T.1.B). Algorithm:
|
|
130
|
-
* 1. First sentence (split on `.!?\n`), trimmed, capped at 80 chars
|
|
131
|
-
* 2. Fallback: first 80 chars of raw content (for sentence-free text)
|
|
132
|
-
* 3. Ultimate fallback: `'untitled memory'` (empty-content edge case)
|
|
133
|
-
*
|
|
134
|
-
* 80 chars chosen to match engine's description display budget without
|
|
135
|
-
* truncation in `manifest.assemble` output (engine serve.rs body_preview).
|
|
136
|
-
*/
|
|
137
|
-
function synthesizeDescription(content) {
|
|
138
|
-
const firstSentence = content.split(/[.!?\n]/)[0]?.trim() ?? content;
|
|
139
|
-
return firstSentence.slice(0, 80) || content.slice(0, 80) || 'untitled memory';
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Translate engine source vocabulary into RagBackend RecallHit vocabulary.
|
|
143
|
-
* Engine uses `'semantic' | 'text' | 'both'` (only present in hybrid
|
|
144
|
-
* results); opensquid uses `'semantic' | 'lexical' | 'fused'`. When
|
|
145
|
-
* engine omits source (non-hybrid modes), default to `'semantic'` —
|
|
146
|
-
* matches the dominant recall-from-vector path.
|
|
147
|
-
*/
|
|
148
|
-
function mapEngineSource(s) {
|
|
149
|
-
switch (s) {
|
|
150
|
-
case 'semantic':
|
|
151
|
-
return 'semantic';
|
|
152
|
-
case 'text':
|
|
153
|
-
return 'lexical';
|
|
154
|
-
case 'both':
|
|
155
|
-
return 'fused';
|
|
156
|
-
default:
|
|
157
|
-
return 'semantic';
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
//# sourceMappingURL=loop_engine.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"loop_engine.js","sourceRoot":"","sources":["../../../src/rag/backends/loop_engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AAEH,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAC9E,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElD,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAiBxD,MAAM,UAAU,iBAAiB,CAAC,OAA8B,EAAE;IAChE,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,IAAI,YAAY,EAAE,CAAC;IACjD,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,QAAQ,CAAC;IACnC,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,IAAI,wBAAwB,CAAC;IAE7D,OAAO;QACL,KAAK,CAAC,IAAI;YACR,qEAAqE;YACrE,mEAAmE;YACnE,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;QACtB,CAAC;QAED,KAAK,CAAC,KAAK,CAAC,IAAY;YACtB,kEAAkE;YAClE,mEAAmE;YACnE,gBAAgB;YAChB,IAAI,CAAC;gBACH,OAAO,MAAM,WAAW,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;YAC5C,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;QAED,KAAK,CAAC,MAAM,CAAC,KAAa,EAAE,CAAS;YACnC,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,YAAY,CAAC;gBACvC,KAAK;gBACL,KAAK,EA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RF)
|
|
3
|
-
* + similarity-threshold gating.
|
|
4
|
-
*
|
|
5
|
-
* The engine returns lessons (text-match similarity) and memories
|
|
6
|
-
* (semantic-vector similarity) on different score scales — they're
|
|
7
|
-
* not directly comparable. RRF sidesteps that: it ignores absolute
|
|
8
|
-
* scores and uses ranks-within-list only. Items appearing in BOTH
|
|
9
|
-
* lists get a strong combined boost — "the text matched AND the
|
|
10
|
-
* embedding is close" is the most reliable signal.
|
|
11
|
-
*
|
|
12
|
-
* The similarity threshold filters PER-SOURCE before merging so a
|
|
13
|
-
* weak hit in one list can't poison the merged ranking. When all
|
|
14
|
-
* results are filtered out, recall returns an empty merged array —
|
|
15
|
-
* "no relevant context" is decision-makable; "top hit at sim=0.31"
|
|
16
|
-
* is noise.
|
|
17
|
-
*/
|
|
18
|
-
/** Conventional RRF damping constant — survives well across domains. */
|
|
19
|
-
export declare const RRF_K = 60;
|
|
20
|
-
/** Default minimum similarity to consider a result relevant. */
|
|
21
|
-
export declare const DEFAULT_MIN_SIMILARITY = 0.5;
|
|
22
|
-
export interface LessonHit {
|
|
23
|
-
kind: "lesson";
|
|
24
|
-
id: string;
|
|
25
|
-
description: string;
|
|
26
|
-
status: string;
|
|
27
|
-
body_preview: string;
|
|
28
|
-
similarity: number;
|
|
29
|
-
applied_count: number;
|
|
30
|
-
}
|
|
31
|
-
export interface MemoryHit {
|
|
32
|
-
kind: "memory";
|
|
33
|
-
id: string;
|
|
34
|
-
description: string;
|
|
35
|
-
body_preview: string;
|
|
36
|
-
similarity: number;
|
|
37
|
-
/** v0.5: present when the engine's `memory.search` ran in hybrid
|
|
38
|
-
* (or text-only) mode. `"both"` means the hit surfaced from both
|
|
39
|
-
* the semantic neighborhood AND the text-match scan — strongest
|
|
40
|
-
* signal. Surfaced through to the MCP response for diagnostics. */
|
|
41
|
-
source?: "semantic" | "text" | "both";
|
|
42
|
-
}
|
|
43
|
-
export type RecallHit = LessonHit | MemoryHit;
|
|
44
|
-
export interface MergedHit {
|
|
45
|
-
kind: "lesson" | "memory";
|
|
46
|
-
id: string;
|
|
47
|
-
description: string;
|
|
48
|
-
body_preview: string;
|
|
49
|
-
/** Original per-source similarity (lesson text-match or memory semantic). */
|
|
50
|
-
similarity: number;
|
|
51
|
-
/** RRF score — higher is better. Not directly comparable to similarity. */
|
|
52
|
-
rrf_score: number;
|
|
53
|
-
/** 1-based rank in the lesson list (undefined if not a lesson hit). */
|
|
54
|
-
lesson_rank?: number;
|
|
55
|
-
/** 1-based rank in the memory list (undefined if not a memory hit). */
|
|
56
|
-
memory_rank?: number;
|
|
57
|
-
/** v0.5: when this hit came from a memory and the engine produced
|
|
58
|
-
* the memory in hybrid (or text-only) mode, this carries the
|
|
59
|
-
* sub-source attribution: `"semantic"`, `"text"`, or `"both"`.
|
|
60
|
-
* Lesson hits leave this undefined (engine.recall doesn't expose
|
|
61
|
-
* a sub-source). */
|
|
62
|
-
source?: "semantic" | "text" | "both";
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Filter a hit list to those with similarity at or above `threshold`.
|
|
66
|
-
* Stable: preserves the input order (which is engine-side rank).
|
|
67
|
-
*/
|
|
68
|
-
export declare function filterBySimilarity<T extends {
|
|
69
|
-
similarity: number;
|
|
70
|
-
}>(hits: T[], threshold: number): T[];
|
|
71
|
-
/**
|
|
72
|
-
* Reciprocal Rank Fusion across two ranked lists. The RRF score for
|
|
73
|
-
* an item is `sum over each source list: 1 / (RRF_K + rank_in_that_list)`,
|
|
74
|
-
* where rank is 1-based. Items appearing in both lists accumulate
|
|
75
|
-
* contributions and naturally rank above single-source items.
|
|
76
|
-
*
|
|
77
|
-
* Returns merged hits ordered by descending `rrf_score`. Identity is
|
|
78
|
-
* by `id` — a lesson and a memory with the same id (engine never
|
|
79
|
-
* collides these in practice) would merge; we treat that as harmless.
|
|
80
|
-
*/
|
|
81
|
-
export declare function mergeRrf(lessons: LessonHit[], memories: MemoryHit[]): MergedHit[];
|
|
82
|
-
//# sourceMappingURL=recall.d.ts.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AAM,CAAC;CACvC;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS;IAAE,UAAU,EAAE,MAAM,CAAA;CAAE,EACjE,IAAI,EAAE,CAAC,EAAE,EACT,SAAS,EAAE,MAAM,GAChB,CAAC,EAAE,CAGL;AAED;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,SAAS,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,SAAS,EAAE,CAwCjF"}
|
package/dist/recall.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Phase 4: recall ranking utilities — Reciprocal Rank Fusion (RRF)
|
|
3
|
-
* + similarity-threshold gating.
|
|
4
|
-
*
|
|
5
|
-
* The engine returns lessons (text-match similarity) and memories
|
|
6
|
-
* (semantic-vector similarity) on different score scales — they're
|
|
7
|
-
* not directly comparable. RRF sidesteps that: it ignores absolute
|
|
8
|
-
* scores and uses ranks-within-list only. Items appearing in BOTH
|
|
9
|
-
* lists get a strong combined boost — "the text matched AND the
|
|
10
|
-
* embedding is close" is the most reliable signal.
|
|
11
|
-
*
|
|
12
|
-
* The similarity threshold filters PER-SOURCE before merging so a
|
|
13
|
-
* weak hit in one list can't poison the merged ranking. When all
|
|
14
|
-
* results are filtered out, recall returns an empty merged array —
|
|
15
|
-
* "no relevant context" is decision-makable; "top hit at sim=0.31"
|
|
16
|
-
* is noise.
|
|
17
|
-
*/
|
|
18
|
-
/** Conventional RRF damping constant — survives well across domains. */
|
|
19
|
-
export const RRF_K = 60;
|
|
20
|
-
/** Default minimum similarity to consider a result relevant. */
|
|
21
|
-
export const DEFAULT_MIN_SIMILARITY = 0.5;
|
|
22
|
-
/**
|
|
23
|
-
* Filter a hit list to those with similarity at or above `threshold`.
|
|
24
|
-
* Stable: preserves the input order (which is engine-side rank).
|
|
25
|
-
*/
|
|
26
|
-
export function filterBySimilarity(hits, threshold) {
|
|
27
|
-
if (threshold <= 0)
|
|
28
|
-
return hits;
|
|
29
|
-
return hits.filter((h) => h.similarity >= threshold);
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Reciprocal Rank Fusion across two ranked lists. The RRF score for
|
|
33
|
-
* an item is `sum over each source list: 1 / (RRF_K + rank_in_that_list)`,
|
|
34
|
-
* where rank is 1-based. Items appearing in both lists accumulate
|
|
35
|
-
* contributions and naturally rank above single-source items.
|
|
36
|
-
*
|
|
37
|
-
* Returns merged hits ordered by descending `rrf_score`. Identity is
|
|
38
|
-
* by `id` — a lesson and a memory with the same id (engine never
|
|
39
|
-
* collides these in practice) would merge; we treat that as harmless.
|
|
40
|
-
*/
|
|
41
|
-
export function mergeRrf(lessons, memories) {
|
|
42
|
-
const byId = new Map();
|
|
43
|
-
lessons.forEach((h, idx) => {
|
|
44
|
-
const rank = idx + 1; // 1-based
|
|
45
|
-
const score = 1 / (RRF_K + rank);
|
|
46
|
-
byId.set(h.id, {
|
|
47
|
-
kind: "lesson",
|
|
48
|
-
id: h.id,
|
|
49
|
-
description: h.description,
|
|
50
|
-
body_preview: h.body_preview,
|
|
51
|
-
similarity: h.similarity,
|
|
52
|
-
rrf_score: score,
|
|
53
|
-
lesson_rank: rank,
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
memories.forEach((h, idx) => {
|
|
57
|
-
const rank = idx + 1;
|
|
58
|
-
const score = 1 / (RRF_K + rank);
|
|
59
|
-
const existing = byId.get(h.id);
|
|
60
|
-
if (existing) {
|
|
61
|
-
existing.rrf_score += score;
|
|
62
|
-
existing.memory_rank = rank;
|
|
63
|
-
if (h.source)
|
|
64
|
-
existing.source = h.source;
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
byId.set(h.id, {
|
|
68
|
-
kind: "memory",
|
|
69
|
-
id: h.id,
|
|
70
|
-
description: h.description,
|
|
71
|
-
body_preview: h.body_preview,
|
|
72
|
-
similarity: h.similarity,
|
|
73
|
-
rrf_score: score,
|
|
74
|
-
memory_rank: rank,
|
|
75
|
-
source: h.source,
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
return Array.from(byId.values()).sort((a, b) => b.rrf_score - a.rrf_score);
|
|
80
|
-
}
|
|
81
|
-
//# sourceMappingURL=recall.js.map
|
package/dist/recall.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"recall.js","sourceRoot":"","sources":["../src.legacy/recall.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,wEAAwE;AACxE,MAAM,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;AAExB,gEAAgE;AAChE,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAG,CAAC;AAgD1C;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAChC,IAAS,EACT,SAAiB;IAEjB,IAAI,SAAS,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAChC,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,IAAI,SAAS,CAAC,CAAC;AACvD,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,QAAQ,CAAC,OAAoB,EAAE,QAAqB;IAClE,MAAM,IAAI,GAAG,IAAI,GAAG,EAAqB,CAAC;IAE1C,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE;QACzB,MAAM,IAAI,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,UAAU;QAChC,MAAM,KAAK,GAAG,CAAC,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC;QACjC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;YACb,IAAI,EAAE,QAAQ;YACd,EAAE,EAAE,CAAC,CAAC,EAAE;YACR,WAAW,EAAE,CAAC,CAAC,WAAW;YAC1B,YAAY,EAAE,CAAC,CAAC,YAAY;YAC5B,UAAU,EAAE,CAAC,CAAC,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-CHAT-AS-TERMINAL CAT.5.1).
|
|
3
|
-
*
|
|
4
|
-
* The chat-transport daemon (`src/channels/daemon/autospawn.ts`) already
|
|
5
|
-
* autospawns from the MCP chat-bridge boot. The HEADLESS RESPONDER — the
|
|
6
|
-
* agent-bridge daemon that ANSWERS chat when no terminal is live (CAT.5 the
|
|
7
|
-
* project umbrella's headless responder, CAT.6 the project-less `general`
|
|
8
|
-
* session) — did NOT. This module mirrors that chat-daemon autospawn so the
|
|
9
|
-
* headless responder is ALWAYS-ON too: started opportunistically on MCP boot,
|
|
10
|
-
* keyed PER-INSTANCE so `loop` + `general` run concurrently (CAT.5.1's
|
|
11
|
-
* per-scope lock/pid in daemon.ts).
|
|
12
|
-
*
|
|
13
|
-
* SAFE to autospawn the project headless even while a terminal is live: CAT.5's
|
|
14
|
-
* lease-ownership guard makes it STAND DOWN. The headless only answers when it
|
|
15
|
-
* owns a fresh umbrella lease; while a human `chat watch` lease is present the
|
|
16
|
-
* dispatcher's flush-time `isLeaseFreshAndOwnedBy` guard suppresses it — it
|
|
17
|
-
* idles at zero token cost (fs-only heartbeat) until the human lease lapses.
|
|
18
|
-
*
|
|
19
|
-
* Behavior (mirrors `ensureChatDaemonRunning`):
|
|
20
|
-
* - No-op when no chat platform is configured.
|
|
21
|
-
* - No-op when the SCOPED daemon (its own pidfile) is already running.
|
|
22
|
-
* - Else acquire an atomic per-scope spawn-lock (`fs.open(lock, 'wx')`) so two
|
|
23
|
-
* MCP servers don't double-spawn; the loser waits briefly for the pidfile.
|
|
24
|
-
* Stale lock (> 15s) is reclaimed.
|
|
25
|
-
* - Always async + non-throwing. A resolution failure (no project uuid / no
|
|
26
|
-
* pack) → `{ status: 'no_config' }` (skip that scope, never throw).
|
|
27
|
-
*
|
|
28
|
-
* It spawns `dist/cli.js agent-bridge start [--general]` DETACHED:
|
|
29
|
-
* - general: `agent-bridge start --general` (env as-is — the worker resolves
|
|
30
|
-
* the built-in `general` pack itself).
|
|
31
|
-
* - project umbrella: `agent-bridge start` with `OPENSQUID_PROJECT_UUID` +
|
|
32
|
-
* `OPENSQUID_PACK_ROOT` injected into the child env (resolved exactly like
|
|
33
|
-
* cli.ts's non-general path: `resolveProjectUuid` + `resolvePackRootFromEnv`).
|
|
34
|
-
* If the project uuid can't be resolved → skip (no-op).
|
|
35
|
-
*
|
|
36
|
-
* Imports from: node:fs, node:os, node:path, node:child_process, node:url,
|
|
37
|
-
* ../../channels/config, ../../channels/routing, ../paths, ./daemon.
|
|
38
|
-
* Imported by: src/mcp/chat-bridge-server.ts (boot) + tests.
|
|
39
|
-
*/
|
|
40
|
-
import { type AgentBridgeScopeKey } from './daemon.js';
|
|
41
|
-
export interface AgentBridgeAutoSpawnResult {
|
|
42
|
-
status: 'spawned' | 'already_running' | 'waited_for_peer' | 'no_config' | 'error';
|
|
43
|
-
pid?: number;
|
|
44
|
-
error?: string;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* What to autospawn: either the project-less `general` session, or a project
|
|
48
|
-
* umbrella's headless responder (keyed by umbrella id + cwd → project/pack).
|
|
49
|
-
*/
|
|
50
|
-
export type EnsureTarget = {
|
|
51
|
-
kind: 'general';
|
|
52
|
-
} | {
|
|
53
|
-
kind: 'umbrella';
|
|
54
|
-
/** The umbrella the cwd resolves to (CAT.5 — the scope identity). */
|
|
55
|
-
umbrellaId: string;
|
|
56
|
-
/** Working dir to resolve the project uuid / pack root from. */
|
|
57
|
-
cwd: string;
|
|
58
|
-
};
|
|
59
|
-
/**
|
|
60
|
-
* Resolve the CLI binary (`dist/cli.js`). From the MCP server at
|
|
61
|
-
* `dist/mcp/chat-bridge-server.js` the CLI sits at `dist/cli.js`; from this
|
|
62
|
-
* module's built location (`dist/runtime/agent_bridge/autospawn.js`) it's three
|
|
63
|
-
* dirs up. We resolve relative to the MCP-server layout to match the chat
|
|
64
|
-
* daemon's `resolveCliEntrypoint`, honoring `OPENSQUID_CLI_ENTRYPOINT`.
|
|
65
|
-
*/
|
|
66
|
-
export declare function resolveCliEntrypoint(): string;
|
|
67
|
-
/** A pidfile-liveness probe result, scope-keyed. */
|
|
68
|
-
export interface ScopedStatus {
|
|
69
|
-
running: boolean;
|
|
70
|
-
pid?: number;
|
|
71
|
-
}
|
|
72
|
-
/** A detached spawn invocation: argv (after the cli entrypoint) + child env. */
|
|
73
|
-
export interface SpawnInvocation {
|
|
74
|
-
args: string[];
|
|
75
|
-
env: NodeJS.ProcessEnv;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Injection seams for tests — exercise the autospawn FSM WITHOUT reading the
|
|
79
|
-
* developer's real chat config or spawning a live daemon.
|
|
80
|
-
*/
|
|
81
|
-
export interface EnsureAgentBridgeDeps {
|
|
82
|
-
/** Override the spawned worker's entrypoint (defaults to `dist/cli.js`). */
|
|
83
|
-
entrypoint?: string;
|
|
84
|
-
/** Override the "is any platform configured" probe. */
|
|
85
|
-
isConfigured?: () => Promise<boolean>;
|
|
86
|
-
/** Override the scoped-liveness probe. */
|
|
87
|
-
statusFn?: (scope: AgentBridgeScopeKey) => Promise<ScopedStatus>;
|
|
88
|
-
/** Override the detached spawn. */
|
|
89
|
-
spawnFn?: (entrypoint: string, inv: SpawnInvocation) => {
|
|
90
|
-
pid?: number;
|
|
91
|
-
};
|
|
92
|
-
/** Override the project-uuid resolver (tests). */
|
|
93
|
-
resolveProjectUuidFn?: (opts: {
|
|
94
|
-
cwd: string;
|
|
95
|
-
env?: NodeJS.ProcessEnv;
|
|
96
|
-
}) => Promise<string | null>;
|
|
97
|
-
/** Override the pack-root resolver (tests). */
|
|
98
|
-
resolvePackRootFn?: (env?: NodeJS.ProcessEnv) => string;
|
|
99
|
-
/** Override base env threaded into the child (defaults to `process.env`). */
|
|
100
|
-
env?: NodeJS.ProcessEnv;
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Best-effort: ensure the headless agent-bridge responder for `target` is
|
|
104
|
-
* running. Returns on the no-op paths (no config, already running, peer
|
|
105
|
-
* spawning, unresolvable scope). NEVER throws.
|
|
106
|
-
*/
|
|
107
|
-
export declare function ensureAgentBridgeRunning(target: EnsureTarget, opts?: EnsureAgentBridgeDeps): Promise<AgentBridgeAutoSpawnResult>;
|
|
108
|
-
/**
|
|
109
|
-
* MCP-boot convenience (CAT.5.1): ensure (a) the GENERAL headless responder
|
|
110
|
-
* (always) and (b) the headless responder for the umbrella the cwd resolves to
|
|
111
|
-
* (if any). Each is fire-and-forget at the call site; this helper awaits both
|
|
112
|
-
* and returns their results for logging. Never throws.
|
|
113
|
-
*
|
|
114
|
-
* `cwd` defaults to `CLAUDE_PROJECT_DIR ?? process.cwd()` (matches the MCP
|
|
115
|
-
* server's active-umbrella resolution). `umbrellaForCwd` lets the caller pass
|
|
116
|
-
* the already-resolved umbrella (the MCP boot resolves it once for logging).
|
|
117
|
-
*/
|
|
118
|
-
export declare function ensureHeadlessRespondersForBoot(opts: {
|
|
119
|
-
/** The umbrella the cwd resolves to (null ⇒ only the general responder). */
|
|
120
|
-
umbrellaForCwd: string | null;
|
|
121
|
-
/** Working dir for the project/pack resolution. */
|
|
122
|
-
cwd?: string;
|
|
123
|
-
/** Test seam — forwarded to each `ensureAgentBridgeRunning`. */
|
|
124
|
-
deps?: EnsureAgentBridgeDeps;
|
|
125
|
-
/** Test seam — override the ensure fn itself (asserts call shape). */
|
|
126
|
-
ensureFn?: typeof ensureAgentBridgeRunning;
|
|
127
|
-
}): Promise<{
|
|
128
|
-
general: AgentBridgeAutoSpawnResult;
|
|
129
|
-
umbrella: AgentBridgeAutoSpawnResult | null;
|
|
130
|
-
}>;
|
|
131
|
-
//# sourceMappingURL=autospawn.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"autospawn.d.ts","sourceRoot":"","sources":["../../../src/runtime/agent_bridge/autospawn.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAWH,OAAO,EAIL,KAAK,mBAAmB,EAC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