@anyswarm/core 0.5.0 → 0.5.2
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/AGENTS.md +1 -1
- package/README.md +21 -13
- package/deploy/worker/Dockerfile +12 -4
- package/dist/deploy/worker/Dockerfile +12 -4
- package/dist/examples/README.md +35 -12
- package/dist/examples/authoring/README.md +24 -0
- package/dist/examples/authoring/business.d.ts +2 -0
- package/dist/examples/authoring/business.js +4 -0
- package/dist/examples/authoring/config.d.ts +5 -0
- package/dist/examples/authoring/config.js +2 -0
- package/dist/examples/authoring/eject.json +5 -0
- package/dist/examples/authoring/harness.d.ts +4 -0
- package/dist/examples/authoring/harness.js +19 -0
- package/dist/examples/autoresearch/README.md +40 -0
- package/dist/examples/autoresearch/REQUIREMENTS.zh.md +11 -0
- package/dist/examples/autoresearch/config.d.ts +51 -0
- package/dist/examples/autoresearch/config.js +57 -0
- package/dist/examples/autoresearch/demo.d.ts +11 -0
- package/dist/examples/autoresearch/demo.js +52 -0
- package/dist/examples/autoresearch/eject.json +17 -0
- package/dist/examples/autoresearch/frontiercs2-config.d.ts +2 -0
- package/dist/examples/autoresearch/frontiercs2-config.js +3 -0
- package/dist/examples/autoresearch/frontiercs2.d.ts +87 -0
- package/dist/examples/autoresearch/frontiercs2.js +211 -0
- package/dist/examples/autoresearch/prepare-demo.d.ts +1 -0
- package/dist/examples/autoresearch/prepare-demo.js +15 -0
- package/dist/examples/autoresearch/prepare.d.ts +95 -0
- package/dist/examples/autoresearch/prepare.js +257 -0
- package/dist/examples/autoresearch/process.d.ts +13 -0
- package/dist/examples/autoresearch/process.js +48 -0
- package/dist/examples/autoresearch/project.d.ts +21 -0
- package/dist/examples/autoresearch/project.js +392 -0
- package/dist/examples/autoresearch/research-service.d.ts +106 -0
- package/dist/examples/autoresearch/research-service.js +255 -0
- package/dist/examples/code/README.md +33 -0
- package/dist/examples/code/REQUIREMENTS.zh.md +11 -0
- package/dist/examples/code/candidate.d.ts +19 -0
- package/dist/examples/code/candidate.js +80 -0
- package/dist/examples/code/config.d.ts +32 -0
- package/dist/examples/code/config.js +18 -0
- package/dist/examples/code/eject.json +5 -0
- package/dist/examples/code/project.d.ts +3 -0
- package/dist/examples/code/project.js +605 -0
- package/dist/examples/code/prompts.d.ts +5 -0
- package/dist/examples/code/prompts.js +12 -0
- package/dist/examples/code/verification.d.ts +19 -0
- package/dist/examples/code/verification.js +268 -0
- package/dist/examples/code/worktree.d.ts +17 -0
- package/dist/examples/code/worktree.js +233 -0
- package/dist/examples/harness-session/README.md +3 -6
- package/dist/examples/lead-worker/harness/dynamic-scheduler.d.ts +2 -1
- package/dist/examples/lead-worker/harness/dynamic-scheduler.js +5 -2
- package/dist/examples/lead-worker/harness/index.d.ts +60 -0
- package/dist/examples/lead-worker/harness/index.js +77 -6
- package/dist/examples/lead-worker/project.js +2 -2
- package/dist/examples/lead-worker/services/board.d.ts +5 -0
- package/dist/examples/lead-worker/services/board.js +19 -1
- package/dist/examples/messages/README.md +5 -5
- package/dist/examples/messages/handoff.d.ts +2 -0
- package/dist/examples/messages/handoff.js +5 -1
- package/dist/examples/messages/project.js +52 -2
- package/dist/examples/notes/README.md +13 -18
- package/dist/examples/notes/project.js +67 -6
- package/dist/examples/peermesh/harness/router.js +3 -1
- package/dist/examples/peermesh/harness/team.d.ts +8 -0
- package/dist/examples/peermesh/harness/team.js +13 -0
- package/dist/examples/peermesh/project.js +22 -4
- package/dist/examples/services/agent-control/README.md +3 -3
- package/dist/examples/services/mathlib-search/Dockerfile +4 -2
- package/dist/examples/services/mathlib-search/README.md +1 -1
- package/dist/examples/services/mcp-managed/README.md +2 -2
- package/dist/examples/services/persistent-board/README.md +16 -3
- package/dist/examples/services/persistent-board/business.d.ts +7 -0
- package/dist/examples/services/persistent-board/business.js +7 -0
- package/dist/examples/services/persistent-board/index.js +10 -0
- package/dist/examples/services/persistent-board/live.d.ts +3 -0
- package/dist/examples/services/persistent-board/live.js +58 -0
- package/dist/examples/subagents/README.md +5 -5
- package/dist/examples/subagents/business.js +3 -1
- package/dist/examples/subagents/config.js +3 -3
- package/dist/examples/subagents/harness/controller.d.ts +15 -0
- package/dist/examples/subagents/harness/controller.js +181 -32
- package/dist/examples/subagents/project.d.ts +2 -0
- package/dist/examples/subagents/project.js +43 -34
- package/dist/examples/subagents/prompts/prompts.d.ts +1 -0
- package/dist/examples/subagents/prompts/prompts.js +3 -0
- package/dist/examples/subagents/services/collaboration-service.d.ts +3 -2
- package/dist/examples/subagents/services/collaboration-service.js +14 -2
- package/dist/examples/substrate/README.md +2 -2
- package/dist/examples/substrate/harness/index.d.ts +1 -1
- package/dist/examples/substrate/harness/index.js +77 -12
- package/dist/examples/substrate/project.js +4 -1
- package/dist/examples/super/README.md +52 -0
- package/dist/examples/super/actions.d.ts +95 -0
- package/dist/examples/super/actions.js +230 -0
- package/dist/examples/super/artifact.d.ts +4 -0
- package/dist/examples/super/artifact.js +51 -0
- package/dist/examples/super/config.d.ts +80 -0
- package/dist/examples/super/config.js +83 -0
- package/dist/examples/super/coordinator.d.ts +33 -0
- package/dist/examples/super/coordinator.js +151 -0
- package/dist/examples/super/daemon.d.ts +11 -0
- package/dist/examples/super/daemon.js +109 -0
- package/dist/examples/super/decisions.d.ts +8 -0
- package/dist/examples/super/decisions.js +52 -0
- package/dist/examples/super/eject.json +5 -0
- package/dist/examples/super/execution.d.ts +11 -0
- package/dist/examples/super/execution.js +136 -0
- package/dist/examples/super/github.d.ts +62 -0
- package/dist/examples/super/github.js +269 -0
- package/dist/examples/super/inbox.d.ts +162 -0
- package/dist/examples/super/inbox.js +284 -0
- package/dist/examples/super/location.d.ts +5 -0
- package/dist/examples/super/location.js +64 -0
- package/dist/examples/super/operator.d.ts +1 -0
- package/dist/examples/super/operator.js +31 -0
- package/dist/examples/super/outbox.d.ts +5 -0
- package/dist/examples/super/outbox.js +103 -0
- package/dist/examples/super/project.d.ts +4 -0
- package/dist/examples/super/project.js +251 -0
- package/dist/examples/super/prompts.d.ts +3 -0
- package/dist/examples/super/prompts.js +25 -0
- package/dist/examples/taskpool/deploy/service-hosts/Dockerfile +4 -2
- package/dist/examples/taskpool/harness/controller.d.ts +35 -6
- package/dist/examples/taskpool/harness/controller.js +73 -7
- package/dist/examples/taskpool/project.js +18 -2
- package/dist/scripts/anyswarm-arguments.d.ts +18 -6
- package/dist/scripts/anyswarm-arguments.js +88 -52
- package/dist/scripts/anyswarm-author.d.ts +5 -0
- package/dist/scripts/anyswarm-author.js +24 -0
- package/dist/scripts/anyswarm-eject.d.ts +11 -0
- package/dist/scripts/anyswarm-eject.js +164 -0
- package/dist/scripts/anyswarm-harnesses.d.ts +1 -0
- package/dist/scripts/anyswarm-harnesses.js +10 -0
- package/dist/scripts/anyswarm-installation.d.ts +7 -40
- package/dist/scripts/anyswarm-installation.js +17 -285
- package/dist/scripts/anyswarm-launch.d.ts +7 -0
- package/dist/scripts/anyswarm-launch.js +37 -0
- package/dist/scripts/anyswarm-progress.d.ts +6 -0
- package/dist/scripts/anyswarm-progress.js +102 -0
- package/dist/scripts/anyswarm-project.d.ts +3 -1
- package/dist/scripts/anyswarm-project.js +49 -35
- package/dist/scripts/anyswarm-source-runner.d.ts +1 -0
- package/dist/scripts/anyswarm-source-runner.js +200 -0
- package/dist/scripts/anyswarm.js +28 -3
- package/dist/scripts/build-provenance.json +1 -0
- package/dist/scripts/build.js +7 -1
- package/dist/scripts/generate-architecture-api.js +2 -0
- package/dist/scripts/generate-architecture-prompts.js +24 -2
- package/dist/scripts/local-environment.d.ts +13 -2
- package/dist/scripts/local-environment.js +111 -28
- package/dist/scripts/local-setup-smoke.js +3 -2
- package/dist/scripts/local-setup-worker.d.ts +1 -1
- package/dist/scripts/local-setup-worker.js +15 -6
- package/dist/scripts/local-setup.d.ts +5 -2
- package/dist/scripts/local-setup.js +167 -79
- package/dist/scripts/opensandbox-agent-worker.js +2 -2
- package/dist/scripts/pack-release.d.ts +1 -0
- package/dist/scripts/pack-release.js +66 -0
- package/dist/scripts/pi-session-bridge.js +11 -3
- package/dist/scripts/run-harness.js +3 -1
- package/dist/scripts/setup-bootstrap.js +43 -6
- package/dist/src/core/allocation-ledger.js +4 -3
- package/dist/src/core/host-identity.d.ts +2 -0
- package/dist/src/core/host-identity.js +11 -0
- package/dist/src/core/index.d.ts +4 -2
- package/dist/src/core/index.js +12 -4
- package/dist/src/core/mcp-service.js +2 -2
- package/dist/src/core/runtime-management.d.ts +6 -0
- package/dist/src/core/runtime-management.js +24 -0
- package/dist/src/core/sandbox/executor-driver.d.ts +4 -2
- package/dist/src/core/sandbox/executor-driver.js +12 -14
- package/dist/src/core/sandbox/local-executor.d.ts +13 -1
- package/dist/src/core/sandbox/local-executor.js +69 -19
- package/dist/src/core/sandbox/local-worker.js +32 -21
- package/dist/src/core/sandbox/opensandbox-backend.d.ts +2 -0
- package/dist/src/core/sandbox/opensandbox-backend.js +36 -11
- package/dist/src/core/sandbox/sandbox-connection.d.ts +2 -0
- package/dist/src/core/sandbox/sandbox-connection.js +14 -6
- package/dist/src/core/service-live-state.d.ts +14 -0
- package/dist/src/core/service-live-state.js +161 -0
- package/dist/src/core/service-observation-types.d.ts +21 -1
- package/dist/src/core/service-process.d.ts +1 -1
- package/dist/src/core/service-process.js +45 -4
- package/dist/src/core/service-types.d.ts +5 -1
- package/dist/src/core/services.d.ts +1 -1
- package/dist/src/core/services.js +8 -3
- package/dist/src/core/types.d.ts +3 -0
- package/dist/src/core/worker-image.js +3 -3
- package/dist/src/harness/harness-session-types.d.ts +10 -0
- package/dist/src/harness/harness-session.js +42 -5
- package/dist/src/harness/project-harness.d.ts +14 -1
- package/dist/src/harness/project-harness.js +38 -12
- package/dist/src/harness/project-input.js +81 -15
- package/dist/src/harness/project-rpc-client.d.ts +1 -0
- package/dist/src/harness/project-rpc-client.js +5 -0
- package/dist/src/harness/project-rpc.d.ts +8 -2
- package/dist/src/harness/project-rpc.js +31 -7
- package/dist/src/harness/project-runtime.js +6 -2
- package/dist/src/harness/typescript-loader.d.ts +2 -0
- package/dist/src/harness/typescript-loader.js +41 -0
- package/dist/src/trace-viewer/public/app.js +6 -5
- package/dist/src/trace-viewer/reader.mjs +42 -2
- package/docs/INDEX.md +5 -2
- package/docs/architecture/00-overview.md +1 -1
- package/docs/architecture/01-agent-core.md +1 -1
- package/docs/architecture/04-services.md +1 -1
- package/docs/architecture/06-observability-experiments.md +1 -1
- package/docs/architecture/07-run-configuration.md +38 -18
- package/docs/architecture/08-prompts.md +22 -0
- package/docs/architecture/10-service-api-reference.md +53 -18
- package/docs/architecture/11-storage-reference.md +18 -1
- package/docs/architecture/12-code-coverage.md +152 -89
- package/docs/architecture/15-core-runtime.md +8 -0
- package/docs/architecture/16-pi-opensandbox-backend.md +5 -5
- package/docs/architecture/17-harness-reporting.md +1 -1
- package/docs/architecture/19-substrate-harness.md +28 -1
- package/docs/architecture/20-lead-worker-harness.md +34 -1
- package/docs/architecture/22-website.md +5 -6
- package/docs/architecture/23-project-harness.md +152 -8
- package/docs/architecture/24-runtime-recovery.md +10 -3
- package/docs/architecture/26-code.md +54 -0
- package/docs/architecture/27-personal.md +58 -0
- package/docs/architecture/28-autoresearch.md +43 -0
- package/docs/architecture/INDEX.md +3 -0
- package/docs/architecture/prompts/08-lead-worker-harness.md +4 -2
- package/docs/architecture/prompts/08-subagents-harness.md +21 -0
- package/docs/architecture/prompts/21-personal.md +44 -0
- package/docs/architecture/prompts/22-autoresearch.md +63 -0
- package/docs/architecture/prompts/26-code.md +55 -0
- package/docs/architecture/prompts/source-manifest.json +152 -33
- package/docs/architecture/source-map.json +473 -25
- package/docs/designs/core-harness/01-core.md +2 -2
- package/docs/designs/core-harness/06-project-harness.md +13 -2
- package/docs/designs/core-harness/README.md +7 -2
- package/docs/en/agents.md +1 -1
- package/docs/en/build-your-harness.md +3 -5
- package/docs/en/changelog.md +20 -4
- package/docs/en/first-harness.md +9 -12
- package/docs/en/harnesses/lead-worker.md +1 -1
- package/docs/en/harnesses/peermesh.md +2 -2
- package/docs/en/harnesses/subagents.md +2 -2
- package/docs/en/harnesses/substrate.md +4 -4
- package/docs/en/harnesses/taskpool.md +2 -2
- package/docs/en/latest.md +14 -121
- package/docs/en/overview.md +1 -1
- package/docs/en/quickstart.md +42 -39
- package/docs/en/reference/api.md +14 -4
- package/docs/en/reference/cli.md +53 -47
- package/docs/en/runtime.md +2 -2
- package/docs/en/sandbox.md +3 -3
- package/docs/en/services.md +4 -0
- package/docs/operations/trace-viewer.md +1 -1
- package/docs/workflows/development.md +28 -21
- package/docs/workflows/release-and-docs-versioning.md +77 -0
- package/docs/workflows/release-cli-acceptance.md +85 -0
- package/docs/zh/agents.md +1 -1
- package/docs/zh/build-your-harness.md +3 -5
- package/docs/zh/changelog.md +20 -4
- package/docs/zh/first-harness.md +9 -12
- package/docs/zh/harnesses/lead-worker.md +1 -1
- package/docs/zh/harnesses/peermesh.md +2 -2
- package/docs/zh/harnesses/subagents.md +2 -2
- package/docs/zh/harnesses/substrate.md +4 -4
- package/docs/zh/harnesses/taskpool.md +2 -2
- package/docs/zh/latest.md +15 -122
- package/docs/zh/overview.md +1 -1
- package/docs/zh/quickstart.md +42 -39
- package/docs/zh/reference/api.md +14 -4
- package/docs/zh/reference/cli.md +24 -40
- package/docs/zh/runtime.md +2 -2
- package/docs/zh/sandbox.md +3 -3
- package/docs/zh/services.md +4 -0
- package/examples/README.md +35 -12
- package/examples/authoring/README.md +24 -0
- package/examples/authoring/business.ts +4 -0
- package/examples/authoring/config.ts +2 -0
- package/examples/authoring/eject.json +5 -0
- package/examples/authoring/harness.ts +21 -0
- package/examples/autoresearch/README.md +40 -0
- package/examples/autoresearch/REQUIREMENTS.zh.md +11 -0
- package/examples/autoresearch/config.ts +90 -0
- package/examples/autoresearch/demo.ts +55 -0
- package/examples/autoresearch/eject.json +17 -0
- package/examples/autoresearch/frontiercs2-config.ts +4 -0
- package/examples/autoresearch/frontiercs2.ts +237 -0
- package/examples/autoresearch/prepare-demo.ts +15 -0
- package/examples/autoresearch/prepare.ts +267 -0
- package/examples/autoresearch/process.ts +50 -0
- package/examples/autoresearch/project.ts +380 -0
- package/examples/autoresearch/research-service.ts +302 -0
- package/examples/code/README.md +33 -0
- package/examples/code/REQUIREMENTS.zh.md +11 -0
- package/examples/code/candidate.ts +89 -0
- package/examples/code/config.ts +19 -0
- package/examples/code/eject.json +5 -0
- package/examples/code/project.ts +581 -0
- package/examples/code/prompts.ts +16 -0
- package/examples/code/verification.ts +239 -0
- package/examples/code/worktree.ts +188 -0
- package/examples/harness-session/README.md +3 -6
- package/examples/lead-worker/harness/dynamic-scheduler.ts +6 -3
- package/examples/lead-worker/harness/index.ts +61 -6
- package/examples/lead-worker/project.ts +2 -2
- package/examples/lead-worker/services/board.ts +14 -1
- package/examples/messages/README.md +5 -5
- package/examples/messages/handoff.ts +6 -2
- package/examples/messages/project.ts +47 -2
- package/examples/notes/README.md +13 -18
- package/examples/notes/project.ts +57 -9
- package/examples/peermesh/harness/router.ts +2 -2
- package/examples/peermesh/harness/team.ts +11 -0
- package/examples/peermesh/project.ts +19 -4
- package/examples/services/agent-control/README.md +3 -3
- package/examples/services/mathlib-search/Dockerfile +4 -2
- package/examples/services/mathlib-search/README.md +1 -1
- package/examples/services/mcp-managed/README.md +2 -2
- package/examples/services/persistent-board/README.md +16 -3
- package/examples/services/persistent-board/business.ts +10 -0
- package/examples/services/persistent-board/index.ts +10 -0
- package/examples/services/persistent-board/live.ts +54 -0
- package/examples/subagents/README.md +5 -5
- package/examples/subagents/business.ts +3 -1
- package/examples/subagents/config.ts +4 -3
- package/examples/subagents/harness/controller.ts +161 -29
- package/examples/subagents/project.ts +47 -33
- package/examples/subagents/prompts/prompts.ts +4 -0
- package/examples/subagents/services/collaboration-service.ts +14 -2
- package/examples/substrate/README.md +2 -2
- package/examples/substrate/harness/index.ts +67 -11
- package/examples/substrate/project.ts +5 -1
- package/examples/super/README.md +52 -0
- package/examples/super/actions.ts +196 -0
- package/examples/super/artifact.ts +56 -0
- package/examples/super/config.ts +95 -0
- package/examples/super/coordinator.ts +158 -0
- package/examples/super/daemon.ts +84 -0
- package/examples/super/decisions.ts +46 -0
- package/examples/super/eject.json +5 -0
- package/examples/super/execution.ts +131 -0
- package/examples/super/github.ts +242 -0
- package/examples/super/inbox.ts +306 -0
- package/examples/super/location.ts +54 -0
- package/examples/super/operator.ts +28 -0
- package/examples/super/outbox.ts +97 -0
- package/examples/super/project.ts +225 -0
- package/examples/super/prompts.ts +27 -0
- package/examples/taskpool/deploy/service-hosts/Dockerfile +4 -2
- package/examples/taskpool/harness/controller.ts +59 -7
- package/examples/taskpool/project.ts +18 -2
- package/npm-shrinkwrap.development.json +700 -0
- package/npm-shrinkwrap.json +95 -1969
- package/package.development.json +88 -0
- package/package.json +11 -8
- package/scripts/anyswarm-arguments.ts +91 -54
- package/scripts/anyswarm-author.ts +25 -0
- package/scripts/anyswarm-eject.ts +145 -0
- package/scripts/anyswarm-harnesses.ts +10 -0
- package/scripts/anyswarm-installation.ts +18 -288
- package/scripts/anyswarm-launch.ts +36 -0
- package/scripts/anyswarm-progress.ts +95 -0
- package/scripts/anyswarm-project.ts +35 -34
- package/scripts/anyswarm-source-runner.ts +176 -0
- package/scripts/anyswarm.ts +24 -3
- package/scripts/build.ts +8 -1
- package/scripts/generate-architecture-api.ts +2 -0
- package/scripts/generate-architecture-prompts.ts +35 -2
- package/scripts/local-environment.ts +117 -28
- package/scripts/local-setup-smoke.ts +3 -2
- package/scripts/local-setup-worker.ts +17 -7
- package/scripts/local-setup.ts +166 -73
- package/scripts/opensandbox-agent-worker.ts +2 -2
- package/scripts/pack-release.ts +70 -0
- package/scripts/pi-session-bridge.ts +10 -2
- package/scripts/run-harness.ts +3 -1
- package/scripts/setup-bootstrap.ts +41 -6
- package/src/core/allocation-ledger.ts +5 -3
- package/src/core/host-identity.ts +11 -0
- package/src/core/index.ts +12 -6
- package/src/core/mcp-service.ts +2 -2
- package/src/core/runtime-management.ts +22 -0
- package/src/core/sandbox/executor-driver.ts +15 -18
- package/src/core/sandbox/local-executor.ts +65 -19
- package/src/core/sandbox/local-worker.ts +29 -21
- package/src/core/sandbox/opensandbox-backend.ts +36 -11
- package/src/core/sandbox/sandbox-connection.ts +14 -5
- package/src/core/service-live-state.ts +156 -0
- package/src/core/service-observation-types.ts +23 -1
- package/src/core/service-process.ts +36 -3
- package/src/core/service-types.ts +3 -1
- package/src/core/services.ts +8 -3
- package/src/core/types.ts +3 -0
- package/src/core/worker-image.ts +3 -3
- package/src/harness/harness-session-types.ts +13 -1
- package/src/harness/harness-session.ts +40 -7
- package/src/harness/project-harness.ts +38 -12
- package/src/harness/project-input.ts +73 -15
- package/src/harness/project-rpc-client.ts +5 -0
- package/src/harness/project-rpc.ts +29 -8
- package/src/harness/project-runtime.ts +4 -2
- package/src/harness/typescript-loader.ts +37 -0
- package/src/trace-viewer/public/app.js +6 -5
- package/src/trace-viewer/reader.mjs +42 -2
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { createRuntime, recoverRuntime, runInput, ServiceRegistry, inProcessService, } from '@anyswarm/core';
|
|
3
|
+
import { defaults, runtimeOptions } from './config.js';
|
|
4
|
+
import { reviewerPrompt, routerPrompt, workerPrompt } from './prompts.js';
|
|
5
|
+
export function personalRuntime(outputDir, status) {
|
|
6
|
+
const { image, options } = runtimeOptions(outputDir);
|
|
7
|
+
const services = new ServiceRegistry();
|
|
8
|
+
services.register('personal', inProcessService({
|
|
9
|
+
description: 'Bounded work, source and delivery status for the local owner.',
|
|
10
|
+
operations: {
|
|
11
|
+
status: {
|
|
12
|
+
description: 'Read status', sideEffect: 'read', idempotent: true,
|
|
13
|
+
inputSchema: { type: 'object', additionalProperties: false }, outputSchema: { type: 'object' },
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
}, { status }, {
|
|
17
|
+
readState: () => ({
|
|
18
|
+
state: status(), capturedAt: new Date().toISOString(),
|
|
19
|
+
presentation: {
|
|
20
|
+
summary: [{ label: 'Repository', path: '/repository' }, { label: 'Source', path: '/source/state' }],
|
|
21
|
+
tables: [{ title: 'Recent work events', path: '/events', columns: [
|
|
22
|
+
{ label: 'Work', path: '/job' }, { label: 'Thread', path: '/thread' },
|
|
23
|
+
{ label: 'Queue', path: '/state' }, { label: 'Result', path: '/result' },
|
|
24
|
+
{ label: 'Reply', path: '/reply' }, { label: 'Problem', path: '/problem' },
|
|
25
|
+
] }],
|
|
26
|
+
},
|
|
27
|
+
}),
|
|
28
|
+
}));
|
|
29
|
+
const profile = (prompt, tools, writable = false) => ({
|
|
30
|
+
addedSystemPrompt: prompt, image, model: 'default', writable, tools, services: {},
|
|
31
|
+
});
|
|
32
|
+
const config = { ...options, services, maxAgents: defaults.maxWork * 2, profiles: {
|
|
33
|
+
router: profile(routerPrompt, []),
|
|
34
|
+
worker: profile(workerPrompt, ['read', 'edit', 'write'], true),
|
|
35
|
+
reviewer: profile(reviewerPrompt, ['read']),
|
|
36
|
+
} };
|
|
37
|
+
return {
|
|
38
|
+
durable: Boolean(options.persistence),
|
|
39
|
+
create: () => createRuntime(config),
|
|
40
|
+
async recover(runDirectory) {
|
|
41
|
+
if (!options.persistence)
|
|
42
|
+
return { cleanup: 'pending', reason: 'Set the original durable callback configuration to recover resources.' };
|
|
43
|
+
const runtime = await recoverRuntime({ ...config, runDirectory, cleanupOnly: true });
|
|
44
|
+
return runtime.close({ timeoutMs: 30_000 });
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export function memberBackend(runtime, members) {
|
|
49
|
+
const seed = (files) => Object.fromEntries(Object.entries(files).map(([path, data]) => [path, { encoding: 'utf8', data }]));
|
|
50
|
+
return {
|
|
51
|
+
async open(entry, signal) {
|
|
52
|
+
const spawned = new Set();
|
|
53
|
+
async function spawn(profile, files, parentId) {
|
|
54
|
+
signal.throwIfAborted();
|
|
55
|
+
const agent = await runtime.spawn({ profile, files, parentId, requestId: randomUUID() });
|
|
56
|
+
spawned.add(agent.id);
|
|
57
|
+
members.set(agent.id, entry.job.id);
|
|
58
|
+
return agent;
|
|
59
|
+
}
|
|
60
|
+
async function closeMember(id) {
|
|
61
|
+
const receipt = await runtime.stop(id, { timeoutMs: 15_000 });
|
|
62
|
+
if (receipt.cleanup === 'complete') {
|
|
63
|
+
spawned.delete(id);
|
|
64
|
+
members.delete(id);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
async function turn(agent, input, turnSignal = signal) {
|
|
68
|
+
signal.throwIfAborted();
|
|
69
|
+
const result = await runInput(runtime, agent.id, JSON.stringify(input), {
|
|
70
|
+
requestId: randomUUID(), signal: turnSignal, timeoutMs: 180_000,
|
|
71
|
+
});
|
|
72
|
+
return result.settled.output ?? (await runtime.get(agent.id)).latestOutput ?? '';
|
|
73
|
+
}
|
|
74
|
+
const router = await spawn('router');
|
|
75
|
+
return {
|
|
76
|
+
route: input => turn(router, input),
|
|
77
|
+
async start(role, text, files) {
|
|
78
|
+
const worker = await spawn(role, seed(files), router.id);
|
|
79
|
+
const controller = new AbortController();
|
|
80
|
+
const turnSignal = AbortSignal.any([signal, controller.signal]);
|
|
81
|
+
let settled = false;
|
|
82
|
+
const result = (async () => {
|
|
83
|
+
try {
|
|
84
|
+
const summary = await turn(worker, { assignment: text, allowedPaths: Object.keys(files) }, turnSignal);
|
|
85
|
+
turnSignal.throwIfAborted();
|
|
86
|
+
if (role === 'reviewer')
|
|
87
|
+
return { summary };
|
|
88
|
+
const view = await runtime.files.snapshot(worker.id, {
|
|
89
|
+
requestId: randomUUID(), paths: Object.keys(files), maxBytes: defaults.fileBytes * Object.keys(files).length,
|
|
90
|
+
});
|
|
91
|
+
turnSignal.throwIfAborted();
|
|
92
|
+
const exported = Object.fromEntries(Object.keys(files).map(path => {
|
|
93
|
+
const file = view.files[path];
|
|
94
|
+
if (!file || file.mode === 0o755)
|
|
95
|
+
throw new Error('Worker changed an approved file type or removed it.');
|
|
96
|
+
const text = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(Buffer.from(file.data, file.encoding));
|
|
97
|
+
if (text.includes('\0'))
|
|
98
|
+
throw new Error('Worker output was not text.');
|
|
99
|
+
return [path, text];
|
|
100
|
+
}));
|
|
101
|
+
return { summary, files: exported };
|
|
102
|
+
}
|
|
103
|
+
finally {
|
|
104
|
+
settled = true;
|
|
105
|
+
await closeMember(worker.id);
|
|
106
|
+
}
|
|
107
|
+
})();
|
|
108
|
+
// A Router may decide to stop without ever waiting for this member.
|
|
109
|
+
void result.catch(() => { });
|
|
110
|
+
return {
|
|
111
|
+
id: worker.id, result,
|
|
112
|
+
async steer(text) {
|
|
113
|
+
if (settled)
|
|
114
|
+
return 'settled';
|
|
115
|
+
try {
|
|
116
|
+
const receipt = await runtime.send(worker.id, text, { mode: 'steer', wakeIfIdle: false, requestId: randomUUID() });
|
|
117
|
+
return receipt.status === 'accepted' ? receipt.disposition : receipt.status;
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
return 'unavailable';
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
async stop() {
|
|
124
|
+
controller.abort();
|
|
125
|
+
await result.catch(() => { });
|
|
126
|
+
return spawned.has(worker.id) ? 'cleanup_pending' : 'stopped';
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
},
|
|
130
|
+
async close() {
|
|
131
|
+
await Promise.allSettled([...spawned].reverse().map(closeMember));
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { type PersonalSettings } from './config.js';
|
|
2
|
+
import { type Delivery, type Entry, type Inbox } from './inbox.js';
|
|
3
|
+
export declare function safePath(path: string): boolean;
|
|
4
|
+
export declare function githubToken(): string;
|
|
5
|
+
export declare class GitHubApiError extends Error {
|
|
6
|
+
readonly status: number;
|
|
7
|
+
readonly permission: string | null;
|
|
8
|
+
readonly permissionDenied: boolean;
|
|
9
|
+
constructor(status: number, permission: string | null, permissionDenied?: boolean);
|
|
10
|
+
}
|
|
11
|
+
type Pull = {
|
|
12
|
+
number: number;
|
|
13
|
+
html_url: string;
|
|
14
|
+
body: string | null;
|
|
15
|
+
};
|
|
16
|
+
type Ref = {
|
|
17
|
+
object: {
|
|
18
|
+
sha: string;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
type Repo = {
|
|
22
|
+
full_name: string;
|
|
23
|
+
default_branch: string;
|
|
24
|
+
permissions?: {
|
|
25
|
+
push?: boolean;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
export declare class GitHub {
|
|
29
|
+
#private;
|
|
30
|
+
readonly repository: string;
|
|
31
|
+
private readonly token;
|
|
32
|
+
constructor(repository: string, token: string);
|
|
33
|
+
private request;
|
|
34
|
+
private get;
|
|
35
|
+
private list;
|
|
36
|
+
private optional;
|
|
37
|
+
inspect(signal: AbortSignal): Promise<{
|
|
38
|
+
account: string;
|
|
39
|
+
repo: Repo;
|
|
40
|
+
}>;
|
|
41
|
+
private admitComments;
|
|
42
|
+
poll(settings: PersonalSettings, inbox: Inbox, signal: AbortSignal): Promise<string>;
|
|
43
|
+
issue(number: number, signal: AbortSignal): Promise<boolean>;
|
|
44
|
+
head(signal: AbortSignal): Promise<{
|
|
45
|
+
name: string;
|
|
46
|
+
sha: string;
|
|
47
|
+
}>;
|
|
48
|
+
file(path: string, revision: string, signal: AbortSignal): Promise<string>;
|
|
49
|
+
reconcile(step: NonNullable<Delivery['checkpoint']>, entry: Entry, signal: AbortSignal): Promise<Pull | Ref | undefined>;
|
|
50
|
+
private findPull;
|
|
51
|
+
writeBranch(branch: string, base: string, signal: AbortSignal): Promise<Ref>;
|
|
52
|
+
writeCommit(entry: Entry, signal: AbortSignal): Promise<{
|
|
53
|
+
object: {
|
|
54
|
+
sha: string;
|
|
55
|
+
};
|
|
56
|
+
}>;
|
|
57
|
+
writePull(entry: Entry, signal: AbortSignal): Promise<Pull>;
|
|
58
|
+
private commentPath;
|
|
59
|
+
findReply(entry: Entry, account: string, signal: AbortSignal): Promise<string | undefined>;
|
|
60
|
+
writeReply(entry: Entry, signal: AbortSignal): Promise<string>;
|
|
61
|
+
}
|
|
62
|
+
export {};
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { defaults, PersonalConfigurationError } from './config.js';
|
|
3
|
+
import { digest } from './inbox.js';
|
|
4
|
+
const ownerName = /^[A-Za-z0-9][A-Za-z0-9-]{0,38}$/;
|
|
5
|
+
const repositoryName = /^[A-Za-z0-9][A-Za-z0-9-]{0,38}\/[A-Za-z0-9_.-]{1,100}$/;
|
|
6
|
+
const markerPrefix = '<!-- anys-super:';
|
|
7
|
+
const routePrefix = /^\/super\s+/i;
|
|
8
|
+
const sha = /^[a-f0-9]{40}$/;
|
|
9
|
+
export function safePath(path) {
|
|
10
|
+
return path.length <= 180 && path.split('/').every(part => /^[A-Za-z0-9][A-Za-z0-9_.-]*$/.test(part));
|
|
11
|
+
}
|
|
12
|
+
export function githubToken() {
|
|
13
|
+
const configured = process.env.ANYSWARM_SUPER_GITHUB_TOKEN || process.env.GH_TOKEN || process.env.GITHUB_TOKEN;
|
|
14
|
+
if (configured)
|
|
15
|
+
return configured;
|
|
16
|
+
try {
|
|
17
|
+
const token = execFileSync('gh', ['auth', 'token', '--hostname', 'github.com'], {
|
|
18
|
+
encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'], timeout: 3000,
|
|
19
|
+
}).trim();
|
|
20
|
+
if (token)
|
|
21
|
+
return token;
|
|
22
|
+
}
|
|
23
|
+
catch { /* Refuse an unavailable gh credential below. */ }
|
|
24
|
+
throw new PersonalConfigurationError('PERSONAL_GITHUB_CREDENTIAL_MISSING', 'Set ANYSWARM_SUPER_GITHUB_TOKEN or run gh auth login --hostname github.com.');
|
|
25
|
+
}
|
|
26
|
+
export class GitHubApiError extends Error {
|
|
27
|
+
status;
|
|
28
|
+
permission;
|
|
29
|
+
permissionDenied;
|
|
30
|
+
constructor(status, permission, permissionDenied = false) {
|
|
31
|
+
super(`GitHub returned HTTP ${status}${permission ? ` (endpoint permissions: ${permission})` : ''}`);
|
|
32
|
+
this.status = status;
|
|
33
|
+
this.permission = permission;
|
|
34
|
+
this.permissionDenied = permissionDenied;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const encode = encodeURIComponent;
|
|
38
|
+
export class GitHub {
|
|
39
|
+
repository;
|
|
40
|
+
token;
|
|
41
|
+
#base;
|
|
42
|
+
#owner;
|
|
43
|
+
#lastPullRead = 0;
|
|
44
|
+
constructor(repository, token) {
|
|
45
|
+
this.repository = repository;
|
|
46
|
+
this.token = token;
|
|
47
|
+
if (!repositoryName.test(repository))
|
|
48
|
+
throw new Error('Use an owner/repository GitHub name.');
|
|
49
|
+
this.#base = '/repos/' + repository;
|
|
50
|
+
this.#owner = repository.split('/')[0];
|
|
51
|
+
}
|
|
52
|
+
async request(path, signal, body) {
|
|
53
|
+
const url = new URL(path, 'https://api.github.com');
|
|
54
|
+
if (url.origin !== 'https://api.github.com')
|
|
55
|
+
throw new Error('Unexpected GitHub pagination host');
|
|
56
|
+
const response = await fetch(url, {
|
|
57
|
+
method: body === undefined ? 'GET' : 'POST', signal: AbortSignal.any([signal, AbortSignal.timeout(20_000)]),
|
|
58
|
+
redirect: 'error',
|
|
59
|
+
headers: { authorization: `Bearer ${this.token}`, accept: 'application/vnd.github+json',
|
|
60
|
+
'content-type': 'application/json', 'user-agent': 'anyswarm-personal' },
|
|
61
|
+
...(body !== undefined && { body: JSON.stringify(body) }),
|
|
62
|
+
});
|
|
63
|
+
if (!response.ok) {
|
|
64
|
+
await response.body?.cancel();
|
|
65
|
+
throw new GitHubApiError(response.status, response.headers.get('x-accepted-github-permissions'), response.status === 401 || (response.status === 403 && response.headers.get('x-ratelimit-remaining') !== '0'
|
|
66
|
+
&& !response.headers.has('retry-after')));
|
|
67
|
+
}
|
|
68
|
+
const next = response.headers.get('link')?.match(/<([^>]+)>; rel="next"/)?.[1] ?? null;
|
|
69
|
+
return { data: await response.json(), next };
|
|
70
|
+
}
|
|
71
|
+
async get(path, signal, body) {
|
|
72
|
+
return (await this.request(path, signal, body)).data;
|
|
73
|
+
}
|
|
74
|
+
async list(path, signal) {
|
|
75
|
+
const items = [];
|
|
76
|
+
let cursor = path;
|
|
77
|
+
for (let page = 0; cursor && page < 20; page++) {
|
|
78
|
+
const { data, next } = await this.request(cursor, signal);
|
|
79
|
+
items.push(...data);
|
|
80
|
+
cursor = next;
|
|
81
|
+
}
|
|
82
|
+
if (cursor)
|
|
83
|
+
throw new Error('GitHub returned more than 20 pages; narrow the source scope.');
|
|
84
|
+
return items;
|
|
85
|
+
}
|
|
86
|
+
async optional(path, signal) {
|
|
87
|
+
try {
|
|
88
|
+
return await this.get(path, signal);
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
if (error instanceof GitHubApiError && error.status === 404)
|
|
92
|
+
return;
|
|
93
|
+
throw error;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
async inspect(signal) {
|
|
97
|
+
const [account, repo] = await Promise.all([
|
|
98
|
+
this.get('/user', signal), this.get(this.#base, signal),
|
|
99
|
+
this.get(this.#base + '/issues/comments?per_page=1', signal),
|
|
100
|
+
]);
|
|
101
|
+
if (!ownerName.test(account.login))
|
|
102
|
+
throw new Error('GitHub did not return a usable account.');
|
|
103
|
+
return { account: account.login, repo };
|
|
104
|
+
}
|
|
105
|
+
admitComments(comments, settings, inbox, pull) {
|
|
106
|
+
for (const comment of comments) {
|
|
107
|
+
if (Date.parse(comment.created_at) < Date.parse(settings.since) || !comment.user ||
|
|
108
|
+
!settings.users.includes(comment.user.login.toLowerCase()) || comment.user.type !== 'User' ||
|
|
109
|
+
comment.body.includes(markerPrefix))
|
|
110
|
+
continue;
|
|
111
|
+
const match = /^https:\/\/api\.github\.com\/repos\/([^/]+\/[^/]+)\/issues\/(\d+)$/.exec(comment.issue_url);
|
|
112
|
+
if (!match || match[1].toLowerCase() !== settings.repository.toLowerCase())
|
|
113
|
+
continue;
|
|
114
|
+
const thread = Number(match[2]);
|
|
115
|
+
const kind = new URL(comment.html_url).pathname.includes('/pull/') ? 'pull' : 'issue';
|
|
116
|
+
const existing = inbox.topic(thread, kind);
|
|
117
|
+
if (pull !== undefined && (kind !== 'pull' || thread !== pull))
|
|
118
|
+
continue;
|
|
119
|
+
if (pull === undefined && kind === 'pull' && existing?.readPullFeedback)
|
|
120
|
+
continue;
|
|
121
|
+
if (!existing && (kind === 'pull' || !routePrefix.test(comment.body)))
|
|
122
|
+
continue;
|
|
123
|
+
const text = comment.body.replace(routePrefix, '').trim();
|
|
124
|
+
if (!text || Buffer.byteLength(text) > 16_384)
|
|
125
|
+
continue;
|
|
126
|
+
const admission = inbox.accept({ id: 'github:' + comment.id, thread, kind, author: comment.user.login, text });
|
|
127
|
+
if (admission.state === 'capacity')
|
|
128
|
+
throw new Error('Personal inbox is full; pending work must finish before advancing the source cursor.');
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
async poll(settings, inbox, signal) {
|
|
132
|
+
let readError;
|
|
133
|
+
for (const pull of inbox.unreadPulls(this.#lastPullRead)) {
|
|
134
|
+
signal.throwIfAborted();
|
|
135
|
+
this.#lastPullRead = pull;
|
|
136
|
+
try {
|
|
137
|
+
const comments = await this.list(this.#base + `/issues/${pull}/comments?per_page=100&since=` + encode(settings.since), signal);
|
|
138
|
+
this.admitComments(comments, settings, inbox, pull);
|
|
139
|
+
inbox.finishPullRead(pull);
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
readError ??= error;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const mark = inbox.get('githubCursor') ?? settings.since;
|
|
146
|
+
const overlap = new Date(Date.parse(mark) - 2000).toISOString();
|
|
147
|
+
const comments = await this.list(this.#base + '/issues/comments?per_page=100&sort=updated&direction=asc&since=' + encode(overlap), signal);
|
|
148
|
+
this.admitComments(comments, settings, inbox);
|
|
149
|
+
let cursor = mark;
|
|
150
|
+
for (const comment of comments)
|
|
151
|
+
if (comment.updated_at > cursor)
|
|
152
|
+
cursor = comment.updated_at;
|
|
153
|
+
inbox.put('githubCursor', cursor);
|
|
154
|
+
if (readError)
|
|
155
|
+
throw readError;
|
|
156
|
+
return new Date().toISOString();
|
|
157
|
+
}
|
|
158
|
+
async issue(number, signal) {
|
|
159
|
+
if (!Number.isSafeInteger(number) || number < 1)
|
|
160
|
+
return false;
|
|
161
|
+
const issue = await this.optional(this.#base + '/issues/' + number, signal);
|
|
162
|
+
return issue?.number === number && !issue.pull_request;
|
|
163
|
+
}
|
|
164
|
+
async head(signal) {
|
|
165
|
+
const repo = await this.get(this.#base, signal);
|
|
166
|
+
const ref = await this.get(this.#base + '/git/ref/heads/' + encode(repo.default_branch), signal);
|
|
167
|
+
return { name: repo.default_branch, sha: ref.object.sha };
|
|
168
|
+
}
|
|
169
|
+
async file(path, revision, signal) {
|
|
170
|
+
if (!safePath(path) || !sha.test(revision))
|
|
171
|
+
throw new Error('Invalid approved file identity');
|
|
172
|
+
const commit = await this.get(this.#base + '/git/commits/' + revision, signal);
|
|
173
|
+
let current = commit.tree.sha;
|
|
174
|
+
const parts = path.split('/');
|
|
175
|
+
for (const [index, name] of parts.entries()) {
|
|
176
|
+
const tree = await this.get(this.#base + '/git/trees/' + current, signal);
|
|
177
|
+
const node = tree.tree.find(item => item.path === name);
|
|
178
|
+
const last = index === parts.length - 1;
|
|
179
|
+
if (!node || (last ? node.type !== 'blob' || node.mode !== '100644' : node.type !== 'tree')) {
|
|
180
|
+
throw new Error(`Allowlisted file is missing or is not a regular non-executable file: ${path}`);
|
|
181
|
+
}
|
|
182
|
+
if (node.size !== undefined && node.size > defaults.fileBytes)
|
|
183
|
+
throw new Error(`Allowlisted file exceeds the size limit: ${path}`);
|
|
184
|
+
current = node.sha;
|
|
185
|
+
}
|
|
186
|
+
const blob = await this.get(this.#base + '/git/blobs/' + current, signal);
|
|
187
|
+
if (blob.encoding !== 'base64' || blob.size > defaults.fileBytes)
|
|
188
|
+
throw new Error(`Unsupported blob: ${path}`);
|
|
189
|
+
const bytes = Buffer.from(blob.content, 'base64');
|
|
190
|
+
const text = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(bytes);
|
|
191
|
+
if (text.includes('\0'))
|
|
192
|
+
throw new Error(`Allowlisted file is not text: ${path}`);
|
|
193
|
+
return text;
|
|
194
|
+
}
|
|
195
|
+
async reconcile(step, entry, signal) {
|
|
196
|
+
const delivery = entry.delivery;
|
|
197
|
+
const branch = delivery.branch;
|
|
198
|
+
const ref = await this.optional(this.#base + '/git/ref/heads/' + encode(branch), signal);
|
|
199
|
+
if (!ref)
|
|
200
|
+
return;
|
|
201
|
+
if (step === 'branch')
|
|
202
|
+
return ref.object.sha === delivery.artifact.base ? ref : undefined;
|
|
203
|
+
if (step === 'commit') {
|
|
204
|
+
const commit = await this.get(this.#base + '/commits/' + ref.object.sha, signal);
|
|
205
|
+
return commit.commit.message.includes(commitMarker(entry)) ? ref : undefined;
|
|
206
|
+
}
|
|
207
|
+
return this.findPull(entry, signal);
|
|
208
|
+
}
|
|
209
|
+
async findPull(entry, signal) {
|
|
210
|
+
const matches = await this.list(this.#base + '/pulls?state=all&head=' + encode(this.#owner + ':' + entry.delivery.branch), signal);
|
|
211
|
+
return matches.find(pull => pull.body?.includes(pullMarker(entry)));
|
|
212
|
+
}
|
|
213
|
+
async writeBranch(branch, base, signal) {
|
|
214
|
+
return this.get(this.#base + '/git/refs', signal, { ref: 'refs/heads/' + branch, sha: base });
|
|
215
|
+
}
|
|
216
|
+
async writeCommit(entry, signal) {
|
|
217
|
+
const delivery = entry.delivery;
|
|
218
|
+
const expectedHeadOid = entry.job.commit ?? delivery.artifact.base;
|
|
219
|
+
const result = await this.get('/graphql', signal, {
|
|
220
|
+
query: 'mutation($input: CreateCommitOnBranchInput!) { createCommitOnBranch(input: $input) { commit { oid } } }',
|
|
221
|
+
variables: { input: {
|
|
222
|
+
branch: { repositoryNameWithOwner: this.repository, branchName: delivery.branch },
|
|
223
|
+
expectedHeadOid, message: { headline: `Personal: update for issue #${entry.job.thread}`, body: commitMarker(entry) },
|
|
224
|
+
fileChanges: { additions: Object.entries(delivery.artifact.files).map(([path, text]) => ({ path, contents: Buffer.from(text).toString('base64') })) },
|
|
225
|
+
} },
|
|
226
|
+
});
|
|
227
|
+
if (result.errors?.some(error => error.type === 'FORBIDDEN')) {
|
|
228
|
+
throw new GitHubApiError(403, 'Contents: write', true);
|
|
229
|
+
}
|
|
230
|
+
const oid = result.data?.createCommitOnBranch?.commit?.oid;
|
|
231
|
+
if (!oid || !sha.test(oid))
|
|
232
|
+
throw new Error('GitHub could not confirm the commit');
|
|
233
|
+
return { object: { sha: oid } };
|
|
234
|
+
}
|
|
235
|
+
async writePull(entry, signal) {
|
|
236
|
+
const { name } = await this.head(signal);
|
|
237
|
+
return this.get(this.#base + '/pulls', signal, {
|
|
238
|
+
draft: true, head: entry.delivery.branch, base: name,
|
|
239
|
+
title: `Personal work for #${entry.job.thread}`,
|
|
240
|
+
body: `Work requested in #${entry.job.thread}.\n\n${pullMarker(entry)}`,
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
commentPath(entry) {
|
|
244
|
+
return this.#base + '/issues/' + entry.input.thread + '/comments';
|
|
245
|
+
}
|
|
246
|
+
async findReply(entry, account, signal) {
|
|
247
|
+
const marker = replyMarker(entry);
|
|
248
|
+
const comments = await this.list(this.commentPath(entry) + '?per_page=100', signal);
|
|
249
|
+
return comments.find(comment => comment.user?.login.toLowerCase() === account.toLowerCase() && comment.body.includes(marker))?.html_url;
|
|
250
|
+
}
|
|
251
|
+
async writeReply(entry, signal) {
|
|
252
|
+
const delivery = entry.delivery;
|
|
253
|
+
const artifact = delivery.artifact;
|
|
254
|
+
const proof = artifact ? [
|
|
255
|
+
'', delivery.url ? `Draft PR: ${delivery.url}` : 'Patch saved locally. Use /jobs in Personal for its path.',
|
|
256
|
+
...artifact.checks, `Patch SHA-256: ${artifact.sha256}`,
|
|
257
|
+
...(delivery.publish === 'approval' ? ['Publishing is awaiting authorization.'] : []),
|
|
258
|
+
] : [];
|
|
259
|
+
const result = await this.get(this.commentPath(entry), signal, {
|
|
260
|
+
body: [delivery.text, ...proof, '', replyMarker(entry)].join('\n'),
|
|
261
|
+
});
|
|
262
|
+
if (!result.html_url)
|
|
263
|
+
throw new Error('GitHub did not return a comment receipt');
|
|
264
|
+
return result.html_url;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
const commitMarker = (entry) => 'anys-super-event:' + digest(entry.input.id).slice(0, 24);
|
|
268
|
+
const pullMarker = (entry) => markerPrefix + 'job:' + entry.job.id + ' -->';
|
|
269
|
+
const replyMarker = (entry) => markerPrefix + 'reply:' + digest(entry.input.id + (entry.delivery?.replyVersion ? ':' + entry.delivery.replyVersion : '')).slice(0, 24) + ' -->';
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
export declare const digest: (bytes: string | Buffer) => string;
|
|
2
|
+
export type Inbound = {
|
|
3
|
+
id: string;
|
|
4
|
+
thread: number;
|
|
5
|
+
kind: 'issue' | 'pull';
|
|
6
|
+
author: string;
|
|
7
|
+
text: string;
|
|
8
|
+
};
|
|
9
|
+
export type Artifact = {
|
|
10
|
+
base: string;
|
|
11
|
+
files: Record<string, string>;
|
|
12
|
+
patch: string;
|
|
13
|
+
sha256: string;
|
|
14
|
+
checks: string[];
|
|
15
|
+
summary?: string;
|
|
16
|
+
review?: string;
|
|
17
|
+
};
|
|
18
|
+
export type Delivery = {
|
|
19
|
+
text: string;
|
|
20
|
+
result: 'completed' | 'failed' | 'waiting';
|
|
21
|
+
question?: string;
|
|
22
|
+
artifact?: Artifact;
|
|
23
|
+
branch?: string;
|
|
24
|
+
branchConfirmed?: boolean;
|
|
25
|
+
pull?: number;
|
|
26
|
+
commit?: string;
|
|
27
|
+
url?: string;
|
|
28
|
+
comment?: string;
|
|
29
|
+
originalComment?: string;
|
|
30
|
+
replyVersion?: 'publication';
|
|
31
|
+
checkpoint?: 'branch' | 'commit' | 'pull';
|
|
32
|
+
publish?: 'queued' | 'sending' | 'confirmed' | 'approval' | 'rejected' | 'unknown';
|
|
33
|
+
ownerApproved?: boolean;
|
|
34
|
+
rejectionReason?: string;
|
|
35
|
+
reply: 'queued' | 'sending' | 'confirmed' | 'unknown';
|
|
36
|
+
};
|
|
37
|
+
type State = 'queued' | 'working' | 'prepared' | 'unknown' | 'delivered' | 'failed' | 'stopped';
|
|
38
|
+
type Job = {
|
|
39
|
+
id: string;
|
|
40
|
+
thread: number;
|
|
41
|
+
last?: Artifact;
|
|
42
|
+
branch?: string;
|
|
43
|
+
pull?: number;
|
|
44
|
+
readPullFeedback?: boolean;
|
|
45
|
+
commit?: string;
|
|
46
|
+
question?: string;
|
|
47
|
+
};
|
|
48
|
+
type PriorTurn = {
|
|
49
|
+
request: string;
|
|
50
|
+
response?: string;
|
|
51
|
+
result?: Delivery['result'];
|
|
52
|
+
};
|
|
53
|
+
export type Entry = {
|
|
54
|
+
job: Job;
|
|
55
|
+
input: Inbound;
|
|
56
|
+
state: State;
|
|
57
|
+
delivery?: Delivery;
|
|
58
|
+
problem?: string;
|
|
59
|
+
history?: PriorTurn[];
|
|
60
|
+
};
|
|
61
|
+
type Admission = {
|
|
62
|
+
id: string;
|
|
63
|
+
job?: string;
|
|
64
|
+
state: State | 'conflict' | 'unbound' | 'capacity';
|
|
65
|
+
duplicate?: boolean;
|
|
66
|
+
};
|
|
67
|
+
export declare const PERSONAL_SCHEMA_SQL = "\n PRAGMA journal_mode = WAL;\n PRAGMA synchronous = FULL;\n CREATE TABLE IF NOT EXISTS jobs (id TEXT PRIMARY KEY, thread INTEGER UNIQUE NOT NULL, pull INTEGER UNIQUE, data TEXT NOT NULL);\n CREATE TABLE IF NOT EXISTS events (\n seq INTEGER PRIMARY KEY, id TEXT UNIQUE NOT NULL, job TEXT NOT NULL, hash TEXT NOT NULL,\n input TEXT NOT NULL, state TEXT NOT NULL, delivery TEXT, problem TEXT\n );\n CREATE INDEX IF NOT EXISTS events_queue ON events (job, state, seq);\n CREATE TABLE IF NOT EXISTS conflicts (id TEXT PRIMARY KEY, detected TEXT NOT NULL);\n CREATE TABLE IF NOT EXISTS metadata (key TEXT PRIMARY KEY, data TEXT NOT NULL);\n ";
|
|
68
|
+
export declare function openInbox(directory: string, readOnly?: boolean): {
|
|
69
|
+
topic(thread: number, kind: Inbound['kind']): Job | undefined;
|
|
70
|
+
resolveWork(selector: string | number): Job | undefined;
|
|
71
|
+
accept(input: Inbound): Admission;
|
|
72
|
+
claim(exclude?: readonly string[]): Entry | undefined;
|
|
73
|
+
recover(): void;
|
|
74
|
+
unreadPulls(after: number): number[];
|
|
75
|
+
finishPullRead(pull: number): void;
|
|
76
|
+
prepare(entry: Entry, delivery: Delivery): boolean;
|
|
77
|
+
resumeApproved(): void;
|
|
78
|
+
decidePublication(work: string, approve: boolean, rejectionReason?: string, expectedEvent?: string): {
|
|
79
|
+
readonly text: string;
|
|
80
|
+
readonly result: 'completed' | 'failed' | 'waiting';
|
|
81
|
+
readonly question?: string;
|
|
82
|
+
readonly artifact?: Artifact;
|
|
83
|
+
readonly branch?: string;
|
|
84
|
+
readonly branchConfirmed?: boolean;
|
|
85
|
+
readonly pull?: number;
|
|
86
|
+
readonly commit?: string;
|
|
87
|
+
readonly url?: string;
|
|
88
|
+
readonly rejectionReason?: string;
|
|
89
|
+
readonly ownerApproved: boolean | undefined;
|
|
90
|
+
readonly originalComment: string | undefined;
|
|
91
|
+
readonly comment: undefined;
|
|
92
|
+
readonly checkpoint: undefined;
|
|
93
|
+
readonly publish: 'queued';
|
|
94
|
+
readonly reply: 'queued';
|
|
95
|
+
readonly replyVersion: 'publication';
|
|
96
|
+
} | {
|
|
97
|
+
readonly text: string;
|
|
98
|
+
readonly result: 'completed' | 'failed' | 'waiting';
|
|
99
|
+
readonly question?: string;
|
|
100
|
+
readonly artifact?: Artifact;
|
|
101
|
+
readonly branch?: string;
|
|
102
|
+
readonly branchConfirmed?: boolean;
|
|
103
|
+
readonly pull?: number;
|
|
104
|
+
readonly commit?: string;
|
|
105
|
+
readonly url?: string;
|
|
106
|
+
readonly comment?: string;
|
|
107
|
+
readonly originalComment?: string;
|
|
108
|
+
readonly replyVersion?: 'publication';
|
|
109
|
+
readonly checkpoint?: 'branch' | 'commit' | 'pull';
|
|
110
|
+
readonly ownerApproved?: boolean;
|
|
111
|
+
readonly reply: 'queued' | 'sending' | 'confirmed' | 'unknown';
|
|
112
|
+
readonly publish: 'rejected';
|
|
113
|
+
readonly rejectionReason: string | undefined;
|
|
114
|
+
} | undefined;
|
|
115
|
+
decisions(limit?: number): ({
|
|
116
|
+
kind: 'question';
|
|
117
|
+
entry: Entry;
|
|
118
|
+
} | {
|
|
119
|
+
kind: 'publication';
|
|
120
|
+
entry: Entry;
|
|
121
|
+
})[];
|
|
122
|
+
pending(): Entry[];
|
|
123
|
+
setDelivery(entry: Entry, delivery: Delivery, state?: State, problem?: string): boolean;
|
|
124
|
+
work(id: string): Job | undefined;
|
|
125
|
+
stop(id: string): number;
|
|
126
|
+
get<T>(key: string): T | undefined;
|
|
127
|
+
put(key: string, data: unknown): void;
|
|
128
|
+
status(limit?: number, work?: string | number): {
|
|
129
|
+
jobs: {
|
|
130
|
+
id: string;
|
|
131
|
+
issue: number;
|
|
132
|
+
pull: number | undefined;
|
|
133
|
+
branch: string | undefined;
|
|
134
|
+
waiting: string | undefined;
|
|
135
|
+
artifact: {
|
|
136
|
+
patch: string;
|
|
137
|
+
sha256: string;
|
|
138
|
+
checks: string[];
|
|
139
|
+
summary: string | undefined;
|
|
140
|
+
review: string | undefined;
|
|
141
|
+
} | undefined;
|
|
142
|
+
}[];
|
|
143
|
+
events: {
|
|
144
|
+
id: string;
|
|
145
|
+
job: string;
|
|
146
|
+
thread: number;
|
|
147
|
+
state: State;
|
|
148
|
+
problem: string | undefined;
|
|
149
|
+
result: "completed" | "failed" | "waiting" | undefined;
|
|
150
|
+
publish: "approval" | "confirmed" | "queued" | "rejected" | "sending" | "unknown" | undefined;
|
|
151
|
+
reply: "confirmed" | "queued" | "sending" | "unknown" | undefined;
|
|
152
|
+
comment: string | undefined;
|
|
153
|
+
originalComment: string | undefined;
|
|
154
|
+
url: string | undefined;
|
|
155
|
+
rejectionReason: string | undefined;
|
|
156
|
+
}[];
|
|
157
|
+
conflicts: Record<string, import("node:sqlite").SQLOutputValue>[];
|
|
158
|
+
};
|
|
159
|
+
close: () => void;
|
|
160
|
+
};
|
|
161
|
+
export type Inbox = ReturnType<typeof openInbox>;
|
|
162
|
+
export {};
|