claude-code-swarm 0.3.4 → 0.3.5
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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +22 -1
- package/.claude-plugin/run-agent-inbox-mcp.sh +76 -0
- package/.claude-plugin/run-minimem-mcp.sh +98 -0
- package/.claude-plugin/run-opentasks-mcp.sh +65 -0
- package/CLAUDE.md +196 -36
- package/e2e/helpers/cleanup.mjs +17 -3
- package/e2e/helpers/map-mock-server.mjs +201 -25
- package/e2e/helpers/sidecar.mjs +222 -0
- package/e2e/helpers/workspace.mjs +2 -1
- package/e2e/tier5-sidecar-inbox.test.mjs +900 -0
- package/e2e/tier6-inbox-mcp.test.mjs +173 -0
- package/e2e/tier6-live-agent.test.mjs +759 -0
- package/e2e/vitest.config.e2e.mjs +1 -1
- package/hooks/hooks.json +15 -8
- package/package.json +13 -1
- package/references/agent-inbox/CLAUDE.md +151 -0
- package/references/agent-inbox/README.md +238 -0
- package/references/agent-inbox/docs/CLAUDE-CODE-SWARM-PROPOSAL.md +137 -0
- package/references/agent-inbox/docs/DESIGN.md +1156 -0
- package/references/agent-inbox/hooks/inbox-hook.mjs +119 -0
- package/references/agent-inbox/hooks/register-hook.mjs +69 -0
- package/references/agent-inbox/package-lock.json +3347 -0
- package/references/agent-inbox/package.json +58 -0
- package/references/agent-inbox/rules/agent-inbox.md +78 -0
- package/references/agent-inbox/src/federation/address.ts +61 -0
- package/references/agent-inbox/src/federation/connection-manager.ts +573 -0
- package/references/agent-inbox/src/federation/delivery-queue.ts +222 -0
- package/references/agent-inbox/src/federation/index.ts +6 -0
- package/references/agent-inbox/src/federation/routing-engine.ts +188 -0
- package/references/agent-inbox/src/federation/trust.ts +71 -0
- package/references/agent-inbox/src/index.ts +390 -0
- package/references/agent-inbox/src/ipc/ipc-server.ts +207 -0
- package/references/agent-inbox/src/jsonrpc/mail-server.ts +382 -0
- package/references/agent-inbox/src/map/map-client.ts +414 -0
- package/references/agent-inbox/src/mcp/mcp-server.ts +272 -0
- package/references/agent-inbox/src/mesh/delivery-bridge.ts +110 -0
- package/references/agent-inbox/src/mesh/mesh-connector.ts +41 -0
- package/references/agent-inbox/src/mesh/mesh-transport.ts +157 -0
- package/references/agent-inbox/src/mesh/type-mapper.ts +239 -0
- package/references/agent-inbox/src/push/notifier.ts +233 -0
- package/references/agent-inbox/src/registry/warm-registry.ts +255 -0
- package/references/agent-inbox/src/router/message-router.ts +175 -0
- package/references/agent-inbox/src/storage/interface.ts +48 -0
- package/references/agent-inbox/src/storage/memory.ts +145 -0
- package/references/agent-inbox/src/storage/sqlite.ts +671 -0
- package/references/agent-inbox/src/traceability/traceability.ts +183 -0
- package/references/agent-inbox/src/types.ts +303 -0
- package/references/agent-inbox/test/federation/address.test.ts +101 -0
- package/references/agent-inbox/test/federation/connection-manager.test.ts +546 -0
- package/references/agent-inbox/test/federation/delivery-queue.test.ts +159 -0
- package/references/agent-inbox/test/federation/integration.test.ts +857 -0
- package/references/agent-inbox/test/federation/routing-engine.test.ts +117 -0
- package/references/agent-inbox/test/federation/sdk-integration.test.ts +744 -0
- package/references/agent-inbox/test/federation/trust.test.ts +89 -0
- package/references/agent-inbox/test/ipc-jsonrpc.test.ts +113 -0
- package/references/agent-inbox/test/ipc-server.test.ts +197 -0
- package/references/agent-inbox/test/mail-server.test.ts +285 -0
- package/references/agent-inbox/test/map-client.test.ts +408 -0
- package/references/agent-inbox/test/mesh/delivery-bridge.test.ts +178 -0
- package/references/agent-inbox/test/mesh/e2e-mesh.test.ts +527 -0
- package/references/agent-inbox/test/mesh/e2e-real-meshpeer.test.ts +629 -0
- package/references/agent-inbox/test/mesh/federation-mesh.test.ts +269 -0
- package/references/agent-inbox/test/mesh/mesh-connector.test.ts +66 -0
- package/references/agent-inbox/test/mesh/mesh-transport.test.ts +191 -0
- package/references/agent-inbox/test/mesh/meshpeer-integration.test.ts +442 -0
- package/references/agent-inbox/test/mesh/mock-mesh.ts +125 -0
- package/references/agent-inbox/test/mesh/mock-meshpeer.ts +266 -0
- package/references/agent-inbox/test/mesh/type-mapper.test.ts +226 -0
- package/references/agent-inbox/test/message-router.test.ts +184 -0
- package/references/agent-inbox/test/push-notifier.test.ts +139 -0
- package/references/agent-inbox/test/registry/warm-registry.test.ts +171 -0
- package/references/agent-inbox/test/sqlite-prefix.test.ts +192 -0
- package/references/agent-inbox/test/sqlite-storage.test.ts +243 -0
- package/references/agent-inbox/test/storage.test.ts +196 -0
- package/references/agent-inbox/test/traceability.test.ts +123 -0
- package/references/agent-inbox/test/wake.test.ts +330 -0
- package/references/agent-inbox/tsconfig.json +20 -0
- package/references/agent-inbox/tsup.config.ts +10 -0
- package/references/agent-inbox/vitest.config.ts +8 -0
- package/references/minimem/.claude/settings.json +7 -0
- package/references/minimem/.sudocode/issues.jsonl +18 -0
- package/references/minimem/.sudocode/specs.jsonl +1 -0
- package/references/minimem/CLAUDE.md +329 -0
- package/references/minimem/README.md +565 -0
- package/references/minimem/claude-plugin/.claude-plugin/plugin.json +10 -0
- package/references/minimem/claude-plugin/.mcp.json +7 -0
- package/references/minimem/claude-plugin/README.md +158 -0
- package/references/minimem/claude-plugin/commands/recall.md +47 -0
- package/references/minimem/claude-plugin/commands/remember.md +41 -0
- package/references/minimem/claude-plugin/hooks/__tests__/hooks.test.ts +272 -0
- package/references/minimem/claude-plugin/hooks/hooks.json +27 -0
- package/references/minimem/claude-plugin/hooks/session-end.sh +86 -0
- package/references/minimem/claude-plugin/hooks/session-start.sh +85 -0
- package/references/minimem/claude-plugin/skills/memory/SKILL.md +108 -0
- package/references/minimem/media/banner.png +0 -0
- package/references/minimem/package-lock.json +5373 -0
- package/references/minimem/package.json +76 -0
- package/references/minimem/scripts/postbuild.js +49 -0
- package/references/minimem/src/__tests__/edge-cases.test.ts +371 -0
- package/references/minimem/src/__tests__/errors.test.ts +265 -0
- package/references/minimem/src/__tests__/helpers.ts +199 -0
- package/references/minimem/src/__tests__/internal.test.ts +407 -0
- package/references/minimem/src/__tests__/knowledge-frontmatter.test.ts +148 -0
- package/references/minimem/src/__tests__/knowledge.test.ts +148 -0
- package/references/minimem/src/__tests__/minimem.integration.test.ts +1127 -0
- package/references/minimem/src/__tests__/session.test.ts +190 -0
- package/references/minimem/src/cli/__tests__/commands.test.ts +760 -0
- package/references/minimem/src/cli/__tests__/contained-layout.test.ts +286 -0
- package/references/minimem/src/cli/commands/__tests__/conflicts.test.ts +141 -0
- package/references/minimem/src/cli/commands/append.ts +76 -0
- package/references/minimem/src/cli/commands/config.ts +262 -0
- package/references/minimem/src/cli/commands/conflicts.ts +415 -0
- package/references/minimem/src/cli/commands/daemon.ts +169 -0
- package/references/minimem/src/cli/commands/index.ts +12 -0
- package/references/minimem/src/cli/commands/init.ts +166 -0
- package/references/minimem/src/cli/commands/mcp.ts +221 -0
- package/references/minimem/src/cli/commands/push-pull.ts +213 -0
- package/references/minimem/src/cli/commands/search.ts +223 -0
- package/references/minimem/src/cli/commands/status.ts +84 -0
- package/references/minimem/src/cli/commands/store.ts +189 -0
- package/references/minimem/src/cli/commands/sync-init.ts +290 -0
- package/references/minimem/src/cli/commands/sync.ts +70 -0
- package/references/minimem/src/cli/commands/upsert.ts +197 -0
- package/references/minimem/src/cli/config.ts +611 -0
- package/references/minimem/src/cli/index.ts +299 -0
- package/references/minimem/src/cli/shared.ts +189 -0
- package/references/minimem/src/cli/sync/__tests__/central.test.ts +152 -0
- package/references/minimem/src/cli/sync/__tests__/conflicts.test.ts +209 -0
- package/references/minimem/src/cli/sync/__tests__/daemon.test.ts +118 -0
- package/references/minimem/src/cli/sync/__tests__/detection.test.ts +207 -0
- package/references/minimem/src/cli/sync/__tests__/integration.test.ts +476 -0
- package/references/minimem/src/cli/sync/__tests__/registry.test.ts +363 -0
- package/references/minimem/src/cli/sync/__tests__/state.test.ts +255 -0
- package/references/minimem/src/cli/sync/__tests__/validation.test.ts +193 -0
- package/references/minimem/src/cli/sync/__tests__/watcher.test.ts +178 -0
- package/references/minimem/src/cli/sync/central.ts +292 -0
- package/references/minimem/src/cli/sync/conflicts.ts +205 -0
- package/references/minimem/src/cli/sync/daemon.ts +407 -0
- package/references/minimem/src/cli/sync/detection.ts +138 -0
- package/references/minimem/src/cli/sync/index.ts +107 -0
- package/references/minimem/src/cli/sync/operations.ts +373 -0
- package/references/minimem/src/cli/sync/registry.ts +279 -0
- package/references/minimem/src/cli/sync/state.ts +358 -0
- package/references/minimem/src/cli/sync/validation.ts +206 -0
- package/references/minimem/src/cli/sync/watcher.ts +237 -0
- package/references/minimem/src/cli/version.ts +34 -0
- package/references/minimem/src/core/index.ts +9 -0
- package/references/minimem/src/core/indexer.ts +628 -0
- package/references/minimem/src/core/searcher.ts +221 -0
- package/references/minimem/src/db/schema.ts +183 -0
- package/references/minimem/src/db/sqlite-vec.ts +24 -0
- package/references/minimem/src/embeddings/__tests__/embeddings.test.ts +431 -0
- package/references/minimem/src/embeddings/batch-gemini.ts +392 -0
- package/references/minimem/src/embeddings/batch-openai.ts +409 -0
- package/references/minimem/src/embeddings/embeddings.ts +434 -0
- package/references/minimem/src/index.ts +132 -0
- package/references/minimem/src/internal.ts +299 -0
- package/references/minimem/src/minimem.ts +1291 -0
- package/references/minimem/src/search/__tests__/hybrid.test.ts +247 -0
- package/references/minimem/src/search/graph.ts +234 -0
- package/references/minimem/src/search/hybrid.ts +151 -0
- package/references/minimem/src/search/search.ts +256 -0
- package/references/minimem/src/server/__tests__/mcp.test.ts +347 -0
- package/references/minimem/src/server/__tests__/tools.test.ts +364 -0
- package/references/minimem/src/server/mcp.ts +326 -0
- package/references/minimem/src/server/tools.ts +720 -0
- package/references/minimem/src/session.ts +460 -0
- package/references/minimem/src/store/__tests__/manifest.test.ts +177 -0
- package/references/minimem/src/store/__tests__/materialize.test.ts +52 -0
- package/references/minimem/src/store/__tests__/store-graph.test.ts +228 -0
- package/references/minimem/src/store/index.ts +27 -0
- package/references/minimem/src/store/manifest.ts +203 -0
- package/references/minimem/src/store/materialize.ts +185 -0
- package/references/minimem/src/store/store-graph.ts +252 -0
- package/references/minimem/tsconfig.json +19 -0
- package/references/minimem/tsup.config.ts +26 -0
- package/references/minimem/vitest.config.ts +29 -0
- package/references/multi-agent-protocol/.sudocode/issues.jsonl +120 -0
- package/references/multi-agent-protocol/.sudocode/specs.jsonl +15 -0
- package/references/multi-agent-protocol/LICENSE +21 -0
- package/references/multi-agent-protocol/README.md +113 -0
- package/references/multi-agent-protocol/docs/00-design-specification.md +496 -0
- package/references/multi-agent-protocol/docs/01-open-questions.md +1050 -0
- package/references/multi-agent-protocol/docs/02-wire-protocol.md +296 -0
- package/references/multi-agent-protocol/docs/03-streaming-semantics.md +252 -0
- package/references/multi-agent-protocol/docs/04-error-handling.md +231 -0
- package/references/multi-agent-protocol/docs/05-connection-model.md +244 -0
- package/references/multi-agent-protocol/docs/06-visibility-permissions.md +243 -0
- package/references/multi-agent-protocol/docs/07-federation.md +335 -0
- package/references/multi-agent-protocol/docs/08-macro-agent-migration.md +253 -0
- package/references/multi-agent-protocol/docs/09-authentication.md +748 -0
- package/references/multi-agent-protocol/docs/10-environment-awareness.md +242 -0
- package/references/multi-agent-protocol/docs/10-mail-protocol.md +553 -0
- package/references/multi-agent-protocol/docs/11-anp-inspired-improvements.md +1079 -0
- package/references/multi-agent-protocol/docs/11-trajectory-protocol.md +292 -0
- package/references/multi-agent-protocol/docs/12-anp-implementation-plan.md +641 -0
- package/references/multi-agent-protocol/docs/agent-iam-integration.md +877 -0
- package/references/multi-agent-protocol/docs/agentic-mesh-integration-draft.md +459 -0
- package/references/multi-agent-protocol/docs/git-transport-draft.md +251 -0
- package/references/multi-agent-protocol/docs-site/Gemfile +22 -0
- package/references/multi-agent-protocol/docs-site/README.md +82 -0
- package/references/multi-agent-protocol/docs-site/_config.yml +91 -0
- package/references/multi-agent-protocol/docs-site/_includes/head_custom.html +20 -0
- package/references/multi-agent-protocol/docs-site/_sass/color_schemes/map.scss +42 -0
- package/references/multi-agent-protocol/docs-site/_sass/custom/custom.scss +34 -0
- package/references/multi-agent-protocol/docs-site/examples/full-integration.md +510 -0
- package/references/multi-agent-protocol/docs-site/examples/index.md +138 -0
- package/references/multi-agent-protocol/docs-site/examples/simple-chat.md +282 -0
- package/references/multi-agent-protocol/docs-site/examples/task-queue.md +399 -0
- package/references/multi-agent-protocol/docs-site/getting-started/index.md +98 -0
- package/references/multi-agent-protocol/docs-site/getting-started/installation.md +219 -0
- package/references/multi-agent-protocol/docs-site/getting-started/overview.md +172 -0
- package/references/multi-agent-protocol/docs-site/getting-started/quickstart.md +237 -0
- package/references/multi-agent-protocol/docs-site/index.md +136 -0
- package/references/multi-agent-protocol/docs-site/protocol/authentication.md +391 -0
- package/references/multi-agent-protocol/docs-site/protocol/connection-model.md +376 -0
- package/references/multi-agent-protocol/docs-site/protocol/design.md +284 -0
- package/references/multi-agent-protocol/docs-site/protocol/error-handling.md +312 -0
- package/references/multi-agent-protocol/docs-site/protocol/federation.md +449 -0
- package/references/multi-agent-protocol/docs-site/protocol/index.md +129 -0
- package/references/multi-agent-protocol/docs-site/protocol/permissions.md +398 -0
- package/references/multi-agent-protocol/docs-site/protocol/streaming.md +353 -0
- package/references/multi-agent-protocol/docs-site/protocol/wire-protocol.md +369 -0
- package/references/multi-agent-protocol/docs-site/sdk/api/agent.md +357 -0
- package/references/multi-agent-protocol/docs-site/sdk/api/client.md +380 -0
- package/references/multi-agent-protocol/docs-site/sdk/api/index.md +62 -0
- package/references/multi-agent-protocol/docs-site/sdk/api/server.md +453 -0
- package/references/multi-agent-protocol/docs-site/sdk/api/types.md +468 -0
- package/references/multi-agent-protocol/docs-site/sdk/guides/agent.md +375 -0
- package/references/multi-agent-protocol/docs-site/sdk/guides/authentication.md +405 -0
- package/references/multi-agent-protocol/docs-site/sdk/guides/client.md +352 -0
- package/references/multi-agent-protocol/docs-site/sdk/guides/index.md +89 -0
- package/references/multi-agent-protocol/docs-site/sdk/guides/server.md +360 -0
- package/references/multi-agent-protocol/docs-site/sdk/guides/testing.md +446 -0
- package/references/multi-agent-protocol/docs-site/sdk/guides/transports.md +363 -0
- package/references/multi-agent-protocol/docs-site/sdk/index.md +206 -0
- package/references/multi-agent-protocol/package-lock.json +4230 -0
- package/references/multi-agent-protocol/package.json +56 -0
- package/references/multi-agent-protocol/schema/meta.json +584 -0
- package/references/multi-agent-protocol/schema/schema.json +3067 -0
- package/references/openhive/.claude/settings.json +6 -0
- package/references/openhive/.dockerignore +54 -0
- package/references/openhive/.github/workflows/docker.yml +52 -0
- package/references/openhive/.sudocode/issues.jsonl +24 -0
- package/references/openhive/.sudocode/specs.jsonl +4 -0
- package/references/openhive/CLAUDE.md +88 -0
- package/references/openhive/Dockerfile +105 -0
- package/references/openhive/README.md +745 -0
- package/references/openhive/bin/openhive.js +6 -0
- package/references/openhive/cloudbuild.yaml +80 -0
- package/references/openhive/deploy/cloud-run.sh +106 -0
- package/references/openhive/deploy/openhive.env.example +80 -0
- package/references/openhive/deploy/openhive.service +91 -0
- package/references/openhive/docker-compose.yml +67 -0
- package/references/openhive/docker-entrypoint.sh +117 -0
- package/references/openhive/docs/API_MIGRATION.md +176 -0
- package/references/openhive/docs/DEPLOYMENT.md +847 -0
- package/references/openhive/docs/DESIGN_v1.md +489 -0
- package/references/openhive/docs/DESIGN_v2.md +564 -0
- package/references/openhive/docs/HEADSCALE_HOSTING_SPEC.md +513 -0
- package/references/openhive/docs/HIVE_SYNC_DESIGN.md +2362 -0
- package/references/openhive/docs/HIVE_SYNC_IMPLEMENTATION_PLAN.md +1169 -0
- package/references/openhive/docs/HOSTING.md +601 -0
- package/references/openhive/docs/IMPLEMENTATION_PLAN.md +428 -0
- package/references/openhive/docs/LOCAL_SETUP.md +506 -0
- package/references/openhive/docs/MACRO_AGENT_ATLAS_EXTENSION.md +351 -0
- package/references/openhive/docs/MEMORY_BANK_SYNC_SPEC.md +909 -0
- package/references/openhive/docs/PLAN_v1.md +471 -0
- package/references/openhive/docs/PLAN_v2.md +623 -0
- package/references/openhive/docs/WEBSOCKET.md +267 -0
- package/references/openhive/docs/openswarm-bootstrap-token-spec.md +240 -0
- package/references/openhive/ecosystem.config.cjs +76 -0
- package/references/openhive/fly.toml +63 -0
- package/references/openhive/package-lock.json +17640 -0
- package/references/openhive/package.json +128 -0
- package/references/openhive/packages/openhive-types/package-lock.json +1473 -0
- package/references/openhive/packages/openhive-types/package.json +42 -0
- package/references/openhive/packages/openhive-types/src/index.ts +36 -0
- package/references/openhive/packages/openhive-types/src/map-coordination.ts +92 -0
- package/references/openhive/packages/openhive-types/src/map-session-sync.ts +50 -0
- package/references/openhive/packages/openhive-types/src/map-sync.ts +68 -0
- package/references/openhive/packages/openhive-types/tsconfig.json +15 -0
- package/references/openhive/packages/openhive-types/tsconfig.tsbuildinfo +1 -0
- package/references/openhive/packages/openhive-types/tsup.config.ts +12 -0
- package/references/openhive/railway.json +13 -0
- package/references/openhive/railway.toml +24 -0
- package/references/openhive/render.yaml +51 -0
- package/references/openhive/src/__tests__/auth.test.ts +148 -0
- package/references/openhive/src/__tests__/bridge/credentials.test.ts +65 -0
- package/references/openhive/src/__tests__/bridge/dal.test.ts +279 -0
- package/references/openhive/src/__tests__/bridge/inbound.test.ts +349 -0
- package/references/openhive/src/__tests__/bridge/manager.test.ts +419 -0
- package/references/openhive/src/__tests__/bridge/mentions.test.ts +83 -0
- package/references/openhive/src/__tests__/bridge/outbound.test.ts +209 -0
- package/references/openhive/src/__tests__/bridge/slack-adapter.test.ts +276 -0
- package/references/openhive/src/__tests__/cli.test.ts +342 -0
- package/references/openhive/src/__tests__/config.test.ts +205 -0
- package/references/openhive/src/__tests__/coordination/coordination.test.ts +1072 -0
- package/references/openhive/src/__tests__/coordination/cross-instance.test.ts +540 -0
- package/references/openhive/src/__tests__/coordination/e2e.test.ts +780 -0
- package/references/openhive/src/__tests__/data-dir.test.ts +332 -0
- package/references/openhive/src/__tests__/db.test.ts +258 -0
- package/references/openhive/src/__tests__/discovery.test.ts +288 -0
- package/references/openhive/src/__tests__/events/dal.test.ts +371 -0
- package/references/openhive/src/__tests__/events/dispatch.test.ts +202 -0
- package/references/openhive/src/__tests__/events/e2e.test.ts +528 -0
- package/references/openhive/src/__tests__/events/normalizers.test.ts +263 -0
- package/references/openhive/src/__tests__/events/router.test.ts +314 -0
- package/references/openhive/src/__tests__/events/routes.test.ts +407 -0
- package/references/openhive/src/__tests__/follows.test.ts +328 -0
- package/references/openhive/src/__tests__/helpers/test-dirs.ts +44 -0
- package/references/openhive/src/__tests__/ingest-keys.test.ts +925 -0
- package/references/openhive/src/__tests__/map/sync-client-content.test.ts +288 -0
- package/references/openhive/src/__tests__/map/sync-client.test.ts +500 -0
- package/references/openhive/src/__tests__/map/sync-listener.test.ts +504 -0
- package/references/openhive/src/__tests__/middleware/hostname-guard.test.ts +73 -0
- package/references/openhive/src/__tests__/migrations.test.ts +260 -0
- package/references/openhive/src/__tests__/opentasks/client.test.ts +497 -0
- package/references/openhive/src/__tests__/opentasks/discovery.test.ts +283 -0
- package/references/openhive/src/__tests__/opentasks/e2e.test.ts +767 -0
- package/references/openhive/src/__tests__/routes/agents.test.ts +417 -0
- package/references/openhive/src/__tests__/routes/opentasks-content.test.ts +493 -0
- package/references/openhive/src/__tests__/routes/resource-content.test.ts +1741 -0
- package/references/openhive/src/__tests__/sessions/adapters.test.ts +524 -0
- package/references/openhive/src/__tests__/sessions/routes.test.ts +1053 -0
- package/references/openhive/src/__tests__/sessions/storage.test.ts +545 -0
- package/references/openhive/src/__tests__/sessions/trajectory-checkpoints.test.ts +349 -0
- package/references/openhive/src/__tests__/sessions/trajectory-routes.test.ts +290 -0
- package/references/openhive/src/__tests__/swarm/config.test.ts +125 -0
- package/references/openhive/src/__tests__/swarm/credentials.test.ts +254 -0
- package/references/openhive/src/__tests__/swarm/dal.test.ts +290 -0
- package/references/openhive/src/__tests__/swarm/e2e.test.ts +827 -0
- package/references/openhive/src/__tests__/swarm/fixtures/exit-immediately.js +3 -0
- package/references/openhive/src/__tests__/swarm/fixtures/map-server.js +147 -0
- package/references/openhive/src/__tests__/swarm/fixtures/sleep-server.js +52 -0
- package/references/openhive/src/__tests__/swarm/local-provider.test.ts +279 -0
- package/references/openhive/src/__tests__/swarm/manager.test.ts +305 -0
- package/references/openhive/src/__tests__/swarm/routes.test.ts +396 -0
- package/references/openhive/src/__tests__/swarm/workspace.test.ts +257 -0
- package/references/openhive/src/__tests__/swarmhub/client.test.ts +324 -0
- package/references/openhive/src/__tests__/swarmhub/config.test.ts +213 -0
- package/references/openhive/src/__tests__/swarmhub/connector.test.ts +581 -0
- package/references/openhive/src/__tests__/swarmhub/routes.test.ts +639 -0
- package/references/openhive/src/__tests__/swarmhub/slack-client.test.ts +164 -0
- package/references/openhive/src/__tests__/swarmhub/slack-connector.test.ts +164 -0
- package/references/openhive/src/__tests__/swarmhub/slack-routes.test.ts +373 -0
- package/references/openhive/src/__tests__/swarmhub/webhook-handler.test.ts +295 -0
- package/references/openhive/src/__tests__/sync/resource-sync.test.ts +1418 -0
- package/references/openhive/src/__tests__/sync/sync.test.ts +800 -0
- package/references/openhive/src/api/index.ts +65 -0
- package/references/openhive/src/api/middleware/auth.ts +227 -0
- package/references/openhive/src/api/middleware/hostname-guard.ts +38 -0
- package/references/openhive/src/api/routes/admin.ts +366 -0
- package/references/openhive/src/api/routes/agents.ts +223 -0
- package/references/openhive/src/api/routes/auth.ts +164 -0
- package/references/openhive/src/api/routes/bridges.ts +384 -0
- package/references/openhive/src/api/routes/comments.ts +294 -0
- package/references/openhive/src/api/routes/coordination.ts +312 -0
- package/references/openhive/src/api/routes/events.ts +158 -0
- package/references/openhive/src/api/routes/federation.ts +367 -0
- package/references/openhive/src/api/routes/feed.ts +212 -0
- package/references/openhive/src/api/routes/hives.ts +264 -0
- package/references/openhive/src/api/routes/map.ts +674 -0
- package/references/openhive/src/api/routes/memory-banks.ts +971 -0
- package/references/openhive/src/api/routes/posts.ts +342 -0
- package/references/openhive/src/api/routes/resource-content.ts +727 -0
- package/references/openhive/src/api/routes/resources.ts +1013 -0
- package/references/openhive/src/api/routes/search.ts +45 -0
- package/references/openhive/src/api/routes/sessions.ts +1187 -0
- package/references/openhive/src/api/routes/swarm-hosting.ts +313 -0
- package/references/openhive/src/api/routes/sync-protocol.ts +168 -0
- package/references/openhive/src/api/routes/sync.ts +279 -0
- package/references/openhive/src/api/routes/uploads.ts +174 -0
- package/references/openhive/src/api/routes/webhooks.ts +603 -0
- package/references/openhive/src/api/schemas/agents.ts +26 -0
- package/references/openhive/src/api/schemas/comments.ts +22 -0
- package/references/openhive/src/api/schemas/hives.ts +33 -0
- package/references/openhive/src/api/schemas/posts.ts +37 -0
- package/references/openhive/src/api/schemas/sync.ts +56 -0
- package/references/openhive/src/auth/index.ts +2 -0
- package/references/openhive/src/auth/jwks.ts +58 -0
- package/references/openhive/src/bridge/adapters/slack.ts +306 -0
- package/references/openhive/src/bridge/credentials.ts +72 -0
- package/references/openhive/src/bridge/inbound.ts +288 -0
- package/references/openhive/src/bridge/index.ts +42 -0
- package/references/openhive/src/bridge/manager.ts +425 -0
- package/references/openhive/src/bridge/mentions.ts +42 -0
- package/references/openhive/src/bridge/outbound.ts +103 -0
- package/references/openhive/src/bridge/schema.ts +82 -0
- package/references/openhive/src/bridge/types.ts +238 -0
- package/references/openhive/src/cli/network.ts +480 -0
- package/references/openhive/src/cli.ts +620 -0
- package/references/openhive/src/config.ts +611 -0
- package/references/openhive/src/coordination/index.ts +43 -0
- package/references/openhive/src/coordination/listener.ts +92 -0
- package/references/openhive/src/coordination/schema.ts +79 -0
- package/references/openhive/src/coordination/service.ts +233 -0
- package/references/openhive/src/coordination/types.ts +177 -0
- package/references/openhive/src/data-dir.ts +105 -0
- package/references/openhive/src/db/adapters/index.ts +21 -0
- package/references/openhive/src/db/adapters/postgres.ts +310 -0
- package/references/openhive/src/db/adapters/sqlite.ts +56 -0
- package/references/openhive/src/db/adapters/types.ts +65 -0
- package/references/openhive/src/db/dal/agents.ts +430 -0
- package/references/openhive/src/db/dal/bridge.ts +336 -0
- package/references/openhive/src/db/dal/comments.ts +213 -0
- package/references/openhive/src/db/dal/coordination.ts +361 -0
- package/references/openhive/src/db/dal/events.ts +381 -0
- package/references/openhive/src/db/dal/follows.ts +96 -0
- package/references/openhive/src/db/dal/hives.ts +198 -0
- package/references/openhive/src/db/dal/ingest-keys.ts +176 -0
- package/references/openhive/src/db/dal/instances.ts +196 -0
- package/references/openhive/src/db/dal/invites.ts +123 -0
- package/references/openhive/src/db/dal/map.ts +750 -0
- package/references/openhive/src/db/dal/posts.ts +274 -0
- package/references/openhive/src/db/dal/remote-agents.ts +56 -0
- package/references/openhive/src/db/dal/search.ts +238 -0
- package/references/openhive/src/db/dal/sync-events.ts +160 -0
- package/references/openhive/src/db/dal/sync-groups.ts +100 -0
- package/references/openhive/src/db/dal/sync-peer-configs.ts +216 -0
- package/references/openhive/src/db/dal/sync-peers.ts +145 -0
- package/references/openhive/src/db/dal/syncable-resources.ts +888 -0
- package/references/openhive/src/db/dal/trajectory-checkpoints.ts +291 -0
- package/references/openhive/src/db/dal/uploads.ts +124 -0
- package/references/openhive/src/db/dal/votes.ts +124 -0
- package/references/openhive/src/db/index.ts +293 -0
- package/references/openhive/src/db/providers/index.ts +75 -0
- package/references/openhive/src/db/providers/postgres.ts +529 -0
- package/references/openhive/src/db/providers/sqlite.ts +1383 -0
- package/references/openhive/src/db/providers/turso.ts +1360 -0
- package/references/openhive/src/db/providers/types.ts +516 -0
- package/references/openhive/src/db/schema.ts +641 -0
- package/references/openhive/src/discovery/index.ts +403 -0
- package/references/openhive/src/events/dispatch.ts +106 -0
- package/references/openhive/src/events/index.ts +17 -0
- package/references/openhive/src/events/normalizers/github.ts +133 -0
- package/references/openhive/src/events/normalizers/index.ts +62 -0
- package/references/openhive/src/events/normalizers/slack.ts +50 -0
- package/references/openhive/src/events/router.ts +156 -0
- package/references/openhive/src/events/schema.ts +66 -0
- package/references/openhive/src/events/types.ts +130 -0
- package/references/openhive/src/federation/index.ts +1 -0
- package/references/openhive/src/federation/service.ts +776 -0
- package/references/openhive/src/headscale/client.ts +256 -0
- package/references/openhive/src/headscale/config.ts +212 -0
- package/references/openhive/src/headscale/index.ts +23 -0
- package/references/openhive/src/headscale/manager.ts +249 -0
- package/references/openhive/src/headscale/sync.ts +272 -0
- package/references/openhive/src/headscale/types.ts +231 -0
- package/references/openhive/src/index.ts +225 -0
- package/references/openhive/src/map/client-entry.ts +26 -0
- package/references/openhive/src/map/index.ts +76 -0
- package/references/openhive/src/map/schema.ts +119 -0
- package/references/openhive/src/map/service.ts +323 -0
- package/references/openhive/src/map/sync-client.ts +696 -0
- package/references/openhive/src/map/sync-listener.ts +409 -0
- package/references/openhive/src/map/types.ts +290 -0
- package/references/openhive/src/network/factory.ts +118 -0
- package/references/openhive/src/network/headscale-provider.ts +437 -0
- package/references/openhive/src/network/index.ts +43 -0
- package/references/openhive/src/network/tailscale-client.ts +289 -0
- package/references/openhive/src/network/tailscale-provider.ts +287 -0
- package/references/openhive/src/network/types.ts +178 -0
- package/references/openhive/src/opentasks-client/client.ts +374 -0
- package/references/openhive/src/opentasks-client/index.ts +7 -0
- package/references/openhive/src/realtime/index.ts +282 -0
- package/references/openhive/src/server.ts +1069 -0
- package/references/openhive/src/services/email.ts +177 -0
- package/references/openhive/src/services/sitemap.ts +135 -0
- package/references/openhive/src/sessions/adapters/claude.ts +466 -0
- package/references/openhive/src/sessions/adapters/codex.ts +265 -0
- package/references/openhive/src/sessions/adapters/index.ts +263 -0
- package/references/openhive/src/sessions/adapters/raw.ts +144 -0
- package/references/openhive/src/sessions/adapters/types.ts +83 -0
- package/references/openhive/src/sessions/index.ts +50 -0
- package/references/openhive/src/sessions/storage/adapters/gcs.ts +277 -0
- package/references/openhive/src/sessions/storage/adapters/local.ts +240 -0
- package/references/openhive/src/sessions/storage/adapters/s3.ts +321 -0
- package/references/openhive/src/sessions/storage/index.ts +231 -0
- package/references/openhive/src/sessions/storage/types.ts +189 -0
- package/references/openhive/src/sessions/types.ts +415 -0
- package/references/openhive/src/shared/types/index.ts +45 -0
- package/references/openhive/src/shared/types/map-coordination.ts +92 -0
- package/references/openhive/src/shared/types/map-session-sync.ts +170 -0
- package/references/openhive/src/shared/types/map-sync.ts +68 -0
- package/references/openhive/src/skill.ts +203 -0
- package/references/openhive/src/storage/adapters/local.ts +169 -0
- package/references/openhive/src/storage/adapters/s3.ts +195 -0
- package/references/openhive/src/storage/index.ts +64 -0
- package/references/openhive/src/storage/types.ts +69 -0
- package/references/openhive/src/swarm/credentials.ts +98 -0
- package/references/openhive/src/swarm/dal.ts +206 -0
- package/references/openhive/src/swarm/index.ts +28 -0
- package/references/openhive/src/swarm/manager.ts +917 -0
- package/references/openhive/src/swarm/providers/local.ts +338 -0
- package/references/openhive/src/swarm/providers/sandboxed-local.ts +478 -0
- package/references/openhive/src/swarm/providers/workspace.ts +52 -0
- package/references/openhive/src/swarm/schema.ts +43 -0
- package/references/openhive/src/swarm/types.ts +333 -0
- package/references/openhive/src/swarmhub/client.ts +279 -0
- package/references/openhive/src/swarmhub/connector.ts +463 -0
- package/references/openhive/src/swarmhub/index.ts +43 -0
- package/references/openhive/src/swarmhub/routes.ts +296 -0
- package/references/openhive/src/swarmhub/types.ts +213 -0
- package/references/openhive/src/swarmhub/webhook-handler.ts +126 -0
- package/references/openhive/src/sync/compaction.ts +193 -0
- package/references/openhive/src/sync/coordination-hooks.ts +154 -0
- package/references/openhive/src/sync/crypto.ts +79 -0
- package/references/openhive/src/sync/gossip.ts +136 -0
- package/references/openhive/src/sync/hooks.ts +202 -0
- package/references/openhive/src/sync/materializer-repo.ts +256 -0
- package/references/openhive/src/sync/materializer.ts +682 -0
- package/references/openhive/src/sync/middleware.ts +140 -0
- package/references/openhive/src/sync/peer-resolver.ts +157 -0
- package/references/openhive/src/sync/resource-hooks.ts +161 -0
- package/references/openhive/src/sync/schema.ts +158 -0
- package/references/openhive/src/sync/service.ts +990 -0
- package/references/openhive/src/sync/types.ts +369 -0
- package/references/openhive/src/terminal/index.ts +4 -0
- package/references/openhive/src/terminal/pty-manager.ts +337 -0
- package/references/openhive/src/terminal/resolve-tui.ts +44 -0
- package/references/openhive/src/terminal/terminal-ws.ts +251 -0
- package/references/openhive/src/types.ts +442 -0
- package/references/openhive/src/utils/git-remote.ts +329 -0
- package/references/openhive/src/web/App.tsx +77 -0
- package/references/openhive/src/web/__tests__/components/dashboard/RecentActivity.test.tsx +77 -0
- package/references/openhive/src/web/__tests__/components/dashboard/StatsOverview.test.tsx +62 -0
- package/references/openhive/src/web/__tests__/components/dashboard/SwarmStatusSummary.test.tsx +122 -0
- package/references/openhive/src/web/__tests__/components/dashboard/SyncResourcesStatus.test.tsx +104 -0
- package/references/openhive/src/web/__tests__/components/layout/Sidebar.test.tsx +110 -0
- package/references/openhive/src/web/__tests__/components/swarm/StatusBadges.test.tsx +65 -0
- package/references/openhive/src/web/__tests__/components/terminal/query-responses.test.ts +143 -0
- package/references/openhive/src/web/__tests__/components/terminal/terminal-mouse.test.ts +509 -0
- package/references/openhive/src/web/__tests__/hooks/useEventsApi.test.ts +378 -0
- package/references/openhive/src/web/__tests__/pages/Dashboard.test.tsx +57 -0
- package/references/openhive/src/web/__tests__/pages/Events.test.tsx +886 -0
- package/references/openhive/src/web/__tests__/pages/Explore.test.tsx +63 -0
- package/references/openhive/src/web/__tests__/routing.test.tsx +79 -0
- package/references/openhive/src/web/__tests__/setup.ts +37 -0
- package/references/openhive/src/web/__tests__/stores/dashboard.test.ts +49 -0
- package/references/openhive/src/web/components/common/AgentBadge.tsx +58 -0
- package/references/openhive/src/web/components/common/Avatar.tsx +78 -0
- package/references/openhive/src/web/components/common/ErrorBoundary.tsx +76 -0
- package/references/openhive/src/web/components/common/Highlight.tsx +79 -0
- package/references/openhive/src/web/components/common/ImageUpload.tsx +209 -0
- package/references/openhive/src/web/components/common/LoadingSpinner.tsx +37 -0
- package/references/openhive/src/web/components/common/Logo.tsx +21 -0
- package/references/openhive/src/web/components/common/Markdown.tsx +53 -0
- package/references/openhive/src/web/components/common/ProtectedRoute.tsx +18 -0
- package/references/openhive/src/web/components/common/ThemeToggle.tsx +38 -0
- package/references/openhive/src/web/components/common/TimeAgo.tsx +17 -0
- package/references/openhive/src/web/components/common/Toast.tsx +70 -0
- package/references/openhive/src/web/components/common/VoteButtons.tsx +100 -0
- package/references/openhive/src/web/components/dashboard/RecentActivity.tsx +100 -0
- package/references/openhive/src/web/components/dashboard/StatsOverview.tsx +40 -0
- package/references/openhive/src/web/components/dashboard/SwarmStatusSummary.tsx +89 -0
- package/references/openhive/src/web/components/dashboard/SyncResourcesStatus.tsx +81 -0
- package/references/openhive/src/web/components/feed/FeedControls.tsx +38 -0
- package/references/openhive/src/web/components/feed/NewPostsIndicator.tsx +75 -0
- package/references/openhive/src/web/components/feed/PostCard.tsx +129 -0
- package/references/openhive/src/web/components/feed/PostList.tsx +83 -0
- package/references/openhive/src/web/components/layout/Footer.tsx +5 -0
- package/references/openhive/src/web/components/layout/Layout.tsx +29 -0
- package/references/openhive/src/web/components/layout/Sidebar.tsx +348 -0
- package/references/openhive/src/web/components/post/CommentForm.tsx +59 -0
- package/references/openhive/src/web/components/post/CommentTree.tsx +145 -0
- package/references/openhive/src/web/components/resources/MemoryBrowser.tsx +208 -0
- package/references/openhive/src/web/components/resources/OpenTasksSummary.tsx +138 -0
- package/references/openhive/src/web/components/resources/SkillBrowser.tsx +284 -0
- package/references/openhive/src/web/components/swarm/StatusBadges.tsx +56 -0
- package/references/openhive/src/web/components/terminal/TerminalPanel.tsx +485 -0
- package/references/openhive/src/web/components/terminal/index.ts +2 -0
- package/references/openhive/src/web/components/terminal/query-responses.ts +70 -0
- package/references/openhive/src/web/components/terminal/terminal-mouse.ts +222 -0
- package/references/openhive/src/web/hooks/useApi.ts +740 -0
- package/references/openhive/src/web/hooks/useDocumentTitle.ts +49 -0
- package/references/openhive/src/web/hooks/useInfiniteScroll.ts +58 -0
- package/references/openhive/src/web/hooks/useRealtimeUpdates.ts +154 -0
- package/references/openhive/src/web/hooks/useWebSocket.ts +225 -0
- package/references/openhive/src/web/index.html +73 -0
- package/references/openhive/src/web/lib/api.ts +518 -0
- package/references/openhive/src/web/main.tsx +32 -0
- package/references/openhive/src/web/pages/About.tsx +131 -0
- package/references/openhive/src/web/pages/Agent.tsx +130 -0
- package/references/openhive/src/web/pages/Agents.tsx +69 -0
- package/references/openhive/src/web/pages/AuthCallback.tsx +75 -0
- package/references/openhive/src/web/pages/Dashboard.tsx +41 -0
- package/references/openhive/src/web/pages/Events.tsx +1025 -0
- package/references/openhive/src/web/pages/Explore.tsx +43 -0
- package/references/openhive/src/web/pages/Hive.tsx +134 -0
- package/references/openhive/src/web/pages/Hives.tsx +64 -0
- package/references/openhive/src/web/pages/Home.tsx +43 -0
- package/references/openhive/src/web/pages/Login.tsx +122 -0
- package/references/openhive/src/web/pages/Post.tsx +216 -0
- package/references/openhive/src/web/pages/ResourceDetail.tsx +426 -0
- package/references/openhive/src/web/pages/Resources.tsx +276 -0
- package/references/openhive/src/web/pages/Search.tsx +234 -0
- package/references/openhive/src/web/pages/SessionDetail.tsx +703 -0
- package/references/openhive/src/web/pages/Sessions.tsx +129 -0
- package/references/openhive/src/web/pages/Settings.tsx +826 -0
- package/references/openhive/src/web/pages/SwarmCraft.tsx +16 -0
- package/references/openhive/src/web/pages/Swarms.tsx +981 -0
- package/references/openhive/src/web/pages/Terminal.tsx +69 -0
- package/references/openhive/src/web/postcss.config.js +5 -0
- package/references/openhive/src/web/public/favicon.svg +11 -0
- package/references/openhive/src/web/public/manifest.json +21 -0
- package/references/openhive/src/web/stores/auth.ts +207 -0
- package/references/openhive/src/web/stores/dashboard.ts +23 -0
- package/references/openhive/src/web/stores/realtime.ts +90 -0
- package/references/openhive/src/web/stores/theme.ts +70 -0
- package/references/openhive/src/web/stores/toast.ts +63 -0
- package/references/openhive/src/web/styles/globals.css +503 -0
- package/references/openhive/src/web/sw.ts +228 -0
- package/references/openhive/src/web/utils/serviceWorker.ts +86 -0
- package/references/openhive/src/web/vite.config.ts +81 -0
- package/references/openhive/tsconfig.json +32 -0
- package/references/openhive/tsup.config.ts +17 -0
- package/references/openhive/vitest.config.ts +30 -0
- package/references/openhive/vitest.web.config.ts +20 -0
- package/references/opentasks/.claude/settings.json +6 -0
- package/references/opentasks/.claude-plugin/plugin.json +20 -0
- package/references/opentasks/.lintstagedrc.json +4 -0
- package/references/opentasks/.prettierignore +4 -0
- package/references/opentasks/.prettierrc.json +11 -0
- package/references/opentasks/.sudocode/issues.jsonl +89 -0
- package/references/opentasks/.sudocode/specs.jsonl +24 -0
- package/references/opentasks/README.md +401 -0
- package/references/opentasks/docs/ARCHITECTURE.md +841 -0
- package/references/opentasks/docs/DESIGN.md +689 -0
- package/references/opentasks/docs/INTERFACE.md +670 -0
- package/references/opentasks/docs/PERSISTENCE.md +1638 -0
- package/references/opentasks/docs/PROVIDERS.md +1412 -0
- package/references/opentasks/docs/SCHEMA.md +815 -0
- package/references/opentasks/docs/TESTING.md +1081 -0
- package/references/opentasks/eslint.config.js +58 -0
- package/references/opentasks/package-lock.json +4348 -0
- package/references/opentasks/package.json +81 -0
- package/references/opentasks/skills/opentasks/SKILL.md +139 -0
- package/references/opentasks/skills/opentasks/dependency-management.md +119 -0
- package/references/opentasks/skills/opentasks/feedback-and-review.md +100 -0
- package/references/opentasks/skills/opentasks/linking-external-data.md +103 -0
- package/references/opentasks/skills/opentasks/spec-to-implementation.md +98 -0
- package/references/opentasks/src/__tests__/cli-tools.test.ts +800 -0
- package/references/opentasks/src/__tests__/cli.test.ts +97 -0
- package/references/opentasks/src/__tests__/p1-p3-gaps.test.ts +635 -0
- package/references/opentasks/src/cli.ts +929 -0
- package/references/opentasks/src/client/__tests__/client-crud.test.ts +546 -0
- package/references/opentasks/src/client/__tests__/client.test.ts +658 -0
- package/references/opentasks/src/client/__tests__/socket-discovery.test.ts +122 -0
- package/references/opentasks/src/client/client.ts +560 -0
- package/references/opentasks/src/client/index.ts +32 -0
- package/references/opentasks/src/config/__tests__/defaults.test.ts +66 -0
- package/references/opentasks/src/config/__tests__/env.test.ts +155 -0
- package/references/opentasks/src/config/__tests__/index.test.ts +148 -0
- package/references/opentasks/src/config/__tests__/loader.test.ts +173 -0
- package/references/opentasks/src/config/__tests__/merge.test.ts +121 -0
- package/references/opentasks/src/config/__tests__/schema.test.ts +446 -0
- package/references/opentasks/src/config/defaults.ts +18 -0
- package/references/opentasks/src/config/env.ts +170 -0
- package/references/opentasks/src/config/errors.ts +33 -0
- package/references/opentasks/src/config/index.ts +63 -0
- package/references/opentasks/src/config/loader.ts +90 -0
- package/references/opentasks/src/config/merge.ts +64 -0
- package/references/opentasks/src/config/schema.ts +767 -0
- package/references/opentasks/src/core/__tests__/conditional-redirects.test.ts +116 -0
- package/references/opentasks/src/core/__tests__/connections.test.ts +194 -0
- package/references/opentasks/src/core/__tests__/hash.test.ts +161 -0
- package/references/opentasks/src/core/__tests__/id.test.ts +175 -0
- package/references/opentasks/src/core/__tests__/init.test.ts +115 -0
- package/references/opentasks/src/core/__tests__/location.test.ts +94 -0
- package/references/opentasks/src/core/__tests__/merge-driver.test.ts +300 -0
- package/references/opentasks/src/core/__tests__/redirects.test.ts +169 -0
- package/references/opentasks/src/core/__tests__/resolve-location-target.test.ts +468 -0
- package/references/opentasks/src/core/__tests__/uri.test.ts +228 -0
- package/references/opentasks/src/core/__tests__/worktree.test.ts +160 -0
- package/references/opentasks/src/core/conditional-redirects.ts +100 -0
- package/references/opentasks/src/core/connections.ts +217 -0
- package/references/opentasks/src/core/discover.ts +195 -0
- package/references/opentasks/src/core/hash.ts +74 -0
- package/references/opentasks/src/core/id.ts +174 -0
- package/references/opentasks/src/core/index.ts +108 -0
- package/references/opentasks/src/core/init.ts +66 -0
- package/references/opentasks/src/core/location.ts +139 -0
- package/references/opentasks/src/core/merge-driver.ts +280 -0
- package/references/opentasks/src/core/redirects.ts +182 -0
- package/references/opentasks/src/core/uri.ts +270 -0
- package/references/opentasks/src/core/worktree.ts +504 -0
- package/references/opentasks/src/daemon/__tests__/e2e-live-agent.test.ts +344 -0
- package/references/opentasks/src/daemon/__tests__/e2e-session-pipeline.test.ts +447 -0
- package/references/opentasks/src/daemon/__tests__/e2e-watch.test.ts +279 -0
- package/references/opentasks/src/daemon/__tests__/entire-linker.test.ts +1074 -0
- package/references/opentasks/src/daemon/__tests__/entire-watcher.test.ts +659 -0
- package/references/opentasks/src/daemon/__tests__/flush.test.ts +306 -0
- package/references/opentasks/src/daemon/__tests__/integration.test.ts +338 -0
- package/references/opentasks/src/daemon/__tests__/ipc.test.ts +406 -0
- package/references/opentasks/src/daemon/__tests__/lifecycle.test.ts +378 -0
- package/references/opentasks/src/daemon/__tests__/lock.test.ts +240 -0
- package/references/opentasks/src/daemon/__tests__/methods/graph.test.ts +372 -0
- package/references/opentasks/src/daemon/__tests__/methods/provider.test.ts +238 -0
- package/references/opentasks/src/daemon/__tests__/methods/tools.test.ts +690 -0
- package/references/opentasks/src/daemon/__tests__/multi-location.test.ts +945 -0
- package/references/opentasks/src/daemon/__tests__/registry.test.ts +268 -0
- package/references/opentasks/src/daemon/__tests__/watcher.test.ts +329 -0
- package/references/opentasks/src/daemon/entire-linker.ts +615 -0
- package/references/opentasks/src/daemon/entire-watcher.ts +415 -0
- package/references/opentasks/src/daemon/factory.ts +133 -0
- package/references/opentasks/src/daemon/flush.ts +168 -0
- package/references/opentasks/src/daemon/index.ts +120 -0
- package/references/opentasks/src/daemon/ipc.ts +491 -0
- package/references/opentasks/src/daemon/lifecycle.ts +1106 -0
- package/references/opentasks/src/daemon/location-state.ts +481 -0
- package/references/opentasks/src/daemon/lock.ts +168 -0
- package/references/opentasks/src/daemon/methods/__tests__/graph.test.ts +359 -0
- package/references/opentasks/src/daemon/methods/__tests__/provider.test.ts +227 -0
- package/references/opentasks/src/daemon/methods/__tests__/tools.test.ts +360 -0
- package/references/opentasks/src/daemon/methods/__tests__/watch.test.ts +656 -0
- package/references/opentasks/src/daemon/methods/archive.ts +193 -0
- package/references/opentasks/src/daemon/methods/graph.ts +274 -0
- package/references/opentasks/src/daemon/methods/lifecycle.ts +112 -0
- package/references/opentasks/src/daemon/methods/location.ts +118 -0
- package/references/opentasks/src/daemon/methods/provider.ts +159 -0
- package/references/opentasks/src/daemon/methods/tools.ts +221 -0
- package/references/opentasks/src/daemon/methods/watch.ts +206 -0
- package/references/opentasks/src/daemon/registry.ts +244 -0
- package/references/opentasks/src/daemon/types.ts +163 -0
- package/references/opentasks/src/daemon/watcher.ts +248 -0
- package/references/opentasks/src/entire/__tests__/agent-registry.test.ts +127 -0
- package/references/opentasks/src/entire/__tests__/claude-generator.test.ts +49 -0
- package/references/opentasks/src/entire/__tests__/commit-msg.test.ts +89 -0
- package/references/opentasks/src/entire/__tests__/cursor-agent.test.ts +224 -0
- package/references/opentasks/src/entire/__tests__/flush-sentinel.test.ts +93 -0
- package/references/opentasks/src/entire/__tests__/gemini-agent.test.ts +375 -0
- package/references/opentasks/src/entire/__tests__/git-hooks.test.ts +85 -0
- package/references/opentasks/src/entire/__tests__/hook-managers.test.ts +128 -0
- package/references/opentasks/src/entire/__tests__/opencode-agent.test.ts +329 -0
- package/references/opentasks/src/entire/__tests__/redaction.test.ts +143 -0
- package/references/opentasks/src/entire/__tests__/session-store.test.ts +83 -0
- package/references/opentasks/src/entire/__tests__/summarize.test.ts +346 -0
- package/references/opentasks/src/entire/__tests__/transcript-timestamp.test.ts +127 -0
- package/references/opentasks/src/entire/__tests__/types.test.ts +112 -0
- package/references/opentasks/src/entire/__tests__/utils.test.ts +296 -0
- package/references/opentasks/src/entire/__tests__/validation.test.ts +103 -0
- package/references/opentasks/src/entire/__tests__/worktree.test.ts +66 -0
- package/references/opentasks/src/entire/agent/registry.ts +143 -0
- package/references/opentasks/src/entire/agent/session-types.ts +117 -0
- package/references/opentasks/src/entire/agent/types.ts +217 -0
- package/references/opentasks/src/entire/commands/clean.ts +134 -0
- package/references/opentasks/src/entire/commands/disable.ts +85 -0
- package/references/opentasks/src/entire/commands/doctor.ts +152 -0
- package/references/opentasks/src/entire/commands/enable.ts +149 -0
- package/references/opentasks/src/entire/commands/explain.ts +271 -0
- package/references/opentasks/src/entire/commands/reset.ts +105 -0
- package/references/opentasks/src/entire/commands/resume.ts +194 -0
- package/references/opentasks/src/entire/commands/rewind.ts +204 -0
- package/references/opentasks/src/entire/commands/status.ts +150 -0
- package/references/opentasks/src/entire/config.ts +153 -0
- package/references/opentasks/src/entire/git-operations.ts +485 -0
- package/references/opentasks/src/entire/hooks/git-hooks.ts +171 -0
- package/references/opentasks/src/entire/hooks/lifecycle.ts +224 -0
- package/references/opentasks/src/entire/index.ts +644 -0
- package/references/opentasks/src/entire/security/redaction.ts +263 -0
- package/references/opentasks/src/entire/session/state-machine.ts +463 -0
- package/references/opentasks/src/entire/store/checkpoint-store.ts +489 -0
- package/references/opentasks/src/entire/store/native-store.ts +178 -0
- package/references/opentasks/src/entire/store/provider-types.ts +99 -0
- package/references/opentasks/src/entire/store/session-store.ts +233 -0
- package/references/opentasks/src/entire/strategy/attribution.ts +300 -0
- package/references/opentasks/src/entire/strategy/common.ts +222 -0
- package/references/opentasks/src/entire/strategy/content-overlap.ts +242 -0
- package/references/opentasks/src/entire/strategy/manual-commit.ts +1008 -0
- package/references/opentasks/src/entire/strategy/types.ts +285 -0
- package/references/opentasks/src/entire/summarize/claude-generator.ts +119 -0
- package/references/opentasks/src/entire/summarize/summarize.ts +432 -0
- package/references/opentasks/src/entire/types.ts +408 -0
- package/references/opentasks/src/entire/utils/chunk-files.ts +49 -0
- package/references/opentasks/src/entire/utils/commit-message.ts +65 -0
- package/references/opentasks/src/entire/utils/detect-agent.ts +36 -0
- package/references/opentasks/src/entire/utils/hook-managers.ts +118 -0
- package/references/opentasks/src/entire/utils/ide-tags.ts +32 -0
- package/references/opentasks/src/entire/utils/paths.ts +59 -0
- package/references/opentasks/src/entire/utils/preview-rewind.ts +86 -0
- package/references/opentasks/src/entire/utils/rewind-conflict.ts +121 -0
- package/references/opentasks/src/entire/utils/shadow-branch.ts +113 -0
- package/references/opentasks/src/entire/utils/string-utils.ts +46 -0
- package/references/opentasks/src/entire/utils/todo-extract.ts +193 -0
- package/references/opentasks/src/entire/utils/trailers.ts +190 -0
- package/references/opentasks/src/entire/utils/transcript-parse.ts +177 -0
- package/references/opentasks/src/entire/utils/transcript-timestamp.ts +61 -0
- package/references/opentasks/src/entire/utils/tree-ops.ts +227 -0
- package/references/opentasks/src/entire/utils/tty.ts +72 -0
- package/references/opentasks/src/entire/utils/validation.ts +67 -0
- package/references/opentasks/src/entire/utils/worktree.ts +58 -0
- package/references/opentasks/src/graph/EdgeTypeRegistry.ts +330 -0
- package/references/opentasks/src/graph/FederatedGraph.ts +796 -0
- package/references/opentasks/src/graph/GraphologyAdapter.ts +374 -0
- package/references/opentasks/src/graph/HydratingFederatedGraph.ts +533 -0
- package/references/opentasks/src/graph/__tests__/EdgeTypeRegistry.test.ts +263 -0
- package/references/opentasks/src/graph/__tests__/FederatedGraph.test.ts +821 -0
- package/references/opentasks/src/graph/__tests__/GraphologyAdapter.test.ts +408 -0
- package/references/opentasks/src/graph/__tests__/HydratingFederatedGraph.test.ts +735 -0
- package/references/opentasks/src/graph/__tests__/debounce.test.ts +276 -0
- package/references/opentasks/src/graph/__tests__/e2e-store-roundtrip.test.ts +349 -0
- package/references/opentasks/src/graph/__tests__/edge-cases.test.ts +595 -0
- package/references/opentasks/src/graph/__tests__/expansion.test.ts +304 -0
- package/references/opentasks/src/graph/__tests__/git-graph-syncer.test.ts +572 -0
- package/references/opentasks/src/graph/__tests__/provider-store.test.ts +1091 -0
- package/references/opentasks/src/graph/__tests__/query.test.ts +991 -0
- package/references/opentasks/src/graph/__tests__/store.test.ts +998 -0
- package/references/opentasks/src/graph/__tests__/sync.test.ts +178 -0
- package/references/opentasks/src/graph/__tests__/validation.test.ts +657 -0
- package/references/opentasks/src/graph/coordination.ts +454 -0
- package/references/opentasks/src/graph/debounce.ts +154 -0
- package/references/opentasks/src/graph/expansion.ts +364 -0
- package/references/opentasks/src/graph/git-graph-syncer.ts +321 -0
- package/references/opentasks/src/graph/history.ts +438 -0
- package/references/opentasks/src/graph/index.ts +145 -0
- package/references/opentasks/src/graph/provider-store.ts +1077 -0
- package/references/opentasks/src/graph/query.ts +651 -0
- package/references/opentasks/src/graph/store.ts +861 -0
- package/references/opentasks/src/graph/sync.ts +116 -0
- package/references/opentasks/src/graph/types.ts +420 -0
- package/references/opentasks/src/graph/validation.ts +520 -0
- package/references/opentasks/src/index.ts +270 -0
- package/references/opentasks/src/materialization/CLAUDE.md +88 -0
- package/references/opentasks/src/materialization/README.md +187 -0
- package/references/opentasks/src/materialization/__tests__/archive-methods.test.ts +194 -0
- package/references/opentasks/src/materialization/__tests__/archiver.test.ts +528 -0
- package/references/opentasks/src/materialization/__tests__/config.test.ts +123 -0
- package/references/opentasks/src/materialization/__tests__/git-remote-store.test.ts +533 -0
- package/references/opentasks/src/materialization/__tests__/graph-id.test.ts +82 -0
- package/references/opentasks/src/materialization/__tests__/http-remote-store.test.ts +263 -0
- package/references/opentasks/src/materialization/__tests__/materialize-before-archive.test.ts +246 -0
- package/references/opentasks/src/materialization/__tests__/remote-store-factory.test.ts +152 -0
- package/references/opentasks/src/materialization/__tests__/snapshot.test.ts +209 -0
- package/references/opentasks/src/materialization/archiver.ts +318 -0
- package/references/opentasks/src/materialization/git-archive-store.ts +568 -0
- package/references/opentasks/src/materialization/git-remote-store.ts +551 -0
- package/references/opentasks/src/materialization/graph-id.ts +173 -0
- package/references/opentasks/src/materialization/http-remote-store.ts +190 -0
- package/references/opentasks/src/materialization/index.ts +62 -0
- package/references/opentasks/src/materialization/remote-store-factory.ts +55 -0
- package/references/opentasks/src/materialization/snapshot.ts +230 -0
- package/references/opentasks/src/materialization/types.ts +410 -0
- package/references/opentasks/src/providers/__tests__/beads.test.ts +752 -0
- package/references/opentasks/src/providers/__tests__/claude-tasks.test.ts +485 -0
- package/references/opentasks/src/providers/__tests__/entire-e2e.test.ts +692 -0
- package/references/opentasks/src/providers/__tests__/entire-sessionlog-e2e.test.ts +1113 -0
- package/references/opentasks/src/providers/__tests__/entire.test.ts +1016 -0
- package/references/opentasks/src/providers/__tests__/from-config.test.ts +183 -0
- package/references/opentasks/src/providers/__tests__/global.test.ts +515 -0
- package/references/opentasks/src/providers/__tests__/materialization.test.ts +567 -0
- package/references/opentasks/src/providers/__tests__/native.test.ts +693 -0
- package/references/opentasks/src/providers/__tests__/registry.test.ts +232 -0
- package/references/opentasks/src/providers/beads.ts +1155 -0
- package/references/opentasks/src/providers/claude-tasks.ts +402 -0
- package/references/opentasks/src/providers/entire.ts +608 -0
- package/references/opentasks/src/providers/from-config.ts +210 -0
- package/references/opentasks/src/providers/global.ts +460 -0
- package/references/opentasks/src/providers/index.ts +147 -0
- package/references/opentasks/src/providers/location.ts +237 -0
- package/references/opentasks/src/providers/materialization.ts +346 -0
- package/references/opentasks/src/providers/native.ts +725 -0
- package/references/opentasks/src/providers/registry.ts +114 -0
- package/references/opentasks/src/providers/sudocode.ts +1292 -0
- package/references/opentasks/src/providers/sync.ts +485 -0
- package/references/opentasks/src/providers/traits/RelationshipQueryable.ts +169 -0
- package/references/opentasks/src/providers/traits/TaskManageable.ts +211 -0
- package/references/opentasks/src/providers/traits/Watchable.ts +260 -0
- package/references/opentasks/src/providers/traits/__tests__/RelationshipQueryable.test.ts +217 -0
- package/references/opentasks/src/providers/traits/__tests__/TaskManageable.test.ts +241 -0
- package/references/opentasks/src/providers/traits/index.ts +42 -0
- package/references/opentasks/src/providers/types.ts +439 -0
- package/references/opentasks/src/schema/__tests__/validation.test.ts +283 -0
- package/references/opentasks/src/schema/base.ts +88 -0
- package/references/opentasks/src/schema/edges.ts +78 -0
- package/references/opentasks/src/schema/index.ts +37 -0
- package/references/opentasks/src/schema/nodes.ts +119 -0
- package/references/opentasks/src/schema/storage.ts +130 -0
- package/references/opentasks/src/schema/validation.ts +209 -0
- package/references/opentasks/src/storage/__tests__/atomic-write.test.ts +227 -0
- package/references/opentasks/src/storage/__tests__/file-lock.test.ts +120 -0
- package/references/opentasks/src/storage/__tests__/jsonl.test.ts +267 -0
- package/references/opentasks/src/storage/__tests__/locked-writer.test.ts +134 -0
- package/references/opentasks/src/storage/__tests__/sqlite.test.ts +572 -0
- package/references/opentasks/src/storage/atomic-write.ts +86 -0
- package/references/opentasks/src/storage/file-lock.ts +215 -0
- package/references/opentasks/src/storage/index.ts +24 -0
- package/references/opentasks/src/storage/interface.ts +289 -0
- package/references/opentasks/src/storage/jsonl.ts +264 -0
- package/references/opentasks/src/storage/locked-writer.ts +140 -0
- package/references/opentasks/src/storage/sqlite-schema.ts +177 -0
- package/references/opentasks/src/storage/sqlite.ts +791 -0
- package/references/opentasks/src/tools/__tests__/annotate.test.ts +381 -0
- package/references/opentasks/src/tools/__tests__/link.test.ts +299 -0
- package/references/opentasks/src/tools/__tests__/query.test.ts +350 -0
- package/references/opentasks/src/tools/__tests__/task.test.ts +218 -0
- package/references/opentasks/src/tools/annotate.ts +277 -0
- package/references/opentasks/src/tools/index.ts +57 -0
- package/references/opentasks/src/tools/link.ts +163 -0
- package/references/opentasks/src/tools/query.ts +468 -0
- package/references/opentasks/src/tools/task.ts +213 -0
- package/references/opentasks/src/tools/types.ts +451 -0
- package/references/opentasks/src/tracking/__tests__/claude-tool-categorizer.test.ts +223 -0
- package/references/opentasks/src/tracking/__tests__/transcript-extractor.test.ts +262 -0
- package/references/opentasks/src/tracking/claude-tool-categorizer.ts +155 -0
- package/references/opentasks/src/tracking/index.ts +32 -0
- package/references/opentasks/src/tracking/skill-tracker.ts +322 -0
- package/references/opentasks/src/tracking/transcript-extractor.ts +225 -0
- package/references/opentasks/tests/e2e/helpers/assertions.ts +211 -0
- package/references/opentasks/tests/e2e/helpers/beads-helpers.ts +487 -0
- package/references/opentasks/tests/e2e/helpers/fixtures.ts +236 -0
- package/references/opentasks/tests/e2e/helpers/index.ts +122 -0
- package/references/opentasks/tests/e2e/helpers/sudocode-helpers.ts +341 -0
- package/references/opentasks/tests/e2e/helpers/system-setup.ts +504 -0
- package/references/opentasks/tests/e2e/helpers/test-agent.ts +504 -0
- package/references/opentasks/tests/e2e/infrastructure.e2e.test.ts +521 -0
- package/references/opentasks/tests/e2e/skill-tracking.e2e.test.ts +625 -0
- package/references/opentasks/tests/e2e/workflows/feedback-loop.e2e.test.ts +279 -0
- package/references/opentasks/tests/e2e/workflows/multi-agent.e2e.test.ts +304 -0
- package/references/opentasks/tests/e2e/workflows/provider-sync/background-sync.e2e.test.ts +292 -0
- package/references/opentasks/tests/e2e/workflows/provider-sync/beads-provider-compat.e2e.test.ts +249 -0
- package/references/opentasks/tests/e2e/workflows/provider-sync/cross-provider-edges.e2e.test.ts +407 -0
- package/references/opentasks/tests/e2e/workflows/provider-sync/federated-ready.e2e.test.ts +504 -0
- package/references/opentasks/tests/e2e/workflows/provider-sync/hydration.e2e.test.ts +340 -0
- package/references/opentasks/tests/e2e/workflows/provider-sync/materialization.e2e.test.ts +370 -0
- package/references/opentasks/tests/e2e/workflows/provider-sync/sudocode-provider-compat.e2e.test.ts +683 -0
- package/references/opentasks/tests/e2e/workflows/provider-sync/watchable-beads.e2e.test.ts +573 -0
- package/references/opentasks/tests/e2e/workflows/spec-driven.e2e.test.ts +244 -0
- package/references/opentasks/tests/e2e/worktree-location.e2e.test.ts +699 -0
- package/references/opentasks/tests/integration/daemon/helpers.ts +147 -0
- package/references/opentasks/tests/integration/daemon/ipc.integration.test.ts +343 -0
- package/references/opentasks/tests/integration/daemon/lifecycle.integration.test.ts +407 -0
- package/references/opentasks/tests/integration/graph/federated-graph.integration.test.ts +660 -0
- package/references/opentasks/tests/integration/helpers/flags.ts +28 -0
- package/references/opentasks/tests/integration/helpers/index.ts +47 -0
- package/references/opentasks/tests/integration/helpers/process.ts +133 -0
- package/references/opentasks/tests/integration/helpers/temp.ts +105 -0
- package/references/opentasks/tests/integration/helpers/wait.ts +133 -0
- package/references/opentasks/tests/integration/helpers.test.ts +120 -0
- package/references/opentasks/tests/integration/providers/beads-task-manageable.integration.test.ts +450 -0
- package/references/opentasks/tests/integration/providers/beads.integration.test.ts +388 -0
- package/references/opentasks/tests/integration/providers/native-task-manageable.integration.test.ts +667 -0
- package/references/opentasks/tests/integration/providers/sudocode-task-manageable.integration.test.ts +406 -0
- package/references/opentasks/tests/integration/providers/sudocode.integration.test.ts +342 -0
- package/references/opentasks/tests/integration/storage/jsonl-durability.integration.test.ts +390 -0
- package/references/opentasks/tests/integration/storage/sqlite-durability.integration.test.ts +527 -0
- package/references/opentasks/tests/integration/worktree/redirect-location-resolution.integration.test.ts +578 -0
- package/references/opentasks/tests/integration/worktree/worktree-flow.integration.test.ts +656 -0
- package/references/opentasks/tsconfig.json +18 -0
- package/references/opentasks/vitest.config.ts +27 -0
- package/references/opentasks/vitest.e2e.config.ts +35 -0
- package/references/opentasks/vitest.integration.config.ts +19 -0
- package/references/openteams/.claude/settings.json +6 -0
- package/references/openteams/CLAUDE.md +98 -0
- package/references/openteams/README.md +508 -0
- package/references/openteams/SKILL.md +198 -0
- package/references/openteams/design.md +250 -0
- package/references/openteams/docs/visual-editor-design.md +1225 -0
- package/references/openteams/editor/index.html +15 -0
- package/references/openteams/editor/package.json +39 -0
- package/references/openteams/editor/src/App.tsx +48 -0
- package/references/openteams/editor/src/components/canvas/Canvas.tsx +131 -0
- package/references/openteams/editor/src/components/canvas/QuickAddMenu.tsx +134 -0
- package/references/openteams/editor/src/components/edges/PeerRouteEdge.tsx +82 -0
- package/references/openteams/editor/src/components/edges/SignalFlowEdge.tsx +77 -0
- package/references/openteams/editor/src/components/edges/SpawnEdge.tsx +54 -0
- package/references/openteams/editor/src/components/inspector/ChannelInspector.tsx +158 -0
- package/references/openteams/editor/src/components/inspector/EdgeInspector.tsx +168 -0
- package/references/openteams/editor/src/components/inspector/Inspector.tsx +46 -0
- package/references/openteams/editor/src/components/inspector/RoleInspector.tsx +508 -0
- package/references/openteams/editor/src/components/inspector/TeamInspector.tsx +126 -0
- package/references/openteams/editor/src/components/nodes/ChannelNode.tsx +103 -0
- package/references/openteams/editor/src/components/nodes/RoleNode.tsx +157 -0
- package/references/openteams/editor/src/components/nodes/node-styles.ts +101 -0
- package/references/openteams/editor/src/components/sidebar/Sidebar.tsx +227 -0
- package/references/openteams/editor/src/components/toolbar/ExportModal.tsx +110 -0
- package/references/openteams/editor/src/components/toolbar/ImportModal.tsx +139 -0
- package/references/openteams/editor/src/components/toolbar/Toolbar.tsx +190 -0
- package/references/openteams/editor/src/hooks/use-autosave.ts +126 -0
- package/references/openteams/editor/src/hooks/use-keyboard.ts +106 -0
- package/references/openteams/editor/src/hooks/use-validation.ts +45 -0
- package/references/openteams/editor/src/index.css +245 -0
- package/references/openteams/editor/src/lib/auto-layout.ts +51 -0
- package/references/openteams/editor/src/lib/bundled-templates.ts +42 -0
- package/references/openteams/editor/src/lib/compiler.ts +75 -0
- package/references/openteams/editor/src/lib/load-template.ts +103 -0
- package/references/openteams/editor/src/lib/rebuild-edges.ts +104 -0
- package/references/openteams/editor/src/lib/serializer.ts +408 -0
- package/references/openteams/editor/src/lib/signal-catalog.ts +50 -0
- package/references/openteams/editor/src/lib/validator.ts +172 -0
- package/references/openteams/editor/src/main.tsx +10 -0
- package/references/openteams/editor/src/stores/canvas-store.ts +80 -0
- package/references/openteams/editor/src/stores/config-store.ts +243 -0
- package/references/openteams/editor/src/stores/history-store.ts +143 -0
- package/references/openteams/editor/src/stores/theme-store.ts +66 -0
- package/references/openteams/editor/src/stores/ui-store.ts +46 -0
- package/references/openteams/editor/src/stores/validation-store.ts +27 -0
- package/references/openteams/editor/src/types/editor.ts +74 -0
- package/references/openteams/editor/src/vite-env.d.ts +1 -0
- package/references/openteams/editor/tests/compiler.test.ts +151 -0
- package/references/openteams/editor/tests/e2e-add-remove.test.ts +386 -0
- package/references/openteams/editor/tests/e2e-components.test.tsx +424 -0
- package/references/openteams/editor/tests/e2e-export-roundtrip.test.ts +299 -0
- package/references/openteams/editor/tests/e2e-template-load.test.ts +204 -0
- package/references/openteams/editor/tests/e2e-ui-store.test.ts +126 -0
- package/references/openteams/editor/tests/e2e-undo-redo.test.ts +203 -0
- package/references/openteams/editor/tests/e2e-validation.test.ts +307 -0
- package/references/openteams/editor/tests/serializer.test.ts +142 -0
- package/references/openteams/editor/tests/setup.ts +52 -0
- package/references/openteams/editor/tests/validator.test.ts +92 -0
- package/references/openteams/editor/tsconfig.json +21 -0
- package/references/openteams/editor/tsconfig.tsbuildinfo +1 -0
- package/references/openteams/editor/vite.config.ts +28 -0
- package/references/openteams/examples/bmad-method/prompts/analyst/ROLE.md +16 -0
- package/references/openteams/examples/bmad-method/prompts/analyst/SOUL.md +5 -0
- package/references/openteams/examples/bmad-method/prompts/architect/ROLE.md +24 -0
- package/references/openteams/examples/bmad-method/prompts/architect/SOUL.md +5 -0
- package/references/openteams/examples/bmad-method/prompts/developer/ROLE.md +25 -0
- package/references/openteams/examples/bmad-method/prompts/developer/SOUL.md +5 -0
- package/references/openteams/examples/bmad-method/prompts/master/ROLE.md +21 -0
- package/references/openteams/examples/bmad-method/prompts/master/SOUL.md +5 -0
- package/references/openteams/examples/bmad-method/prompts/pm/ROLE.md +20 -0
- package/references/openteams/examples/bmad-method/prompts/pm/SOUL.md +5 -0
- package/references/openteams/examples/bmad-method/prompts/qa/ROLE.md +17 -0
- package/references/openteams/examples/bmad-method/prompts/qa/SOUL.md +5 -0
- package/references/openteams/examples/bmad-method/prompts/quick-flow-dev/ROLE.md +23 -0
- package/references/openteams/examples/bmad-method/prompts/quick-flow-dev/SOUL.md +5 -0
- package/references/openteams/examples/bmad-method/prompts/scrum-master/ROLE.md +27 -0
- package/references/openteams/examples/bmad-method/prompts/scrum-master/SOUL.md +5 -0
- package/references/openteams/examples/bmad-method/prompts/tech-writer/ROLE.md +21 -0
- package/references/openteams/examples/bmad-method/prompts/tech-writer/SOUL.md +5 -0
- package/references/openteams/examples/bmad-method/prompts/ux-designer/ROLE.md +16 -0
- package/references/openteams/examples/bmad-method/prompts/ux-designer/SOUL.md +5 -0
- package/references/openteams/examples/bmad-method/roles/analyst.yaml +9 -0
- package/references/openteams/examples/bmad-method/roles/architect.yaml +9 -0
- package/references/openteams/examples/bmad-method/roles/developer.yaml +8 -0
- package/references/openteams/examples/bmad-method/roles/master.yaml +8 -0
- package/references/openteams/examples/bmad-method/roles/pm.yaml +9 -0
- package/references/openteams/examples/bmad-method/roles/qa.yaml +8 -0
- package/references/openteams/examples/bmad-method/roles/quick-flow-dev.yaml +8 -0
- package/references/openteams/examples/bmad-method/roles/scrum-master.yaml +9 -0
- package/references/openteams/examples/bmad-method/roles/tech-writer.yaml +8 -0
- package/references/openteams/examples/bmad-method/roles/ux-designer.yaml +8 -0
- package/references/openteams/examples/bmad-method/team.yaml +161 -0
- package/references/openteams/examples/bug-fix-pipeline/roles/fixer.yaml +9 -0
- package/references/openteams/examples/bug-fix-pipeline/roles/investigator.yaml +8 -0
- package/references/openteams/examples/bug-fix-pipeline/roles/pr-creator.yaml +6 -0
- package/references/openteams/examples/bug-fix-pipeline/roles/triager.yaml +7 -0
- package/references/openteams/examples/bug-fix-pipeline/roles/verifier.yaml +8 -0
- package/references/openteams/examples/bug-fix-pipeline/team.yaml +88 -0
- package/references/openteams/examples/codebase-migration/roles/assessor.yaml +7 -0
- package/references/openteams/examples/codebase-migration/roles/migrator.yaml +9 -0
- package/references/openteams/examples/codebase-migration/roles/planner.yaml +5 -0
- package/references/openteams/examples/codebase-migration/roles/test-extractor.yaml +9 -0
- package/references/openteams/examples/codebase-migration/roles/validator.yaml +7 -0
- package/references/openteams/examples/codebase-migration/team.yaml +81 -0
- package/references/openteams/examples/docs-sync/roles/adr-writer.yaml +7 -0
- package/references/openteams/examples/docs-sync/roles/api-doc-writer.yaml +7 -0
- package/references/openteams/examples/docs-sync/roles/change-detector.yaml +7 -0
- package/references/openteams/examples/docs-sync/roles/doc-reviewer.yaml +7 -0
- package/references/openteams/examples/docs-sync/roles/guide-writer.yaml +7 -0
- package/references/openteams/examples/docs-sync/team.yaml +84 -0
- package/references/openteams/examples/gsd/prompts/codebase-mapper/ROLE.md +17 -0
- package/references/openteams/examples/gsd/prompts/codebase-mapper/SOUL.md +5 -0
- package/references/openteams/examples/gsd/prompts/debugger/ROLE.md +25 -0
- package/references/openteams/examples/gsd/prompts/debugger/SOUL.md +5 -0
- package/references/openteams/examples/gsd/prompts/executor/ROLE.md +34 -0
- package/references/openteams/examples/gsd/prompts/executor/SOUL.md +5 -0
- package/references/openteams/examples/gsd/prompts/integration-checker/ROLE.md +18 -0
- package/references/openteams/examples/gsd/prompts/integration-checker/SOUL.md +3 -0
- package/references/openteams/examples/gsd/prompts/orchestrator/ROLE.md +42 -0
- package/references/openteams/examples/gsd/prompts/orchestrator/SOUL.md +5 -0
- package/references/openteams/examples/gsd/prompts/phase-researcher/ROLE.md +15 -0
- package/references/openteams/examples/gsd/prompts/phase-researcher/SOUL.md +3 -0
- package/references/openteams/examples/gsd/prompts/plan-checker/ROLE.md +17 -0
- package/references/openteams/examples/gsd/prompts/plan-checker/SOUL.md +3 -0
- package/references/openteams/examples/gsd/prompts/planner/ROLE.md +28 -0
- package/references/openteams/examples/gsd/prompts/planner/SOUL.md +5 -0
- package/references/openteams/examples/gsd/prompts/project-researcher/ROLE.md +16 -0
- package/references/openteams/examples/gsd/prompts/project-researcher/SOUL.md +3 -0
- package/references/openteams/examples/gsd/prompts/research-synthesizer/ROLE.md +13 -0
- package/references/openteams/examples/gsd/prompts/research-synthesizer/SOUL.md +3 -0
- package/references/openteams/examples/gsd/prompts/roadmapper/ROLE.md +14 -0
- package/references/openteams/examples/gsd/prompts/roadmapper/SOUL.md +3 -0
- package/references/openteams/examples/gsd/prompts/verifier/ROLE.md +19 -0
- package/references/openteams/examples/gsd/prompts/verifier/SOUL.md +5 -0
- package/references/openteams/examples/gsd/roles/codebase-mapper.yaml +8 -0
- package/references/openteams/examples/gsd/roles/debugger.yaml +8 -0
- package/references/openteams/examples/gsd/roles/executor.yaml +8 -0
- package/references/openteams/examples/gsd/roles/integration-checker.yaml +8 -0
- package/references/openteams/examples/gsd/roles/orchestrator.yaml +9 -0
- package/references/openteams/examples/gsd/roles/phase-researcher.yaml +7 -0
- package/references/openteams/examples/gsd/roles/plan-checker.yaml +8 -0
- package/references/openteams/examples/gsd/roles/planner.yaml +8 -0
- package/references/openteams/examples/gsd/roles/project-researcher.yaml +8 -0
- package/references/openteams/examples/gsd/roles/research-synthesizer.yaml +7 -0
- package/references/openteams/examples/gsd/roles/roadmapper.yaml +7 -0
- package/references/openteams/examples/gsd/roles/verifier.yaml +8 -0
- package/references/openteams/examples/gsd/team.yaml +154 -0
- package/references/openteams/examples/incident-response/roles/communicator.yaml +5 -0
- package/references/openteams/examples/incident-response/roles/fix-proposer.yaml +7 -0
- package/references/openteams/examples/incident-response/roles/incident-triager.yaml +8 -0
- package/references/openteams/examples/incident-response/roles/investigator.yaml +8 -0
- package/references/openteams/examples/incident-response/team.yaml +68 -0
- package/references/openteams/examples/pr-review-checks/roles/code-reviewer.yaml +7 -0
- package/references/openteams/examples/pr-review-checks/roles/security-scanner.yaml +6 -0
- package/references/openteams/examples/pr-review-checks/roles/summarizer.yaml +6 -0
- package/references/openteams/examples/pr-review-checks/roles/test-checker.yaml +8 -0
- package/references/openteams/examples/pr-review-checks/team.yaml +64 -0
- package/references/openteams/examples/security-audit/roles/code-analyzer.yaml +6 -0
- package/references/openteams/examples/security-audit/roles/dep-scanner.yaml +7 -0
- package/references/openteams/examples/security-audit/roles/fixer.yaml +9 -0
- package/references/openteams/examples/security-audit/roles/pr-creator.yaml +6 -0
- package/references/openteams/examples/security-audit/roles/prioritizer.yaml +6 -0
- package/references/openteams/examples/security-audit/roles/secrets-scanner.yaml +6 -0
- package/references/openteams/examples/security-audit/roles/verifier.yaml +8 -0
- package/references/openteams/examples/security-audit/team.yaml +102 -0
- package/references/openteams/media/banner.png +0 -0
- package/references/openteams/media/editor.png +0 -0
- package/references/openteams/package-lock.json +4804 -0
- package/references/openteams/package.json +58 -0
- package/references/openteams/schema/role.schema.json +147 -0
- package/references/openteams/schema/team.schema.json +311 -0
- package/references/openteams/src/cli/editor.ts +170 -0
- package/references/openteams/src/cli/generate.test.ts +191 -0
- package/references/openteams/src/cli/generate.ts +242 -0
- package/references/openteams/src/cli/prompt-utils.ts +42 -0
- package/references/openteams/src/cli/template.test.ts +365 -0
- package/references/openteams/src/cli/template.ts +205 -0
- package/references/openteams/src/cli.ts +22 -0
- package/references/openteams/src/generators/agent-prompt-generator.test.ts +426 -0
- package/references/openteams/src/generators/agent-prompt-generator.ts +556 -0
- package/references/openteams/src/generators/package-generator.test.ts +129 -0
- package/references/openteams/src/generators/package-generator.ts +110 -0
- package/references/openteams/src/generators/skill-generator.test.ts +274 -0
- package/references/openteams/src/generators/skill-generator.ts +394 -0
- package/references/openteams/src/index.ts +84 -0
- package/references/openteams/src/template/builtins.test.ts +74 -0
- package/references/openteams/src/template/builtins.ts +108 -0
- package/references/openteams/src/template/install-service.test.ts +452 -0
- package/references/openteams/src/template/install-service.ts +332 -0
- package/references/openteams/src/template/loader.test.ts +1696 -0
- package/references/openteams/src/template/loader.ts +804 -0
- package/references/openteams/src/template/resolver.test.ts +304 -0
- package/references/openteams/src/template/resolver.ts +251 -0
- package/references/openteams/src/template/types.ts +229 -0
- package/references/openteams/tsconfig.cjs.json +7 -0
- package/references/openteams/tsconfig.esm.json +8 -0
- package/references/openteams/tsconfig.json +16 -0
- package/references/openteams/vitest.config.ts +9 -0
- package/references/sessionlog/.husky/pre-commit +1 -0
- package/references/sessionlog/.lintstagedrc.json +4 -0
- package/references/sessionlog/.prettierignore +4 -0
- package/references/sessionlog/.prettierrc.json +11 -0
- package/references/sessionlog/LICENSE +21 -0
- package/references/sessionlog/README.md +453 -0
- package/references/sessionlog/eslint.config.js +58 -0
- package/references/sessionlog/package-lock.json +3672 -0
- package/references/sessionlog/package.json +65 -0
- package/references/sessionlog/src/__tests__/agent-hooks.test.ts +570 -0
- package/references/sessionlog/src/__tests__/agent-registry.test.ts +127 -0
- package/references/sessionlog/src/__tests__/claude-code-hooks.test.ts +225 -0
- package/references/sessionlog/src/__tests__/claude-generator.test.ts +46 -0
- package/references/sessionlog/src/__tests__/commit-msg.test.ts +86 -0
- package/references/sessionlog/src/__tests__/cursor-agent.test.ts +224 -0
- package/references/sessionlog/src/__tests__/e2e-live.test.ts +890 -0
- package/references/sessionlog/src/__tests__/event-log.test.ts +183 -0
- package/references/sessionlog/src/__tests__/flush-sentinel.test.ts +105 -0
- package/references/sessionlog/src/__tests__/gemini-agent.test.ts +375 -0
- package/references/sessionlog/src/__tests__/git-hooks.test.ts +78 -0
- package/references/sessionlog/src/__tests__/hook-managers.test.ts +121 -0
- package/references/sessionlog/src/__tests__/lifecycle-tasks.test.ts +759 -0
- package/references/sessionlog/src/__tests__/opencode-agent.test.ts +338 -0
- package/references/sessionlog/src/__tests__/redaction.test.ts +136 -0
- package/references/sessionlog/src/__tests__/session-repo.test.ts +353 -0
- package/references/sessionlog/src/__tests__/session-store.test.ts +166 -0
- package/references/sessionlog/src/__tests__/setup-ccweb.test.ts +466 -0
- package/references/sessionlog/src/__tests__/skill-live.test.ts +461 -0
- package/references/sessionlog/src/__tests__/summarize.test.ts +348 -0
- package/references/sessionlog/src/__tests__/task-plan-e2e.test.ts +610 -0
- package/references/sessionlog/src/__tests__/task-plan-live.test.ts +632 -0
- package/references/sessionlog/src/__tests__/transcript-timestamp.test.ts +121 -0
- package/references/sessionlog/src/__tests__/types.test.ts +166 -0
- package/references/sessionlog/src/__tests__/utils.test.ts +333 -0
- package/references/sessionlog/src/__tests__/validation.test.ts +103 -0
- package/references/sessionlog/src/__tests__/worktree.test.ts +57 -0
- package/references/sessionlog/src/agent/registry.ts +143 -0
- package/references/sessionlog/src/agent/session-types.ts +113 -0
- package/references/sessionlog/src/agent/types.ts +220 -0
- package/references/sessionlog/src/cli.ts +597 -0
- package/references/sessionlog/src/commands/clean.ts +133 -0
- package/references/sessionlog/src/commands/disable.ts +84 -0
- package/references/sessionlog/src/commands/doctor.ts +145 -0
- package/references/sessionlog/src/commands/enable.ts +202 -0
- package/references/sessionlog/src/commands/explain.ts +261 -0
- package/references/sessionlog/src/commands/reset.ts +105 -0
- package/references/sessionlog/src/commands/resume.ts +180 -0
- package/references/sessionlog/src/commands/rewind.ts +195 -0
- package/references/sessionlog/src/commands/setup-ccweb.ts +275 -0
- package/references/sessionlog/src/commands/status.ts +172 -0
- package/references/sessionlog/src/config.ts +165 -0
- package/references/sessionlog/src/events/event-log.ts +126 -0
- package/references/sessionlog/src/git-operations.ts +558 -0
- package/references/sessionlog/src/hooks/git-hooks.ts +165 -0
- package/references/sessionlog/src/hooks/lifecycle.ts +391 -0
- package/references/sessionlog/src/index.ts +650 -0
- package/references/sessionlog/src/security/redaction.ts +283 -0
- package/references/sessionlog/src/session/state-machine.ts +452 -0
- package/references/sessionlog/src/store/checkpoint-store.ts +509 -0
- package/references/sessionlog/src/store/native-store.ts +173 -0
- package/references/sessionlog/src/store/provider-types.ts +99 -0
- package/references/sessionlog/src/store/session-store.ts +266 -0
- package/references/sessionlog/src/strategy/attribution.ts +296 -0
- package/references/sessionlog/src/strategy/common.ts +207 -0
- package/references/sessionlog/src/strategy/content-overlap.ts +228 -0
- package/references/sessionlog/src/strategy/manual-commit.ts +988 -0
- package/references/sessionlog/src/strategy/types.ts +279 -0
- package/references/sessionlog/src/summarize/claude-generator.ts +115 -0
- package/references/sessionlog/src/summarize/summarize.ts +432 -0
- package/references/sessionlog/src/types.ts +508 -0
- package/references/sessionlog/src/utils/chunk-files.ts +49 -0
- package/references/sessionlog/src/utils/commit-message.ts +65 -0
- package/references/sessionlog/src/utils/detect-agent.ts +36 -0
- package/references/sessionlog/src/utils/hook-managers.ts +125 -0
- package/references/sessionlog/src/utils/ide-tags.ts +32 -0
- package/references/sessionlog/src/utils/paths.ts +79 -0
- package/references/sessionlog/src/utils/preview-rewind.ts +80 -0
- package/references/sessionlog/src/utils/rewind-conflict.ts +121 -0
- package/references/sessionlog/src/utils/shadow-branch.ts +109 -0
- package/references/sessionlog/src/utils/string-utils.ts +46 -0
- package/references/sessionlog/src/utils/todo-extract.ts +188 -0
- package/references/sessionlog/src/utils/trailers.ts +187 -0
- package/references/sessionlog/src/utils/transcript-parse.ts +177 -0
- package/references/sessionlog/src/utils/transcript-timestamp.ts +59 -0
- package/references/sessionlog/src/utils/tree-ops.ts +219 -0
- package/references/sessionlog/src/utils/tty.ts +72 -0
- package/references/sessionlog/src/utils/validation.ts +65 -0
- package/references/sessionlog/src/utils/worktree.ts +58 -0
- package/references/sessionlog/src/wire-types.ts +59 -0
- package/references/sessionlog/templates/setup-env.sh +153 -0
- package/references/sessionlog/tsconfig.json +18 -0
- package/references/sessionlog/vitest.config.ts +12 -0
- package/references/skill-tree/.claude/settings.json +6 -0
- package/references/skill-tree/.sudocode/issues.jsonl +19 -0
- package/references/skill-tree/.sudocode/specs.jsonl +3 -0
- package/references/skill-tree/CLAUDE.md +132 -0
- package/references/skill-tree/README.md +396 -0
- package/references/skill-tree/docs/GAPS_v1.md +221 -0
- package/references/skill-tree/docs/INTEGRATION_PLAN.md +467 -0
- package/references/skill-tree/docs/TODOS.md +91 -0
- package/references/skill-tree/docs/anthropic_skill_guide.md +1364 -0
- package/references/skill-tree/docs/design/federated-skill-trees.md +524 -0
- package/references/skill-tree/docs/design/multi-agent-sync.md +759 -0
- package/references/skill-tree/docs/scraper/BRAINSTORM.md +583 -0
- package/references/skill-tree/docs/scraper/POC_PLAN.md +420 -0
- package/references/skill-tree/docs/scraper/README.md +170 -0
- package/references/skill-tree/examples/basic-usage.ts +157 -0
- package/references/skill-tree/package-lock.json +1852 -0
- package/references/skill-tree/package.json +66 -0
- package/references/skill-tree/plan.md +78 -0
- package/references/skill-tree/scraper/README.md +123 -0
- package/references/skill-tree/scraper/docs/DESIGN.md +683 -0
- package/references/skill-tree/scraper/docs/PLAN.md +336 -0
- package/references/skill-tree/scraper/drizzle.config.ts +10 -0
- package/references/skill-tree/scraper/package-lock.json +6329 -0
- package/references/skill-tree/scraper/package.json +68 -0
- package/references/skill-tree/scraper/test/fixtures/invalid-skill/missing-description.md +7 -0
- package/references/skill-tree/scraper/test/fixtures/invalid-skill/missing-name.md +7 -0
- package/references/skill-tree/scraper/test/fixtures/minimal-skill/SKILL.md +27 -0
- package/references/skill-tree/scraper/test/fixtures/skill-json/SKILL.json +21 -0
- package/references/skill-tree/scraper/test/fixtures/skill-with-meta/SKILL.md +54 -0
- package/references/skill-tree/scraper/test/fixtures/skill-with-meta/_meta.json +24 -0
- package/references/skill-tree/scraper/test/fixtures/valid-skill/SKILL.md +93 -0
- package/references/skill-tree/scraper/test/fixtures/valid-skill/_meta.json +22 -0
- package/references/skill-tree/scraper/tsup.config.ts +14 -0
- package/references/skill-tree/scraper/vitest.config.ts +17 -0
- package/references/skill-tree/scripts/convert-to-vitest.ts +166 -0
- package/references/skill-tree/skills/skill-writer/SKILL.md +339 -0
- package/references/skill-tree/skills/skill-writer/references/examples.md +326 -0
- package/references/skill-tree/skills/skill-writer/references/patterns.md +210 -0
- package/references/skill-tree/skills/skill-writer/references/quality-checklist.md +123 -0
- package/references/skill-tree/test/run-all.ts +106 -0
- package/references/skill-tree/test/utils.ts +128 -0
- package/references/skill-tree/vitest.config.ts +16 -0
- package/references/swarmkit/LICENSE +21 -0
- package/references/swarmkit/README.md +130 -0
- package/references/swarmkit/docs/design.md +453 -0
- package/references/swarmkit/docs/package-setup-reference.md +519 -0
- package/references/swarmkit/package-lock.json +1938 -0
- package/references/swarmkit/package.json +43 -0
- package/references/swarmkit/src/cli.ts +41 -0
- package/references/swarmkit/src/commands/add.ts +126 -0
- package/references/swarmkit/src/commands/doctor.ts +117 -0
- package/references/swarmkit/src/commands/hive.ts +279 -0
- package/references/swarmkit/src/commands/init/phases/configure.ts +74 -0
- package/references/swarmkit/src/commands/init/phases/global-setup.ts +104 -0
- package/references/swarmkit/src/commands/init/phases/packages.ts +44 -0
- package/references/swarmkit/src/commands/init/phases/project.ts +81 -0
- package/references/swarmkit/src/commands/init/phases/use-case.ts +47 -0
- package/references/swarmkit/src/commands/init/state.test.ts +23 -0
- package/references/swarmkit/src/commands/init/state.ts +22 -0
- package/references/swarmkit/src/commands/init/wizard.ts +160 -0
- package/references/swarmkit/src/commands/init.ts +17 -0
- package/references/swarmkit/src/commands/login.ts +106 -0
- package/references/swarmkit/src/commands/logout.ts +22 -0
- package/references/swarmkit/src/commands/remove.ts +72 -0
- package/references/swarmkit/src/commands/status.ts +101 -0
- package/references/swarmkit/src/commands/update.ts +62 -0
- package/references/swarmkit/src/commands/whoami.ts +41 -0
- package/references/swarmkit/src/config/global.test.ts +258 -0
- package/references/swarmkit/src/config/global.ts +141 -0
- package/references/swarmkit/src/config/keys.test.ts +109 -0
- package/references/swarmkit/src/config/keys.ts +49 -0
- package/references/swarmkit/src/doctor/checks.test.ts +366 -0
- package/references/swarmkit/src/doctor/checks.ts +292 -0
- package/references/swarmkit/src/doctor/types.ts +33 -0
- package/references/swarmkit/src/hub/auth-flow.test.ts +127 -0
- package/references/swarmkit/src/hub/auth-flow.ts +144 -0
- package/references/swarmkit/src/hub/client.test.ts +224 -0
- package/references/swarmkit/src/hub/client.ts +185 -0
- package/references/swarmkit/src/hub/credentials.test.ts +132 -0
- package/references/swarmkit/src/hub/credentials.ts +51 -0
- package/references/swarmkit/src/index.ts +116 -0
- package/references/swarmkit/src/packages/installer.test.ts +365 -0
- package/references/swarmkit/src/packages/installer.ts +206 -0
- package/references/swarmkit/src/packages/plugin.test.ts +141 -0
- package/references/swarmkit/src/packages/plugin.ts +46 -0
- package/references/swarmkit/src/packages/registry.test.ts +235 -0
- package/references/swarmkit/src/packages/registry.ts +209 -0
- package/references/swarmkit/src/packages/setup.test.ts +1395 -0
- package/references/swarmkit/src/packages/setup.ts +671 -0
- package/references/swarmkit/src/utils/ui.test.ts +115 -0
- package/references/swarmkit/src/utils/ui.ts +62 -0
- package/references/swarmkit/tsconfig.json +17 -0
- package/references/swarmkit/vitest.config.ts +9 -0
- package/scripts/bootstrap.mjs +26 -1
- package/scripts/generate-agents.mjs +5 -1
- package/scripts/map-hook.mjs +97 -64
- package/scripts/map-sidecar.mjs +179 -25
- package/scripts/team-loader.mjs +12 -41
- package/skills/swarm/SKILL.md +89 -25
- package/src/__tests__/agent-generator.test.mjs +6 -13
- package/src/__tests__/bootstrap.test.mjs +124 -1
- package/src/__tests__/config.test.mjs +72 -27
- package/src/__tests__/e2e-live-map.test.mjs +536 -0
- package/src/__tests__/e2e-mesh-sidecar.test.mjs +570 -0
- package/src/__tests__/e2e-native-task-hooks.test.mjs +376 -0
- package/src/__tests__/e2e-sidecar-bridge.test.mjs +477 -0
- package/src/__tests__/helpers.mjs +13 -0
- package/src/__tests__/inbox.test.mjs +22 -89
- package/src/__tests__/index.test.mjs +33 -9
- package/src/__tests__/integration.test.mjs +513 -0
- package/src/__tests__/map-events.test.mjs +514 -150
- package/src/__tests__/mesh-connection.test.mjs +308 -0
- package/src/__tests__/opentasks-client.test.mjs +517 -0
- package/src/__tests__/paths.test.mjs +185 -54
- package/src/__tests__/sidecar-client.test.mjs +35 -0
- package/src/__tests__/sidecar-server.test.mjs +124 -0
- package/src/__tests__/skilltree-client.test.mjs +80 -0
- package/src/agent-generator.mjs +104 -33
- package/src/bootstrap.mjs +150 -10
- package/src/config.mjs +35 -1
- package/src/context-output.mjs +58 -8
- package/src/inbox.mjs +9 -54
- package/src/index.mjs +36 -7
- package/src/map-connection.mjs +1 -0
- package/src/map-events.mjs +350 -80
- package/src/mesh-connection.mjs +148 -0
- package/src/opentasks-client.mjs +269 -0
- package/src/paths.mjs +178 -28
- package/src/sessionlog.mjs +14 -9
- package/src/sidecar-client.mjs +79 -25
- package/src/sidecar-server.mjs +175 -16
- package/src/skilltree-client.mjs +173 -0
- package/src/template.mjs +68 -4
- package/vitest.config.mjs +1 -0
|
@@ -0,0 +1,1360 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turso Database Provider
|
|
3
|
+
*
|
|
4
|
+
* Uses libSQL client to connect to Turso (serverless SQLite).
|
|
5
|
+
* This is the recommended provider for serverless deployments
|
|
6
|
+
* like Vercel, Cloudflare Workers, and Cloud Run.
|
|
7
|
+
*
|
|
8
|
+
* Turso provides:
|
|
9
|
+
* - SQLite-compatible syntax
|
|
10
|
+
* - HTTP-based connections (no persistent filesystem needed)
|
|
11
|
+
* - Edge locations for low latency
|
|
12
|
+
* - Automatic replication
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { createClient, Client, InStatement, ResultSet } from '@libsql/client';
|
|
16
|
+
import { nanoid } from 'nanoid';
|
|
17
|
+
import bcrypt from 'bcrypt';
|
|
18
|
+
import type {
|
|
19
|
+
DatabaseProvider,
|
|
20
|
+
TursoProviderConfig,
|
|
21
|
+
AgentRepository,
|
|
22
|
+
PostRepository,
|
|
23
|
+
CommentRepository,
|
|
24
|
+
HiveRepository,
|
|
25
|
+
VoteRepository,
|
|
26
|
+
FollowRepository,
|
|
27
|
+
InviteRepository,
|
|
28
|
+
UploadRepository,
|
|
29
|
+
InstanceRepository,
|
|
30
|
+
SearchRepository,
|
|
31
|
+
CreateAgentInput,
|
|
32
|
+
CreateHumanInput,
|
|
33
|
+
UpdateAgentInput,
|
|
34
|
+
CreatePostInput,
|
|
35
|
+
UpdatePostInput,
|
|
36
|
+
ListPostsOptions,
|
|
37
|
+
CreateCommentInput,
|
|
38
|
+
UpdateCommentInput,
|
|
39
|
+
ListCommentsOptions,
|
|
40
|
+
CreateHiveInput,
|
|
41
|
+
UpdateHiveInput,
|
|
42
|
+
CastVoteInput,
|
|
43
|
+
CreateInviteInput,
|
|
44
|
+
CreateUploadInput,
|
|
45
|
+
Upload,
|
|
46
|
+
CreateInstanceInput,
|
|
47
|
+
SearchOptions,
|
|
48
|
+
SearchResults,
|
|
49
|
+
} from './types.js';
|
|
50
|
+
import type { Agent, AgentPublic, Post, PostWithAuthor, Comment, CommentWithAuthor, Hive, Vote, Follow, InviteCode, FederatedInstance } from '../../types.js';
|
|
51
|
+
|
|
52
|
+
const SALT_ROUNDS = 10;
|
|
53
|
+
|
|
54
|
+
// Schema (same as SQLite)
|
|
55
|
+
const CREATE_TABLES = `
|
|
56
|
+
CREATE TABLE IF NOT EXISTS schema_version (version INTEGER PRIMARY KEY);
|
|
57
|
+
|
|
58
|
+
CREATE TABLE IF NOT EXISTS agents (
|
|
59
|
+
id TEXT PRIMARY KEY,
|
|
60
|
+
name TEXT UNIQUE NOT NULL,
|
|
61
|
+
api_key_hash TEXT,
|
|
62
|
+
description TEXT,
|
|
63
|
+
avatar_url TEXT,
|
|
64
|
+
karma INTEGER DEFAULT 0,
|
|
65
|
+
is_verified INTEGER DEFAULT 0,
|
|
66
|
+
is_admin INTEGER DEFAULT 0,
|
|
67
|
+
metadata TEXT,
|
|
68
|
+
verification_status TEXT DEFAULT 'pending',
|
|
69
|
+
verification_data TEXT,
|
|
70
|
+
account_type TEXT DEFAULT 'agent',
|
|
71
|
+
email TEXT UNIQUE,
|
|
72
|
+
password_hash TEXT,
|
|
73
|
+
email_verified INTEGER DEFAULT 0,
|
|
74
|
+
password_reset_token TEXT,
|
|
75
|
+
password_reset_expires TEXT,
|
|
76
|
+
created_at TEXT DEFAULT (datetime('now')),
|
|
77
|
+
updated_at TEXT DEFAULT (datetime('now')),
|
|
78
|
+
last_seen_at TEXT
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
CREATE TABLE IF NOT EXISTS hives (
|
|
82
|
+
id TEXT PRIMARY KEY,
|
|
83
|
+
name TEXT UNIQUE NOT NULL,
|
|
84
|
+
description TEXT,
|
|
85
|
+
owner_id TEXT NOT NULL,
|
|
86
|
+
is_public INTEGER DEFAULT 1,
|
|
87
|
+
settings TEXT,
|
|
88
|
+
member_count INTEGER DEFAULT 0,
|
|
89
|
+
created_at TEXT DEFAULT (datetime('now')),
|
|
90
|
+
updated_at TEXT DEFAULT (datetime('now'))
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
CREATE TABLE IF NOT EXISTS posts (
|
|
94
|
+
id TEXT PRIMARY KEY,
|
|
95
|
+
hive_id TEXT NOT NULL,
|
|
96
|
+
author_id TEXT NOT NULL,
|
|
97
|
+
title TEXT NOT NULL,
|
|
98
|
+
content TEXT,
|
|
99
|
+
url TEXT,
|
|
100
|
+
score INTEGER DEFAULT 0,
|
|
101
|
+
comment_count INTEGER DEFAULT 0,
|
|
102
|
+
is_pinned INTEGER DEFAULT 0,
|
|
103
|
+
created_at TEXT DEFAULT (datetime('now')),
|
|
104
|
+
updated_at TEXT DEFAULT (datetime('now'))
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
CREATE TABLE IF NOT EXISTS comments (
|
|
108
|
+
id TEXT PRIMARY KEY,
|
|
109
|
+
post_id TEXT NOT NULL,
|
|
110
|
+
parent_id TEXT,
|
|
111
|
+
author_id TEXT NOT NULL,
|
|
112
|
+
content TEXT NOT NULL,
|
|
113
|
+
score INTEGER DEFAULT 0,
|
|
114
|
+
depth INTEGER DEFAULT 0,
|
|
115
|
+
path TEXT NOT NULL,
|
|
116
|
+
created_at TEXT DEFAULT (datetime('now')),
|
|
117
|
+
updated_at TEXT DEFAULT (datetime('now'))
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
CREATE TABLE IF NOT EXISTS votes (
|
|
121
|
+
id TEXT PRIMARY KEY,
|
|
122
|
+
agent_id TEXT NOT NULL,
|
|
123
|
+
target_type TEXT NOT NULL,
|
|
124
|
+
target_id TEXT NOT NULL,
|
|
125
|
+
value INTEGER NOT NULL,
|
|
126
|
+
created_at TEXT DEFAULT (datetime('now')),
|
|
127
|
+
UNIQUE(agent_id, target_type, target_id)
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
CREATE TABLE IF NOT EXISTS memberships (
|
|
131
|
+
id TEXT PRIMARY KEY,
|
|
132
|
+
agent_id TEXT NOT NULL,
|
|
133
|
+
hive_id TEXT NOT NULL,
|
|
134
|
+
role TEXT DEFAULT 'member',
|
|
135
|
+
joined_at TEXT DEFAULT (datetime('now')),
|
|
136
|
+
UNIQUE(agent_id, hive_id)
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
CREATE TABLE IF NOT EXISTS follows (
|
|
140
|
+
id TEXT PRIMARY KEY,
|
|
141
|
+
follower_id TEXT NOT NULL,
|
|
142
|
+
following_id TEXT NOT NULL,
|
|
143
|
+
created_at TEXT DEFAULT (datetime('now')),
|
|
144
|
+
UNIQUE(follower_id, following_id)
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
CREATE TABLE IF NOT EXISTS invite_codes (
|
|
148
|
+
id TEXT PRIMARY KEY,
|
|
149
|
+
code TEXT UNIQUE NOT NULL,
|
|
150
|
+
created_by TEXT,
|
|
151
|
+
used_by TEXT,
|
|
152
|
+
uses_left INTEGER DEFAULT 1,
|
|
153
|
+
expires_at TEXT,
|
|
154
|
+
created_at TEXT DEFAULT (datetime('now'))
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
CREATE TABLE IF NOT EXISTS uploads (
|
|
158
|
+
id TEXT PRIMARY KEY,
|
|
159
|
+
agent_id TEXT NOT NULL,
|
|
160
|
+
filename TEXT NOT NULL,
|
|
161
|
+
mime_type TEXT NOT NULL,
|
|
162
|
+
size INTEGER NOT NULL,
|
|
163
|
+
storage_key TEXT UNIQUE NOT NULL,
|
|
164
|
+
purpose TEXT NOT NULL,
|
|
165
|
+
created_at TEXT DEFAULT (datetime('now'))
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
CREATE TABLE IF NOT EXISTS federated_instances (
|
|
169
|
+
id TEXT PRIMARY KEY,
|
|
170
|
+
url TEXT UNIQUE NOT NULL,
|
|
171
|
+
name TEXT NOT NULL,
|
|
172
|
+
public_key TEXT,
|
|
173
|
+
status TEXT DEFAULT 'pending',
|
|
174
|
+
is_trusted INTEGER DEFAULT 0,
|
|
175
|
+
agent_count INTEGER DEFAULT 0,
|
|
176
|
+
post_count INTEGER DEFAULT 0,
|
|
177
|
+
last_sync TEXT,
|
|
178
|
+
last_error TEXT,
|
|
179
|
+
created_at TEXT DEFAULT (datetime('now')),
|
|
180
|
+
updated_at TEXT DEFAULT (datetime('now'))
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
CREATE INDEX IF NOT EXISTS idx_posts_hive ON posts(hive_id);
|
|
184
|
+
CREATE INDEX IF NOT EXISTS idx_posts_author ON posts(author_id);
|
|
185
|
+
CREATE INDEX IF NOT EXISTS idx_comments_post ON comments(post_id);
|
|
186
|
+
CREATE INDEX IF NOT EXISTS idx_votes_target ON votes(target_type, target_id);
|
|
187
|
+
CREATE INDEX IF NOT EXISTS idx_memberships_hive ON memberships(hive_id);
|
|
188
|
+
CREATE INDEX IF NOT EXISTS idx_follows_follower ON follows(follower_id);
|
|
189
|
+
CREATE INDEX IF NOT EXISTS idx_follows_following ON follows(following_id);
|
|
190
|
+
`;
|
|
191
|
+
|
|
192
|
+
// Helpers
|
|
193
|
+
function rowToAgent(row: Record<string, unknown>): Agent {
|
|
194
|
+
return {
|
|
195
|
+
...row,
|
|
196
|
+
is_verified: Boolean(row.is_verified),
|
|
197
|
+
is_admin: Boolean(row.is_admin),
|
|
198
|
+
email_verified: Boolean(row.email_verified),
|
|
199
|
+
account_type: (row.account_type as string) || 'agent',
|
|
200
|
+
metadata: row.metadata ? JSON.parse(row.metadata as string) : null,
|
|
201
|
+
verification_data: row.verification_data ? JSON.parse(row.verification_data as string) : null,
|
|
202
|
+
} as Agent;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function toPublicAgent(agent: Agent): AgentPublic {
|
|
206
|
+
return {
|
|
207
|
+
id: agent.id,
|
|
208
|
+
name: agent.name,
|
|
209
|
+
description: agent.description,
|
|
210
|
+
avatar_url: agent.avatar_url,
|
|
211
|
+
karma: agent.karma,
|
|
212
|
+
is_verified: agent.is_verified,
|
|
213
|
+
created_at: agent.created_at,
|
|
214
|
+
account_type: agent.account_type || 'agent',
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export class TursoProvider implements DatabaseProvider {
|
|
219
|
+
readonly type = 'turso' as const;
|
|
220
|
+
private client: Client;
|
|
221
|
+
|
|
222
|
+
agents: AgentRepository;
|
|
223
|
+
posts: PostRepository;
|
|
224
|
+
comments: CommentRepository;
|
|
225
|
+
hives: HiveRepository;
|
|
226
|
+
votes: VoteRepository;
|
|
227
|
+
follows: FollowRepository;
|
|
228
|
+
invites: InviteRepository;
|
|
229
|
+
uploads: UploadRepository;
|
|
230
|
+
instances: InstanceRepository;
|
|
231
|
+
search: SearchRepository;
|
|
232
|
+
|
|
233
|
+
// Sync repositories — stubs until sync layer is migrated to Provider pattern (NEW-11)
|
|
234
|
+
syncGroups: any = null;
|
|
235
|
+
syncPeers: any = null;
|
|
236
|
+
syncEvents: any = null;
|
|
237
|
+
syncPeerConfigs: any = null;
|
|
238
|
+
|
|
239
|
+
constructor(private config: TursoProviderConfig) {
|
|
240
|
+
this.client = createClient({
|
|
241
|
+
url: config.url,
|
|
242
|
+
authToken: config.authToken,
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
// Initialize repositories
|
|
246
|
+
this.agents = this.createAgentRepository();
|
|
247
|
+
this.posts = this.createPostRepository();
|
|
248
|
+
this.comments = this.createCommentRepository();
|
|
249
|
+
this.hives = this.createHiveRepository();
|
|
250
|
+
this.votes = this.createVoteRepository();
|
|
251
|
+
this.follows = this.createFollowRepository();
|
|
252
|
+
this.invites = this.createInviteRepository();
|
|
253
|
+
this.uploads = this.createUploadRepository();
|
|
254
|
+
this.instances = this.createInstanceRepository();
|
|
255
|
+
this.search = this.createSearchRepository();
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
private async execute(sql: string, args: unknown[] = []): Promise<ResultSet> {
|
|
259
|
+
return this.client.execute({ sql, args: args as InStatement['args'] });
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
private async executeMultiple(statements: string[]): Promise<void> {
|
|
263
|
+
for (const sql of statements) {
|
|
264
|
+
if (sql.trim()) {
|
|
265
|
+
await this.client.execute(sql);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
async initialize(): Promise<void> {
|
|
271
|
+
// Create tables (split by semicolon and execute each)
|
|
272
|
+
const statements = CREATE_TABLES.split(';').filter(s => s.trim());
|
|
273
|
+
await this.executeMultiple(statements);
|
|
274
|
+
await this.migrate();
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
async close(): Promise<void> {
|
|
278
|
+
this.client.close();
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
async transaction<T>(fn: () => Promise<T>): Promise<T> {
|
|
282
|
+
// Turso supports transactions via batch
|
|
283
|
+
// For simplicity, just execute the function
|
|
284
|
+
// Full transaction support would need client.batch()
|
|
285
|
+
return fn();
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
async migrate(): Promise<void> {
|
|
289
|
+
const version = await this.getSchemaVersion();
|
|
290
|
+
if (version === 0) {
|
|
291
|
+
await this.execute('INSERT INTO schema_version (version) VALUES (?)', [6]);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
async getSchemaVersion(): Promise<number> {
|
|
296
|
+
try {
|
|
297
|
+
const result = await this.execute('SELECT version FROM schema_version');
|
|
298
|
+
return (result.rows[0]?.version as number) ?? 0;
|
|
299
|
+
} catch {
|
|
300
|
+
return 0;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// ============================================================================
|
|
305
|
+
// Repository Implementations (Async versions)
|
|
306
|
+
// ============================================================================
|
|
307
|
+
|
|
308
|
+
private createAgentRepository(): AgentRepository {
|
|
309
|
+
const execute = this.execute.bind(this);
|
|
310
|
+
|
|
311
|
+
const findById = async (id: string): Promise<Agent | null> => {
|
|
312
|
+
const result = await execute('SELECT * FROM agents WHERE id = ?', [id]);
|
|
313
|
+
if (result.rows.length === 0) return null;
|
|
314
|
+
return rowToAgent(result.rows[0] as Record<string, unknown>);
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
return {
|
|
318
|
+
async create(input: CreateAgentInput) {
|
|
319
|
+
const id = nanoid();
|
|
320
|
+
const apiKey = nanoid(32);
|
|
321
|
+
const apiKeyHash = await bcrypt.hash(apiKey, SALT_ROUNDS);
|
|
322
|
+
|
|
323
|
+
await execute(`
|
|
324
|
+
INSERT INTO agents (id, name, api_key_hash, description, avatar_url, is_admin, metadata)
|
|
325
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
326
|
+
`, [id, input.name, apiKeyHash, input.description || null, input.avatar_url || null, input.is_admin ? 1 : 0, input.metadata ? JSON.stringify(input.metadata) : null]);
|
|
327
|
+
|
|
328
|
+
const agent = await findById(id);
|
|
329
|
+
return { agent: agent!, apiKey };
|
|
330
|
+
},
|
|
331
|
+
|
|
332
|
+
findById,
|
|
333
|
+
|
|
334
|
+
async findByName(name: string) {
|
|
335
|
+
const result = await execute('SELECT * FROM agents WHERE name = ?', [name]);
|
|
336
|
+
if (result.rows.length === 0) return null;
|
|
337
|
+
return rowToAgent(result.rows[0] as Record<string, unknown>);
|
|
338
|
+
},
|
|
339
|
+
|
|
340
|
+
async findByApiKey(apiKey: string) {
|
|
341
|
+
const result = await execute('SELECT * FROM agents WHERE api_key_hash IS NOT NULL');
|
|
342
|
+
for (const row of result.rows) {
|
|
343
|
+
if (await bcrypt.compare(apiKey, (row as Record<string, unknown>).api_key_hash as string)) {
|
|
344
|
+
return rowToAgent(row as Record<string, unknown>);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
return null;
|
|
348
|
+
},
|
|
349
|
+
|
|
350
|
+
async update(id: string, input: UpdateAgentInput) {
|
|
351
|
+
const updates: string[] = [];
|
|
352
|
+
const values: unknown[] = [];
|
|
353
|
+
|
|
354
|
+
if (input.description !== undefined) { updates.push('description = ?'); values.push(input.description); }
|
|
355
|
+
if (input.avatar_url !== undefined) { updates.push('avatar_url = ?'); values.push(input.avatar_url); }
|
|
356
|
+
if (input.metadata !== undefined) { updates.push('metadata = ?'); values.push(JSON.stringify(input.metadata)); }
|
|
357
|
+
if (input.verification_status !== undefined) { updates.push('verification_status = ?'); values.push(input.verification_status); }
|
|
358
|
+
if (input.verification_data !== undefined) { updates.push('verification_data = ?'); values.push(JSON.stringify(input.verification_data)); }
|
|
359
|
+
if (input.is_verified !== undefined) { updates.push('is_verified = ?'); values.push(input.is_verified ? 1 : 0); }
|
|
360
|
+
if (input.is_admin !== undefined) { updates.push('is_admin = ?'); values.push(input.is_admin ? 1 : 0); }
|
|
361
|
+
|
|
362
|
+
if (updates.length === 0) return findById(id);
|
|
363
|
+
|
|
364
|
+
updates.push("updated_at = datetime('now')");
|
|
365
|
+
values.push(id);
|
|
366
|
+
|
|
367
|
+
await execute(`UPDATE agents SET ${updates.join(', ')} WHERE id = ?`, values);
|
|
368
|
+
return findById(id);
|
|
369
|
+
},
|
|
370
|
+
|
|
371
|
+
async updateKarma(id: string, delta: number) {
|
|
372
|
+
await execute(`UPDATE agents SET karma = karma + ?, updated_at = datetime('now') WHERE id = ?`, [delta, id]);
|
|
373
|
+
},
|
|
374
|
+
|
|
375
|
+
async updateLastSeen(id: string) {
|
|
376
|
+
await execute(`UPDATE agents SET last_seen_at = datetime('now') WHERE id = ?`, [id]);
|
|
377
|
+
},
|
|
378
|
+
|
|
379
|
+
async list(options) {
|
|
380
|
+
let query = 'SELECT * FROM agents';
|
|
381
|
+
const conditions: string[] = [];
|
|
382
|
+
const values: unknown[] = [];
|
|
383
|
+
|
|
384
|
+
if (options.verified_only) conditions.push('is_verified = 1');
|
|
385
|
+
if (conditions.length > 0) query += ' WHERE ' + conditions.join(' AND ');
|
|
386
|
+
query += ' ORDER BY created_at DESC';
|
|
387
|
+
if (options.limit) { query += ' LIMIT ?'; values.push(options.limit); }
|
|
388
|
+
if (options.offset) { query += ' OFFSET ?'; values.push(options.offset); }
|
|
389
|
+
|
|
390
|
+
const result = await execute(query, values);
|
|
391
|
+
return result.rows.map(row => rowToAgent(row as Record<string, unknown>));
|
|
392
|
+
},
|
|
393
|
+
|
|
394
|
+
async count() {
|
|
395
|
+
const result = await execute('SELECT COUNT(*) as count FROM agents');
|
|
396
|
+
return (result.rows[0] as Record<string, number>).count;
|
|
397
|
+
},
|
|
398
|
+
|
|
399
|
+
async delete(id: string) {
|
|
400
|
+
const result = await execute('DELETE FROM agents WHERE id = ?', [id]);
|
|
401
|
+
return result.rowsAffected > 0;
|
|
402
|
+
},
|
|
403
|
+
|
|
404
|
+
toPublic: toPublicAgent,
|
|
405
|
+
|
|
406
|
+
async createHuman(input: CreateHumanInput) {
|
|
407
|
+
const id = nanoid();
|
|
408
|
+
const passwordHash = await bcrypt.hash(input.password, SALT_ROUNDS);
|
|
409
|
+
|
|
410
|
+
await execute(`
|
|
411
|
+
INSERT INTO agents (id, name, email, password_hash, description, avatar_url, account_type, is_verified, verification_status)
|
|
412
|
+
VALUES (?, ?, ?, ?, ?, ?, 'human', 0, 'pending')
|
|
413
|
+
`, [id, input.name, input.email.toLowerCase(), passwordHash, input.description || null, input.avatar_url || null]);
|
|
414
|
+
|
|
415
|
+
return (await findById(id))!;
|
|
416
|
+
},
|
|
417
|
+
|
|
418
|
+
async findByEmail(email: string) {
|
|
419
|
+
const result = await execute('SELECT * FROM agents WHERE email = ? AND account_type = ?', [email.toLowerCase(), 'human']);
|
|
420
|
+
if (result.rows.length === 0) return null;
|
|
421
|
+
return rowToAgent(result.rows[0] as Record<string, unknown>);
|
|
422
|
+
},
|
|
423
|
+
|
|
424
|
+
async verifyPassword(agent: Agent, password: string) {
|
|
425
|
+
if (!agent.password_hash) return false;
|
|
426
|
+
return bcrypt.compare(password, agent.password_hash);
|
|
427
|
+
},
|
|
428
|
+
|
|
429
|
+
async setPassword(id: string, password: string) {
|
|
430
|
+
const passwordHash = await bcrypt.hash(password, SALT_ROUNDS);
|
|
431
|
+
await execute(`UPDATE agents SET password_hash = ?, updated_at = datetime('now') WHERE id = ?`, [passwordHash, id]);
|
|
432
|
+
},
|
|
433
|
+
|
|
434
|
+
async verifyEmail(id: string) {
|
|
435
|
+
await execute(`UPDATE agents SET email_verified = 1, is_verified = 1, verification_status = 'verified', updated_at = datetime('now') WHERE id = ?`, [id]);
|
|
436
|
+
},
|
|
437
|
+
|
|
438
|
+
async isEmailTaken(email: string) {
|
|
439
|
+
const result = await execute('SELECT id FROM agents WHERE email = ?', [email.toLowerCase()]);
|
|
440
|
+
return result.rows.length > 0;
|
|
441
|
+
},
|
|
442
|
+
|
|
443
|
+
async isNameTaken(name: string) {
|
|
444
|
+
const result = await execute('SELECT id FROM agents WHERE name = ?', [name]);
|
|
445
|
+
return result.rows.length > 0;
|
|
446
|
+
},
|
|
447
|
+
|
|
448
|
+
async setResetToken(id: string, token: string, expiresAt: Date) {
|
|
449
|
+
await execute(`UPDATE agents SET password_reset_token = ?, password_reset_expires = ?, updated_at = datetime('now') WHERE id = ?`, [token, expiresAt.toISOString(), id]);
|
|
450
|
+
},
|
|
451
|
+
|
|
452
|
+
async findByResetToken(token: string) {
|
|
453
|
+
const result = await execute('SELECT * FROM agents WHERE password_reset_token = ?', [token]);
|
|
454
|
+
if (result.rows.length === 0) return null;
|
|
455
|
+
|
|
456
|
+
const agent = rowToAgent(result.rows[0] as Record<string, unknown>);
|
|
457
|
+
if (agent.password_reset_expires && new Date(agent.password_reset_expires) < new Date()) {
|
|
458
|
+
return null;
|
|
459
|
+
}
|
|
460
|
+
return agent;
|
|
461
|
+
},
|
|
462
|
+
|
|
463
|
+
async resetPassword(id: string, newPassword: string) {
|
|
464
|
+
const passwordHash = await bcrypt.hash(newPassword, SALT_ROUNDS);
|
|
465
|
+
await execute(`UPDATE agents SET password_hash = ?, password_reset_token = NULL, password_reset_expires = NULL, updated_at = datetime('now') WHERE id = ?`, [passwordHash, id]);
|
|
466
|
+
},
|
|
467
|
+
|
|
468
|
+
async clearResetToken(id: string) {
|
|
469
|
+
await execute(`UPDATE agents SET password_reset_token = NULL, password_reset_expires = NULL, updated_at = datetime('now') WHERE id = ?`, [id]);
|
|
470
|
+
},
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
private createPostRepository(): PostRepository {
|
|
475
|
+
const execute = this.execute.bind(this);
|
|
476
|
+
|
|
477
|
+
const findById = async (id: string): Promise<Post | null> => {
|
|
478
|
+
const result = await execute('SELECT * FROM posts WHERE id = ?', [id]);
|
|
479
|
+
if (result.rows.length === 0) return null;
|
|
480
|
+
return result.rows[0] as Post;
|
|
481
|
+
};
|
|
482
|
+
|
|
483
|
+
return {
|
|
484
|
+
async create(input: CreatePostInput) {
|
|
485
|
+
const id = nanoid();
|
|
486
|
+
await execute(`
|
|
487
|
+
INSERT INTO posts (id, hive_id, author_id, title, content, url)
|
|
488
|
+
VALUES (?, ?, ?, ?, ?, ?)
|
|
489
|
+
`, [id, input.hive_id, input.author_id, input.title, input.content || null, input.url || null]);
|
|
490
|
+
|
|
491
|
+
return (await findById(id))!;
|
|
492
|
+
},
|
|
493
|
+
|
|
494
|
+
findById,
|
|
495
|
+
|
|
496
|
+
async findWithAuthor(id: string, viewerId?: string) {
|
|
497
|
+
let query = `
|
|
498
|
+
SELECT p.*, a.name as author_name, a.avatar_url as author_avatar, a.karma as author_karma,
|
|
499
|
+
a.is_verified as author_verified, a.created_at as author_created_at, a.account_type as author_account_type,
|
|
500
|
+
h.name as hive_name
|
|
501
|
+
FROM posts p
|
|
502
|
+
JOIN agents a ON p.author_id = a.id
|
|
503
|
+
JOIN hives h ON p.hive_id = h.id
|
|
504
|
+
WHERE p.id = ?
|
|
505
|
+
`;
|
|
506
|
+
|
|
507
|
+
const result = await execute(query, [id]);
|
|
508
|
+
if (result.rows.length === 0) return null;
|
|
509
|
+
|
|
510
|
+
const row = result.rows[0] as Record<string, unknown>;
|
|
511
|
+
|
|
512
|
+
// Get user's vote if viewerId provided
|
|
513
|
+
let userVote: 1 | -1 | null = null;
|
|
514
|
+
if (viewerId) {
|
|
515
|
+
const voteResult = await execute(`SELECT value FROM votes WHERE agent_id = ? AND target_type = 'post' AND target_id = ?`, [viewerId, id]);
|
|
516
|
+
if (voteResult.rows.length > 0) {
|
|
517
|
+
userVote = (voteResult.rows[0] as Record<string, number>).value as 1 | -1;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
return {
|
|
522
|
+
id: row.id,
|
|
523
|
+
hive_id: row.hive_id,
|
|
524
|
+
author_id: row.author_id,
|
|
525
|
+
title: row.title,
|
|
526
|
+
content: row.content,
|
|
527
|
+
url: row.url,
|
|
528
|
+
score: row.score,
|
|
529
|
+
comment_count: row.comment_count,
|
|
530
|
+
is_pinned: Boolean(row.is_pinned),
|
|
531
|
+
created_at: row.created_at,
|
|
532
|
+
updated_at: row.updated_at,
|
|
533
|
+
hive_name: row.hive_name,
|
|
534
|
+
user_vote: userVote,
|
|
535
|
+
author: {
|
|
536
|
+
id: row.author_id,
|
|
537
|
+
name: row.author_name,
|
|
538
|
+
description: null,
|
|
539
|
+
avatar_url: row.author_avatar,
|
|
540
|
+
karma: row.author_karma,
|
|
541
|
+
is_verified: Boolean(row.author_verified),
|
|
542
|
+
created_at: row.author_created_at,
|
|
543
|
+
account_type: row.author_account_type || 'agent',
|
|
544
|
+
},
|
|
545
|
+
} as PostWithAuthor;
|
|
546
|
+
},
|
|
547
|
+
|
|
548
|
+
async update(id: string, input: UpdatePostInput) {
|
|
549
|
+
const updates: string[] = [];
|
|
550
|
+
const values: unknown[] = [];
|
|
551
|
+
|
|
552
|
+
if (input.title !== undefined) { updates.push('title = ?'); values.push(input.title); }
|
|
553
|
+
if (input.content !== undefined) { updates.push('content = ?'); values.push(input.content); }
|
|
554
|
+
if (input.url !== undefined) { updates.push('url = ?'); values.push(input.url); }
|
|
555
|
+
if (input.is_pinned !== undefined) { updates.push('is_pinned = ?'); values.push(input.is_pinned ? 1 : 0); }
|
|
556
|
+
|
|
557
|
+
if (updates.length === 0) return findById(id);
|
|
558
|
+
|
|
559
|
+
updates.push("updated_at = datetime('now')");
|
|
560
|
+
values.push(id);
|
|
561
|
+
|
|
562
|
+
await execute(`UPDATE posts SET ${updates.join(', ')} WHERE id = ?`, values);
|
|
563
|
+
return findById(id);
|
|
564
|
+
},
|
|
565
|
+
|
|
566
|
+
async delete(id: string) {
|
|
567
|
+
const result = await execute('DELETE FROM posts WHERE id = ?', [id]);
|
|
568
|
+
return result.rowsAffected > 0;
|
|
569
|
+
},
|
|
570
|
+
|
|
571
|
+
async updateScore(id: string, delta: number) {
|
|
572
|
+
await execute(`UPDATE posts SET score = score + ? WHERE id = ?`, [delta, id]);
|
|
573
|
+
},
|
|
574
|
+
|
|
575
|
+
async updateCommentCount(id: string, delta: number) {
|
|
576
|
+
await execute(`UPDATE posts SET comment_count = comment_count + ? WHERE id = ?`, [delta, id]);
|
|
577
|
+
},
|
|
578
|
+
|
|
579
|
+
async list(options: ListPostsOptions) {
|
|
580
|
+
const sort = options.sort || 'hot';
|
|
581
|
+
let orderBy: string;
|
|
582
|
+
|
|
583
|
+
switch (sort) {
|
|
584
|
+
case 'new': orderBy = 'p.created_at DESC'; break;
|
|
585
|
+
case 'top': orderBy = 'p.score DESC, p.created_at DESC'; break;
|
|
586
|
+
case 'hot':
|
|
587
|
+
default:
|
|
588
|
+
orderBy = "(p.score + 1) / (1 + (julianday('now') - julianday(p.created_at)) * 24) DESC";
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
let query = `
|
|
592
|
+
SELECT p.*, a.name as author_name, a.avatar_url as author_avatar, a.karma as author_karma,
|
|
593
|
+
a.is_verified as author_verified, a.created_at as author_created_at, a.account_type as author_account_type,
|
|
594
|
+
h.name as hive_name
|
|
595
|
+
FROM posts p
|
|
596
|
+
JOIN agents a ON p.author_id = a.id
|
|
597
|
+
JOIN hives h ON p.hive_id = h.id
|
|
598
|
+
`;
|
|
599
|
+
|
|
600
|
+
const conditions: string[] = [];
|
|
601
|
+
const values: unknown[] = [];
|
|
602
|
+
|
|
603
|
+
if (options.hive_id) { conditions.push('p.hive_id = ?'); values.push(options.hive_id); }
|
|
604
|
+
if (options.hive_name) { conditions.push('h.name = ?'); values.push(options.hive_name); }
|
|
605
|
+
if (options.author_id) { conditions.push('p.author_id = ?'); values.push(options.author_id); }
|
|
606
|
+
|
|
607
|
+
if (conditions.length > 0) query += ' WHERE ' + conditions.join(' AND ');
|
|
608
|
+
query += ` ORDER BY ${orderBy}`;
|
|
609
|
+
if (options.limit) { query += ' LIMIT ?'; values.push(options.limit); }
|
|
610
|
+
if (options.offset) { query += ' OFFSET ?'; values.push(options.offset); }
|
|
611
|
+
|
|
612
|
+
const result = await execute(query, values);
|
|
613
|
+
|
|
614
|
+
return result.rows.map(row => {
|
|
615
|
+
const r = row as Record<string, unknown>;
|
|
616
|
+
return {
|
|
617
|
+
id: r.id,
|
|
618
|
+
hive_id: r.hive_id,
|
|
619
|
+
author_id: r.author_id,
|
|
620
|
+
title: r.title,
|
|
621
|
+
content: r.content,
|
|
622
|
+
url: r.url,
|
|
623
|
+
score: r.score,
|
|
624
|
+
comment_count: r.comment_count,
|
|
625
|
+
is_pinned: Boolean(r.is_pinned),
|
|
626
|
+
created_at: r.created_at,
|
|
627
|
+
updated_at: r.updated_at,
|
|
628
|
+
hive_name: r.hive_name,
|
|
629
|
+
user_vote: null,
|
|
630
|
+
author: {
|
|
631
|
+
id: r.author_id,
|
|
632
|
+
name: r.author_name,
|
|
633
|
+
description: null,
|
|
634
|
+
avatar_url: r.author_avatar,
|
|
635
|
+
karma: r.author_karma,
|
|
636
|
+
is_verified: Boolean(r.author_verified),
|
|
637
|
+
created_at: r.author_created_at,
|
|
638
|
+
account_type: r.author_account_type || 'agent',
|
|
639
|
+
},
|
|
640
|
+
};
|
|
641
|
+
}) as PostWithAuthor[];
|
|
642
|
+
},
|
|
643
|
+
|
|
644
|
+
async count(hive_id?: string) {
|
|
645
|
+
const query = hive_id
|
|
646
|
+
? 'SELECT COUNT(*) as count FROM posts WHERE hive_id = ?'
|
|
647
|
+
: 'SELECT COUNT(*) as count FROM posts';
|
|
648
|
+
const result = await execute(query, hive_id ? [hive_id] : []);
|
|
649
|
+
return (result.rows[0] as Record<string, number>).count;
|
|
650
|
+
},
|
|
651
|
+
};
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
// Simplified implementations for remaining repositories
|
|
655
|
+
private createCommentRepository(): CommentRepository {
|
|
656
|
+
const execute = this.execute.bind(this);
|
|
657
|
+
const posts = this.posts;
|
|
658
|
+
|
|
659
|
+
const findById = async (id: string): Promise<Comment | null> => {
|
|
660
|
+
const result = await execute('SELECT * FROM comments WHERE id = ?', [id]);
|
|
661
|
+
if (result.rows.length === 0) return null;
|
|
662
|
+
return result.rows[0] as Comment;
|
|
663
|
+
};
|
|
664
|
+
|
|
665
|
+
return {
|
|
666
|
+
async create(input: CreateCommentInput) {
|
|
667
|
+
const id = nanoid();
|
|
668
|
+
let depth = 0;
|
|
669
|
+
let path = id;
|
|
670
|
+
|
|
671
|
+
if (input.parent_id) {
|
|
672
|
+
const parent = await findById(input.parent_id);
|
|
673
|
+
if (parent) {
|
|
674
|
+
depth = parent.depth + 1;
|
|
675
|
+
path = parent.path + '.' + id;
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
await execute(`
|
|
680
|
+
INSERT INTO comments (id, post_id, parent_id, author_id, content, depth, path)
|
|
681
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
682
|
+
`, [id, input.post_id, input.parent_id || null, input.author_id, input.content, depth, path]);
|
|
683
|
+
|
|
684
|
+
await posts.updateCommentCount(input.post_id, 1);
|
|
685
|
+
return (await findById(id))!;
|
|
686
|
+
},
|
|
687
|
+
|
|
688
|
+
findById,
|
|
689
|
+
|
|
690
|
+
async update(id: string, input: UpdateCommentInput) {
|
|
691
|
+
await execute(`UPDATE comments SET content = ?, updated_at = datetime('now') WHERE id = ?`, [input.content, id]);
|
|
692
|
+
return findById(id);
|
|
693
|
+
},
|
|
694
|
+
|
|
695
|
+
async delete(id: string) {
|
|
696
|
+
const comment = await findById(id);
|
|
697
|
+
if (!comment) return false;
|
|
698
|
+
|
|
699
|
+
const countResult = await execute(`SELECT COUNT(*) as count FROM comments WHERE path LIKE ?`, [comment.path + '.%']);
|
|
700
|
+
const totalDeleted = (countResult.rows[0] as Record<string, number>).count + 1;
|
|
701
|
+
|
|
702
|
+
await execute(`DELETE FROM comments WHERE path LIKE ? OR id = ?`, [comment.path + '.%', id]);
|
|
703
|
+
await posts.updateCommentCount(comment.post_id, -totalDeleted);
|
|
704
|
+
|
|
705
|
+
return true;
|
|
706
|
+
},
|
|
707
|
+
|
|
708
|
+
async updateScore(id: string, delta: number) {
|
|
709
|
+
await execute(`UPDATE comments SET score = score + ? WHERE id = ?`, [delta, id]);
|
|
710
|
+
},
|
|
711
|
+
|
|
712
|
+
async list(options: ListCommentsOptions) {
|
|
713
|
+
const sort = options.sort || 'top';
|
|
714
|
+
const orderBy = sort === 'new' ? 'c.created_at DESC' : 'c.score DESC, c.created_at DESC';
|
|
715
|
+
|
|
716
|
+
const query = `
|
|
717
|
+
SELECT c.*, a.name as author_name, a.avatar_url as author_avatar, a.karma as author_karma,
|
|
718
|
+
a.is_verified as author_verified, a.created_at as author_created_at, a.account_type as author_account_type
|
|
719
|
+
FROM comments c
|
|
720
|
+
JOIN agents a ON c.author_id = a.id
|
|
721
|
+
WHERE c.post_id = ?
|
|
722
|
+
ORDER BY ${orderBy}
|
|
723
|
+
${options.limit ? 'LIMIT ?' : ''} ${options.offset ? 'OFFSET ?' : ''}
|
|
724
|
+
`;
|
|
725
|
+
|
|
726
|
+
const values: unknown[] = [options.post_id];
|
|
727
|
+
if (options.limit) values.push(options.limit);
|
|
728
|
+
if (options.offset) values.push(options.offset);
|
|
729
|
+
|
|
730
|
+
const result = await execute(query, values);
|
|
731
|
+
|
|
732
|
+
return result.rows.map(row => {
|
|
733
|
+
const r = row as Record<string, unknown>;
|
|
734
|
+
return {
|
|
735
|
+
id: r.id,
|
|
736
|
+
post_id: r.post_id,
|
|
737
|
+
parent_id: r.parent_id,
|
|
738
|
+
author_id: r.author_id,
|
|
739
|
+
content: r.content,
|
|
740
|
+
score: r.score,
|
|
741
|
+
depth: r.depth,
|
|
742
|
+
path: r.path,
|
|
743
|
+
created_at: r.created_at,
|
|
744
|
+
updated_at: r.updated_at,
|
|
745
|
+
user_vote: null,
|
|
746
|
+
author: {
|
|
747
|
+
id: r.author_id,
|
|
748
|
+
name: r.author_name,
|
|
749
|
+
description: null,
|
|
750
|
+
avatar_url: r.author_avatar,
|
|
751
|
+
karma: r.author_karma,
|
|
752
|
+
is_verified: Boolean(r.author_verified),
|
|
753
|
+
created_at: r.author_created_at,
|
|
754
|
+
account_type: r.author_account_type || 'agent',
|
|
755
|
+
},
|
|
756
|
+
};
|
|
757
|
+
}) as CommentWithAuthor[];
|
|
758
|
+
},
|
|
759
|
+
|
|
760
|
+
async count(post_id: string) {
|
|
761
|
+
const result = await execute('SELECT COUNT(*) as count FROM comments WHERE post_id = ?', [post_id]);
|
|
762
|
+
return (result.rows[0] as Record<string, number>).count;
|
|
763
|
+
},
|
|
764
|
+
|
|
765
|
+
buildTree(comments: CommentWithAuthor[]): CommentWithAuthor[] {
|
|
766
|
+
const map = new Map<string, CommentWithAuthor>();
|
|
767
|
+
const roots: CommentWithAuthor[] = [];
|
|
768
|
+
|
|
769
|
+
for (const comment of comments) {
|
|
770
|
+
map.set(comment.id, { ...comment, replies: [] });
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
for (const comment of comments) {
|
|
774
|
+
const node = map.get(comment.id)!;
|
|
775
|
+
if (comment.parent_id && map.has(comment.parent_id)) {
|
|
776
|
+
map.get(comment.parent_id)!.replies!.push(node);
|
|
777
|
+
} else {
|
|
778
|
+
roots.push(node);
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
return roots;
|
|
783
|
+
},
|
|
784
|
+
};
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
private createHiveRepository(): HiveRepository {
|
|
788
|
+
const execute = this.execute.bind(this);
|
|
789
|
+
|
|
790
|
+
const findById = async (id: string): Promise<Hive | null> => {
|
|
791
|
+
const result = await execute('SELECT * FROM hives WHERE id = ?', [id]);
|
|
792
|
+
if (result.rows.length === 0) return null;
|
|
793
|
+
const row = result.rows[0] as Record<string, unknown>;
|
|
794
|
+
return { ...row, is_public: Boolean(row.is_public), settings: row.settings ? JSON.parse(row.settings as string) : null } as Hive;
|
|
795
|
+
};
|
|
796
|
+
|
|
797
|
+
return {
|
|
798
|
+
async create(input: CreateHiveInput) {
|
|
799
|
+
const id = nanoid();
|
|
800
|
+
await execute(`
|
|
801
|
+
INSERT INTO hives (id, name, description, owner_id, is_public, settings, member_count)
|
|
802
|
+
VALUES (?, ?, ?, ?, ?, ?, 1)
|
|
803
|
+
`, [id, input.name.toLowerCase(), input.description || null, input.owner_id, input.is_public !== false ? 1 : 0, input.settings ? JSON.stringify(input.settings) : null]);
|
|
804
|
+
|
|
805
|
+
await execute(`INSERT INTO memberships (id, agent_id, hive_id, role) VALUES (?, ?, ?, 'owner')`, [nanoid(), input.owner_id, id]);
|
|
806
|
+
|
|
807
|
+
return (await findById(id))!;
|
|
808
|
+
},
|
|
809
|
+
|
|
810
|
+
findById,
|
|
811
|
+
|
|
812
|
+
async findByName(name: string) {
|
|
813
|
+
const result = await execute('SELECT * FROM hives WHERE name = ?', [name.toLowerCase()]);
|
|
814
|
+
if (result.rows.length === 0) return null;
|
|
815
|
+
const row = result.rows[0] as Record<string, unknown>;
|
|
816
|
+
return { ...row, is_public: Boolean(row.is_public), settings: row.settings ? JSON.parse(row.settings as string) : null } as Hive;
|
|
817
|
+
},
|
|
818
|
+
|
|
819
|
+
async update(id: string, input: UpdateHiveInput) {
|
|
820
|
+
const updates: string[] = [];
|
|
821
|
+
const values: unknown[] = [];
|
|
822
|
+
|
|
823
|
+
if (input.description !== undefined) { updates.push('description = ?'); values.push(input.description); }
|
|
824
|
+
if (input.is_public !== undefined) { updates.push('is_public = ?'); values.push(input.is_public ? 1 : 0); }
|
|
825
|
+
if (input.settings !== undefined) { updates.push('settings = ?'); values.push(JSON.stringify(input.settings)); }
|
|
826
|
+
|
|
827
|
+
if (updates.length === 0) return findById(id);
|
|
828
|
+
|
|
829
|
+
updates.push("updated_at = datetime('now')");
|
|
830
|
+
values.push(id);
|
|
831
|
+
|
|
832
|
+
await execute(`UPDATE hives SET ${updates.join(', ')} WHERE id = ?`, values);
|
|
833
|
+
return findById(id);
|
|
834
|
+
},
|
|
835
|
+
|
|
836
|
+
async delete(id: string) {
|
|
837
|
+
const result = await execute('DELETE FROM hives WHERE id = ?', [id]);
|
|
838
|
+
return result.rowsAffected > 0;
|
|
839
|
+
},
|
|
840
|
+
|
|
841
|
+
async list(options) {
|
|
842
|
+
let query = 'SELECT * FROM hives';
|
|
843
|
+
const values: unknown[] = [];
|
|
844
|
+
|
|
845
|
+
if (options.member_id) {
|
|
846
|
+
query = 'SELECT h.* FROM hives h JOIN memberships m ON h.id = m.hive_id WHERE m.agent_id = ?';
|
|
847
|
+
values.push(options.member_id);
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
query += ' ORDER BY member_count DESC, created_at DESC';
|
|
851
|
+
if (options.limit) { query += ' LIMIT ?'; values.push(options.limit); }
|
|
852
|
+
if (options.offset) { query += ' OFFSET ?'; values.push(options.offset); }
|
|
853
|
+
|
|
854
|
+
const result = await execute(query, values);
|
|
855
|
+
return result.rows.map(row => {
|
|
856
|
+
const r = row as Record<string, unknown>;
|
|
857
|
+
return { ...r, is_public: Boolean(r.is_public), settings: r.settings ? JSON.parse(r.settings as string) : null };
|
|
858
|
+
}) as Hive[];
|
|
859
|
+
},
|
|
860
|
+
|
|
861
|
+
async count() {
|
|
862
|
+
const result = await execute('SELECT COUNT(*) as count FROM hives');
|
|
863
|
+
return (result.rows[0] as Record<string, number>).count;
|
|
864
|
+
},
|
|
865
|
+
|
|
866
|
+
async getMembers(hiveId: string) {
|
|
867
|
+
const result = await execute('SELECT agent_id, role, joined_at FROM memberships WHERE hive_id = ?', [hiveId]);
|
|
868
|
+
return result.rows as Array<{ agent_id: string; role: string; joined_at: string }>;
|
|
869
|
+
},
|
|
870
|
+
|
|
871
|
+
async isMember(hiveId: string, agentId: string) {
|
|
872
|
+
const result = await execute('SELECT id FROM memberships WHERE hive_id = ? AND agent_id = ?', [hiveId, agentId]);
|
|
873
|
+
return result.rows.length > 0;
|
|
874
|
+
},
|
|
875
|
+
|
|
876
|
+
async getMembership(hiveId: string, agentId: string) {
|
|
877
|
+
const result = await execute('SELECT role FROM memberships WHERE hive_id = ? AND agent_id = ?', [hiveId, agentId]);
|
|
878
|
+
if (result.rows.length === 0) return null;
|
|
879
|
+
return { role: (result.rows[0] as Record<string, string>).role };
|
|
880
|
+
},
|
|
881
|
+
|
|
882
|
+
async join(hiveId: string, agentId: string, role = 'member') {
|
|
883
|
+
try {
|
|
884
|
+
await execute(`INSERT INTO memberships (id, agent_id, hive_id, role) VALUES (?, ?, ?, ?)`, [nanoid(), agentId, hiveId, role]);
|
|
885
|
+
await execute(`UPDATE hives SET member_count = member_count + 1 WHERE id = ?`, [hiveId]);
|
|
886
|
+
return true;
|
|
887
|
+
} catch {
|
|
888
|
+
return false;
|
|
889
|
+
}
|
|
890
|
+
},
|
|
891
|
+
|
|
892
|
+
async leave(hiveId: string, agentId: string) {
|
|
893
|
+
const result = await execute('DELETE FROM memberships WHERE hive_id = ? AND agent_id = ?', [hiveId, agentId]);
|
|
894
|
+
if (result.rowsAffected > 0) {
|
|
895
|
+
await execute(`UPDATE hives SET member_count = member_count - 1 WHERE id = ?`, [hiveId]);
|
|
896
|
+
return true;
|
|
897
|
+
}
|
|
898
|
+
return false;
|
|
899
|
+
},
|
|
900
|
+
|
|
901
|
+
async updateRole(hiveId: string, agentId: string, role: string) {
|
|
902
|
+
const result = await execute('UPDATE memberships SET role = ? WHERE hive_id = ? AND agent_id = ?', [role, hiveId, agentId]);
|
|
903
|
+
return result.rowsAffected > 0;
|
|
904
|
+
},
|
|
905
|
+
};
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
private createVoteRepository(): VoteRepository {
|
|
909
|
+
const execute = this.execute.bind(this);
|
|
910
|
+
const posts = this.posts;
|
|
911
|
+
const comments = this.comments;
|
|
912
|
+
const agents = this.agents;
|
|
913
|
+
|
|
914
|
+
const get = async (agentId: string, targetType: 'post' | 'comment', targetId: string): Promise<Vote | null> => {
|
|
915
|
+
const result = await execute('SELECT * FROM votes WHERE agent_id = ? AND target_type = ? AND target_id = ?', [agentId, targetType, targetId]);
|
|
916
|
+
if (result.rows.length === 0) return null;
|
|
917
|
+
return result.rows[0] as Vote;
|
|
918
|
+
};
|
|
919
|
+
|
|
920
|
+
const remove = async (agentId: string, targetType: 'post' | 'comment', targetId: string): Promise<boolean> => {
|
|
921
|
+
const result = await execute('DELETE FROM votes WHERE agent_id = ? AND target_type = ? AND target_id = ?', [agentId, targetType, targetId]);
|
|
922
|
+
return result.rowsAffected > 0;
|
|
923
|
+
};
|
|
924
|
+
|
|
925
|
+
return {
|
|
926
|
+
async cast(input: CastVoteInput) {
|
|
927
|
+
const existing = await get(input.agent_id, input.target_type, input.target_id);
|
|
928
|
+
let scoreDelta = 0;
|
|
929
|
+
|
|
930
|
+
if (existing) {
|
|
931
|
+
if (existing.value === input.value) {
|
|
932
|
+
await remove(input.agent_id, input.target_type, input.target_id);
|
|
933
|
+
scoreDelta = -input.value;
|
|
934
|
+
|
|
935
|
+
if (input.target_type === 'post') {
|
|
936
|
+
await posts.updateScore(input.target_id, scoreDelta);
|
|
937
|
+
const post = await posts.findById(input.target_id);
|
|
938
|
+
if (post) await agents.updateKarma(post.author_id, scoreDelta);
|
|
939
|
+
} else {
|
|
940
|
+
await comments.updateScore(input.target_id, scoreDelta);
|
|
941
|
+
const comment = await comments.findById(input.target_id);
|
|
942
|
+
if (comment) await agents.updateKarma(comment.author_id, scoreDelta);
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
return { vote: null, scoreDelta };
|
|
946
|
+
} else {
|
|
947
|
+
await execute('UPDATE votes SET value = ? WHERE id = ?', [input.value, existing.id]);
|
|
948
|
+
scoreDelta = input.value * 2;
|
|
949
|
+
}
|
|
950
|
+
} else {
|
|
951
|
+
const id = nanoid();
|
|
952
|
+
await execute(`INSERT INTO votes (id, agent_id, target_type, target_id, value) VALUES (?, ?, ?, ?, ?)`, [id, input.agent_id, input.target_type, input.target_id, input.value]);
|
|
953
|
+
scoreDelta = input.value;
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
if (input.target_type === 'post') {
|
|
957
|
+
await posts.updateScore(input.target_id, scoreDelta);
|
|
958
|
+
const post = await posts.findById(input.target_id);
|
|
959
|
+
if (post) await agents.updateKarma(post.author_id, scoreDelta);
|
|
960
|
+
} else {
|
|
961
|
+
await comments.updateScore(input.target_id, scoreDelta);
|
|
962
|
+
const comment = await comments.findById(input.target_id);
|
|
963
|
+
if (comment) await agents.updateKarma(comment.author_id, scoreDelta);
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
const vote = await get(input.agent_id, input.target_type, input.target_id);
|
|
967
|
+
return { vote, scoreDelta };
|
|
968
|
+
},
|
|
969
|
+
|
|
970
|
+
get,
|
|
971
|
+
|
|
972
|
+
async getForTarget(targetType: 'post' | 'comment', targetId: string) {
|
|
973
|
+
const result = await execute('SELECT * FROM votes WHERE target_type = ? AND target_id = ?', [targetType, targetId]);
|
|
974
|
+
return result.rows as Vote[];
|
|
975
|
+
},
|
|
976
|
+
|
|
977
|
+
remove,
|
|
978
|
+
};
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
private createFollowRepository(): FollowRepository {
|
|
982
|
+
const execute = this.execute.bind(this);
|
|
983
|
+
|
|
984
|
+
return {
|
|
985
|
+
async follow(followerId: string, followingId: string) {
|
|
986
|
+
if (followerId === followingId) return null;
|
|
987
|
+
try {
|
|
988
|
+
const id = nanoid();
|
|
989
|
+
await execute(`INSERT INTO follows (id, follower_id, following_id) VALUES (?, ?, ?)`, [id, followerId, followingId]);
|
|
990
|
+
const result = await execute('SELECT * FROM follows WHERE id = ?', [id]);
|
|
991
|
+
return result.rows[0] as Follow || null;
|
|
992
|
+
} catch {
|
|
993
|
+
return null;
|
|
994
|
+
}
|
|
995
|
+
},
|
|
996
|
+
|
|
997
|
+
async unfollow(followerId: string, followingId: string) {
|
|
998
|
+
const result = await execute('DELETE FROM follows WHERE follower_id = ? AND following_id = ?', [followerId, followingId]);
|
|
999
|
+
return result.rowsAffected > 0;
|
|
1000
|
+
},
|
|
1001
|
+
|
|
1002
|
+
async isFollowing(followerId: string, followingId: string) {
|
|
1003
|
+
const result = await execute('SELECT id FROM follows WHERE follower_id = ? AND following_id = ?', [followerId, followingId]);
|
|
1004
|
+
return result.rows.length > 0;
|
|
1005
|
+
},
|
|
1006
|
+
|
|
1007
|
+
async getFollowers(agentId: string, limit = 50, offset = 0) {
|
|
1008
|
+
const result = await execute(`
|
|
1009
|
+
SELECT a.id, a.name, a.description, a.avatar_url, a.karma, a.is_verified, a.created_at, a.account_type
|
|
1010
|
+
FROM follows f
|
|
1011
|
+
JOIN agents a ON f.follower_id = a.id
|
|
1012
|
+
WHERE f.following_id = ?
|
|
1013
|
+
ORDER BY f.created_at DESC
|
|
1014
|
+
LIMIT ? OFFSET ?
|
|
1015
|
+
`, [agentId, limit, offset]);
|
|
1016
|
+
|
|
1017
|
+
return result.rows.map(row => {
|
|
1018
|
+
const r = row as Record<string, unknown>;
|
|
1019
|
+
return { ...r, is_verified: Boolean(r.is_verified) };
|
|
1020
|
+
}) as AgentPublic[];
|
|
1021
|
+
},
|
|
1022
|
+
|
|
1023
|
+
async getFollowing(agentId: string, limit = 50, offset = 0) {
|
|
1024
|
+
const result = await execute(`
|
|
1025
|
+
SELECT a.id, a.name, a.description, a.avatar_url, a.karma, a.is_verified, a.created_at, a.account_type
|
|
1026
|
+
FROM follows f
|
|
1027
|
+
JOIN agents a ON f.following_id = a.id
|
|
1028
|
+
WHERE f.follower_id = ?
|
|
1029
|
+
ORDER BY f.created_at DESC
|
|
1030
|
+
LIMIT ? OFFSET ?
|
|
1031
|
+
`, [agentId, limit, offset]);
|
|
1032
|
+
|
|
1033
|
+
return result.rows.map(row => {
|
|
1034
|
+
const r = row as Record<string, unknown>;
|
|
1035
|
+
return { ...r, is_verified: Boolean(r.is_verified) };
|
|
1036
|
+
}) as AgentPublic[];
|
|
1037
|
+
},
|
|
1038
|
+
|
|
1039
|
+
async getFollowerCount(agentId: string) {
|
|
1040
|
+
const result = await execute('SELECT COUNT(*) as count FROM follows WHERE following_id = ?', [agentId]);
|
|
1041
|
+
return (result.rows[0] as Record<string, number>).count;
|
|
1042
|
+
},
|
|
1043
|
+
|
|
1044
|
+
async getFollowingCount(agentId: string) {
|
|
1045
|
+
const result = await execute('SELECT COUNT(*) as count FROM follows WHERE follower_id = ?', [agentId]);
|
|
1046
|
+
return (result.rows[0] as Record<string, number>).count;
|
|
1047
|
+
},
|
|
1048
|
+
};
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
private createInviteRepository(): InviteRepository {
|
|
1052
|
+
const execute = this.execute.bind(this);
|
|
1053
|
+
|
|
1054
|
+
const findById = async (id: string): Promise<InviteCode | null> => {
|
|
1055
|
+
const result = await execute('SELECT * FROM invite_codes WHERE id = ?', [id]);
|
|
1056
|
+
if (result.rows.length === 0) return null;
|
|
1057
|
+
return result.rows[0] as InviteCode;
|
|
1058
|
+
};
|
|
1059
|
+
|
|
1060
|
+
const findByCode = async (code: string): Promise<InviteCode | null> => {
|
|
1061
|
+
const result = await execute('SELECT * FROM invite_codes WHERE code = ?', [code.toUpperCase()]);
|
|
1062
|
+
if (result.rows.length === 0) return null;
|
|
1063
|
+
return result.rows[0] as InviteCode;
|
|
1064
|
+
};
|
|
1065
|
+
|
|
1066
|
+
return {
|
|
1067
|
+
async create(input: CreateInviteInput) {
|
|
1068
|
+
const id = nanoid();
|
|
1069
|
+
const code = nanoid(12).toUpperCase();
|
|
1070
|
+
|
|
1071
|
+
await execute(`
|
|
1072
|
+
INSERT INTO invite_codes (id, code, created_by, uses_left, expires_at)
|
|
1073
|
+
VALUES (?, ?, ?, ?, ?)
|
|
1074
|
+
`, [id, code, input.created_by || null, input.uses_left ?? 1, input.expires_at?.toISOString() || null]);
|
|
1075
|
+
|
|
1076
|
+
return (await findById(id))!;
|
|
1077
|
+
},
|
|
1078
|
+
|
|
1079
|
+
findById,
|
|
1080
|
+
findByCode,
|
|
1081
|
+
|
|
1082
|
+
async validate(code: string) {
|
|
1083
|
+
const invite = await findByCode(code);
|
|
1084
|
+
if (!invite) return { valid: false, reason: 'Invalid invite code' };
|
|
1085
|
+
if (invite.uses_left <= 0) return { valid: false, reason: 'Invite code has been used' };
|
|
1086
|
+
if (invite.expires_at && new Date(invite.expires_at) < new Date()) {
|
|
1087
|
+
return { valid: false, reason: 'Invite code has expired' };
|
|
1088
|
+
}
|
|
1089
|
+
return { valid: true };
|
|
1090
|
+
},
|
|
1091
|
+
|
|
1092
|
+
async use(code: string, usedBy: string) {
|
|
1093
|
+
const validation = await this.validate(code);
|
|
1094
|
+
if (!validation.valid) return false;
|
|
1095
|
+
|
|
1096
|
+
const invite = await findByCode(code);
|
|
1097
|
+
if (!invite) return false;
|
|
1098
|
+
|
|
1099
|
+
await execute('UPDATE invite_codes SET uses_left = uses_left - 1, used_by = ? WHERE id = ?', [usedBy, invite.id]);
|
|
1100
|
+
return true;
|
|
1101
|
+
},
|
|
1102
|
+
|
|
1103
|
+
async list(options) {
|
|
1104
|
+
let query = 'SELECT * FROM invite_codes';
|
|
1105
|
+
const values: unknown[] = [];
|
|
1106
|
+
|
|
1107
|
+
if (options.valid_only) {
|
|
1108
|
+
query += " WHERE uses_left > 0 AND (expires_at IS NULL OR expires_at > datetime('now'))";
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
query += ' ORDER BY created_at DESC';
|
|
1112
|
+
if (options.limit) { query += ' LIMIT ?'; values.push(options.limit); }
|
|
1113
|
+
if (options.offset) { query += ' OFFSET ?'; values.push(options.offset); }
|
|
1114
|
+
|
|
1115
|
+
const result = await execute(query, values);
|
|
1116
|
+
return result.rows as InviteCode[];
|
|
1117
|
+
},
|
|
1118
|
+
|
|
1119
|
+
async delete(id: string) {
|
|
1120
|
+
const result = await execute('DELETE FROM invite_codes WHERE id = ?', [id]);
|
|
1121
|
+
return result.rowsAffected > 0;
|
|
1122
|
+
},
|
|
1123
|
+
};
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
private createUploadRepository(): UploadRepository {
|
|
1127
|
+
const execute = this.execute.bind(this);
|
|
1128
|
+
|
|
1129
|
+
const findById = async (id: string): Promise<Upload | null> => {
|
|
1130
|
+
const result = await execute('SELECT * FROM uploads WHERE id = ?', [id]);
|
|
1131
|
+
if (result.rows.length === 0) return null;
|
|
1132
|
+
return result.rows[0] as Upload;
|
|
1133
|
+
};
|
|
1134
|
+
|
|
1135
|
+
return {
|
|
1136
|
+
async create(input: CreateUploadInput) {
|
|
1137
|
+
await execute(`
|
|
1138
|
+
INSERT INTO uploads (id, agent_id, filename, mime_type, size, storage_key, purpose)
|
|
1139
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
1140
|
+
`, [input.id, input.agent_id, input.filename, input.mime_type, input.size, input.storage_key, input.purpose]);
|
|
1141
|
+
|
|
1142
|
+
return (await findById(input.id))!;
|
|
1143
|
+
},
|
|
1144
|
+
|
|
1145
|
+
findById,
|
|
1146
|
+
|
|
1147
|
+
async findByKey(key: string) {
|
|
1148
|
+
const result = await execute('SELECT * FROM uploads WHERE storage_key = ?', [key]);
|
|
1149
|
+
if (result.rows.length === 0) return null;
|
|
1150
|
+
return result.rows[0] as Upload;
|
|
1151
|
+
},
|
|
1152
|
+
|
|
1153
|
+
async listByAgent(agentId: string, options) {
|
|
1154
|
+
let query = 'SELECT * FROM uploads WHERE agent_id = ?';
|
|
1155
|
+
const values: unknown[] = [agentId];
|
|
1156
|
+
|
|
1157
|
+
if (options?.purpose) { query += ' AND purpose = ?'; values.push(options.purpose); }
|
|
1158
|
+
query += ' ORDER BY created_at DESC';
|
|
1159
|
+
if (options?.limit) { query += ' LIMIT ?'; values.push(options.limit); }
|
|
1160
|
+
|
|
1161
|
+
const result = await execute(query, values);
|
|
1162
|
+
return result.rows as Upload[];
|
|
1163
|
+
},
|
|
1164
|
+
|
|
1165
|
+
async delete(id: string) {
|
|
1166
|
+
const result = await execute('DELETE FROM uploads WHERE id = ?', [id]);
|
|
1167
|
+
return result.rowsAffected > 0;
|
|
1168
|
+
},
|
|
1169
|
+
|
|
1170
|
+
async deleteByKey(key: string) {
|
|
1171
|
+
const result = await execute('DELETE FROM uploads WHERE storage_key = ?', [key]);
|
|
1172
|
+
return result.rowsAffected > 0;
|
|
1173
|
+
},
|
|
1174
|
+
|
|
1175
|
+
async getStats(agentId: string) {
|
|
1176
|
+
const totalResult = await execute('SELECT COUNT(*) as count, SUM(size) as size FROM uploads WHERE agent_id = ?', [agentId]);
|
|
1177
|
+
const purposeResult = await execute('SELECT purpose, SUM(size) as size FROM uploads WHERE agent_id = ? GROUP BY purpose', [agentId]);
|
|
1178
|
+
|
|
1179
|
+
const totalRow = totalResult.rows[0] as Record<string, number>;
|
|
1180
|
+
const by_purpose: Record<string, number> = {};
|
|
1181
|
+
|
|
1182
|
+
for (const row of purposeResult.rows) {
|
|
1183
|
+
const r = row as Record<string, unknown>;
|
|
1184
|
+
by_purpose[r.purpose as string] = (r.size as number) || 0;
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
return { total_count: totalRow.count || 0, total_size: totalRow.size || 0, by_purpose };
|
|
1188
|
+
},
|
|
1189
|
+
};
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
private createInstanceRepository(): InstanceRepository {
|
|
1193
|
+
const execute = this.execute.bind(this);
|
|
1194
|
+
|
|
1195
|
+
const findById = async (id: string): Promise<FederatedInstance | null> => {
|
|
1196
|
+
const result = await execute('SELECT * FROM federated_instances WHERE id = ?', [id]);
|
|
1197
|
+
if (result.rows.length === 0) return null;
|
|
1198
|
+
const row = result.rows[0] as Record<string, unknown>;
|
|
1199
|
+
return { ...row, is_trusted: Boolean(row.is_trusted) } as FederatedInstance;
|
|
1200
|
+
};
|
|
1201
|
+
|
|
1202
|
+
return {
|
|
1203
|
+
async create(input: CreateInstanceInput) {
|
|
1204
|
+
const id = nanoid();
|
|
1205
|
+
const normalizedUrl = input.url.replace(/\/$/, '').toLowerCase();
|
|
1206
|
+
|
|
1207
|
+
await execute(`
|
|
1208
|
+
INSERT INTO federated_instances (id, url, name, public_key)
|
|
1209
|
+
VALUES (?, ?, ?, ?)
|
|
1210
|
+
`, [id, normalizedUrl, input.name, input.public_key || null]);
|
|
1211
|
+
|
|
1212
|
+
return (await findById(id))!;
|
|
1213
|
+
},
|
|
1214
|
+
|
|
1215
|
+
findById,
|
|
1216
|
+
|
|
1217
|
+
async findByUrl(url: string) {
|
|
1218
|
+
const normalizedUrl = url.replace(/\/$/, '').toLowerCase();
|
|
1219
|
+
const result = await execute('SELECT * FROM federated_instances WHERE url = ?', [normalizedUrl]);
|
|
1220
|
+
if (result.rows.length === 0) return null;
|
|
1221
|
+
const row = result.rows[0] as Record<string, unknown>;
|
|
1222
|
+
return { ...row, is_trusted: Boolean(row.is_trusted) } as FederatedInstance;
|
|
1223
|
+
},
|
|
1224
|
+
|
|
1225
|
+
async update(id: string, input: Partial<FederatedInstance>) {
|
|
1226
|
+
const updates: string[] = [];
|
|
1227
|
+
const values: unknown[] = [];
|
|
1228
|
+
|
|
1229
|
+
if (input.name !== undefined) { updates.push('name = ?'); values.push(input.name); }
|
|
1230
|
+
if (input.public_key !== undefined) { updates.push('public_key = ?'); values.push(input.public_key); }
|
|
1231
|
+
if (input.is_trusted !== undefined) { updates.push('is_trusted = ?'); values.push(input.is_trusted ? 1 : 0); }
|
|
1232
|
+
if (input.last_sync !== undefined) { updates.push('last_sync = ?'); values.push(input.last_sync); }
|
|
1233
|
+
|
|
1234
|
+
if (updates.length === 0) return findById(id);
|
|
1235
|
+
|
|
1236
|
+
updates.push("updated_at = datetime('now')");
|
|
1237
|
+
values.push(id);
|
|
1238
|
+
|
|
1239
|
+
await execute(`UPDATE federated_instances SET ${updates.join(', ')} WHERE id = ?`, values);
|
|
1240
|
+
return findById(id);
|
|
1241
|
+
},
|
|
1242
|
+
|
|
1243
|
+
async delete(id: string) {
|
|
1244
|
+
const result = await execute('DELETE FROM federated_instances WHERE id = ?', [id]);
|
|
1245
|
+
return result.rowsAffected > 0;
|
|
1246
|
+
},
|
|
1247
|
+
|
|
1248
|
+
async list(options) {
|
|
1249
|
+
let query = 'SELECT * FROM federated_instances';
|
|
1250
|
+
const conditions: string[] = [];
|
|
1251
|
+
const values: unknown[] = [];
|
|
1252
|
+
|
|
1253
|
+
if (options?.status) { conditions.push('status = ?'); values.push(options.status); }
|
|
1254
|
+
if (conditions.length > 0) query += ' WHERE ' + conditions.join(' AND ');
|
|
1255
|
+
|
|
1256
|
+
query += ' ORDER BY created_at DESC';
|
|
1257
|
+
if (options?.limit) { query += ' LIMIT ?'; values.push(options.limit); }
|
|
1258
|
+
if (options?.offset) { query += ' OFFSET ?'; values.push(options.offset); }
|
|
1259
|
+
|
|
1260
|
+
const result = await execute(query, values);
|
|
1261
|
+
return result.rows.map(row => {
|
|
1262
|
+
const r = row as Record<string, unknown>;
|
|
1263
|
+
return { ...r, is_trusted: Boolean(r.is_trusted) };
|
|
1264
|
+
}) as FederatedInstance[];
|
|
1265
|
+
},
|
|
1266
|
+
|
|
1267
|
+
async count() {
|
|
1268
|
+
const total = (await execute('SELECT COUNT(*) as count FROM federated_instances')).rows[0] as Record<string, number>;
|
|
1269
|
+
const active = (await execute("SELECT COUNT(*) as count FROM federated_instances WHERE status = 'active'")).rows[0] as Record<string, number>;
|
|
1270
|
+
const blocked = (await execute("SELECT COUNT(*) as count FROM federated_instances WHERE status = 'blocked'")).rows[0] as Record<string, number>;
|
|
1271
|
+
return { total: total.count, active: active.count, blocked: blocked.count };
|
|
1272
|
+
},
|
|
1273
|
+
};
|
|
1274
|
+
}
|
|
1275
|
+
|
|
1276
|
+
private createSearchRepository(): SearchRepository {
|
|
1277
|
+
const execute = this.execute.bind(this);
|
|
1278
|
+
|
|
1279
|
+
return {
|
|
1280
|
+
async search(options: SearchOptions) {
|
|
1281
|
+
// Turso supports FTS5 like SQLite
|
|
1282
|
+
// For now, use LIKE-based search as fallback
|
|
1283
|
+
const searchTerm = `%${options.query}%`;
|
|
1284
|
+
const limit = options.limit || 20;
|
|
1285
|
+
const results: SearchResults = {
|
|
1286
|
+
posts: [],
|
|
1287
|
+
comments: [],
|
|
1288
|
+
agents: [],
|
|
1289
|
+
hives: [],
|
|
1290
|
+
total: { posts: 0, comments: 0, agents: 0, hives: 0 },
|
|
1291
|
+
};
|
|
1292
|
+
|
|
1293
|
+
// Search posts
|
|
1294
|
+
const postsResult = await execute(`
|
|
1295
|
+
SELECT p.*, a.name as author_name, a.avatar_url as author_avatar, a.karma as author_karma,
|
|
1296
|
+
a.is_verified as author_verified, a.created_at as author_created_at, a.account_type as author_account_type,
|
|
1297
|
+
h.name as hive_name
|
|
1298
|
+
FROM posts p
|
|
1299
|
+
JOIN agents a ON p.author_id = a.id
|
|
1300
|
+
JOIN hives h ON p.hive_id = h.id
|
|
1301
|
+
WHERE p.title LIKE ? OR p.content LIKE ?
|
|
1302
|
+
ORDER BY p.score DESC
|
|
1303
|
+
LIMIT ?
|
|
1304
|
+
`, [searchTerm, searchTerm, limit]);
|
|
1305
|
+
|
|
1306
|
+
results.posts = postsResult.rows.map(row => {
|
|
1307
|
+
const r = row as Record<string, unknown>;
|
|
1308
|
+
return {
|
|
1309
|
+
id: r.id,
|
|
1310
|
+
hive_id: r.hive_id,
|
|
1311
|
+
author_id: r.author_id,
|
|
1312
|
+
title: r.title,
|
|
1313
|
+
content: r.content,
|
|
1314
|
+
url: r.url,
|
|
1315
|
+
score: r.score,
|
|
1316
|
+
comment_count: r.comment_count,
|
|
1317
|
+
is_pinned: Boolean(r.is_pinned),
|
|
1318
|
+
created_at: r.created_at,
|
|
1319
|
+
updated_at: r.updated_at,
|
|
1320
|
+
hive_name: r.hive_name,
|
|
1321
|
+
author: {
|
|
1322
|
+
id: r.author_id,
|
|
1323
|
+
name: r.author_name,
|
|
1324
|
+
description: null,
|
|
1325
|
+
avatar_url: r.author_avatar,
|
|
1326
|
+
karma: r.author_karma,
|
|
1327
|
+
is_verified: Boolean(r.author_verified),
|
|
1328
|
+
created_at: r.author_created_at,
|
|
1329
|
+
account_type: r.author_account_type || 'agent',
|
|
1330
|
+
},
|
|
1331
|
+
};
|
|
1332
|
+
}) as PostWithAuthor[];
|
|
1333
|
+
|
|
1334
|
+
// Count totals
|
|
1335
|
+
results.total = await this.countResults(options.query);
|
|
1336
|
+
|
|
1337
|
+
return results;
|
|
1338
|
+
},
|
|
1339
|
+
|
|
1340
|
+
async countResults(query: string) {
|
|
1341
|
+
const searchTerm = `%${query}%`;
|
|
1342
|
+
const posts = (await execute('SELECT COUNT(*) as count FROM posts WHERE title LIKE ? OR content LIKE ?', [searchTerm, searchTerm])).rows[0] as Record<string, number>;
|
|
1343
|
+
const comments = (await execute('SELECT COUNT(*) as count FROM comments WHERE content LIKE ?', [searchTerm])).rows[0] as Record<string, number>;
|
|
1344
|
+
const agents = (await execute('SELECT COUNT(*) as count FROM agents WHERE name LIKE ? OR description LIKE ?', [searchTerm, searchTerm])).rows[0] as Record<string, number>;
|
|
1345
|
+
const hives = (await execute('SELECT COUNT(*) as count FROM hives WHERE name LIKE ? OR description LIKE ?', [searchTerm, searchTerm])).rows[0] as Record<string, number>;
|
|
1346
|
+
|
|
1347
|
+
return {
|
|
1348
|
+
posts: posts.count,
|
|
1349
|
+
comments: comments.count,
|
|
1350
|
+
agents: agents.count,
|
|
1351
|
+
hives: hives.count,
|
|
1352
|
+
};
|
|
1353
|
+
},
|
|
1354
|
+
};
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1358
|
+
export function createTursoProvider(config: TursoProviderConfig): TursoProvider {
|
|
1359
|
+
return new TursoProvider(config);
|
|
1360
|
+
}
|