attention-manifest-protocol 0.4.2 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +341 -293
- package/CHANGELOG.zh-CN.md +41 -8
- package/README.md +250 -171
- package/README.zh-CN.md +251 -171
- package/lib/assignment/assign.d.ts +102 -0
- package/lib/assignment/assign.js +556 -0
- package/lib/assignment/binding.d.ts +103 -0
- package/lib/assignment/binding.js +575 -0
- package/lib/assignment/errors.d.ts +14 -0
- package/lib/assignment/errors.js +16 -0
- package/lib/assignment/guards.d.ts +18 -0
- package/lib/assignment/guards.js +28 -0
- package/lib/assignment/index.d.ts +10 -0
- package/lib/assignment/index.js +10 -0
- package/lib/assignment/types.d.ts +169 -0
- package/lib/assignment/types.js +1 -0
- package/lib/attention/budget.d.ts +1 -1
- package/lib/attention/budget.js +31 -9
- package/lib/bayes/engine.js +2 -1
- package/lib/bayes/reliability.js +25 -10
- package/lib/boundary/frame.d.ts +10 -4
- package/lib/boundary/frame.js +346 -109
- package/lib/boundary/kinds.d.ts +11 -0
- package/lib/boundary/kinds.js +33 -0
- package/lib/boundary/refTable.d.ts +19 -9
- package/lib/boundary/refTable.js +128 -30
- package/lib/boundary/toolCall.d.ts +22 -10
- package/lib/boundary/toolCall.js +798 -97
- package/lib/concept/conceptBudget.js +10 -1
- package/lib/concurrency/idempotency.d.ts +4 -3
- package/lib/concurrency/idempotency.js +57 -13
- package/lib/concurrency/retry.js +18 -3
- package/lib/context/agentContext.d.ts +13 -0
- package/lib/context/agentContext.js +14 -1
- package/lib/context/ast.d.ts +4 -1
- package/lib/context/ast.js +13 -3
- package/lib/context/contentStore.js +22 -9
- package/lib/context/contextBuilder.d.ts +457 -0
- package/lib/context/contextBuilder.js +1395 -0
- package/lib/context/contextPackage.d.ts +214 -0
- package/lib/context/contextPackage.js +191 -0
- package/lib/context/index.d.ts +14 -3
- package/lib/context/index.js +9 -1
- package/lib/context/relevance.d.ts +171 -0
- package/lib/context/relevance.js +250 -0
- package/lib/context/workspaceDiff.d.ts +105 -0
- package/lib/context/workspaceDiff.js +238 -0
- package/lib/context/workspaceService.d.ts +236 -1
- package/lib/context/workspaceService.js +1501 -73
- package/lib/cooperation/collaboration.d.ts +9 -0
- package/lib/cooperation/session.d.ts +4 -4
- package/lib/cooperation/session.js +3 -3
- package/lib/database/adapter/filesystemStore.d.ts +145 -0
- package/lib/database/adapter/filesystemStore.js +321 -0
- package/lib/database/adapter/index.d.ts +2 -0
- package/lib/database/adapter/index.js +2 -0
- package/lib/database/adapter/workspaceSessionStore.d.ts +118 -0
- package/lib/database/adapter/workspaceSessionStore.js +120 -0
- package/lib/database/entity/fileGraph.d.ts +53 -0
- package/lib/database/entity/fileGraph.js +15 -0
- package/lib/database/entity/fileTree.d.ts +76 -0
- package/lib/database/entity/fileTree.js +39 -0
- package/lib/database/entity/hook.d.ts +29 -0
- package/lib/database/entity/hook.js +18 -0
- package/lib/database/entity/index.d.ts +4 -0
- package/lib/database/entity/index.js +4 -0
- package/lib/database/entity/workspaceSession.d.ts +53 -0
- package/lib/database/entity/workspaceSession.js +28 -0
- package/lib/database/repository/fileAnnotationRepository.d.ts +75 -0
- package/lib/database/repository/fileAnnotationRepository.js +109 -0
- package/lib/database/repository/fileGraphRepository.d.ts +188 -0
- package/lib/database/repository/fileGraphRepository.js +648 -0
- package/lib/database/repository/fileNodeRepository.d.ts +116 -0
- package/lib/database/repository/fileNodeRepository.js +263 -0
- package/lib/database/repository/fileOutlineRepository.d.ts +40 -0
- package/lib/database/repository/fileOutlineRepository.js +104 -0
- package/lib/database/repository/fileWriteRepository.d.ts +41 -0
- package/lib/database/repository/fileWriteRepository.js +93 -0
- package/lib/database/repository/hookRepository.d.ts +67 -0
- package/lib/database/repository/hookRepository.js +150 -0
- package/lib/database/repository/index.d.ts +7 -0
- package/lib/database/repository/index.js +7 -0
- package/lib/database/repository/workspaceSessionRepository.d.ts +134 -0
- package/lib/database/repository/workspaceSessionRepository.js +327 -0
- package/lib/database/service/database.d.ts +14 -0
- package/lib/database/service/database.js +21 -0
- package/lib/database/sql/schema.js +187 -0
- package/lib/database/store/database.js +6 -1
- package/lib/delegate/team.d.ts +5 -0
- package/lib/delegate/team.js +83 -20
- package/lib/discover/classify.d.ts +20 -0
- package/lib/discover/classify.js +85 -0
- package/lib/discover/host.d.ts +20 -0
- package/lib/discover/host.js +89 -0
- package/lib/discover/index.d.ts +11 -0
- package/lib/discover/index.js +11 -0
- package/lib/discover/kinds.d.ts +14 -0
- package/lib/discover/kinds.js +23 -0
- package/lib/discover/tree.d.ts +7 -0
- package/lib/discover/tree.js +432 -0
- package/lib/discover/types.d.ts +115 -0
- package/lib/discover/types.js +1 -0
- package/lib/error/boundaryRejection.d.ts +1 -1
- package/lib/evaluation/agreement.js +2 -2
- package/lib/execution/handles.js +6 -0
- package/lib/execution/pin.js +2 -2
- package/lib/file/cfb.d.ts +56 -0
- package/lib/file/cfb.js +396 -0
- package/lib/file/dependency.d.ts +151 -0
- package/lib/file/dependency.js +568 -0
- package/lib/file/directory.d.ts +34 -0
- package/lib/file/directory.js +141 -0
- package/lib/file/errors.d.ts +20 -0
- package/lib/file/errors.js +18 -0
- package/lib/file/exportGraph.d.ts +31 -0
- package/lib/file/exportGraph.js +554 -0
- package/lib/file/file.d.ts +40 -0
- package/lib/file/file.js +339 -0
- package/lib/file/importGraph.d.ts +121 -0
- package/lib/file/importGraph.js +1022 -0
- package/lib/file/index.d.ts +45 -0
- package/lib/file/index.js +30 -0
- package/lib/file/metadata.d.ts +66 -0
- package/lib/file/metadata.js +470 -0
- package/lib/file/path.d.ts +60 -0
- package/lib/file/path.js +259 -0
- package/lib/file/read.d.ts +168 -0
- package/lib/file/read.js +541 -0
- package/lib/file/runtime.d.ts +95 -0
- package/lib/file/runtime.js +150 -0
- package/lib/file/service.d.ts +227 -0
- package/lib/file/service.js +663 -0
- package/lib/file/syntaxTree.d.ts +7 -0
- package/lib/file/syntaxTree.js +38 -0
- package/lib/file/time.d.ts +38 -0
- package/lib/file/time.js +44 -0
- package/lib/file/tree.d.ts +53 -0
- package/lib/file/tree.js +417 -0
- package/lib/file/types.d.ts +371 -0
- package/lib/file/types.js +1 -0
- package/lib/file/write.d.ts +159 -0
- package/lib/file/write.js +1028 -0
- package/lib/file/zip.d.ts +35 -0
- package/lib/file/zip.js +349 -0
- package/lib/fingerprint/algorithm.d.ts +97 -0
- package/lib/fingerprint/algorithm.js +271 -0
- package/lib/fingerprint/bytes.d.ts +18 -0
- package/lib/fingerprint/bytes.js +31 -0
- package/lib/fingerprint/error.d.ts +73 -0
- package/lib/fingerprint/error.js +86 -0
- package/lib/fingerprint/file.d.ts +71 -0
- package/lib/fingerprint/file.js +254 -0
- package/lib/fingerprint/index.d.ts +37 -0
- package/lib/fingerprint/index.js +12 -0
- package/lib/fingerprint/json.d.ts +41 -0
- package/lib/fingerprint/json.js +94 -0
- package/lib/fingerprint/number.d.ts +32 -0
- package/lib/fingerprint/number.js +95 -0
- package/lib/fingerprint/policy.d.ts +54 -0
- package/lib/fingerprint/policy.js +50 -0
- package/lib/fingerprint/preimage.d.ts +84 -0
- package/lib/fingerprint/preimage.js +133 -0
- package/lib/fingerprint/raw.d.ts +26 -0
- package/lib/fingerprint/raw.js +45 -0
- package/lib/fingerprint/ref.d.ts +39 -0
- package/lib/fingerprint/ref.js +178 -0
- package/lib/fingerprint/text.d.ts +42 -0
- package/lib/fingerprint/text.js +155 -0
- package/lib/fingerprint/tree.d.ts +56 -0
- package/lib/fingerprint/tree.js +288 -0
- package/lib/fingerprint/verify.d.ts +20 -0
- package/lib/fingerprint/verify.js +99 -0
- package/lib/global/filesystem.d.ts +43 -0
- package/lib/global/filesystem.js +75 -0
- package/lib/global/index.d.ts +8 -0
- package/lib/global/index.js +8 -0
- package/lib/global/service.d.ts +51 -0
- package/lib/global/service.js +98 -0
- package/lib/governance/transport.js +18 -6
- package/lib/hook/ast.d.ts +29 -0
- package/lib/hook/ast.js +22 -0
- package/lib/hook/code.d.ts +55 -0
- package/lib/hook/code.js +47 -0
- package/lib/hook/dependency.d.ts +45 -0
- package/lib/hook/dependency.js +28 -0
- package/lib/hook/diff.d.ts +114 -0
- package/lib/hook/diff.js +327 -0
- package/lib/hook/exportation.d.ts +31 -0
- package/lib/hook/exportation.js +24 -0
- package/lib/hook/file.d.ts +44 -0
- package/lib/hook/file.js +154 -0
- package/lib/hook/importation.d.ts +33 -0
- package/lib/hook/importation.js +22 -0
- package/lib/hook/index.d.ts +30 -0
- package/lib/hook/index.js +23 -0
- package/lib/hook/outline.d.ts +35 -0
- package/lib/hook/outline.js +27 -0
- package/lib/hook/project.d.ts +65 -0
- package/lib/hook/project.js +217 -0
- package/lib/hook/types.d.ts +114 -0
- package/lib/hook/types.js +407 -0
- package/lib/index.d.ts +9 -0
- package/lib/index.js +9 -0
- package/lib/lock/lease.js +28 -3
- package/lib/manifest/cardSign.d.ts +1 -1
- package/lib/manifest/cardSign.js +37 -7
- package/lib/manifest/federation.js +13 -6
- package/lib/manifest/trust.d.ts +2 -0
- package/lib/manifest/trust.js +27 -6
- package/lib/module/index.d.ts +4 -0
- package/lib/module/index.js +4 -0
- package/lib/module/mcp/client.js +21 -2
- package/lib/module/mcp/filesystemServer.d.ts +24 -0
- package/lib/module/mcp/filesystemServer.js +102 -0
- package/lib/module/mcp/http.js +32 -19
- package/lib/module/mcp/workspaceServer.js +20 -3
- package/lib/module/tool/filesystemExecutor.d.ts +18 -0
- package/lib/module/tool/filesystemExecutor.js +49 -0
- package/lib/module/tool/globalExecutor.d.ts +17 -0
- package/lib/module/tool/globalExecutor.js +39 -0
- package/lib/module/tool/globalFilesystemExecutor.d.ts +18 -0
- package/lib/module/tool/globalFilesystemExecutor.js +49 -0
- package/lib/module/tool/workspaceExecutor.d.ts +9 -0
- package/lib/module/tool/workspaceExecutor.js +16 -3
- package/lib/naming/aliases.d.ts +48 -0
- package/lib/naming/aliases.js +79 -0
- package/lib/naming/catalog.d.ts +117 -0
- package/lib/naming/catalog.js +108 -0
- package/lib/naming/grammar.d.ts +67 -0
- package/lib/naming/grammar.js +212 -0
- package/lib/naming/ids.d.ts +157 -0
- package/lib/naming/ids.js +119 -0
- package/lib/naming/index.d.ts +13 -0
- package/lib/naming/index.js +13 -0
- package/lib/outline/index.d.ts +9 -0
- package/lib/outline/index.js +8 -0
- package/lib/outline/office.d.ts +160 -0
- package/lib/outline/office.js +2375 -0
- package/lib/outline/officeBridge.d.ts +32 -0
- package/lib/outline/officeBridge.js +27 -0
- package/lib/outline/outline.d.ts +159 -0
- package/lib/outline/outline.js +837 -0
- package/lib/outline/outlineIndex.d.ts +97 -0
- package/lib/outline/outlineIndex.js +325 -0
- package/lib/outline/outlineKeywords.d.ts +59 -0
- package/lib/outline/outlineKeywords.js +143 -0
- package/lib/outline/outlineStrategies.d.ts +414 -0
- package/lib/outline/outlineStrategies.js +8324 -0
- package/lib/outline/reactOutline.d.ts +37 -0
- package/lib/outline/reactOutline.js +1070 -0
- package/lib/outline/shellOutline.d.ts +65 -0
- package/lib/outline/shellOutline.js +873 -0
- package/lib/outline/sqlOutline.d.ts +170 -0
- package/lib/outline/sqlOutline.js +1536 -0
- package/lib/outline/strategy.d.ts +46 -0
- package/lib/outline/strategy.js +1 -0
- package/lib/outline/types.d.ts +95 -0
- package/lib/outline/types.js +1 -0
- package/lib/outline/visualBasicOutline.d.ts +27 -0
- package/lib/outline/visualBasicOutline.js +750 -0
- package/lib/protocol/filesystem.d.ts +55 -0
- package/lib/protocol/filesystem.js +105 -0
- package/lib/protocol/global.d.ts +42 -0
- package/lib/protocol/global.js +63 -0
- package/lib/protocol/globalFilesystem.d.ts +40 -0
- package/lib/protocol/globalFilesystem.js +59 -0
- package/lib/protocol/index.d.ts +4 -0
- package/lib/protocol/index.js +4 -0
- package/lib/protocol/protocol.d.ts +4 -0
- package/lib/protocol/wire.js +5 -2
- package/lib/protocol/workspace.d.ts +305 -0
- package/lib/protocol/workspace.js +258 -0
- package/lib/receipt/receipt.d.ts +8 -0
- package/lib/registry/content.js +9 -3
- package/lib/runtime/kernelRuntime.js +9 -1
- package/lib/scenario/scenario.js +5 -4
- package/lib/semantic/canonical.d.ts +61 -0
- package/lib/semantic/canonical.js +135 -8
- package/lib/semantic/jsonValue.d.ts +31 -0
- package/lib/semantic/jsonValue.js +122 -0
- package/lib/semantic/sha256.js +3 -0
- package/lib/semantic/time.d.ts +14 -0
- package/lib/semantic/time.js +56 -0
- package/lib/session/context.d.ts +76 -0
- package/lib/session/context.js +419 -0
- package/lib/session/errors.d.ts +24 -0
- package/lib/session/errors.js +22 -0
- package/lib/session/identity.d.ts +24 -0
- package/lib/session/identity.js +56 -0
- package/lib/session/index.d.ts +14 -0
- package/lib/session/index.js +12 -0
- package/lib/session/registry.d.ts +130 -0
- package/lib/session/registry.js +908 -0
- package/lib/session/types.d.ts +227 -0
- package/lib/session/types.js +14 -0
- package/lib/structure/index.d.ts +1 -0
- package/lib/structure/index.js +1 -0
- package/lib/structure/trie.d.ts +88 -0
- package/lib/structure/trie.js +183 -0
- package/lib/syntax/byteIndex.d.ts +44 -0
- package/lib/syntax/byteIndex.js +148 -0
- package/lib/syntax/charset.d.ts +88 -0
- package/lib/syntax/charset.js +276 -0
- package/lib/syntax/index.d.ts +6 -0
- package/lib/syntax/index.js +5 -0
- package/lib/syntax/syntaxRegistry.d.ts +150 -0
- package/lib/syntax/syntaxRegistry.js +314 -0
- package/lib/syntax/syntaxTree.d.ts +106 -0
- package/lib/syntax/syntaxTree.js +668 -0
- package/lib/syntax/types.d.ts +15 -0
- package/lib/syntax/types.js +1 -0
- package/lib/types/common.d.ts +1 -1
- package/package.json +72 -193
- package/.editorconfig +0 -12
- package/.prettierignore +0 -17
- package/MCP-Token/347/250/216/344/270/216/344/270/213/344/270/200/344/273/243/345/267/245/345/205/267/345/215/217/350/256/256.html +0 -1763
- package/docs/annotation-campaign-A.csv +0 -54
- package/docs/annotation-campaign-B.csv +0 -54
- package/docs/annotation-campaign.csv +0 -54
- package/docs/eval/annotations-A.jsonl +0 -16
- package/docs/eval/annotations.json +0 -122
- package/docs/eval/recorded-labels.json +0 -12
- package/docs/eval/replay-cases.json +0 -14
- package/docs/eval/replay-labels-b.json +0 -14
- package/docs/examples/attention-request.json +0 -16
- package/docs/examples/checkpoint.json +0 -15
- package/docs/examples/claim.json +0 -66
- package/docs/examples/collaboration.json +0 -66
- package/docs/examples/concept-checkpoint.json +0 -15
- package/docs/examples/concept-prune-plan.json +0 -45
- package/docs/examples/federation.json +0 -126
- package/docs/examples/frame-chain.json +0 -77
- package/docs/examples/ledger-snapshot.json +0 -108
- package/docs/examples/manifest.json +0 -77
- package/docs/examples/message.json +0 -19
- package/docs/examples/other-model.json +0 -45
- package/docs/examples/plan.json +0 -50
- package/docs/examples/prune-plan.json +0 -48
- package/docs/examples/receipt.json +0 -22
- package/docs/examples/runtime-run.json +0 -573
- package/docs/examples/team.json +0 -66
- package/docs/examples/verb-note.json +0 -11
- package/docs/probes/bayes-scores.json +0 -1452
- package/docs/probes/calibration-imported.json +0 -141
- package/docs/probes/context-ast-deepseek.json +0 -1577
- package/docs/probes/deepseek-probe.json +0 -917
- package/docs/probes/eval-recorded-replay.json +0 -597
- package/docs/probes/eval-replay.json +0 -124
- package/docs/probes/eval-summary.json +0 -42
- package/docs/probes/runtime-eval.json +0 -4230
- package/docs/schemas/collaboration.schema.json +0 -73
- package/docs/schemas/common.schema.json +0 -125
- package/docs/schemas/compaction.schema.json +0 -121
- package/docs/schemas/concept-compaction.schema.json +0 -73
- package/docs/schemas/concept.schema.json +0 -97
- package/docs/schemas/epistemic.schema.json +0 -178
- package/docs/schemas/federation.schema.json +0 -66
- package/docs/schemas/frame.schema.json +0 -86
- package/docs/schemas/ledger-snapshot.schema.json +0 -30
- package/docs/schemas/manifest.schema.json +0 -169
- package/docs/schemas/message.schema.json +0 -41
- package/docs/schemas/plan.schema.json +0 -189
- package/docs/schemas/receipt.schema.json +0 -45
- package/docs/schemas/social.schema.json +0 -153
- package/docs/schemas/team.schema.json +0 -56
- package/docs/schemas/verb.schema.json +0 -120
- package/eslint.config.mts +0 -96
- package/index.html +0 -13
- package/lib/context/workspaceProtocol.d.ts +0 -30
- package/lib/context/workspaceProtocol.js +0 -49
- package/prettier.config.mts +0 -37
- package/public/favicon.svg +0 -1
- package/public/icons.svg +0 -24
- package/src/attention/attention.ts +0 -347
- package/src/attention/budget.ts +0 -72
- package/src/attention/cognition.ts +0 -519
- package/src/attention/index.ts +0 -8
- package/src/attention/interrupts.ts +0 -228
- package/src/attention/resource.ts +0 -316
- package/src/attention/social.ts +0 -217
- package/src/attention/socialTypes.ts +0 -115
- package/src/authz/authz.ts +0 -305
- package/src/authz/index.ts +0 -1
- package/src/bayes/calibration.ts +0 -204
- package/src/bayes/calibrationRegistry.ts +0 -111
- package/src/bayes/calibrationSelection.ts +0 -154
- package/src/bayes/engine.ts +0 -532
- package/src/bayes/index.ts +0 -6
- package/src/bayes/reliability.ts +0 -62
- package/src/bayes/scopedPriors.ts +0 -88
- package/src/boundary/frame.ts +0 -322
- package/src/boundary/ids.ts +0 -14
- package/src/boundary/index.ts +0 -12
- package/src/boundary/refTable.ts +0 -125
- package/src/boundary/toolCall.ts +0 -212
- package/src/concept/concept.ts +0 -75
- package/src/concept/conceptBudget.ts +0 -346
- package/src/concept/conceptBudgetTypes.ts +0 -79
- package/src/concept/index.ts +0 -3
- package/src/concurrency/idempotency.ts +0 -41
- package/src/concurrency/index.ts +0 -5
- package/src/concurrency/mutex.ts +0 -26
- package/src/concurrency/namedLocks.ts +0 -35
- package/src/concurrency/retry.ts +0 -50
- package/src/concurrency/worker.ts +0 -128
- package/src/context/agentContext.ts +0 -308
- package/src/context/ast.ts +0 -499
- package/src/context/contentStore.ts +0 -75
- package/src/context/context.ts +0 -65
- package/src/context/contextIndex.ts +0 -85
- package/src/context/document.ts +0 -137
- package/src/context/fileStorePath.ts +0 -14
- package/src/context/index.ts +0 -43
- package/src/context/lifecycle.ts +0 -221
- package/src/context/projections.ts +0 -151
- package/src/context/workspace.ts +0 -422
- package/src/context/workspaceProtocol.ts +0 -112
- package/src/context/workspaceService.ts +0 -423
- package/src/cooperation/board.ts +0 -104
- package/src/cooperation/collaboration.ts +0 -60
- package/src/cooperation/index.ts +0 -6
- package/src/cooperation/merge.ts +0 -190
- package/src/cooperation/metrics.ts +0 -57
- package/src/cooperation/session.ts +0 -131
- package/src/cooperation/unified.ts +0 -56
- package/src/counter.ts +0 -9
- package/src/database/adapter/adapters.ts +0 -35
- package/src/database/adapter/index.ts +0 -4
- package/src/database/adapter/runtimeSink.ts +0 -74
- package/src/database/adapter/sessionStore.ts +0 -32
- package/src/database/adapter/turnStore.ts +0 -23
- package/src/database/entity/agent.ts +0 -199
- package/src/database/entity/entity.ts +0 -1046
- package/src/database/entity/handle.ts +0 -79
- package/src/database/entity/index.ts +0 -32
- package/src/database/entity/message.ts +0 -74
- package/src/database/entity/meta.ts +0 -11
- package/src/database/entity/object.ts +0 -42
- package/src/database/entity/outbox.ts +0 -15
- package/src/database/entity/process.ts +0 -65
- package/src/database/entity/registry.ts +0 -155
- package/src/database/entity/runtimeApproval.ts +0 -30
- package/src/database/entity/runtimeSession.ts +0 -13
- package/src/database/entity/runtimeTurn.ts +0 -15
- package/src/database/entity/thread.ts +0 -85
- package/src/database/entity/window.ts +0 -85
- package/src/database/entity/worker.ts +0 -90
- package/src/database/index.ts +0 -6
- package/src/database/repository/addressSpaceRepository.ts +0 -72
- package/src/database/repository/agentRepository.ts +0 -460
- package/src/database/repository/base.ts +0 -41
- package/src/database/repository/executionRepository.ts +0 -477
- package/src/database/repository/handleRepository.ts +0 -64
- package/src/database/repository/index.ts +0 -20
- package/src/database/repository/messageRepository.ts +0 -52
- package/src/database/repository/objectRepository.ts +0 -69
- package/src/database/repository/outboxRepository.ts +0 -63
- package/src/database/repository/processRepository.ts +0 -58
- package/src/database/repository/registryRepository.ts +0 -119
- package/src/database/repository/repository.ts +0 -491
- package/src/database/repository/runtimeApprovalRepository.ts +0 -44
- package/src/database/repository/runtimeSessionRepository.ts +0 -27
- package/src/database/repository/runtimeTurnRepository.ts +0 -39
- package/src/database/repository/socialRepository.ts +0 -185
- package/src/database/repository/threadRepository.ts +0 -57
- package/src/database/repository/windowRepository.ts +0 -88
- package/src/database/repository/workerRepository.ts +0 -69
- package/src/database/service/database.ts +0 -90
- package/src/database/service/handleService.ts +0 -48
- package/src/database/service/index.ts +0 -16
- package/src/database/service/messageService.ts +0 -61
- package/src/database/service/objectService.ts +0 -59
- package/src/database/service/processService.ts +0 -61
- package/src/database/service/registryServices.ts +0 -88
- package/src/database/service/service.ts +0 -183
- package/src/database/service/stepService.ts +0 -53
- package/src/database/service/threadService.ts +0 -65
- package/src/database/service/windowService.ts +0 -30
- package/src/database/service/workerService.ts +0 -57
- package/src/database/sql/index.ts +0 -3
- package/src/database/sql/schema.ts +0 -418
- package/src/database/sql/sql.ts +0 -543
- package/src/database/store/database.ts +0 -210
- package/src/database/store/index.ts +0 -3
- package/src/database/store/store.ts +0 -266
- package/src/delegate/index.ts +0 -2
- package/src/delegate/team.ts +0 -268
- package/src/delegate/teamTypes.ts +0 -47
- package/src/diagnosis/checklist.ts +0 -74
- package/src/diagnosis/context.ts +0 -93
- package/src/diagnosis/frame.ts +0 -256
- package/src/diagnosis/index.ts +0 -5
- package/src/diagnosis/router.ts +0 -72
- package/src/diagnosis/types.ts +0 -89
- package/src/error/agentError.ts +0 -16
- package/src/error/ampError.ts +0 -20
- package/src/error/authzError.ts +0 -14
- package/src/error/boundaryRejection.ts +0 -20
- package/src/error/index.ts +0 -7
- package/src/error/kernelError.ts +0 -27
- package/src/error/mailboxError.ts +0 -9
- package/src/error/windowError.ts +0 -12
- package/src/evaluation/agreement.ts +0 -96
- package/src/evaluation/index.ts +0 -2
- package/src/evaluation/labels.ts +0 -241
- package/src/evidence/evidenceGraph.ts +0 -205
- package/src/evidence/index.ts +0 -4
- package/src/evidence/revalidation.ts +0 -191
- package/src/execution/exec.ts +0 -408
- package/src/execution/handles.ts +0 -65
- package/src/execution/index.ts +0 -3
- package/src/execution/pin.ts +0 -154
- package/src/frame/frame.ts +0 -70
- package/src/frame/index.ts +0 -1
- package/src/goal/goal.ts +0 -43
- package/src/goal/index.ts +0 -2
- package/src/goal/plan.ts +0 -196
- package/src/governance/attentionManifest.ts +0 -802
- package/src/governance/audit.ts +0 -362
- package/src/governance/budget.ts +0 -628
- package/src/governance/context.ts +0 -356
- package/src/governance/control.ts +0 -159
- package/src/governance/cooperation.ts +0 -479
- package/src/governance/credential.ts +0 -359
- package/src/governance/httpServer.ts +0 -99
- package/src/governance/index.ts +0 -32
- package/src/governance/legal.ts +0 -574
- package/src/governance/matrix.ts +0 -460
- package/src/governance/perspectives.ts +0 -406
- package/src/governance/signing.ts +0 -407
- package/src/governance/store.ts +0 -125
- package/src/governance/switching.ts +0 -459
- package/src/governance/toolPolicy.ts +0 -80
- package/src/governance/transport.ts +0 -204
- package/src/governance/types.ts +0 -380
- package/src/governance/workflow.ts +0 -743
- package/src/index.ts +0 -11
- package/src/interaction/index.ts +0 -1
- package/src/interaction/interaction.ts +0 -391
- package/src/ipc/index.ts +0 -4
- package/src/ipc/mailbox.ts +0 -132
- package/src/ipc/memorySocialStore.ts +0 -93
- package/src/ipc/social.ts +0 -93
- package/src/kernel/index.ts +0 -14
- package/src/kernel/scheduler.ts +0 -498
- package/src/ledger/checkpoint.ts +0 -304
- package/src/ledger/index.ts +0 -4
- package/src/ledger/ledger.ts +0 -31
- package/src/ledger/persistence.ts +0 -159
- package/src/ledger/share.ts +0 -80
- package/src/lock/index.ts +0 -2
- package/src/lock/lease.ts +0 -74
- package/src/main.ts +0 -199
- package/src/manifest/agentCard.ts +0 -72
- package/src/manifest/cardSign.ts +0 -87
- package/src/manifest/federation.ts +0 -237
- package/src/manifest/federationTypes.ts +0 -55
- package/src/manifest/index.ts +0 -8
- package/src/manifest/keys.ts +0 -643
- package/src/manifest/manifest.ts +0 -114
- package/src/manifest/sign.ts +0 -134
- package/src/manifest/trust.ts +0 -146
- package/src/mission/index.ts +0 -2
- package/src/mission/missionQueue.ts +0 -75
- package/src/module/index.ts +0 -9
- package/src/module/llm/deepseek.ts +0 -214
- package/src/module/llm/llm.ts +0 -84
- package/src/module/mcp/client.ts +0 -110
- package/src/module/mcp/http.ts +0 -102
- package/src/module/mcp/protocol.ts +0 -77
- package/src/module/mcp/server.ts +0 -148
- package/src/module/mcp/transport.ts +0 -30
- package/src/module/mcp/workspaceServer.ts +0 -111
- package/src/module/sandbox/sandbox.ts +0 -29
- package/src/module/tool/mcpExecutor.ts +0 -54
- package/src/module/tool/policy.ts +0 -52
- package/src/module/tool/redact.ts +0 -29
- package/src/module/tool/tool.ts +0 -53
- package/src/module/tool/workspaceExecutor.ts +0 -35
- package/src/policy/guard.ts +0 -240
- package/src/policy/index.ts +0 -2
- package/src/policy/policy.ts +0 -561
- package/src/process/agent.ts +0 -341
- package/src/process/agentService.ts +0 -236
- package/src/process/agentStore.ts +0 -378
- package/src/process/executionStore.ts +0 -151
- package/src/process/index.ts +0 -5
- package/src/process/process.ts +0 -240
- package/src/process/transitions.ts +0 -19
- package/src/progress/index.ts +0 -2
- package/src/progress/progress.ts +0 -85
- package/src/protocol/a2a.ts +0 -120
- package/src/protocol/channel.ts +0 -44
- package/src/protocol/envelope.ts +0 -655
- package/src/protocol/httpChannel.ts +0 -87
- package/src/protocol/index.ts +0 -6
- package/src/protocol/protocol.ts +0 -138
- package/src/protocol/wire.ts +0 -60
- package/src/receipt/index.ts +0 -1
- package/src/receipt/receipt.ts +0 -47
- package/src/registry/content.ts +0 -69
- package/src/registry/index.ts +0 -23
- package/src/registry/registry.ts +0 -599
- package/src/runtime/action.ts +0 -87
- package/src/runtime/behavior.ts +0 -330
- package/src/runtime/behaviorTuning.ts +0 -163
- package/src/runtime/cognitiveRuntime.ts +0 -703
- package/src/runtime/escalation.ts +0 -35
- package/src/runtime/governedTask.ts +0 -233
- package/src/runtime/index.ts +0 -15
- package/src/runtime/kernelRuntime.ts +0 -144
- package/src/runtime/operation.ts +0 -35
- package/src/runtime/replay.ts +0 -71
- package/src/runtime/routing.ts +0 -58
- package/src/runtime/safety.ts +0 -48
- package/src/runtime/session.ts +0 -341
- package/src/runtime/sessionStore.ts +0 -43
- package/src/runtime/telemetry.ts +0 -55
- package/src/runtime/turnStore.ts +0 -30
- package/src/scenario/index.ts +0 -1
- package/src/scenario/scenario.ts +0 -299
- package/src/semantic/canonical.ts +0 -24
- package/src/semantic/index.ts +0 -2
- package/src/semantic/sha256.ts +0 -82
- package/src/storage/appendLog.ts +0 -372
- package/src/storage/fileAppendSink.ts +0 -40
- package/src/storage/index.ts +0 -2
- package/src/store/bindCache.ts +0 -22
- package/src/store/cache.ts +0 -191
- package/src/store/context.ts +0 -31
- package/src/store/handleStore.ts +0 -31
- package/src/store/index.ts +0 -9
- package/src/store/messageStore.ts +0 -31
- package/src/store/objectStore.ts +0 -31
- package/src/store/processStore.ts +0 -31
- package/src/store/threadStore.ts +0 -31
- package/src/store/windowStore.ts +0 -31
- package/src/structure/abstractSyntaxTree.ts +0 -493
- package/src/structure/avlTree.ts +0 -408
- package/src/structure/binarySearchTree.ts +0 -352
- package/src/structure/binaryTree.ts +0 -525
- package/src/structure/bloomFilter.ts +0 -231
- package/src/structure/compare.ts +0 -110
- package/src/structure/cuckooFilter.ts +0 -337
- package/src/structure/deque.ts +0 -223
- package/src/structure/filterKey.ts +0 -36
- package/src/structure/hash.ts +0 -279
- package/src/structure/heap.ts +0 -268
- package/src/structure/index.ts +0 -20
- package/src/structure/iterator.ts +0 -22
- package/src/structure/lru.ts +0 -619
- package/src/structure/ordered.ts +0 -399
- package/src/structure/priority.ts +0 -915
- package/src/structure/queue.ts +0 -168
- package/src/structure/redBlackTree.ts +0 -680
- package/src/structure/segmentTree.ts +0 -248
- package/src/structure/stack.ts +0 -118
- package/src/structure/unordered.ts +0 -407
- package/src/style.css +0 -278
- package/src/thread/index.ts +0 -2
- package/src/thread/thread.ts +0 -176
- package/src/thread/transitions.ts +0 -17
- package/src/types/common.ts +0 -119
- package/src/types/index.ts +0 -23
- package/src/warrant/epistemic.ts +0 -154
- package/src/warrant/index.ts +0 -3
- package/src/warrant/inquiry.ts +0 -166
- package/src/warrant/warrant.ts +0 -179
- package/src/window/compaction.ts +0 -403
- package/src/window/compactionTypes.ts +0 -119
- package/src/window/index.ts +0 -7
- package/src/window/page.ts +0 -18
- package/src/window/window.ts +0 -244
- package/tools/_helpers.ts +0 -34
- package/tools/a2a-check.ts +0 -110
- package/tools/a2a-flow-check.ts +0 -78
- package/tools/agent-card-check.ts +0 -76
- package/tools/agent-check.ts +0 -236
- package/tools/agent-store-check.ts +0 -153
- package/tools/agreement-check.ts +0 -27
- package/tools/annotation-server-check.ts +0 -48
- package/tools/annotation-server.ts +0 -230
- package/tools/annotation-status.ts +0 -65
- package/tools/approval-access-check.ts +0 -66
- package/tools/arch-check.ts +0 -72
- package/tools/attention-core-check.ts +0 -48
- package/tools/attention-resource-check.ts +0 -169
- package/tools/audit-check.ts +0 -207
- package/tools/authority-check.ts +0 -124
- package/tools/authz-check.ts +0 -138
- package/tools/bayes-check.ts +0 -162
- package/tools/bayes-probe.ts +0 -154
- package/tools/behavior-tuning-check.ts +0 -53
- package/tools/board-check.ts +0 -87
- package/tools/boundary-check.ts +0 -199
- package/tools/bundle-trust-check.ts +0 -96
- package/tools/calibrate-imported.ts +0 -108
- package/tools/calibration-check.ts +0 -44
- package/tools/calibration-registry-check.ts +0 -40
- package/tools/calibration-sim.ts +0 -40
- package/tools/card-sign-check.ts +0 -71
- package/tools/card-trust-check.ts +0 -78
- package/tools/channel-check.ts +0 -86
- package/tools/checkpoint-check.ts +0 -620
- package/tools/cleanup-style-configs.ts +0 -29
- package/tools/cognition-check.ts +0 -648
- package/tools/cognitive-runtime-check.ts +0 -609
- package/tools/collaboration-demo.ts +0 -78
- package/tools/compaction-check.ts +0 -266
- package/tools/concept-check.ts +0 -260
- package/tools/concurrency-check.ts +0 -242
- package/tools/conformance-runtime.ts +0 -389
- package/tools/conformance.ts +0 -651
- package/tools/context-ast-check.ts +0 -90
- package/tools/context-ast-deepseek.ts +0 -242
- package/tools/context-graph-bench.ts +0 -50
- package/tools/context-graph-check.ts +0 -229
- package/tools/context-index-check.ts +0 -48
- package/tools/context-lifecycle-check.ts +0 -69
- package/tools/context-projection-check.ts +0 -73
- package/tools/context-scope-check.ts +0 -134
- package/tools/context-storage-check.ts +0 -113
- package/tools/cooperation-check.ts +0 -517
- package/tools/cooperation-http-check.ts +0 -125
- package/tools/deepseek-llm-check.ts +0 -147
- package/tools/deepseek-probe.ts +0 -494
- package/tools/diagnosis-check.ts +0 -109
- package/tools/diagnosis-router-check.ts +0 -50
- package/tools/document-context-check.ts +0 -237
- package/tools/envelope-check.ts +0 -659
- package/tools/eslint-rules/index.ts +0 -26
- package/tools/eslint-rules/rules/jsdoc-comment-format.ts +0 -105
- package/tools/eslint-rules/rules/no-function-keyword.ts +0 -60
- package/tools/eslint-rules/rules/no-multiline-parameters.ts +0 -71
- package/tools/eslint-rules/rules/no-multiline-type-parameters.ts +0 -57
- package/tools/eslint-rules/rules/no-undefined-comparison.ts +0 -115
- package/tools/eslint-rules/rules/prefer-template-for-string-conversion.ts +0 -97
- package/tools/eslint-rules/rules/require-typeof-parentheses.ts +0 -49
- package/tools/eslint-rules/rules/require-variable-type.ts +0 -36
- package/tools/eslint-rules/rules/variable-naming.ts +0 -175
- package/tools/eval-recorded-replay.ts +0 -215
- package/tools/eval-replay.ts +0 -139
- package/tools/eval-summary.ts +0 -136
- package/tools/evidence-revalidation-check.ts +0 -235
- package/tools/exec-check.ts +0 -217
- package/tools/federation-check.ts +0 -166
- package/tools/federation-demo.ts +0 -45
- package/tools/filter-check.ts +0 -243
- package/tools/governance-check.ts +0 -680
- package/tools/governance-store-check.ts +0 -131
- package/tools/governed-task-check.ts +0 -227
- package/tools/guard-check.ts +0 -122
- package/tools/http-channel-check.ts +0 -125
- package/tools/import-campaign.ts +0 -28
- package/tools/inquiry-check.ts +0 -126
- package/tools/interaction-check.ts +0 -171
- package/tools/interrupts-check.ts +0 -173
- package/tools/ipc-check.ts +0 -170
- package/tools/kernel-async-check.ts +0 -136
- package/tools/kernel-check.ts +0 -369
- package/tools/kernel-runtime-check.ts +0 -276
- package/tools/keys-check.ts +0 -559
- package/tools/label-audit.ts +0 -70
- package/tools/labels-workflow-check.ts +0 -49
- package/tools/linear-structure-check.ts +0 -524
- package/tools/live-exec.ts +0 -62
- package/tools/live-governance-eval.ts +0 -813
- package/tools/live-legacy.ts +0 -50
- package/tools/lru-check.ts +0 -182
- package/tools/make-annotation-campaign.ts +0 -57
- package/tools/mcp-executor-check.ts +0 -33
- package/tools/merge-annotations.ts +0 -32
- package/tools/merge-check.ts +0 -98
- package/tools/metrics-check.ts +0 -84
- package/tools/net-probe.ts +0 -107
- package/tools/oauth-probe.ts +0 -117
- package/tools/outbox-check.ts +0 -50
- package/tools/persistence-check.ts +0 -144
- package/tools/pin-check.ts +0 -116
- package/tools/platform-check.ts +0 -281
- package/tools/policy-check.ts +0 -514
- package/tools/prettier-plugin/index.mts +0 -84
- package/tools/priority-check.ts +0 -627
- package/tools/probe-context7.ts +0 -63
- package/tools/registry-check.ts +0 -252
- package/tools/reliability-check.ts +0 -25
- package/tools/retry-check.ts +0 -85
- package/tools/rewrite-declaration-extensions.ts +0 -98
- package/tools/runtime-check.ts +0 -165
- package/tools/runtime-deepseek-check.ts +0 -85
- package/tools/runtime-eval.ts +0 -358
- package/tools/scenario-check.ts +0 -161
- package/tools/scenario-incident.ts +0 -162
- package/tools/scoped-priors-check.ts +0 -35
- package/tools/scoped-priors-pooling.ts +0 -34
- package/tools/segment-ast-check.ts +0 -649
- package/tools/session-check.ts +0 -196
- package/tools/session-store-check.ts +0 -73
- package/tools/share-check.ts +0 -88
- package/tools/sign-check.ts +0 -95
- package/tools/signing-check.ts +0 -275
- package/tools/snapshot-demo.ts +0 -65
- package/tools/social-check.ts +0 -146
- package/tools/structure-compare-check.ts +0 -95
- package/tools/support/documentScanner.ts +0 -577
- package/tools/support/texScanner.ts +0 -631
- package/tools/support/workspaceScanner.ts +0 -476
- package/tools/team-check.ts +0 -163
- package/tools/team-demo.ts +0 -36
- package/tools/telemetry-check.ts +0 -44
- package/tools/tex-context-check.ts +0 -263
- package/tools/tool-gate-check.ts +0 -98
- package/tools/tree-structure-check.ts +0 -786
- package/tools/trust-flow-check.ts +0 -158
- package/tools/turn-store-check.ts +0 -57
- package/tools/unified-check.ts +0 -83
- package/tools/validate.ts +0 -309
- package/tools/wire-check.ts +0 -96
- package/tools/workspace-agent-check.ts +0 -486
- package/tools/workspace-agent-demo.ts +0 -62
- package/tools/workspace-agent-server.ts +0 -101
- package/tools/workspace-context-check.ts +0 -331
- package/tools/workspace-context.ts +0 -131
- package/tsconfig.build.json +0 -14
- package/tsconfig.json +0 -24
- package/tsconfig.tools.json +0 -31
- package/viz/context-ast.json +0 -1577
|
@@ -2,12 +2,47 @@
|
|
|
2
2
|
* One trusted host scope per service instance. Agent calls cannot register
|
|
3
3
|
* Frames, supply snapshots, read arbitrary hashes or expand project scope.
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
5
|
+
import { randomUUID } from "node:crypto";
|
|
6
|
+
import { posix } from "node:path";
|
|
6
7
|
import { parseToolCall } from "../boundary/toolCall.js";
|
|
7
8
|
import { BoundaryRejection } from "../error/boundaryRejection.js";
|
|
9
|
+
import { parseShort, rawTextDigest } from "../fingerprint/index.js";
|
|
10
|
+
import { HostCatalog } from "../discover/host.js";
|
|
11
|
+
import { buildDiscoveryTree } from "../discover/tree.js";
|
|
12
|
+
import { buildCatalog, deprecatedToolAliases, resolveToolName, ToolIds } from "../naming/index.js";
|
|
13
|
+
import { WorkspaceProtocol, WorkspaceProtocolVersion, WorkspaceServiceId, workspaceToolDefinitions, workspaceToolLeaves } from "../protocol/workspace.js";
|
|
14
|
+
import { digestOf } from "../semantic/canonical.js";
|
|
8
15
|
import { estimateTokens } from "./agentContext.js";
|
|
9
16
|
import { WorkspaceIndex } from "./workspace.js";
|
|
10
|
-
import {
|
|
17
|
+
import { applyByteChanges, applyLineChanges, summarizeDiff } from "./workspaceDiff.js";
|
|
18
|
+
import { WorkspaceDiffError } from "./workspaceDiff.js";
|
|
19
|
+
/**
|
|
20
|
+
* Discriminant guard.
|
|
21
|
+
*
|
|
22
|
+
* A type predicate is used instead of `if (!outcome.ok)` because the tools
|
|
23
|
+
* TypeScript project runs with `strictNullChecks: false`, where truthiness of a
|
|
24
|
+
* literal discriminant does not narrow the union.
|
|
25
|
+
*/
|
|
26
|
+
const writeRejected = (outcome) => outcome.ok === false;
|
|
27
|
+
const runRejected = (outcome) => outcome.ok === false;
|
|
28
|
+
/**
|
|
29
|
+
* Keys a reactive Proxy exposes. `toJSON` is not listed because it is the
|
|
30
|
+
* serialization hook rather than tree data.
|
|
31
|
+
*/
|
|
32
|
+
const ReactiveKeys = [
|
|
33
|
+
"id",
|
|
34
|
+
"kind",
|
|
35
|
+
"label",
|
|
36
|
+
"summary",
|
|
37
|
+
"tags",
|
|
38
|
+
"path",
|
|
39
|
+
"structureKind",
|
|
40
|
+
"startLine",
|
|
41
|
+
"endLine",
|
|
42
|
+
"revision",
|
|
43
|
+
"childCount",
|
|
44
|
+
"children",
|
|
45
|
+
];
|
|
11
46
|
const Defaults = {
|
|
12
47
|
maxFrames: 128,
|
|
13
48
|
maxContexts: 32,
|
|
@@ -15,7 +50,404 @@ const Defaults = {
|
|
|
15
50
|
maxReadChars: 8000,
|
|
16
51
|
maxResponseChars: 131072,
|
|
17
52
|
maxToolCalls: 1000,
|
|
53
|
+
maxWriteChars: 1024 * 1024,
|
|
54
|
+
maxFileLinks: 50,
|
|
55
|
+
maxRunOutputChars: 16 * 1024,
|
|
56
|
+
};
|
|
57
|
+
const MaxReadLines = 2000;
|
|
58
|
+
const DefaultReadLines = 200;
|
|
59
|
+
const MaxPageBytes = 262144;
|
|
60
|
+
const LineFeed = 10;
|
|
61
|
+
const ContinuationMask = 0xc0;
|
|
62
|
+
const ContinuationByte = 0x80;
|
|
63
|
+
/**
|
|
64
|
+
* 0-based UTF-16 offsets at which each line starts. An empty string has no
|
|
65
|
+
* lines, and a trailing newline does not create a final empty line, which is
|
|
66
|
+
* the same counting rule the filesystem read tool reports.
|
|
67
|
+
*/
|
|
68
|
+
const lineStartsOf = (text) => {
|
|
69
|
+
if (text.length === 0) {
|
|
70
|
+
return [];
|
|
71
|
+
}
|
|
72
|
+
const starts = [0];
|
|
73
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
74
|
+
if (text.charCodeAt(index) === LineFeed && index + 1 < text.length) {
|
|
75
|
+
starts.push(index + 1);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return starts;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Largest line index whose start is at or before `position` (0-based).
|
|
82
|
+
*/
|
|
83
|
+
const lineIndexOf = (starts, position) => {
|
|
84
|
+
let low = 0;
|
|
85
|
+
let high = starts.length - 1;
|
|
86
|
+
let answer = 0;
|
|
87
|
+
while (low <= high) {
|
|
88
|
+
const middle = (low + high) >> 1;
|
|
89
|
+
if (starts[middle] <= position) {
|
|
90
|
+
answer = middle;
|
|
91
|
+
low = middle + 1;
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
high = middle - 1;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return answer;
|
|
98
|
+
};
|
|
99
|
+
const isContinuationByte = (bytes, index) => index < bytes.length && (bytes[index] & ContinuationMask) === ContinuationByte;
|
|
100
|
+
/**
|
|
101
|
+
* Decode the longest prefix of `bytes[start..end)` that ends on a character
|
|
102
|
+
* boundary, and report the byte offset actually consumed.
|
|
103
|
+
*
|
|
104
|
+
* Shrinking costs at most the three continuation bytes of a UTF-8 character, so
|
|
105
|
+
* a page never splits one and the decoder is never left holding invalid input.
|
|
106
|
+
*/
|
|
107
|
+
const decodePage = (bytes, start, end) => {
|
|
108
|
+
for (let adjusted = end; adjusted > start; adjusted -= 1) {
|
|
109
|
+
try {
|
|
110
|
+
return { text: new TextDecoder("utf-8", { fatal: true }).decode(bytes.subarray(start, adjusted)), end: adjusted };
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return { text: "", end: start };
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* Page one detail body by characters (default), 1-based lines or UTF-8 bytes.
|
|
120
|
+
*
|
|
121
|
+
* Exactly one addressing mode may appear in a call; mixing them is rejected
|
|
122
|
+
* instead of silently preferring one, because a caller that sent both offsets
|
|
123
|
+
* has already made an addressing mistake.
|
|
124
|
+
*/
|
|
125
|
+
const readPage = (content, args, maxChars, remainingTokens) => {
|
|
126
|
+
const lines = Object.hasOwn(args, "startLine") || Object.hasOwn(args, "maxLines");
|
|
127
|
+
const bytes = Object.hasOwn(args, "offsetBytes") || Object.hasOwn(args, "maxBytes");
|
|
128
|
+
const chars = Object.hasOwn(args, "offset") || Object.hasOwn(args, "maxChars");
|
|
129
|
+
if ((lines ? 1 : 0) + (bytes ? 1 : 0) + (chars ? 1 : 0) > 1) {
|
|
130
|
+
fail("invalid_arguments");
|
|
131
|
+
}
|
|
132
|
+
const charBudget = Math.min(maxChars, remainingTokens * 4);
|
|
133
|
+
if (bytes) {
|
|
134
|
+
const encoded = new TextEncoder().encode(content);
|
|
135
|
+
const requested = args.offsetBytes ?? 0;
|
|
136
|
+
if (requested > encoded.length) {
|
|
137
|
+
fail("invalid_arguments");
|
|
138
|
+
}
|
|
139
|
+
let start = requested;
|
|
140
|
+
while (start < encoded.length && isContinuationByte(encoded, start)) {
|
|
141
|
+
start += 1;
|
|
142
|
+
}
|
|
143
|
+
const size = Math.min(args.maxBytes ?? charBudget, MaxPageBytes, charBudget);
|
|
144
|
+
const decoded = decodePage(encoded, start, Math.min(encoded.length, start + size));
|
|
145
|
+
let text = decoded.text;
|
|
146
|
+
let consumed = decoded.end;
|
|
147
|
+
/**
|
|
148
|
+
* A byte budget smaller than one character still makes progress: the
|
|
149
|
+
* whole first character is returned (at most four bytes) instead of an
|
|
150
|
+
* empty page that would repeat forever.
|
|
151
|
+
*/
|
|
152
|
+
if (text.length === 0 && start < encoded.length) {
|
|
153
|
+
consumed = start + 1;
|
|
154
|
+
while (consumed < encoded.length && isContinuationByte(encoded, consumed)) {
|
|
155
|
+
consumed += 1;
|
|
156
|
+
}
|
|
157
|
+
text = new TextDecoder("utf-8", { fatal: true }).decode(encoded.subarray(start, consumed));
|
|
158
|
+
}
|
|
159
|
+
const charOffset = new TextDecoder("utf-8").decode(encoded.subarray(0, start)).length;
|
|
160
|
+
return {
|
|
161
|
+
offset: charOffset,
|
|
162
|
+
text,
|
|
163
|
+
nextOffset: consumed < encoded.length ? charOffset + text.length : null,
|
|
164
|
+
fields: {
|
|
165
|
+
offsetBytes: start,
|
|
166
|
+
bytesRead: consumed - start,
|
|
167
|
+
nextOffsetBytes: consumed < encoded.length ? consumed : null,
|
|
168
|
+
totalBytes: encoded.length,
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
if (lines) {
|
|
173
|
+
const starts = lineStartsOf(content);
|
|
174
|
+
const startLine = args.startLine ?? 1;
|
|
175
|
+
if (startLine > starts.length + 1) {
|
|
176
|
+
fail("invalid_arguments");
|
|
177
|
+
}
|
|
178
|
+
const maxLines = Math.min(args.maxLines ?? DefaultReadLines, MaxReadLines);
|
|
179
|
+
const first = startLine - 1;
|
|
180
|
+
let last = Math.min(starts.length, first + maxLines);
|
|
181
|
+
while (last > first && (starts[last] ?? content.length) - (starts[first] ?? content.length) > charBudget) {
|
|
182
|
+
last -= 1;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* A single line larger than the page budget is returned whole rather
|
|
186
|
+
* than split: a split line has no line number to resume from, and the
|
|
187
|
+
* caller can switch to byte mode when it really needs a smaller piece.
|
|
188
|
+
*/
|
|
189
|
+
if (last === first && first < starts.length) {
|
|
190
|
+
last = first + 1;
|
|
191
|
+
}
|
|
192
|
+
const startChar = starts[first] ?? content.length;
|
|
193
|
+
const endChar = last < starts.length ? starts[last] : content.length;
|
|
194
|
+
const text = content.slice(startChar, endChar);
|
|
195
|
+
return {
|
|
196
|
+
offset: startChar,
|
|
197
|
+
text,
|
|
198
|
+
nextOffset: endChar < content.length ? endChar : null,
|
|
199
|
+
fields: {
|
|
200
|
+
startLine,
|
|
201
|
+
endLine: text.length === 0 ? null : lineIndexOf(starts, endChar - 1) + 1,
|
|
202
|
+
nextStartLine: endChar < content.length ? lineIndexOf(starts, endChar) + 1 : null,
|
|
203
|
+
totalLines: starts.length,
|
|
204
|
+
},
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
const offset = args.offset ?? 0;
|
|
208
|
+
if (offset > content.length) {
|
|
209
|
+
fail("invalid_arguments");
|
|
210
|
+
}
|
|
211
|
+
const size = Math.min(args.maxChars ?? maxChars, maxChars, remainingTokens * 4);
|
|
212
|
+
const text = content.slice(offset, offset + size);
|
|
213
|
+
return { offset, text, nextOffset: offset + text.length < content.length ? offset + text.length : null, fields: {} };
|
|
214
|
+
};
|
|
215
|
+
/**
|
|
216
|
+
* Apply a whole-node, line-range or byte-range replacement.
|
|
217
|
+
*
|
|
218
|
+
* Line mode replaces complete lines and keeps the file's line-terminator shape:
|
|
219
|
+
* a replacement that lost its final terminator gets the replaced span's own
|
|
220
|
+
* terminator back, while an empty replacement deletes the lines and their
|
|
221
|
+
* separator. Byte mode splices UTF-8 bytes and refuses an offset that falls
|
|
222
|
+
* inside a character, because the result is still decoded as text.
|
|
223
|
+
*/
|
|
224
|
+
const applyWrite = (current, args) => {
|
|
225
|
+
const lines = Object.hasOwn(args, "startLine") || Object.hasOwn(args, "endLine");
|
|
226
|
+
const bytes = Object.hasOwn(args, "offsetBytes") || Object.hasOwn(args, "endBytes");
|
|
227
|
+
if (lines && bytes) {
|
|
228
|
+
fail("invalid_arguments");
|
|
229
|
+
}
|
|
230
|
+
const replacement = args.content;
|
|
231
|
+
if (!lines && !bytes) {
|
|
232
|
+
return { content: replacement, mode: "node", fields: {} };
|
|
233
|
+
}
|
|
234
|
+
if (lines) {
|
|
235
|
+
const startLine = args.startLine;
|
|
236
|
+
const endLine = args.endLine;
|
|
237
|
+
if (startLine === (void 0) || endLine === (void 0) || startLine < 1 || endLine < startLine) {
|
|
238
|
+
fail("invalid_arguments");
|
|
239
|
+
}
|
|
240
|
+
const starts = lineStartsOf(current);
|
|
241
|
+
if (startLine > starts.length || endLine > starts.length) {
|
|
242
|
+
fail("invalid_arguments");
|
|
243
|
+
}
|
|
244
|
+
const startChar = starts[startLine - 1];
|
|
245
|
+
const endChar = endLine < starts.length ? starts[endLine] : current.length;
|
|
246
|
+
const span = current.slice(startChar, endChar);
|
|
247
|
+
const terminator = span.endsWith("\r\n") ? "\r\n" : span.endsWith("\n") ? "\n" : "";
|
|
248
|
+
const inserted = replacement.length === 0 || terminator.length === 0 || replacement.endsWith("\n") ? replacement : `${replacement}${terminator}`;
|
|
249
|
+
return { content: `${current.slice(0, startChar)}${inserted}${current.slice(endChar)}`, mode: "lines", fields: { startLine, endLine } };
|
|
250
|
+
}
|
|
251
|
+
const offsetBytes = args.offsetBytes;
|
|
252
|
+
const endBytes = args.endBytes;
|
|
253
|
+
if (offsetBytes === (void 0) || endBytes === (void 0) || offsetBytes < 0 || endBytes < offsetBytes) {
|
|
254
|
+
fail("invalid_arguments");
|
|
255
|
+
}
|
|
256
|
+
const encoded = new TextEncoder().encode(current);
|
|
257
|
+
if (endBytes > encoded.length || isContinuationByte(encoded, offsetBytes) || isContinuationByte(encoded, endBytes)) {
|
|
258
|
+
fail("invalid_arguments");
|
|
259
|
+
}
|
|
260
|
+
const insert = new TextEncoder().encode(replacement);
|
|
261
|
+
const spliced = new Uint8Array(offsetBytes + insert.length + (encoded.length - endBytes));
|
|
262
|
+
spliced.set(encoded.subarray(0, offsetBytes), 0);
|
|
263
|
+
spliced.set(insert, offsetBytes);
|
|
264
|
+
spliced.set(encoded.subarray(endBytes), offsetBytes + insert.length);
|
|
265
|
+
try {
|
|
266
|
+
return { content: new TextDecoder("utf-8", { fatal: true }).decode(spliced), mode: "bytes", fields: { offsetBytes, endBytes } };
|
|
267
|
+
}
|
|
268
|
+
catch {
|
|
269
|
+
return fail("invalid_arguments");
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
/**
|
|
273
|
+
* Detection order is specificity order: lockfile-specific package managers
|
|
274
|
+
* before plain npm, real build systems before the auxiliary `Makefile`, so the
|
|
275
|
+
* first match is the primary brand and later matches stay in `detected`.
|
|
276
|
+
*/
|
|
277
|
+
const ProjectBrands = [
|
|
278
|
+
{
|
|
279
|
+
brand: "pnpm",
|
|
280
|
+
language: "typescript/javascript",
|
|
281
|
+
manifests: ["package.json"],
|
|
282
|
+
evidence: ["pnpm-lock.yaml", "pnpm-workspace.yaml"],
|
|
283
|
+
commands: { build: "pnpm run build", compile: "pnpm run compile", run: "pnpm start", test: "pnpm test" },
|
|
284
|
+
},
|
|
285
|
+
{
|
|
286
|
+
brand: "yarn",
|
|
287
|
+
language: "typescript/javascript",
|
|
288
|
+
manifests: ["package.json"],
|
|
289
|
+
evidence: ["yarn.lock"],
|
|
290
|
+
commands: { build: "yarn build", compile: "yarn compile", run: "yarn start", test: "yarn test" },
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
brand: "bun",
|
|
294
|
+
language: "typescript/javascript",
|
|
295
|
+
manifests: ["package.json"],
|
|
296
|
+
evidence: ["bun.lockb", "bun.lock"],
|
|
297
|
+
commands: { build: "bun run build", compile: "bun run compile", run: "bun start", test: "bun test" },
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
brand: "npm",
|
|
301
|
+
language: "typescript/javascript",
|
|
302
|
+
manifests: ["package.json"],
|
|
303
|
+
commands: { build: "npm run build", compile: "npm run compile", run: "npm start", test: "npm test" },
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
brand: "maven",
|
|
307
|
+
language: "java",
|
|
308
|
+
manifests: ["pom.xml"],
|
|
309
|
+
commands: { build: "mvn package -DskipTests", compile: "mvn compile", run: "mvn exec:java", test: "mvn test" },
|
|
310
|
+
},
|
|
311
|
+
{
|
|
312
|
+
brand: "gradle",
|
|
313
|
+
language: "java/kotlin",
|
|
314
|
+
manifests: ["build.gradle", "build.gradle.kts"],
|
|
315
|
+
commands: { build: "gradle build", compile: "gradle compileJava", run: "gradle run", test: "gradle test" },
|
|
316
|
+
},
|
|
317
|
+
{
|
|
318
|
+
brand: "cmake",
|
|
319
|
+
language: "c/c++",
|
|
320
|
+
manifests: ["CMakeLists.txt"],
|
|
321
|
+
commands: { build: "cmake --build build --config Release", compile: "cmake --build build", test: "ctest --test-dir build --output-on-failure" },
|
|
322
|
+
},
|
|
323
|
+
{
|
|
324
|
+
brand: "cargo",
|
|
325
|
+
language: "rust",
|
|
326
|
+
manifests: ["Cargo.toml"],
|
|
327
|
+
commands: { build: "cargo build", compile: "cargo check", run: "cargo run", test: "cargo test" },
|
|
328
|
+
},
|
|
329
|
+
{
|
|
330
|
+
brand: "go",
|
|
331
|
+
language: "go",
|
|
332
|
+
manifests: ["go.mod"],
|
|
333
|
+
commands: { build: "go build ./...", compile: "go vet ./...", run: "go run .", test: "go test ./..." },
|
|
334
|
+
},
|
|
335
|
+
{
|
|
336
|
+
brand: "python",
|
|
337
|
+
language: "python",
|
|
338
|
+
manifests: ["pyproject.toml"],
|
|
339
|
+
commands: { build: "python -m build", compile: "python -m compileall .", test: "python -m pytest -q" },
|
|
340
|
+
},
|
|
341
|
+
{
|
|
342
|
+
brand: "setuptools",
|
|
343
|
+
language: "python",
|
|
344
|
+
manifests: ["setup.py"],
|
|
345
|
+
commands: { build: "python -m build", test: "python -m pytest -q" },
|
|
346
|
+
},
|
|
347
|
+
{
|
|
348
|
+
brand: "composer",
|
|
349
|
+
language: "php",
|
|
350
|
+
manifests: ["composer.json"],
|
|
351
|
+
commands: { build: "composer install --no-interaction", test: "composer test" },
|
|
352
|
+
},
|
|
353
|
+
{
|
|
354
|
+
brand: "dotnet",
|
|
355
|
+
language: "c#/f#",
|
|
356
|
+
manifests: [],
|
|
357
|
+
suffixes: [".sln", ".csproj", ".fsproj", ".vbproj"],
|
|
358
|
+
commands: { build: "dotnet build", compile: "dotnet build", run: "dotnet run", test: "dotnet test" },
|
|
359
|
+
},
|
|
360
|
+
{
|
|
361
|
+
brand: "bundler",
|
|
362
|
+
language: "ruby",
|
|
363
|
+
manifests: ["Gemfile"],
|
|
364
|
+
commands: { build: "bundle install", test: "bundle exec rake test" },
|
|
365
|
+
},
|
|
366
|
+
{
|
|
367
|
+
brand: "swift",
|
|
368
|
+
language: "swift",
|
|
369
|
+
manifests: ["Package.swift"],
|
|
370
|
+
commands: { build: "swift build", compile: "swift build", run: "swift run", test: "swift test" },
|
|
371
|
+
},
|
|
372
|
+
{
|
|
373
|
+
brand: "sbt",
|
|
374
|
+
language: "scala",
|
|
375
|
+
manifests: ["build.sbt"],
|
|
376
|
+
commands: { build: "sbt package", compile: "sbt compile", run: "sbt run", test: "sbt test" },
|
|
377
|
+
},
|
|
378
|
+
{
|
|
379
|
+
brand: "make",
|
|
380
|
+
language: "c/c++",
|
|
381
|
+
manifests: ["Makefile"],
|
|
382
|
+
commands: { build: "make", compile: "make all", run: "make run", test: "make test" },
|
|
383
|
+
},
|
|
384
|
+
];
|
|
385
|
+
const ProjectActionOrder = ["build", "compile", "run", "test"];
|
|
386
|
+
const actionsOf = (commands) => ProjectActionOrder.filter((action) => commands[action] !== (void 0));
|
|
387
|
+
/**
|
|
388
|
+
* Prefer the checked-in wrapper when one exists: a Gradle project that ships
|
|
389
|
+
* `gradlew` is meant to be built through it, not through a host-global Gradle.
|
|
390
|
+
*/
|
|
391
|
+
const commandsOf = (spec, wrapper) => Object.fromEntries(Object.entries(spec.commands).map(([action, command]) => [
|
|
392
|
+
action,
|
|
393
|
+
wrapper && spec.brand === "gradle" ? command.replace(/^gradle\b/, "./gradlew") : command,
|
|
394
|
+
]));
|
|
395
|
+
/**
|
|
396
|
+
* Detect every brand evidenced by one project's files.
|
|
397
|
+
*
|
|
398
|
+
* Inputs are file entities only; the scan is offline and never opens a
|
|
399
|
+
* manifest, so a `pom.xml` that does not parse still proves a Maven layout.
|
|
400
|
+
*/
|
|
401
|
+
const detectBrands = (files) => {
|
|
402
|
+
const sorted = [...files].sort((left, right) => left.source.uri < right.source.uri ? -1 : left.source.uri > right.source.uri ? 1 : 0);
|
|
403
|
+
const names = new Set(sorted.map((file) => posix.basename(file.source.uri)));
|
|
404
|
+
const detected = [];
|
|
405
|
+
ProjectBrands.forEach((spec) => {
|
|
406
|
+
const manifest = spec.suffixes === (void 0)
|
|
407
|
+
? sorted.find((file) => spec.manifests.includes(posix.basename(file.source.uri)))
|
|
408
|
+
: sorted.find((file) => spec.suffixes.some((suffix) => posix.basename(file.source.uri).toLowerCase().endsWith(suffix)));
|
|
409
|
+
if (manifest === (void 0)) {
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
if (spec.evidence !== (void 0) && !spec.evidence.some((name) => names.has(name))) {
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
detected.push({ brand: spec.brand, language: spec.language, manifest, commands: commandsOf(spec, names.has("gradlew")) });
|
|
416
|
+
});
|
|
417
|
+
return detected;
|
|
18
418
|
};
|
|
419
|
+
/**
|
|
420
|
+
* Keep the failing tail of runner output. A build log's useful part is at the
|
|
421
|
+
* end, and the response budget cannot grow with the build.
|
|
422
|
+
*/
|
|
423
|
+
const clipOutput = (text, max) => text === (void 0) ? { text: "", truncated: false } : text.length <= max ? { text, truncated: false } : { text: text.slice(text.length - max), truncated: true };
|
|
424
|
+
/**
|
|
425
|
+
* Structural order: directories before files, then label, then id.
|
|
426
|
+
*/
|
|
427
|
+
const byStructureOrder = (left, right) => (left.kind === right.kind ? 0 : left.kind === "directory" ? -1 : 1) ||
|
|
428
|
+
(left.label < right.label ? -1 : left.label > right.label ? 1 : 0) ||
|
|
429
|
+
(left.id < right.id ? -1 : left.id > right.id ? 1 : 0);
|
|
430
|
+
/**
|
|
431
|
+
* Outline order: start line first so a file's symbols read top to bottom.
|
|
432
|
+
*/
|
|
433
|
+
const bySourceOrder = (left, right) => (left.source.startLine ?? 0) - (right.source.startLine ?? 0) ||
|
|
434
|
+
(left.label < right.label ? -1 : left.label > right.label ? 1 : 0) ||
|
|
435
|
+
(left.id < right.id ? -1 : left.id > right.id ? 1 : 0);
|
|
436
|
+
/**
|
|
437
|
+
* Shape the validated tool arguments into the diff helper's input. The JSON
|
|
438
|
+
* Schema already enforced number/string types, so these casts add no runtime
|
|
439
|
+
* trust: the helper re-validates every range.
|
|
440
|
+
*/
|
|
441
|
+
const asLineChange = (item) => ({
|
|
442
|
+
startLine: item.startLine,
|
|
443
|
+
endLine: item.endLine,
|
|
444
|
+
content: item.content,
|
|
445
|
+
});
|
|
446
|
+
const asByteChange = (item) => ({
|
|
447
|
+
offsetBytes: item.offsetBytes,
|
|
448
|
+
endBytes: item.endBytes,
|
|
449
|
+
content: item.content,
|
|
450
|
+
});
|
|
19
451
|
class WorkspaceServiceError extends Error {
|
|
20
452
|
code;
|
|
21
453
|
constructor(code) {
|
|
@@ -35,12 +467,35 @@ export class WorkspaceAgentService {
|
|
|
35
467
|
retired = new Map();
|
|
36
468
|
roots;
|
|
37
469
|
definitions = workspaceToolDefinitions();
|
|
470
|
+
host;
|
|
471
|
+
projectIds;
|
|
472
|
+
store;
|
|
473
|
+
writer;
|
|
474
|
+
runner;
|
|
475
|
+
/**
|
|
476
|
+
* Files the host already persisted through this service. The snapshot stays
|
|
477
|
+
* immutable, so this overlay is what keeps a read after a write honest.
|
|
478
|
+
*/
|
|
479
|
+
writes = new Map();
|
|
480
|
+
/**
|
|
481
|
+
* Reactive overlay and child-index cache. `reactive_write` bumps
|
|
482
|
+
* `cacheVersion` and drops the node plus its ancestors, so the next
|
|
483
|
+
* `reactive_read` recomputes exactly the affected subtree.
|
|
484
|
+
*/
|
|
485
|
+
reactiveOverrides = new Map();
|
|
486
|
+
reactiveCache = new Map();
|
|
487
|
+
cacheVersion = 0;
|
|
488
|
+
cachedCatalog;
|
|
38
489
|
calls = 0;
|
|
39
490
|
constructor(options) {
|
|
40
491
|
if (!options.agentId || !Array.isArray(options.projectIds)) {
|
|
41
492
|
throw new Error("workspace service requires a host agent and explicit project scope");
|
|
42
493
|
}
|
|
43
494
|
this.agentId = options.agentId;
|
|
495
|
+
this.host = options.host ?? new HostCatalog();
|
|
496
|
+
this.projectIds = new Set(options.projectIds);
|
|
497
|
+
this.writer = options.writer;
|
|
498
|
+
this.runner = options.runner;
|
|
44
499
|
this.limits = { ...Defaults, ...options.limits };
|
|
45
500
|
Object.entries(this.limits).forEach(([key, value]) => {
|
|
46
501
|
if (!Number.isSafeInteger(value) || value < 1 || value > Defaults[key]) {
|
|
@@ -60,11 +515,17 @@ export class WorkspaceAgentService {
|
|
|
60
515
|
put: () => fail("internal_error"),
|
|
61
516
|
get: (ref) => {
|
|
62
517
|
try {
|
|
63
|
-
|
|
518
|
+
/**
|
|
519
|
+
* `parseShort` is the one definition of a ref's shape, and
|
|
520
|
+
* the algorithm check keeps a future `sha512:` ref from being
|
|
521
|
+
* accepted as if it were this store's `sha256:` namespace.
|
|
522
|
+
*/
|
|
523
|
+
const parsed = parseShort(ref);
|
|
524
|
+
if (parsed === (void 0) || parsed.algorithm !== "sha256") {
|
|
64
525
|
return fail("integrity_failure");
|
|
65
526
|
}
|
|
66
527
|
const content = store.get(ref);
|
|
67
|
-
if (content !== (void 0) &&
|
|
528
|
+
if (content !== (void 0) && rawTextDigest(content) !== ref) {
|
|
68
529
|
return fail("integrity_failure");
|
|
69
530
|
}
|
|
70
531
|
return content;
|
|
@@ -74,6 +535,7 @@ export class WorkspaceAgentService {
|
|
|
74
535
|
}
|
|
75
536
|
},
|
|
76
537
|
};
|
|
538
|
+
this.store = verifiedStore;
|
|
77
539
|
this.index = new WorkspaceIndex({
|
|
78
540
|
version: options.snapshot.version,
|
|
79
541
|
revision: options.snapshot.revision,
|
|
@@ -166,21 +628,45 @@ export class WorkspaceAgentService {
|
|
|
166
628
|
tools() {
|
|
167
629
|
return structuredClone(this.definitions);
|
|
168
630
|
}
|
|
631
|
+
/**
|
|
632
|
+
* Summarize the advertised definitions as a catalog.
|
|
633
|
+
*
|
|
634
|
+
* The digest binds description, schema and risk, so a host that pinned an
|
|
635
|
+
* approved catalog can detect a descriptor swapped after approval. The
|
|
636
|
+
* result is memoized because the definitions are immutable for the lifetime
|
|
637
|
+
* of a service instance; rebuilding would compute the same digests again.
|
|
638
|
+
*/
|
|
639
|
+
catalog() {
|
|
640
|
+
if (this.cachedCatalog !== (void 0)) {
|
|
641
|
+
return this.cachedCatalog;
|
|
642
|
+
}
|
|
643
|
+
const entries = this.definitions.map((tool) => ({
|
|
644
|
+
id: tool.name,
|
|
645
|
+
digest: digestOf({ description: tool.description, inputSchema: tool.inputSchema, risk: tool.risk }),
|
|
646
|
+
risk: tool.risk,
|
|
647
|
+
}));
|
|
648
|
+
this.cachedCatalog = buildCatalog(entries, { version: "1.0.0", ttlMs: 0, cacheScope: "private" });
|
|
649
|
+
return this.cachedCatalog;
|
|
650
|
+
}
|
|
169
651
|
call(name, raw) {
|
|
170
652
|
try {
|
|
653
|
+
const canonical = resolveToolName(name);
|
|
171
654
|
if (this.calls >= this.limits.maxToolCalls) {
|
|
172
655
|
return fail("budget_exhausted");
|
|
173
656
|
}
|
|
174
657
|
this.calls += 1;
|
|
175
|
-
|
|
658
|
+
if (canonical === (void 0)) {
|
|
659
|
+
return fail("unknown_tool");
|
|
660
|
+
}
|
|
661
|
+
const tool = this.definitions.find((item) => item.name === canonical);
|
|
176
662
|
if (tool === (void 0)) {
|
|
177
663
|
return fail("unknown_tool");
|
|
178
664
|
}
|
|
179
665
|
const args = parseToolCall(tool, raw).args;
|
|
180
|
-
if (
|
|
666
|
+
if (canonical !== ToolIds.workspaceCapabilities && args.revision !== this.index.revision) {
|
|
181
667
|
return fail("revision_mismatch");
|
|
182
668
|
}
|
|
183
|
-
return this.dispatch(
|
|
669
|
+
return this.dispatch(canonical, args);
|
|
184
670
|
}
|
|
185
671
|
catch (error) {
|
|
186
672
|
const code = error instanceof WorkspaceServiceError ? error.code : error instanceof BoundaryRejection ? "invalid_arguments" : "internal_error";
|
|
@@ -198,74 +684,832 @@ export class WorkspaceAgentService {
|
|
|
198
684
|
return this.index.entity(id) ?? fail("not_available");
|
|
199
685
|
}
|
|
200
686
|
dispatch(name, args) {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
.map((
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
687
|
+
const leaf = workspaceToolLeaves.get(name) ?? fail("unknown_tool");
|
|
688
|
+
switch (leaf) {
|
|
689
|
+
case "capabilities": {
|
|
690
|
+
const catalog = this.catalog();
|
|
691
|
+
return this.reply({
|
|
692
|
+
agentId: this.agentId,
|
|
693
|
+
projectIds: this.roots.map((entity) => entity.id),
|
|
694
|
+
frames: [...this.frames.values()]
|
|
695
|
+
.filter((item) => item.state === "available" || item.state === "materialized")
|
|
696
|
+
.map((item) => ({ frameId: item.frame.id, state: item.state, remainingTokens: item.remainingTokens })),
|
|
697
|
+
limits: { ...this.limits },
|
|
698
|
+
remainingToolCalls: this.limits.maxToolCalls - this.calls,
|
|
699
|
+
tools: this.definitions.map((tool) => tool.name),
|
|
700
|
+
catalog: { version: catalog.version, digest: catalog.digest, sortedBy: catalog.sortedBy, ttlMs: catalog.ttlMs },
|
|
701
|
+
deprecatedAliases: [...deprecatedToolAliases],
|
|
702
|
+
tokenAccounting: "character-estimate; summary text and detail pages only; discovery and JSON envelope excluded",
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
case "tree": {
|
|
706
|
+
const parentId = args.parentId;
|
|
707
|
+
if (parentId !== (void 0)) {
|
|
708
|
+
this.requireEntity(parentId);
|
|
709
|
+
}
|
|
710
|
+
const all = parentId === (void 0) ? this.roots : this.index.children(parentId);
|
|
711
|
+
const offset = args.offset ?? 0;
|
|
712
|
+
const end = Math.min(all.length, offset + (args.limit ?? 32));
|
|
713
|
+
return this.reply({
|
|
714
|
+
items: all.slice(offset, end).map((entity) => ({
|
|
715
|
+
id: entity.id,
|
|
716
|
+
kind: entity.kind,
|
|
717
|
+
label: entity.label,
|
|
718
|
+
parentId: entity.parentId,
|
|
719
|
+
structureKind: entity.structureKind,
|
|
720
|
+
source: entity.source,
|
|
721
|
+
hasDetail: entity.detailRef !== (void 0),
|
|
722
|
+
summaryState: this.index.summaryState(entity.id),
|
|
723
|
+
})),
|
|
724
|
+
total: all.length,
|
|
725
|
+
nextOffset: end < all.length ? end : null,
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
case "query": {
|
|
729
|
+
const query = { ...args };
|
|
730
|
+
delete query.revision;
|
|
731
|
+
const result = this.index.query(query);
|
|
732
|
+
return this.reply({ ...result });
|
|
733
|
+
}
|
|
734
|
+
case "relations": {
|
|
735
|
+
this.requireEntity(args.nodeId);
|
|
736
|
+
const all = this.index.relations(args.nodeId, args.direction, args.relationKind);
|
|
737
|
+
const offset = args.offset ?? 0;
|
|
738
|
+
const end = Math.min(all.length, offset + (args.limit ?? 32));
|
|
739
|
+
return this.reply({ items: all.slice(offset, end), total: all.length, nextOffset: end < all.length ? end : null });
|
|
740
|
+
}
|
|
741
|
+
case "discover": {
|
|
742
|
+
return this.discover(args);
|
|
743
|
+
}
|
|
744
|
+
case "project": {
|
|
745
|
+
return this.project(args);
|
|
746
|
+
}
|
|
747
|
+
case "outline": {
|
|
748
|
+
return this.outline(args);
|
|
749
|
+
}
|
|
750
|
+
case "dependency": {
|
|
751
|
+
return this.dependency(args);
|
|
752
|
+
}
|
|
753
|
+
case "reactive_read": {
|
|
754
|
+
return this.reactiveRead(args);
|
|
755
|
+
}
|
|
756
|
+
case "reactive_write": {
|
|
757
|
+
return this.reactiveWrite(args);
|
|
758
|
+
}
|
|
759
|
+
case "diff_read": {
|
|
760
|
+
return this.diffRead(args);
|
|
761
|
+
}
|
|
762
|
+
case "materialize": {
|
|
763
|
+
return this.materialize(args.frameId, args.budgetTokens);
|
|
764
|
+
}
|
|
765
|
+
default: {
|
|
766
|
+
break;
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
const item = this.contexts.get(args.contextId);
|
|
770
|
+
if (item === (void 0)) {
|
|
771
|
+
return fail("not_available");
|
|
772
|
+
}
|
|
773
|
+
switch (leaf) {
|
|
774
|
+
case "release": {
|
|
775
|
+
const response = this.reply({
|
|
776
|
+
released: true,
|
|
777
|
+
frameId: item.allocation.frame.id,
|
|
778
|
+
remainingTokens: item.allocation.remainingTokens,
|
|
779
|
+
});
|
|
780
|
+
this.contexts.delete(args.contextId);
|
|
781
|
+
this.retired.set(args.contextId, item);
|
|
782
|
+
item.allocation.state = "released";
|
|
783
|
+
return response;
|
|
784
|
+
}
|
|
785
|
+
case "read": {
|
|
786
|
+
return this.read(item, args);
|
|
787
|
+
}
|
|
788
|
+
case "write": {
|
|
789
|
+
return this.write(item, args);
|
|
790
|
+
}
|
|
791
|
+
case "diff_write": {
|
|
792
|
+
return this.diffWrite(item, args);
|
|
793
|
+
}
|
|
794
|
+
default: {
|
|
795
|
+
return fail("unknown_tool");
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
/**
|
|
800
|
+
* Agent-callable project discovery. The result is a structural tree over
|
|
801
|
+
* only the authorized snapshot plus host components that belong to the
|
|
802
|
+
* authorized project scope. Content matches are bounded snippets, never a
|
|
803
|
+
* replacement for a Frame-allocated detail read.
|
|
804
|
+
*/
|
|
805
|
+
discover(args) {
|
|
806
|
+
const query = {
|
|
807
|
+
...(args.text === (void 0) ? {} : { text: args.text }),
|
|
808
|
+
...(args.scope === (void 0) ? {} : { scope: args.scope }),
|
|
809
|
+
...(args.moduleKind === (void 0) ? {} : { moduleKind: args.moduleKind }),
|
|
810
|
+
...(args.componentKind === (void 0) ? {} : { componentKind: args.componentKind }),
|
|
811
|
+
...(args.extension === (void 0) ? {} : { extension: args.extension }),
|
|
812
|
+
...(args.pathPrefix === (void 0) ? {} : { pathPrefix: args.pathPrefix }),
|
|
813
|
+
...(args.content === (void 0) ? {} : { content: args.content }),
|
|
814
|
+
...(args.maxDepth === (void 0) ? {} : { maxDepth: args.maxDepth }),
|
|
815
|
+
...(args.limit === (void 0) ? {} : { limit: args.limit }),
|
|
816
|
+
};
|
|
817
|
+
const projects = this.host
|
|
818
|
+
.projects()
|
|
819
|
+
.filter((project) => this.projectIds.has(project.id) || (project.rootId !== (void 0) && this.projectIds.has(project.rootId)));
|
|
820
|
+
const components = this.host.components().filter((component) => component.projectId === (void 0) || this.projectIds.has(component.projectId));
|
|
821
|
+
const tree = buildDiscoveryTree({
|
|
822
|
+
revision: this.index.revision,
|
|
823
|
+
entities: this.index.snapshot().entities,
|
|
824
|
+
projects,
|
|
825
|
+
components,
|
|
826
|
+
builtIn: this.builtInComponents(),
|
|
827
|
+
query,
|
|
828
|
+
contentOf: (entity) => {
|
|
829
|
+
if (entity.detailRef === (void 0)) {
|
|
830
|
+
return undefined;
|
|
831
|
+
}
|
|
832
|
+
const content = this.store.get(entity.detailRef);
|
|
833
|
+
return content === (void 0) ? undefined : content.slice(0, 65_536);
|
|
834
|
+
},
|
|
835
|
+
});
|
|
836
|
+
return this.reply({ ...tree });
|
|
837
|
+
}
|
|
838
|
+
/**
|
|
839
|
+
* Project scope: one explicitly named project or every authorized root.
|
|
840
|
+
*/
|
|
841
|
+
projectScope(projectId) {
|
|
842
|
+
if (projectId === (void 0)) {
|
|
843
|
+
return this.roots;
|
|
844
|
+
}
|
|
845
|
+
const project = this.requireEntity(projectId);
|
|
846
|
+
if (project.kind !== "project") {
|
|
847
|
+
return fail("invalid_arguments");
|
|
848
|
+
}
|
|
849
|
+
return [project];
|
|
850
|
+
}
|
|
851
|
+
projectSummary(project, files) {
|
|
852
|
+
const detected = detectBrands(files.filter((file) => file.projectId === project.id));
|
|
853
|
+
const primary = detected[0];
|
|
854
|
+
const toBrand = (item) => ({
|
|
855
|
+
brand: item.brand,
|
|
856
|
+
language: item.language,
|
|
857
|
+
manifest: { id: item.manifest.id, path: item.manifest.source.uri },
|
|
858
|
+
actions: actionsOf(item.commands),
|
|
859
|
+
commands: item.commands,
|
|
860
|
+
});
|
|
861
|
+
return {
|
|
862
|
+
projectId: project.id,
|
|
863
|
+
label: project.label,
|
|
864
|
+
cwd: primary === (void 0) ? "." : posix.dirname(primary.manifest.source.uri),
|
|
865
|
+
brand: primary === (void 0) ? "unknown" : primary.brand,
|
|
866
|
+
language: primary === (void 0) ? "unknown" : primary.language,
|
|
867
|
+
manifest: primary === (void 0) ? null : { id: primary.manifest.id, path: primary.manifest.source.uri },
|
|
868
|
+
actions: primary === (void 0) ? [] : actionsOf(primary.commands),
|
|
869
|
+
commands: primary === (void 0) ? {} : primary.commands,
|
|
870
|
+
detected: detected.map(toBrand),
|
|
871
|
+
};
|
|
872
|
+
}
|
|
873
|
+
/**
|
|
874
|
+
* Brand detection plus host-delegated build/compile/run/test.
|
|
875
|
+
*
|
|
876
|
+
* A non-detect action requires an unambiguous project, picks one command
|
|
877
|
+
* from the brand table, and hands it to the runner port. The agent never
|
|
878
|
+
* supplies command text, and the host can refuse with a closed error code.
|
|
879
|
+
*/
|
|
880
|
+
project(args) {
|
|
881
|
+
const projects = this.projectScope(args.projectId);
|
|
882
|
+
const files = this.index.snapshot().entities.filter((entity) => entity.kind === "file");
|
|
883
|
+
const summaries = projects.map((project) => this.projectSummary(project, files));
|
|
884
|
+
const action = args.action ?? "detect";
|
|
885
|
+
if (action === "detect") {
|
|
886
|
+
return this.reply({ action, projects: summaries, total: summaries.length });
|
|
887
|
+
}
|
|
888
|
+
if (summaries.length !== 1) {
|
|
889
|
+
return fail("invalid_arguments");
|
|
890
|
+
}
|
|
891
|
+
const summary = summaries[0];
|
|
892
|
+
const requestedBrand = args.brand;
|
|
893
|
+
/**
|
|
894
|
+
* A mixed repository can detect several brands. Without an explicit
|
|
895
|
+
* `brand`, prefer the first detected brand that actually defines the
|
|
896
|
+
* requested action, so `run` does not fail merely because the most
|
|
897
|
+
* specific manifest has no run target. With `brand`, the choice is
|
|
898
|
+
* exactly that brand and a missing action is `unsupported_action`.
|
|
899
|
+
*/
|
|
900
|
+
const candidates = summary.detected.filter((brand) => requestedBrand === (void 0) || brand.brand === requestedBrand);
|
|
901
|
+
const chosen = candidates.find((brand) => brand.commands[action] !== (void 0)) ?? candidates[0];
|
|
902
|
+
if (chosen === (void 0)) {
|
|
903
|
+
return fail("invalid_arguments");
|
|
904
|
+
}
|
|
905
|
+
const command = chosen.commands[action];
|
|
906
|
+
if (command === (void 0)) {
|
|
907
|
+
return fail("unsupported_action");
|
|
908
|
+
}
|
|
909
|
+
const cwd = posix.dirname(chosen.manifest.path);
|
|
910
|
+
const payload = { projectId: summary.projectId, brand: chosen.brand, action, command, cwd };
|
|
911
|
+
if (args.dryRun === true) {
|
|
912
|
+
return this.reply({ ...payload, dryRun: true });
|
|
913
|
+
}
|
|
914
|
+
if (this.runner === (void 0)) {
|
|
915
|
+
return fail("run_unavailable");
|
|
916
|
+
}
|
|
917
|
+
const outcome = this.runner.run({
|
|
918
|
+
agentId: this.agentId,
|
|
919
|
+
projectId: summary.projectId,
|
|
920
|
+
brand: chosen.brand,
|
|
921
|
+
action,
|
|
922
|
+
command,
|
|
923
|
+
cwd,
|
|
924
|
+
});
|
|
925
|
+
if (runRejected(outcome)) {
|
|
926
|
+
return fail(outcome.code);
|
|
927
|
+
}
|
|
928
|
+
/**
|
|
929
|
+
* The port is host code, so validate its shape before it reaches the
|
|
930
|
+
* reply: a missing exit code or a non-string stream would otherwise
|
|
931
|
+
* produce a malformed response instead of a closed `internal_error`.
|
|
932
|
+
*/
|
|
933
|
+
if (!Number.isSafeInteger(outcome.exitCode) ||
|
|
934
|
+
(outcome.stdout !== (void 0) && typeof (outcome.stdout) !== "string") ||
|
|
935
|
+
(outcome.stderr !== (void 0) && typeof (outcome.stderr) !== "string") ||
|
|
936
|
+
(outcome.durationMs !== (void 0) && (!Number.isFinite(outcome.durationMs) || outcome.durationMs < 0))) {
|
|
937
|
+
return fail("internal_error");
|
|
938
|
+
}
|
|
939
|
+
const stdout = clipOutput(outcome.stdout, this.limits.maxRunOutputChars);
|
|
940
|
+
const stderr = clipOutput(outcome.stderr, this.limits.maxRunOutputChars);
|
|
941
|
+
return this.reply({
|
|
942
|
+
...payload,
|
|
943
|
+
dryRun: false,
|
|
944
|
+
exitCode: outcome.exitCode,
|
|
945
|
+
...(outcome.durationMs === (void 0) ? {} : { durationMs: outcome.durationMs }),
|
|
946
|
+
stdout: stdout.text,
|
|
947
|
+
stderr: stderr.text,
|
|
948
|
+
stdoutTruncated: stdout.truncated,
|
|
949
|
+
stderrTruncated: stderr.truncated,
|
|
950
|
+
});
|
|
951
|
+
}
|
|
952
|
+
/**
|
|
953
|
+
* Cascading outline: project → directory → file → symbol/knowledge.
|
|
954
|
+
*
|
|
955
|
+
* Depth and node count are bounded; `childCount` is computed before the
|
|
956
|
+
* node limit is applied so a truncated node stays distinguishable from a
|
|
957
|
+
* leaf. File bodies are never read here.
|
|
958
|
+
*/
|
|
959
|
+
outline(args) {
|
|
960
|
+
const projects = this.projectScope(args.projectId);
|
|
961
|
+
const limit = Math.min(args.limit ?? 500, 2000);
|
|
962
|
+
const maxDepth = Math.min(args.maxDepth ?? 8, 12);
|
|
963
|
+
const includeSymbols = args.includeSymbols !== false;
|
|
964
|
+
const pathPrefix = args.pathPrefix;
|
|
965
|
+
const extension = args.extension?.replace(/^\./, "").toLowerCase();
|
|
966
|
+
let emitted = 0;
|
|
967
|
+
let truncated = false;
|
|
968
|
+
const fileMatches = (file) => {
|
|
969
|
+
if (pathPrefix !== (void 0) && !file.source.uri.startsWith(pathPrefix)) {
|
|
970
|
+
return false;
|
|
971
|
+
}
|
|
972
|
+
return extension === (void 0) || posix.extname(file.source.uri).replace(/^\./, "").toLowerCase() === extension;
|
|
973
|
+
};
|
|
974
|
+
const childrenOf = (entity) => {
|
|
975
|
+
if (entity.kind === "project" || entity.kind === "directory") {
|
|
976
|
+
return this.index
|
|
977
|
+
.children(entity.id)
|
|
978
|
+
.filter((child) => child.kind === "directory" || child.kind === "file")
|
|
979
|
+
.sort(byStructureOrder);
|
|
980
|
+
}
|
|
981
|
+
if (entity.kind === "file") {
|
|
982
|
+
return includeSymbols
|
|
983
|
+
? this.index
|
|
984
|
+
.children(entity.id)
|
|
985
|
+
.filter((child) => child.kind === "symbol" || child.kind === "knowledge")
|
|
986
|
+
.sort(bySourceOrder)
|
|
987
|
+
: [];
|
|
988
|
+
}
|
|
989
|
+
return this.index
|
|
990
|
+
.children(entity.id)
|
|
991
|
+
.filter((child) => child.kind === "symbol" || child.kind === "knowledge")
|
|
992
|
+
.sort(bySourceOrder);
|
|
993
|
+
};
|
|
994
|
+
const build = (entity, depth) => {
|
|
995
|
+
if (emitted >= limit) {
|
|
996
|
+
truncated = true;
|
|
997
|
+
return (void 0);
|
|
998
|
+
}
|
|
999
|
+
emitted += 1;
|
|
1000
|
+
const children = childrenOf(entity).filter((child) => child.kind !== "file" || fileMatches(child));
|
|
1001
|
+
const node = {
|
|
1002
|
+
id: entity.id,
|
|
1003
|
+
kind: entity.kind,
|
|
1004
|
+
label: entity.label,
|
|
1005
|
+
path: entity.source.uri,
|
|
1006
|
+
...(entity.structureKind === (void 0) ? {} : { structureKind: entity.structureKind }),
|
|
1007
|
+
...(entity.source.startLine === (void 0) ? {} : { startLine: entity.source.startLine }),
|
|
1008
|
+
...(entity.source.endLine === (void 0) ? {} : { endLine: entity.source.endLine }),
|
|
1009
|
+
childCount: children.length,
|
|
1010
|
+
children: [],
|
|
1011
|
+
};
|
|
1012
|
+
if (depth >= maxDepth) {
|
|
1013
|
+
return node;
|
|
1014
|
+
}
|
|
1015
|
+
for (let index = 0; index < children.length; index += 1) {
|
|
1016
|
+
const child = build(children[index], depth + 1);
|
|
1017
|
+
if (child === (void 0)) {
|
|
1018
|
+
break;
|
|
1019
|
+
}
|
|
1020
|
+
node.children.push(child);
|
|
1021
|
+
}
|
|
1022
|
+
return node;
|
|
1023
|
+
};
|
|
1024
|
+
const roots = [];
|
|
1025
|
+
projects.forEach((project) => {
|
|
1026
|
+
const node = build(project, 0);
|
|
1027
|
+
if (node !== (void 0)) {
|
|
1028
|
+
roots.push(node);
|
|
1029
|
+
}
|
|
1030
|
+
});
|
|
1031
|
+
return this.reply({ roots, nodes: emitted, truncated, projects: projects.length });
|
|
1032
|
+
}
|
|
1033
|
+
/**
|
|
1034
|
+
* Project-level dependency edges. File-level imports stay on `read`, which
|
|
1035
|
+
* is where the caller already pays for content.
|
|
1036
|
+
*/
|
|
1037
|
+
dependency(args) {
|
|
1038
|
+
const projects = this.projectScope(args.projectId);
|
|
1039
|
+
const direction = args.direction ?? "both";
|
|
1040
|
+
const offset = args.offset ?? 0;
|
|
1041
|
+
const limit = Math.min(args.limit ?? 100, 200);
|
|
1042
|
+
const end = Math.min(projects.length, offset + limit);
|
|
1043
|
+
const rows = projects
|
|
1044
|
+
.slice(offset, end)
|
|
1045
|
+
.map((project) => ({
|
|
1046
|
+
projectId: project.id,
|
|
1047
|
+
label: project.label,
|
|
1048
|
+
dependencies: direction === "incoming" ? [] : this.projectEdges(project.id, "outgoing", "to"),
|
|
1049
|
+
dependents: direction === "outgoing" ? [] : this.projectEdges(project.id, "incoming", "from"),
|
|
1050
|
+
}));
|
|
1051
|
+
return this.reply({ projects: rows, total: projects.length, nextOffset: end < projects.length ? end : null });
|
|
1052
|
+
}
|
|
1053
|
+
projectEdges(projectId, direction, side) {
|
|
1054
|
+
const seen = new Set();
|
|
1055
|
+
const edges = [];
|
|
1056
|
+
this.index.relations(projectId, direction, "project_depends_on").forEach((edge) => {
|
|
1057
|
+
const target = this.index.entity(side === "from" ? edge.from : edge.to);
|
|
1058
|
+
if (target === (void 0) || seen.has(target.id)) {
|
|
1059
|
+
return;
|
|
1060
|
+
}
|
|
1061
|
+
seen.add(target.id);
|
|
1062
|
+
edges.push({
|
|
1063
|
+
id: target.id,
|
|
1064
|
+
kind: target.kind,
|
|
1065
|
+
label: target.label,
|
|
1066
|
+
path: target.source.uri,
|
|
1067
|
+
method: edge.method,
|
|
1068
|
+
...(edge.source.startLine === (void 0) ? {} : { line: edge.source.startLine }),
|
|
1069
|
+
});
|
|
1070
|
+
});
|
|
1071
|
+
return edges.sort((left, right) => left.path < right.path ? -1 : left.path > right.path ? 1 : left.id < right.id ? -1 : left.id > right.id ? 1 : 0);
|
|
1072
|
+
}
|
|
1073
|
+
/**
|
|
1074
|
+
* Reactive tree. In process every node is a Proxy: `label`, `summary`,
|
|
1075
|
+
* `tags`, `revision`, `childCount` and `children` are computed on first
|
|
1076
|
+
* access and the child index is cached until `reactive_write` invalidates
|
|
1077
|
+
* it. `toJSON` builds the bounded plain projection the wire sees, so the
|
|
1078
|
+
* laziness cannot grow a response without bound.
|
|
1079
|
+
*/
|
|
1080
|
+
reactiveRead(args) {
|
|
1081
|
+
const nodeId = args.nodeId;
|
|
1082
|
+
if (nodeId !== (void 0) && args.projectId !== (void 0)) {
|
|
1083
|
+
return fail("invalid_arguments");
|
|
1084
|
+
}
|
|
1085
|
+
const roots = nodeId === (void 0) ? this.projectScope(args.projectId) : [this.requireEntity(nodeId)];
|
|
1086
|
+
const maxDepth = Math.min(args.maxDepth ?? 8, 12);
|
|
1087
|
+
const limit = Math.min(args.limit ?? 500, 2000);
|
|
1088
|
+
const nodes = roots.map((entity) => this.reactiveProxy(entity, maxDepth, limit));
|
|
1089
|
+
return this.reply({ revision: this.index.revision, cacheVersion: this.cacheVersion, roots: nodes, nodes: nodes.length });
|
|
1090
|
+
}
|
|
1091
|
+
reactiveProxy(entity, maxDepth, limit) {
|
|
1092
|
+
const base = {};
|
|
1093
|
+
/**
|
|
1094
|
+
* A fresh budget per serialization: the same proxy may be stringified
|
|
1095
|
+
* more than once (service reply, then executor), and a shared counter
|
|
1096
|
+
* would make the second pass look truncated.
|
|
1097
|
+
*/
|
|
1098
|
+
const plain = () => this.reactivePlain(entity, maxDepth, limit, { nodes: 0 }, 0);
|
|
1099
|
+
return new Proxy(base, {
|
|
1100
|
+
get: (host, property) => {
|
|
1101
|
+
if (property === "toJSON") {
|
|
1102
|
+
return plain;
|
|
1103
|
+
}
|
|
1104
|
+
if (typeof (property) !== "string") {
|
|
1105
|
+
return (void 0);
|
|
1106
|
+
}
|
|
1107
|
+
switch (property) {
|
|
1108
|
+
case "id":
|
|
1109
|
+
return entity.id;
|
|
1110
|
+
case "kind":
|
|
1111
|
+
return entity.kind;
|
|
1112
|
+
case "label":
|
|
1113
|
+
return this.reactiveLabel(entity);
|
|
1114
|
+
case "summary":
|
|
1115
|
+
return this.reactiveSummary(entity);
|
|
1116
|
+
case "tags":
|
|
1117
|
+
return this.reactiveTags(entity);
|
|
1118
|
+
case "path":
|
|
1119
|
+
return entity.source.uri;
|
|
1120
|
+
case "structureKind":
|
|
1121
|
+
return entity.structureKind;
|
|
1122
|
+
case "startLine":
|
|
1123
|
+
return entity.source.startLine;
|
|
1124
|
+
case "endLine":
|
|
1125
|
+
return entity.source.endLine;
|
|
1126
|
+
case "revision":
|
|
1127
|
+
return this.revisionOf(entity);
|
|
1128
|
+
case "childCount":
|
|
1129
|
+
return this.reactiveChildren(entity).length;
|
|
1130
|
+
case "children":
|
|
1131
|
+
return this.reactiveChildren(entity).map((child) => this.reactiveProxy(child, maxDepth, limit));
|
|
1132
|
+
case "hasOwnProperty":
|
|
1133
|
+
return Object.prototype.hasOwnProperty;
|
|
1134
|
+
default:
|
|
1135
|
+
return host[property];
|
|
1136
|
+
}
|
|
1137
|
+
},
|
|
1138
|
+
ownKeys: () => [...ReactiveKeys],
|
|
1139
|
+
getOwnPropertyDescriptor: () => ({ configurable: true, enumerable: true }),
|
|
1140
|
+
has: (host, property) => typeof (property) === "string" && (ReactiveKeys.includes(property) || property in host),
|
|
1141
|
+
});
|
|
1142
|
+
}
|
|
1143
|
+
reactivePlain(entity, maxDepth, limit, budget, depth) {
|
|
1144
|
+
budget.nodes += 1;
|
|
1145
|
+
const children = this.reactiveChildren(entity);
|
|
1146
|
+
const node = {
|
|
1147
|
+
id: entity.id,
|
|
1148
|
+
kind: entity.kind,
|
|
1149
|
+
label: this.reactiveLabel(entity),
|
|
1150
|
+
path: entity.source.uri,
|
|
1151
|
+
summary: this.reactiveSummary(entity),
|
|
1152
|
+
tags: this.reactiveTags(entity),
|
|
1153
|
+
...(entity.structureKind === (void 0) ? {} : { structureKind: entity.structureKind }),
|
|
1154
|
+
...(entity.source.startLine === (void 0) ? {} : { startLine: entity.source.startLine }),
|
|
1155
|
+
...(entity.source.endLine === (void 0) ? {} : { endLine: entity.source.endLine }),
|
|
1156
|
+
revision: this.revisionOf(entity),
|
|
1157
|
+
childCount: children.length,
|
|
1158
|
+
children: [],
|
|
1159
|
+
};
|
|
1160
|
+
if (depth >= maxDepth) {
|
|
1161
|
+
return node;
|
|
1162
|
+
}
|
|
1163
|
+
for (let index = 0; index < children.length; index += 1) {
|
|
1164
|
+
if (budget.nodes >= limit) {
|
|
1165
|
+
node.truncated = true;
|
|
1166
|
+
break;
|
|
1167
|
+
}
|
|
1168
|
+
node.children.push(this.reactivePlain(children[index], maxDepth, limit, budget, depth + 1));
|
|
1169
|
+
}
|
|
1170
|
+
return node;
|
|
1171
|
+
}
|
|
1172
|
+
reactiveChildren(entity) {
|
|
1173
|
+
const cached = this.reactiveCache.get(entity.id);
|
|
1174
|
+
if (cached !== (void 0)) {
|
|
1175
|
+
return cached;
|
|
1176
|
+
}
|
|
1177
|
+
const structural = entity.kind === "project" || entity.kind === "directory";
|
|
1178
|
+
const children = this.index
|
|
1179
|
+
.children(entity.id)
|
|
1180
|
+
.filter((child) => structural ? child.kind === "directory" || child.kind === "file" : child.kind === "symbol" || child.kind === "knowledge")
|
|
1181
|
+
.sort(structural ? byStructureOrder : bySourceOrder);
|
|
1182
|
+
this.reactiveCache.set(entity.id, children);
|
|
1183
|
+
return children;
|
|
1184
|
+
}
|
|
1185
|
+
reactiveLabel(entity) {
|
|
1186
|
+
return this.reactiveOverrides.get(entity.id)?.label ?? entity.label;
|
|
1187
|
+
}
|
|
1188
|
+
reactiveSummary(entity) {
|
|
1189
|
+
return this.reactiveOverrides.get(entity.id)?.summary ?? entity.summary;
|
|
1190
|
+
}
|
|
1191
|
+
reactiveTags(entity) {
|
|
1192
|
+
return this.reactiveOverrides.get(entity.id)?.tags ?? entity.tags ?? [];
|
|
1193
|
+
}
|
|
1194
|
+
/**
|
|
1195
|
+
* Drop the cached children of the node and every ancestor and bump the
|
|
1196
|
+
* version a caller can compare. The returned ids describe what was
|
|
1197
|
+
* refreshed, whether or not an entry existed for it.
|
|
1198
|
+
*/
|
|
1199
|
+
invalidateReactive(nodeId) {
|
|
1200
|
+
const invalidated = [];
|
|
1201
|
+
let entity = this.index.entity(nodeId);
|
|
1202
|
+
while (entity !== (void 0) && invalidated.length < 64) {
|
|
1203
|
+
this.reactiveCache.delete(entity.id);
|
|
1204
|
+
invalidated.push(entity.id);
|
|
1205
|
+
entity = entity.parentId === (void 0) ? (void 0) : this.index.entity(entity.parentId);
|
|
1206
|
+
}
|
|
1207
|
+
this.cacheVersion += 1;
|
|
1208
|
+
return invalidated;
|
|
1209
|
+
}
|
|
1210
|
+
/**
|
|
1211
|
+
* Reactive write. Annotations stay service-local; `content` is the guarded
|
|
1212
|
+
* file write and reuses the allocation, CAS and host writer of `write`.
|
|
1213
|
+
*/
|
|
1214
|
+
reactiveWrite(args) {
|
|
1215
|
+
const nodeId = args.nodeId;
|
|
1216
|
+
const property = args.property;
|
|
1217
|
+
const entity = this.requireEntity(nodeId);
|
|
1218
|
+
const value = args.value;
|
|
1219
|
+
if (property === "content") {
|
|
1220
|
+
if (typeof (value) !== "string") {
|
|
1221
|
+
return fail("invalid_arguments");
|
|
1222
|
+
}
|
|
1223
|
+
const item = this.contexts.get(args.contextId);
|
|
1224
|
+
if (item === (void 0)) {
|
|
1225
|
+
return fail("not_available");
|
|
1226
|
+
}
|
|
1227
|
+
const response = this.write(item, {
|
|
1228
|
+
nodeId,
|
|
1229
|
+
content: value,
|
|
1230
|
+
...(args.expectRevision === (void 0) ? {} : { expectRevision: args.expectRevision }),
|
|
1231
|
+
...(args.dryRun === (void 0) ? {} : { dryRun: args.dryRun }),
|
|
212
1232
|
});
|
|
1233
|
+
/**
|
|
1234
|
+
* A real content write also invalidates the reactive cache; a
|
|
1235
|
+
* dry run changed nothing, so it must not bump the version. The
|
|
1236
|
+
* cache coordinates are reported even on the content path so the
|
|
1237
|
+
* reply shape matches the annotation path.
|
|
1238
|
+
*/
|
|
1239
|
+
if (response.ok && args.dryRun !== true) {
|
|
1240
|
+
const invalidated = this.invalidateReactive(nodeId);
|
|
1241
|
+
response.data.cacheVersion = this.cacheVersion;
|
|
1242
|
+
response.data.invalidated = invalidated;
|
|
1243
|
+
}
|
|
1244
|
+
return response;
|
|
1245
|
+
}
|
|
1246
|
+
if (property !== "summary" && property !== "label" && property !== "tags") {
|
|
1247
|
+
return fail("invalid_arguments");
|
|
1248
|
+
}
|
|
1249
|
+
/**
|
|
1250
|
+
* Work on a copy: a dry run must not mutate the stored overlay through
|
|
1251
|
+
* a shared object reference.
|
|
1252
|
+
*/
|
|
1253
|
+
const existing = this.reactiveOverrides.get(nodeId);
|
|
1254
|
+
const overrides = {
|
|
1255
|
+
...(existing === (void 0) ? {} : existing),
|
|
1256
|
+
...(existing?.tags === (void 0) ? {} : { tags: [...existing.tags] }),
|
|
1257
|
+
};
|
|
1258
|
+
if (property === "tags") {
|
|
1259
|
+
if (!Array.isArray(value) || value.some((item) => typeof (item) !== "string")) {
|
|
1260
|
+
return fail("invalid_arguments");
|
|
1261
|
+
}
|
|
1262
|
+
overrides.tags = [...value];
|
|
213
1263
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
1264
|
+
else {
|
|
1265
|
+
if (typeof (value) !== "string") {
|
|
1266
|
+
return fail("invalid_arguments");
|
|
1267
|
+
}
|
|
1268
|
+
if (property === "summary") {
|
|
1269
|
+
overrides.summary = value;
|
|
218
1270
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
1271
|
+
else {
|
|
1272
|
+
overrides.label = value;
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
if (args.dryRun === true) {
|
|
222
1276
|
return this.reply({
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
hasDetail: entity.detailRef !== (void 0),
|
|
231
|
-
summaryState: this.index.summaryState(entity.id),
|
|
232
|
-
})),
|
|
233
|
-
total: all.length,
|
|
234
|
-
nextOffset: end < all.length ? end : null,
|
|
1277
|
+
nodeId,
|
|
1278
|
+
property,
|
|
1279
|
+
value: property === "tags" ? overrides.tags : overrides[property],
|
|
1280
|
+
revision: this.revisionOf(entity),
|
|
1281
|
+
dryRun: true,
|
|
1282
|
+
cacheVersion: this.cacheVersion,
|
|
1283
|
+
invalidated: [],
|
|
235
1284
|
});
|
|
236
1285
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
1286
|
+
this.reactiveOverrides.set(nodeId, overrides);
|
|
1287
|
+
const invalidated = this.invalidateReactive(nodeId);
|
|
1288
|
+
return this.reply({
|
|
1289
|
+
nodeId,
|
|
1290
|
+
property,
|
|
1291
|
+
value: property === "tags" ? overrides.tags : overrides[property],
|
|
1292
|
+
revision: this.revisionOf(entity),
|
|
1293
|
+
cacheVersion: this.cacheVersion,
|
|
1294
|
+
invalidated,
|
|
1295
|
+
});
|
|
1296
|
+
}
|
|
1297
|
+
/**
|
|
1298
|
+
* Comparable project tree. Every node is a project/directory/file; files
|
|
1299
|
+
* carry the content revision plus byte/line metrics so two snapshots can be
|
|
1300
|
+
* diffed without bodies. `includeContent` is gated by the materialized
|
|
1301
|
+
* Context and never widens what the Frame already made readable.
|
|
1302
|
+
*/
|
|
1303
|
+
diffRead(args) {
|
|
1304
|
+
const projects = this.projectScope(args.projectId);
|
|
1305
|
+
const limit = Math.min(args.limit ?? 500, 2000);
|
|
1306
|
+
const includeContent = args.includeContent === true;
|
|
1307
|
+
const context = includeContent ? this.contexts.get(args.contextId) : (void 0);
|
|
1308
|
+
if (includeContent && context === (void 0)) {
|
|
1309
|
+
return fail("not_available");
|
|
242
1310
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
1311
|
+
const pathPrefix = args.pathPrefix;
|
|
1312
|
+
const extension = args.extension?.replace(/^\./, "").toLowerCase();
|
|
1313
|
+
const fileMatches = (file) => {
|
|
1314
|
+
if (pathPrefix !== (void 0) && !file.source.uri.startsWith(pathPrefix)) {
|
|
1315
|
+
return false;
|
|
1316
|
+
}
|
|
1317
|
+
return extension === (void 0) || posix.extname(file.source.uri).replace(/^\./, "").toLowerCase() === extension;
|
|
1318
|
+
};
|
|
1319
|
+
let emitted = 0;
|
|
1320
|
+
let files = 0;
|
|
1321
|
+
let truncated = false;
|
|
1322
|
+
const build = (entity) => {
|
|
1323
|
+
if (emitted >= limit) {
|
|
1324
|
+
truncated = true;
|
|
1325
|
+
return (void 0);
|
|
1326
|
+
}
|
|
1327
|
+
emitted += 1;
|
|
1328
|
+
const children = this.index
|
|
1329
|
+
.children(entity.id)
|
|
1330
|
+
.filter((child) => child.kind === "directory" || (child.kind === "file" && fileMatches(child)))
|
|
1331
|
+
.sort(byStructureOrder);
|
|
1332
|
+
const metrics = entity.kind === "file" ? this.contentMetrics(entity) : { bytes: null, lines: null };
|
|
1333
|
+
const node = {
|
|
1334
|
+
id: entity.id,
|
|
1335
|
+
kind: entity.kind,
|
|
1336
|
+
label: entity.label,
|
|
1337
|
+
path: entity.source.uri,
|
|
1338
|
+
/**
|
|
1339
|
+
* Revision and metrics must describe the same text. A file that
|
|
1340
|
+
* was written through this service serves the accepted content,
|
|
1341
|
+
* so its revision is the writer's; directories never carry an
|
|
1342
|
+
* accepted write and keep the snapshot revision.
|
|
1343
|
+
*/
|
|
1344
|
+
revision: this.revisionOf(entity),
|
|
1345
|
+
bytes: metrics.bytes,
|
|
1346
|
+
lines: metrics.lines,
|
|
1347
|
+
content: null,
|
|
1348
|
+
contentOmitted: false,
|
|
1349
|
+
contentTruncated: false,
|
|
1350
|
+
childCount: children.length,
|
|
1351
|
+
children: [],
|
|
1352
|
+
};
|
|
1353
|
+
if (entity.kind === "file") {
|
|
1354
|
+
files += 1;
|
|
1355
|
+
if (includeContent) {
|
|
1356
|
+
const content = context !== (void 0) && context.readable.has(entity.id) ? this.contentOf(entity) : (void 0);
|
|
1357
|
+
node.contentOmitted = content === (void 0);
|
|
1358
|
+
node.contentTruncated = content !== (void 0) && content.length > this.limits.maxReadChars;
|
|
1359
|
+
node.content = content === (void 0) ? null : content.slice(0, this.limits.maxReadChars);
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
for (let index = 0; index < children.length; index += 1) {
|
|
1363
|
+
const child = build(children[index]);
|
|
1364
|
+
if (child === (void 0)) {
|
|
1365
|
+
break;
|
|
1366
|
+
}
|
|
1367
|
+
node.children.push(child);
|
|
1368
|
+
}
|
|
1369
|
+
return node;
|
|
1370
|
+
};
|
|
1371
|
+
const roots = [];
|
|
1372
|
+
projects.forEach((project) => {
|
|
1373
|
+
const node = build(project);
|
|
1374
|
+
if (node !== (void 0)) {
|
|
1375
|
+
roots.push(node);
|
|
1376
|
+
}
|
|
1377
|
+
});
|
|
1378
|
+
return this.reply({ revision: this.index.revision, roots, files, nodes: emitted, truncated });
|
|
1379
|
+
}
|
|
1380
|
+
contentMetrics(entity) {
|
|
1381
|
+
const content = this.contentOf(entity);
|
|
1382
|
+
return content === (void 0)
|
|
1383
|
+
? { bytes: null, lines: null }
|
|
1384
|
+
: { bytes: new TextEncoder().encode(content).length, lines: lineStartsOf(content).length };
|
|
1385
|
+
}
|
|
1386
|
+
/**
|
|
1387
|
+
* Write from a diff decision: one whole-file replacement, a set of 1-based
|
|
1388
|
+
* line splices, or a set of UTF-8 byte splices. Line/byte changes are
|
|
1389
|
+
* applied bottom-up, the assembled text is diffed against the current
|
|
1390
|
+
* content to report hunks, and persistence goes through the same host
|
|
1391
|
+
* writer, CAS and overlay as `write`.
|
|
1392
|
+
*/
|
|
1393
|
+
diffWrite(item, args) {
|
|
1394
|
+
const nodeId = args.nodeId;
|
|
1395
|
+
if (!item.readable.has(nodeId)) {
|
|
1396
|
+
return fail("not_available");
|
|
249
1397
|
}
|
|
250
|
-
|
|
251
|
-
|
|
1398
|
+
const entity = this.requireEntity(nodeId);
|
|
1399
|
+
if (entity.kind !== "file") {
|
|
1400
|
+
return fail("invalid_arguments");
|
|
252
1401
|
}
|
|
253
|
-
const
|
|
254
|
-
if (
|
|
1402
|
+
const current = this.contentOf(entity);
|
|
1403
|
+
if (current === (void 0)) {
|
|
255
1404
|
return fail("not_available");
|
|
256
1405
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
1406
|
+
const previousRevision = this.revisionOf(entity);
|
|
1407
|
+
const expectRevision = args.expectRevision;
|
|
1408
|
+
if (expectRevision !== (void 0) && expectRevision !== previousRevision) {
|
|
1409
|
+
return fail("fingerprint_mismatch");
|
|
1410
|
+
}
|
|
1411
|
+
const changes = args.changes;
|
|
1412
|
+
const byteChanges = args.byteChanges;
|
|
1413
|
+
/**
|
|
1414
|
+
* Presence, not length, selects the mode: a caller that sent both
|
|
1415
|
+
* `content` and an (even empty) `changes` list made an addressing
|
|
1416
|
+
* mistake rather than asking for a no-op.
|
|
1417
|
+
*/
|
|
1418
|
+
const hasContent = args.content !== (void 0);
|
|
1419
|
+
const hasChanges = args.changes !== (void 0);
|
|
1420
|
+
const hasByteChanges = args.byteChanges !== (void 0);
|
|
1421
|
+
if ((hasContent ? 1 : 0) + (hasChanges ? 1 : 0) + (hasByteChanges ? 1 : 0) !== 1) {
|
|
1422
|
+
return fail("invalid_arguments");
|
|
1423
|
+
}
|
|
1424
|
+
if ((hasChanges && (!Array.isArray(changes) || changes.length === 0)) || (hasByteChanges && (!Array.isArray(byteChanges) || byteChanges.length === 0))) {
|
|
1425
|
+
return fail("invalid_arguments");
|
|
1426
|
+
}
|
|
1427
|
+
let next;
|
|
1428
|
+
let strategy;
|
|
1429
|
+
try {
|
|
1430
|
+
if (hasContent) {
|
|
1431
|
+
next = args.content;
|
|
1432
|
+
strategy = "whole";
|
|
1433
|
+
}
|
|
1434
|
+
else if (hasChanges) {
|
|
1435
|
+
next = applyLineChanges(current, changes.map(asLineChange), this.limits.maxWriteChars);
|
|
1436
|
+
strategy = "lines";
|
|
1437
|
+
}
|
|
1438
|
+
else {
|
|
1439
|
+
next = applyByteChanges(current, byteChanges.map(asByteChange), this.limits.maxWriteChars);
|
|
1440
|
+
strategy = "bytes";
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1443
|
+
catch (error) {
|
|
1444
|
+
return fail(error instanceof WorkspaceDiffError ? error.code : "invalid_arguments");
|
|
1445
|
+
}
|
|
1446
|
+
if (next.length > this.limits.maxWriteChars) {
|
|
1447
|
+
return fail("capacity_exceeded");
|
|
1448
|
+
}
|
|
1449
|
+
const summary = summarizeDiff(entity.source.uri, current, next, args.contextLines);
|
|
1450
|
+
const bytes = new TextEncoder().encode(next).length;
|
|
1451
|
+
const payload = {
|
|
1452
|
+
nodeId,
|
|
1453
|
+
path: entity.source.uri,
|
|
1454
|
+
strategy,
|
|
1455
|
+
dryRun: args.dryRun === true,
|
|
1456
|
+
previousRevision,
|
|
1457
|
+
bytes,
|
|
1458
|
+
lines: lineStartsOf(next).length,
|
|
1459
|
+
added: summary.added,
|
|
1460
|
+
removed: summary.removed,
|
|
1461
|
+
unchanged: summary.unchanged,
|
|
1462
|
+
diffTruncated: summary.truncated,
|
|
1463
|
+
hunks: summary.hunks,
|
|
1464
|
+
remainingTokens: item.allocation.remainingTokens,
|
|
1465
|
+
...this.impacts(nodeId),
|
|
1466
|
+
};
|
|
1467
|
+
if (args.dryRun === true) {
|
|
1468
|
+
return this.reply({ ...payload, revision: null });
|
|
1469
|
+
}
|
|
1470
|
+
if (this.writer === (void 0)) {
|
|
1471
|
+
return fail("write_unavailable");
|
|
1472
|
+
}
|
|
1473
|
+
const outcome = this.writer.write({
|
|
1474
|
+
agentId: this.agentId,
|
|
1475
|
+
nodeId,
|
|
1476
|
+
uri: entity.source.uri,
|
|
1477
|
+
content: next,
|
|
1478
|
+
previousRevision,
|
|
1479
|
+
});
|
|
1480
|
+
if (writeRejected(outcome)) {
|
|
1481
|
+
return fail(outcome.code);
|
|
1482
|
+
}
|
|
1483
|
+
if (typeof (outcome.revision) !== "string" || outcome.revision.length === 0) {
|
|
1484
|
+
return fail("internal_error");
|
|
1485
|
+
}
|
|
1486
|
+
this.writes.set(nodeId, { content: next, revision: outcome.revision, bytes: outcome.bytes ?? bytes });
|
|
1487
|
+
this.invalidateReactive(nodeId);
|
|
1488
|
+
return this.reply({ ...payload, revision: outcome.revision });
|
|
1489
|
+
}
|
|
1490
|
+
builtInComponents() {
|
|
1491
|
+
const components = [
|
|
1492
|
+
{
|
|
1493
|
+
id: WorkspaceServiceId,
|
|
1494
|
+
kind: "service",
|
|
1495
|
+
name: "amp.workspace",
|
|
1496
|
+
description: "Authorized project discovery, context materialization and bounded detail reads.",
|
|
1497
|
+
purpose: "Serve the amp.workspace v1 protocol to agents.",
|
|
1498
|
+
version: "1.0.0",
|
|
1499
|
+
status: "active",
|
|
1500
|
+
},
|
|
1501
|
+
];
|
|
1502
|
+
for (const tool of this.definitions) {
|
|
1503
|
+
components.push({
|
|
1504
|
+
id: tool.name,
|
|
1505
|
+
kind: "tool",
|
|
1506
|
+
name: tool.name,
|
|
1507
|
+
description: tool.description,
|
|
1508
|
+
purpose: "Agent-callable workspace tool.",
|
|
1509
|
+
status: "active",
|
|
262
1510
|
});
|
|
263
|
-
this.contexts.delete(args.contextId);
|
|
264
|
-
this.retired.set(args.contextId, item);
|
|
265
|
-
item.allocation.state = "released";
|
|
266
|
-
return response;
|
|
267
1511
|
}
|
|
268
|
-
return
|
|
1512
|
+
return components;
|
|
269
1513
|
}
|
|
270
1514
|
materialize(frameId, budgetTokens) {
|
|
271
1515
|
const allocation = this.frames.get(frameId);
|
|
@@ -316,6 +1560,13 @@ export class WorkspaceAgentService {
|
|
|
316
1560
|
this.contexts.set(contextId, { context, allocation, readable, response: structuredClone(response), requestedTokens: budgetTokens });
|
|
317
1561
|
return response;
|
|
318
1562
|
}
|
|
1563
|
+
/**
|
|
1564
|
+
* Bounded detail read. The page is addressed by characters, lines or bytes,
|
|
1565
|
+
* and the reply carries the containing file's two impact directions:
|
|
1566
|
+
* `importation` (what this file imports) and `exportation` (which relative
|
|
1567
|
+
* files import it), which is what lets a caller scope an edit without a
|
|
1568
|
+
* second relation query.
|
|
1569
|
+
*/
|
|
319
1570
|
read(item, args) {
|
|
320
1571
|
const nodeId = args.nodeId;
|
|
321
1572
|
if (!item.readable.has(nodeId)) {
|
|
@@ -325,28 +1576,205 @@ export class WorkspaceAgentService {
|
|
|
325
1576
|
if (remaining <= 0) {
|
|
326
1577
|
return fail("budget_exhausted");
|
|
327
1578
|
}
|
|
328
|
-
const
|
|
1579
|
+
const entity = this.requireEntity(nodeId);
|
|
1580
|
+
const file = this.containingFile(nodeId);
|
|
1581
|
+
/**
|
|
1582
|
+
* A symbol or knowledge page is a snapshot extraction of its file. Once
|
|
1583
|
+
* that file has been rewritten through this service the extraction no
|
|
1584
|
+
* longer describes the current bytes, so the page fails closed instead
|
|
1585
|
+
* of presenting stale text with a snapshot revision.
|
|
1586
|
+
*/
|
|
1587
|
+
if (file !== (void 0) && file.id !== nodeId && this.writes.has(file.id)) {
|
|
1588
|
+
return fail("stale_detail");
|
|
1589
|
+
}
|
|
1590
|
+
const accepted = file !== (void 0) && file.id === nodeId ? this.writes.get(nodeId) : (void 0);
|
|
1591
|
+
const content = accepted !== (void 0) ? accepted.content : item.context.expand(nodeId);
|
|
329
1592
|
if (content === (void 0)) {
|
|
330
1593
|
return fail("not_available");
|
|
331
1594
|
}
|
|
332
|
-
const
|
|
333
|
-
|
|
334
|
-
|
|
1595
|
+
const page = readPage(content, args, this.limits.maxReadChars, remaining);
|
|
1596
|
+
const tokens = estimateTokens(page.text);
|
|
1597
|
+
/**
|
|
1598
|
+
* Line mode may return one line whole when it is larger than the page
|
|
1599
|
+
* budget. The Frame budget is still hard, so a page that cannot be paid
|
|
1600
|
+
* for is refused instead of driving the allocation negative.
|
|
1601
|
+
*/
|
|
1602
|
+
if (tokens > remaining) {
|
|
1603
|
+
return fail("budget_exhausted");
|
|
335
1604
|
}
|
|
336
|
-
const size = Math.min(args.maxChars ?? this.limits.maxReadChars, this.limits.maxReadChars, remaining * 4);
|
|
337
|
-
const text = content.slice(offset, offset + size);
|
|
338
|
-
const tokens = text.length === 0 ? 0 : estimateTokens(text);
|
|
339
1605
|
const response = this.reply({
|
|
340
1606
|
nodeId,
|
|
341
|
-
source:
|
|
342
|
-
offset,
|
|
343
|
-
text,
|
|
344
|
-
nextOffset:
|
|
1607
|
+
source: accepted === (void 0) ? entity.source : { ...entity.source, revision: accepted.revision },
|
|
1608
|
+
offset: page.offset,
|
|
1609
|
+
text: page.text,
|
|
1610
|
+
nextOffset: page.nextOffset,
|
|
345
1611
|
totalChars: content.length,
|
|
346
1612
|
tokens,
|
|
347
1613
|
remainingTokens: remaining - tokens,
|
|
1614
|
+
...page.fields,
|
|
1615
|
+
...this.impacts(nodeId),
|
|
348
1616
|
});
|
|
349
1617
|
item.allocation.remainingTokens -= tokens;
|
|
350
1618
|
return response;
|
|
351
1619
|
}
|
|
1620
|
+
/**
|
|
1621
|
+
* Host-delegated write. Authorization is the same allocation that `read`
|
|
1622
|
+
* requires: the target file must be in the materialized Context's readable
|
|
1623
|
+
* set, so a write cannot widen the Frame. The snapshot is not re-parsed, so
|
|
1624
|
+
* the returned impact lists describe the indexed graph, while detail reads
|
|
1625
|
+
* of this node immediately serve the accepted text.
|
|
1626
|
+
*/
|
|
1627
|
+
write(item, args) {
|
|
1628
|
+
const nodeId = args.nodeId;
|
|
1629
|
+
if (!item.readable.has(nodeId)) {
|
|
1630
|
+
return fail("not_available");
|
|
1631
|
+
}
|
|
1632
|
+
const entity = this.requireEntity(nodeId);
|
|
1633
|
+
if (entity.kind !== "file") {
|
|
1634
|
+
return fail("invalid_arguments");
|
|
1635
|
+
}
|
|
1636
|
+
const current = this.contentOf(entity);
|
|
1637
|
+
if (current === (void 0)) {
|
|
1638
|
+
return fail("not_available");
|
|
1639
|
+
}
|
|
1640
|
+
const previousRevision = this.revisionOf(entity);
|
|
1641
|
+
const expectRevision = args.expectRevision;
|
|
1642
|
+
if (expectRevision !== (void 0) && expectRevision !== previousRevision) {
|
|
1643
|
+
return fail("fingerprint_mismatch");
|
|
1644
|
+
}
|
|
1645
|
+
const edit = applyWrite(current, args);
|
|
1646
|
+
if (edit.content.length > this.limits.maxWriteChars) {
|
|
1647
|
+
return fail("capacity_exceeded");
|
|
1648
|
+
}
|
|
1649
|
+
const bytes = new TextEncoder().encode(edit.content).length;
|
|
1650
|
+
const summary = {
|
|
1651
|
+
nodeId,
|
|
1652
|
+
path: entity.source.uri,
|
|
1653
|
+
mode: edit.mode,
|
|
1654
|
+
dryRun: args.dryRun === true,
|
|
1655
|
+
previousRevision,
|
|
1656
|
+
...edit.fields,
|
|
1657
|
+
bytes,
|
|
1658
|
+
lines: lineStartsOf(edit.content).length,
|
|
1659
|
+
remainingTokens: item.allocation.remainingTokens,
|
|
1660
|
+
...this.impacts(nodeId),
|
|
1661
|
+
};
|
|
1662
|
+
if (args.dryRun === true) {
|
|
1663
|
+
return this.reply({ ...summary, revision: null });
|
|
1664
|
+
}
|
|
1665
|
+
if (this.writer === (void 0)) {
|
|
1666
|
+
return fail("write_unavailable");
|
|
1667
|
+
}
|
|
1668
|
+
const outcome = this.writer.write({
|
|
1669
|
+
agentId: this.agentId,
|
|
1670
|
+
nodeId,
|
|
1671
|
+
uri: entity.source.uri,
|
|
1672
|
+
content: edit.content,
|
|
1673
|
+
previousRevision,
|
|
1674
|
+
});
|
|
1675
|
+
if (writeRejected(outcome)) {
|
|
1676
|
+
return fail(outcome.code);
|
|
1677
|
+
}
|
|
1678
|
+
if (typeof (outcome.revision) !== "string" || outcome.revision.length === 0) {
|
|
1679
|
+
return fail("internal_error");
|
|
1680
|
+
}
|
|
1681
|
+
this.writes.set(nodeId, { content: edit.content, revision: outcome.revision, bytes: outcome.bytes ?? bytes });
|
|
1682
|
+
return this.reply({ ...summary, revision: outcome.revision });
|
|
1683
|
+
}
|
|
1684
|
+
/**
|
|
1685
|
+
* Nearest enclosing file entity. Symbol and knowledge nodes inherit their
|
|
1686
|
+
* file's imports, so reading a function body still reports the module's
|
|
1687
|
+
* relative dependencies. Projects, directories and packages have no file.
|
|
1688
|
+
*/
|
|
1689
|
+
containingFile(nodeId) {
|
|
1690
|
+
let entity = this.index.entity(nodeId);
|
|
1691
|
+
for (let depth = 0; entity !== (void 0) && depth < 64; depth += 1) {
|
|
1692
|
+
if (entity.kind === "file") {
|
|
1693
|
+
return entity;
|
|
1694
|
+
}
|
|
1695
|
+
entity = entity.parentId === (void 0) ? (void 0) : this.index.entity(entity.parentId);
|
|
1696
|
+
}
|
|
1697
|
+
return (void 0);
|
|
1698
|
+
}
|
|
1699
|
+
contentOf(entity) {
|
|
1700
|
+
const accepted = this.writes.get(entity.id);
|
|
1701
|
+
if (accepted !== (void 0)) {
|
|
1702
|
+
return accepted.content;
|
|
1703
|
+
}
|
|
1704
|
+
return entity.detailRef === (void 0) ? (void 0) : this.store.get(entity.detailRef);
|
|
1705
|
+
}
|
|
1706
|
+
revisionOf(entity) {
|
|
1707
|
+
return this.writes.get(entity.id)?.revision ?? entity.source.revision;
|
|
1708
|
+
}
|
|
1709
|
+
/**
|
|
1710
|
+
* Relative files on both sides of the `imports` relation.
|
|
1711
|
+
*
|
|
1712
|
+
* `exportation` walks incoming edges: another file importing this one is a
|
|
1713
|
+
* consumer of its exports, which is what "who breaks if I change this?"
|
|
1714
|
+
* means. `importation` walks outgoing edges and keeps bare package
|
|
1715
|
+
* specifiers in a separate list because they have no relative path.
|
|
1716
|
+
*/
|
|
1717
|
+
impacts(nodeId) {
|
|
1718
|
+
const emptyExportation = { path: null, files: [], total: 0, truncated: false };
|
|
1719
|
+
const emptyImportation = { path: null, files: [], external: [], externalTotal: 0, externalTruncated: false, total: 0, truncated: false };
|
|
1720
|
+
const file = this.containingFile(nodeId);
|
|
1721
|
+
if (file === (void 0)) {
|
|
1722
|
+
return { exportation: emptyExportation, importation: emptyImportation };
|
|
1723
|
+
}
|
|
1724
|
+
const limit = this.limits.maxFileLinks;
|
|
1725
|
+
const importers = new Map();
|
|
1726
|
+
this.index.relations(file.id, "incoming", "imports").forEach((edge) => {
|
|
1727
|
+
const source = this.containingFile(edge.from);
|
|
1728
|
+
if (source !== (void 0) && !importers.has(source.id)) {
|
|
1729
|
+
importers.set(source.id, this.linkOf(source, edge));
|
|
1730
|
+
}
|
|
1731
|
+
});
|
|
1732
|
+
const dependencies = new Map();
|
|
1733
|
+
const external = new Set();
|
|
1734
|
+
this.index.relations(file.id, "outgoing", "imports").forEach((edge) => {
|
|
1735
|
+
const target = this.index.entity(edge.to);
|
|
1736
|
+
if (target === (void 0)) {
|
|
1737
|
+
return;
|
|
1738
|
+
}
|
|
1739
|
+
if (target.kind === "package") {
|
|
1740
|
+
external.add(target.label);
|
|
1741
|
+
return;
|
|
1742
|
+
}
|
|
1743
|
+
const dependency = this.containingFile(target.id);
|
|
1744
|
+
if (dependency !== (void 0) && !dependencies.has(dependency.id)) {
|
|
1745
|
+
dependencies.set(dependency.id, this.linkOf(dependency, edge));
|
|
1746
|
+
}
|
|
1747
|
+
});
|
|
1748
|
+
const sortLinks = (links) => [...links.values()].sort((left, right) => (left.path < right.path ? -1 : left.path > right.path ? 1 : 0) ||
|
|
1749
|
+
(left.line ?? 0) - (right.line ?? 0) ||
|
|
1750
|
+
(left.id < right.id ? -1 : left.id > right.id ? 1 : 0));
|
|
1751
|
+
const exporters = sortLinks(importers);
|
|
1752
|
+
const imported = sortLinks(dependencies);
|
|
1753
|
+
const externals = [...external].sort();
|
|
1754
|
+
return {
|
|
1755
|
+
exportation: {
|
|
1756
|
+
path: file.source.uri,
|
|
1757
|
+
files: exporters.slice(0, limit),
|
|
1758
|
+
total: exporters.length,
|
|
1759
|
+
truncated: exporters.length > limit,
|
|
1760
|
+
},
|
|
1761
|
+
importation: {
|
|
1762
|
+
path: file.source.uri,
|
|
1763
|
+
files: imported.slice(0, limit),
|
|
1764
|
+
external: externals.slice(0, limit),
|
|
1765
|
+
externalTotal: externals.length,
|
|
1766
|
+
externalTruncated: externals.length > limit,
|
|
1767
|
+
total: imported.length,
|
|
1768
|
+
truncated: imported.length > limit,
|
|
1769
|
+
},
|
|
1770
|
+
};
|
|
1771
|
+
}
|
|
1772
|
+
linkOf(entity, edge) {
|
|
1773
|
+
return {
|
|
1774
|
+
id: entity.id,
|
|
1775
|
+
path: entity.source.uri,
|
|
1776
|
+
...(edge.source.startLine === (void 0) ? {} : { line: edge.source.startLine }),
|
|
1777
|
+
method: edge.method,
|
|
1778
|
+
};
|
|
1779
|
+
}
|
|
352
1780
|
}
|