@capyclaw/publisher 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/node_modules/@capyclaw/foundation/README.md +51 -0
- package/node_modules/@capyclaw/foundation/abi/bridge.mjs +86 -0
- package/node_modules/@capyclaw/foundation/abi/errors.mjs +63 -0
- package/node_modules/@capyclaw/foundation/abi/index.mjs +35 -0
- package/node_modules/@capyclaw/foundation/abi/kinds.mjs +271 -0
- package/node_modules/@capyclaw/foundation/abi/loader.mjs +352 -0
- package/node_modules/@capyclaw/foundation/abi/schema.mjs +98 -0
- package/node_modules/@capyclaw/foundation/abi/spec.mjs +258 -0
- package/node_modules/@capyclaw/foundation/abi/validate.mjs +24 -0
- package/node_modules/@capyclaw/foundation/abi/version.mjs +140 -0
- package/node_modules/@capyclaw/foundation/cordis.patch.yml +5 -0
- package/node_modules/@capyclaw/foundation/kit/index.mjs +6 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/client-panel.mjs +98 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/host-event.mjs +35 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/http-router.mjs +69 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/lifecycle-hook.mjs +55 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/own-server.mjs +113 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/raw.mjs +69 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/runtime-driver.mjs +120 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/service-provider.mjs +77 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/skill-provider.mjs +56 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/tool-provider.mjs +50 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/ui-panel.mjs +64 -0
- package/node_modules/@capyclaw/foundation/lib/ctx-service.mjs +42 -0
- package/node_modules/@capyclaw/foundation/lib/host/caps.mjs +34 -0
- package/node_modules/@capyclaw/foundation/lib/host/contract.mjs +85 -0
- package/node_modules/@capyclaw/foundation/lib/host/dsh.mjs +50 -0
- package/node_modules/@capyclaw/foundation/lib/host/memory.mjs +187 -0
- package/node_modules/@capyclaw/foundation/lib/host.mjs +23 -0
- package/node_modules/@capyclaw/foundation/lib/kernel.mjs +185 -0
- package/node_modules/@capyclaw/foundation/lib/skill/scan.mjs +115 -0
- package/node_modules/@capyclaw/foundation/lib/subsystems/events.mjs +60 -0
- package/node_modules/@capyclaw/foundation/lib/subsystems/log.mjs +51 -0
- package/node_modules/@capyclaw/foundation/lib/subsystems/net.mjs +198 -0
- package/node_modules/@capyclaw/foundation/package.json +53 -0
- package/node_modules/@capyclaw/foundation/runtime/index.mjs +20 -0
- package/node_modules/@capyclaw/plugin-kit/INTEGRATION.md +100 -0
- package/node_modules/@capyclaw/plugin-kit/README.md +70 -0
- package/node_modules/@capyclaw/plugin-kit/bin/sync.mjs +103 -0
- package/node_modules/@capyclaw/plugin-kit/package.json +69 -0
- package/node_modules/@capyclaw/plugin-kit/src/cli.mjs +56 -0
- package/node_modules/@capyclaw/plugin-kit/src/config.mjs +142 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/heartbeat-worker.js +129 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/lease.mjs +60 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/shadow.mjs +219 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/transport.js +13 -0
- package/node_modules/@capyclaw/plugin-kit/src/index.mjs +13 -0
- package/node_modules/@capyclaw/plugin-kit/src/pack.mjs +230 -0
- package/node_modules/@capyclaw/plugin-kit/src/runtime/context.mjs +128 -0
- package/node_modules/@capyclaw/plugin-kit/src/self-contained.mjs +307 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/api.mjs +45 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/http.mjs +113 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/mcp-http.mjs +150 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/server.mjs +131 -0
- package/node_modules/@capyclaw/plugin-kit/src/skills/provider.mjs +82 -0
- package/node_modules/@capyclaw/plugin-kit/src/store/blob-store.mjs +109 -0
- package/node_modules/@capyclaw/plugin-kit/src/store/content-store.mjs +17 -0
- package/node_modules/@capyclaw/plugin-kit/src/store/journal-store.mjs +89 -0
- package/node_modules/@capyclaw/plugin-kit/src/tools/result.mjs +57 -0
- package/node_modules/@capyclaw/plugin-kit/src/tools/validate.mjs +150 -0
- package/node_modules/@capyclaw/plugin-kit/src/tuning.mjs +82 -0
- package/node_modules/@capyclaw/plugin-kit/src/util/fs-lock.mjs +132 -0
- package/node_modules/@capyclaw/plugin-kit/src/util/http.mjs +130 -0
- package/node_modules/@capyclaw/plugin-kit/src/workspace/manager.mjs +656 -0
- package/node_modules/@capyclaw/plugin-kit/src/zip.mjs +181 -0
- package/node_modules/@capyclaw/plugin-validator/bin/cli.mjs +49 -0
- package/node_modules/@capyclaw/plugin-validator/lib/index.mjs +303 -0
- package/node_modules/@capyclaw/plugin-validator/package.json +28 -0
- package/node_modules/@capyclaw/tool-host/README.md +56 -0
- package/node_modules/@capyclaw/tool-host/cordis.patch.yml +4 -0
- package/node_modules/@capyclaw/tool-host/dsh-suite.json +30 -0
- package/node_modules/@capyclaw/tool-host/lib/host.mjs +37 -0
- package/node_modules/@capyclaw/tool-host/package.json +59 -0
- package/node_modules/@capyclaw/tool-host/src/admit-images.mjs +80 -0
- package/node_modules/@capyclaw/tool-host/src/caller-session.mjs +25 -0
- package/node_modules/@capyclaw/tool-host/src/descriptors.mjs +166 -0
- package/node_modules/@capyclaw/tool-host/src/index.mjs +449 -0
- package/node_modules/@capyclaw/tool-host/src/mode-gate.mjs +214 -0
- package/node_modules/semver/LICENSE +15 -0
- package/node_modules/semver/README.md +680 -0
- package/node_modules/semver/bin/semver.js +195 -0
- package/node_modules/semver/classes/comparator.js +143 -0
- package/node_modules/semver/classes/index.js +7 -0
- package/node_modules/semver/classes/range.js +577 -0
- package/node_modules/semver/classes/semver.js +350 -0
- package/node_modules/semver/functions/clean.js +8 -0
- package/node_modules/semver/functions/cmp.js +54 -0
- package/node_modules/semver/functions/coerce.js +62 -0
- package/node_modules/semver/functions/compare-build.js +9 -0
- package/node_modules/semver/functions/compare-loose.js +5 -0
- package/node_modules/semver/functions/compare.js +7 -0
- package/node_modules/semver/functions/diff.js +60 -0
- package/node_modules/semver/functions/eq.js +5 -0
- package/node_modules/semver/functions/gt.js +5 -0
- package/node_modules/semver/functions/gte.js +5 -0
- package/node_modules/semver/functions/inc.js +21 -0
- package/node_modules/semver/functions/lt.js +5 -0
- package/node_modules/semver/functions/lte.js +5 -0
- package/node_modules/semver/functions/major.js +5 -0
- package/node_modules/semver/functions/minor.js +5 -0
- package/node_modules/semver/functions/neq.js +5 -0
- package/node_modules/semver/functions/parse.js +18 -0
- package/node_modules/semver/functions/patch.js +5 -0
- package/node_modules/semver/functions/prerelease.js +8 -0
- package/node_modules/semver/functions/rcompare.js +5 -0
- package/node_modules/semver/functions/rsort.js +5 -0
- package/node_modules/semver/functions/satisfies.js +12 -0
- package/node_modules/semver/functions/sort.js +5 -0
- package/node_modules/semver/functions/truncate.js +48 -0
- package/node_modules/semver/functions/valid.js +8 -0
- package/node_modules/semver/index.js +93 -0
- package/node_modules/semver/internal/constants.js +67 -0
- package/node_modules/semver/internal/debug.js +11 -0
- package/node_modules/semver/internal/identifiers.js +29 -0
- package/node_modules/semver/internal/lrucache.js +42 -0
- package/node_modules/semver/internal/parse-options.js +17 -0
- package/node_modules/semver/internal/re.js +223 -0
- package/node_modules/semver/internal/trim-comparator-whitespace.js +438 -0
- package/node_modules/semver/package.json +78 -0
- package/node_modules/semver/preload.js +4 -0
- package/node_modules/semver/range.bnf +17 -0
- package/node_modules/semver/ranges/gtr.js +6 -0
- package/node_modules/semver/ranges/intersects.js +9 -0
- package/node_modules/semver/ranges/ltr.js +6 -0
- package/node_modules/semver/ranges/max-satisfying.js +27 -0
- package/node_modules/semver/ranges/min-satisfying.js +26 -0
- package/node_modules/semver/ranges/min-version.js +63 -0
- package/node_modules/semver/ranges/outside.js +82 -0
- package/node_modules/semver/ranges/simplify.js +49 -0
- package/node_modules/semver/ranges/subset.js +249 -0
- package/node_modules/semver/ranges/to-comparators.js +10 -0
- package/node_modules/semver/ranges/valid.js +13 -0
- package/node_modules/yaml/LICENSE +13 -0
- package/node_modules/yaml/README.md +172 -0
- package/node_modules/yaml/bin.mjs +11 -0
- package/node_modules/yaml/browser/dist/compose/compose-collection.js +88 -0
- package/node_modules/yaml/browser/dist/compose/compose-doc.js +43 -0
- package/node_modules/yaml/browser/dist/compose/compose-node.js +109 -0
- package/node_modules/yaml/browser/dist/compose/compose-scalar.js +86 -0
- package/node_modules/yaml/browser/dist/compose/composer.js +219 -0
- package/node_modules/yaml/browser/dist/compose/resolve-block-map.js +115 -0
- package/node_modules/yaml/browser/dist/compose/resolve-block-scalar.js +198 -0
- package/node_modules/yaml/browser/dist/compose/resolve-block-seq.js +49 -0
- package/node_modules/yaml/browser/dist/compose/resolve-end.js +37 -0
- package/node_modules/yaml/browser/dist/compose/resolve-flow-collection.js +207 -0
- package/node_modules/yaml/browser/dist/compose/resolve-flow-scalar.js +226 -0
- package/node_modules/yaml/browser/dist/compose/resolve-props.js +146 -0
- package/node_modules/yaml/browser/dist/compose/util-contains-newline.js +34 -0
- package/node_modules/yaml/browser/dist/compose/util-empty-scalar-position.js +26 -0
- package/node_modules/yaml/browser/dist/compose/util-flow-indent-check.js +15 -0
- package/node_modules/yaml/browser/dist/compose/util-map-includes.js +13 -0
- package/node_modules/yaml/browser/dist/doc/Document.js +335 -0
- package/node_modules/yaml/browser/dist/doc/anchors.js +71 -0
- package/node_modules/yaml/browser/dist/doc/applyReviver.js +55 -0
- package/node_modules/yaml/browser/dist/doc/createNode.js +88 -0
- package/node_modules/yaml/browser/dist/doc/directives.js +176 -0
- package/node_modules/yaml/browser/dist/errors.js +57 -0
- package/node_modules/yaml/browser/dist/index.js +17 -0
- package/node_modules/yaml/browser/dist/log.js +11 -0
- package/node_modules/yaml/browser/dist/nodes/Alias.js +118 -0
- package/node_modules/yaml/browser/dist/nodes/Collection.js +147 -0
- package/node_modules/yaml/browser/dist/nodes/Node.js +38 -0
- package/node_modules/yaml/browser/dist/nodes/Pair.js +36 -0
- package/node_modules/yaml/browser/dist/nodes/Scalar.js +24 -0
- package/node_modules/yaml/browser/dist/nodes/YAMLMap.js +144 -0
- package/node_modules/yaml/browser/dist/nodes/YAMLSeq.js +113 -0
- package/node_modules/yaml/browser/dist/nodes/addPairToJSMap.js +63 -0
- package/node_modules/yaml/browser/dist/nodes/identity.js +36 -0
- package/node_modules/yaml/browser/dist/nodes/toJS.js +37 -0
- package/node_modules/yaml/browser/dist/parse/cst-scalar.js +214 -0
- package/node_modules/yaml/browser/dist/parse/cst-stringify.js +61 -0
- package/node_modules/yaml/browser/dist/parse/cst-visit.js +97 -0
- package/node_modules/yaml/browser/dist/parse/cst.js +98 -0
- package/node_modules/yaml/browser/dist/parse/lexer.js +721 -0
- package/node_modules/yaml/browser/dist/parse/line-counter.js +39 -0
- package/node_modules/yaml/browser/dist/parse/parser.js +975 -0
- package/node_modules/yaml/browser/dist/public-api.js +102 -0
- package/node_modules/yaml/browser/dist/schema/Schema.js +37 -0
- package/node_modules/yaml/browser/dist/schema/common/map.js +17 -0
- package/node_modules/yaml/browser/dist/schema/common/null.js +15 -0
- package/node_modules/yaml/browser/dist/schema/common/seq.js +17 -0
- package/node_modules/yaml/browser/dist/schema/common/string.js +14 -0
- package/node_modules/yaml/browser/dist/schema/core/bool.js +19 -0
- package/node_modules/yaml/browser/dist/schema/core/float.js +43 -0
- package/node_modules/yaml/browser/dist/schema/core/int.js +38 -0
- package/node_modules/yaml/browser/dist/schema/core/schema.js +23 -0
- package/node_modules/yaml/browser/dist/schema/json/schema.js +62 -0
- package/node_modules/yaml/browser/dist/schema/tags.js +96 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/binary.js +58 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/bool.js +26 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/float.js +46 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/int.js +71 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/merge.js +67 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/omap.js +74 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/pairs.js +78 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/schema.js +39 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/set.js +93 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/timestamp.js +101 -0
- package/node_modules/yaml/browser/dist/stringify/foldFlowLines.js +146 -0
- package/node_modules/yaml/browser/dist/stringify/stringify.js +129 -0
- package/node_modules/yaml/browser/dist/stringify/stringifyCollection.js +153 -0
- package/node_modules/yaml/browser/dist/stringify/stringifyComment.js +20 -0
- package/node_modules/yaml/browser/dist/stringify/stringifyDocument.js +85 -0
- package/node_modules/yaml/browser/dist/stringify/stringifyNumber.js +25 -0
- package/node_modules/yaml/browser/dist/stringify/stringifyPair.js +150 -0
- package/node_modules/yaml/browser/dist/stringify/stringifyString.js +336 -0
- package/node_modules/yaml/browser/dist/util.js +11 -0
- package/node_modules/yaml/browser/dist/visit.js +233 -0
- package/node_modules/yaml/browser/index.js +5 -0
- package/node_modules/yaml/browser/package.json +3 -0
- package/node_modules/yaml/dist/cli.d.ts +8 -0
- package/node_modules/yaml/dist/cli.mjs +201 -0
- package/node_modules/yaml/dist/compose/compose-collection.d.ts +11 -0
- package/node_modules/yaml/dist/compose/compose-collection.js +90 -0
- package/node_modules/yaml/dist/compose/compose-doc.d.ts +7 -0
- package/node_modules/yaml/dist/compose/compose-doc.js +45 -0
- package/node_modules/yaml/dist/compose/compose-node.d.ts +29 -0
- package/node_modules/yaml/dist/compose/compose-node.js +112 -0
- package/node_modules/yaml/dist/compose/compose-scalar.d.ts +5 -0
- package/node_modules/yaml/dist/compose/compose-scalar.js +88 -0
- package/node_modules/yaml/dist/compose/composer.d.ts +63 -0
- package/node_modules/yaml/dist/compose/composer.js +224 -0
- package/node_modules/yaml/dist/compose/resolve-block-map.d.ts +6 -0
- package/node_modules/yaml/dist/compose/resolve-block-map.js +117 -0
- package/node_modules/yaml/dist/compose/resolve-block-scalar.d.ts +11 -0
- package/node_modules/yaml/dist/compose/resolve-block-scalar.js +200 -0
- package/node_modules/yaml/dist/compose/resolve-block-seq.d.ts +6 -0
- package/node_modules/yaml/dist/compose/resolve-block-seq.js +51 -0
- package/node_modules/yaml/dist/compose/resolve-end.d.ts +6 -0
- package/node_modules/yaml/dist/compose/resolve-end.js +39 -0
- package/node_modules/yaml/dist/compose/resolve-flow-collection.d.ts +7 -0
- package/node_modules/yaml/dist/compose/resolve-flow-collection.js +209 -0
- package/node_modules/yaml/dist/compose/resolve-flow-scalar.d.ts +10 -0
- package/node_modules/yaml/dist/compose/resolve-flow-scalar.js +228 -0
- package/node_modules/yaml/dist/compose/resolve-props.d.ts +23 -0
- package/node_modules/yaml/dist/compose/resolve-props.js +148 -0
- package/node_modules/yaml/dist/compose/util-contains-newline.d.ts +2 -0
- package/node_modules/yaml/dist/compose/util-contains-newline.js +36 -0
- package/node_modules/yaml/dist/compose/util-empty-scalar-position.d.ts +2 -0
- package/node_modules/yaml/dist/compose/util-empty-scalar-position.js +28 -0
- package/node_modules/yaml/dist/compose/util-flow-indent-check.d.ts +3 -0
- package/node_modules/yaml/dist/compose/util-flow-indent-check.js +17 -0
- package/node_modules/yaml/dist/compose/util-map-includes.d.ts +4 -0
- package/node_modules/yaml/dist/compose/util-map-includes.js +15 -0
- package/node_modules/yaml/dist/doc/Document.d.ts +141 -0
- package/node_modules/yaml/dist/doc/Document.js +337 -0
- package/node_modules/yaml/dist/doc/anchors.d.ts +24 -0
- package/node_modules/yaml/dist/doc/anchors.js +76 -0
- package/node_modules/yaml/dist/doc/applyReviver.d.ts +9 -0
- package/node_modules/yaml/dist/doc/applyReviver.js +57 -0
- package/node_modules/yaml/dist/doc/createNode.d.ts +17 -0
- package/node_modules/yaml/dist/doc/createNode.js +90 -0
- package/node_modules/yaml/dist/doc/directives.d.ts +49 -0
- package/node_modules/yaml/dist/doc/directives.js +178 -0
- package/node_modules/yaml/dist/errors.d.ts +21 -0
- package/node_modules/yaml/dist/errors.js +62 -0
- package/node_modules/yaml/dist/index.d.ts +25 -0
- package/node_modules/yaml/dist/index.js +50 -0
- package/node_modules/yaml/dist/log.d.ts +3 -0
- package/node_modules/yaml/dist/log.js +19 -0
- package/node_modules/yaml/dist/nodes/Alias.d.ts +29 -0
- package/node_modules/yaml/dist/nodes/Alias.js +120 -0
- package/node_modules/yaml/dist/nodes/Collection.d.ts +73 -0
- package/node_modules/yaml/dist/nodes/Collection.js +151 -0
- package/node_modules/yaml/dist/nodes/Node.d.ts +53 -0
- package/node_modules/yaml/dist/nodes/Node.js +40 -0
- package/node_modules/yaml/dist/nodes/Pair.d.ts +22 -0
- package/node_modules/yaml/dist/nodes/Pair.js +39 -0
- package/node_modules/yaml/dist/nodes/Scalar.d.ts +47 -0
- package/node_modules/yaml/dist/nodes/Scalar.js +27 -0
- package/node_modules/yaml/dist/nodes/YAMLMap.d.ts +53 -0
- package/node_modules/yaml/dist/nodes/YAMLMap.js +147 -0
- package/node_modules/yaml/dist/nodes/YAMLSeq.d.ts +60 -0
- package/node_modules/yaml/dist/nodes/YAMLSeq.js +115 -0
- package/node_modules/yaml/dist/nodes/addPairToJSMap.d.ts +4 -0
- package/node_modules/yaml/dist/nodes/addPairToJSMap.js +65 -0
- package/node_modules/yaml/dist/nodes/identity.d.ts +23 -0
- package/node_modules/yaml/dist/nodes/identity.js +53 -0
- package/node_modules/yaml/dist/nodes/toJS.d.ts +29 -0
- package/node_modules/yaml/dist/nodes/toJS.js +39 -0
- package/node_modules/yaml/dist/options.d.ts +350 -0
- package/node_modules/yaml/dist/parse/cst-scalar.d.ts +64 -0
- package/node_modules/yaml/dist/parse/cst-scalar.js +218 -0
- package/node_modules/yaml/dist/parse/cst-stringify.d.ts +8 -0
- package/node_modules/yaml/dist/parse/cst-stringify.js +63 -0
- package/node_modules/yaml/dist/parse/cst-visit.d.ts +39 -0
- package/node_modules/yaml/dist/parse/cst-visit.js +99 -0
- package/node_modules/yaml/dist/parse/cst.d.ts +109 -0
- package/node_modules/yaml/dist/parse/cst.js +112 -0
- package/node_modules/yaml/dist/parse/lexer.d.ts +87 -0
- package/node_modules/yaml/dist/parse/lexer.js +723 -0
- package/node_modules/yaml/dist/parse/line-counter.d.ts +22 -0
- package/node_modules/yaml/dist/parse/line-counter.js +41 -0
- package/node_modules/yaml/dist/parse/parser.d.ts +84 -0
- package/node_modules/yaml/dist/parse/parser.js +980 -0
- package/node_modules/yaml/dist/public-api.d.ts +44 -0
- package/node_modules/yaml/dist/public-api.js +107 -0
- package/node_modules/yaml/dist/schema/Schema.d.ts +17 -0
- package/node_modules/yaml/dist/schema/Schema.js +39 -0
- package/node_modules/yaml/dist/schema/common/map.d.ts +2 -0
- package/node_modules/yaml/dist/schema/common/map.js +19 -0
- package/node_modules/yaml/dist/schema/common/null.d.ts +4 -0
- package/node_modules/yaml/dist/schema/common/null.js +17 -0
- package/node_modules/yaml/dist/schema/common/seq.d.ts +2 -0
- package/node_modules/yaml/dist/schema/common/seq.js +19 -0
- package/node_modules/yaml/dist/schema/common/string.d.ts +2 -0
- package/node_modules/yaml/dist/schema/common/string.js +16 -0
- package/node_modules/yaml/dist/schema/core/bool.d.ts +4 -0
- package/node_modules/yaml/dist/schema/core/bool.js +21 -0
- package/node_modules/yaml/dist/schema/core/float.d.ts +4 -0
- package/node_modules/yaml/dist/schema/core/float.js +47 -0
- package/node_modules/yaml/dist/schema/core/int.d.ts +4 -0
- package/node_modules/yaml/dist/schema/core/int.js +42 -0
- package/node_modules/yaml/dist/schema/core/schema.d.ts +1 -0
- package/node_modules/yaml/dist/schema/core/schema.js +25 -0
- package/node_modules/yaml/dist/schema/json/schema.d.ts +2 -0
- package/node_modules/yaml/dist/schema/json/schema.js +64 -0
- package/node_modules/yaml/dist/schema/json-schema.d.ts +69 -0
- package/node_modules/yaml/dist/schema/tags.d.ts +48 -0
- package/node_modules/yaml/dist/schema/tags.js +99 -0
- package/node_modules/yaml/dist/schema/types.d.ts +92 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/binary.d.ts +2 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/binary.js +70 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/bool.d.ts +7 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/bool.js +29 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/float.d.ts +4 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/float.js +50 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/int.d.ts +5 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/int.js +76 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/merge.d.ts +9 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/merge.js +71 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/omap.d.ts +22 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/omap.js +77 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/pairs.d.ts +10 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/pairs.js +82 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/schema.d.ts +1 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/schema.js +41 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/set.d.ts +28 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/set.js +96 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/timestamp.d.ts +6 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/timestamp.js +105 -0
- package/node_modules/yaml/dist/stringify/foldFlowLines.d.ts +34 -0
- package/node_modules/yaml/dist/stringify/foldFlowLines.js +151 -0
- package/node_modules/yaml/dist/stringify/stringify.d.ts +21 -0
- package/node_modules/yaml/dist/stringify/stringify.js +132 -0
- package/node_modules/yaml/dist/stringify/stringifyCollection.d.ts +17 -0
- package/node_modules/yaml/dist/stringify/stringifyCollection.js +155 -0
- package/node_modules/yaml/dist/stringify/stringifyComment.d.ts +10 -0
- package/node_modules/yaml/dist/stringify/stringifyComment.js +24 -0
- package/node_modules/yaml/dist/stringify/stringifyDocument.d.ts +4 -0
- package/node_modules/yaml/dist/stringify/stringifyDocument.js +87 -0
- package/node_modules/yaml/dist/stringify/stringifyNumber.d.ts +2 -0
- package/node_modules/yaml/dist/stringify/stringifyNumber.js +27 -0
- package/node_modules/yaml/dist/stringify/stringifyPair.d.ts +3 -0
- package/node_modules/yaml/dist/stringify/stringifyPair.js +152 -0
- package/node_modules/yaml/dist/stringify/stringifyString.d.ts +9 -0
- package/node_modules/yaml/dist/stringify/stringifyString.js +338 -0
- package/node_modules/yaml/dist/test-events.d.ts +4 -0
- package/node_modules/yaml/dist/test-events.js +134 -0
- package/node_modules/yaml/dist/util.d.ts +16 -0
- package/node_modules/yaml/dist/util.js +28 -0
- package/node_modules/yaml/dist/visit.d.ts +102 -0
- package/node_modules/yaml/dist/visit.js +236 -0
- package/node_modules/yaml/package.json +97 -0
- package/node_modules/yaml/util.js +2 -0
- package/package.json +10 -2
- package/server/impl.mjs +11 -1
|
@@ -0,0 +1,656 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 文件关系中间层(Workspace / Catalog Manager)。
|
|
3
|
+
*
|
|
4
|
+
* 职责边界:
|
|
5
|
+
* BlobStore(store/blob-store.mjs):只存对象,不认识文件名、作品、归属。
|
|
6
|
+
* WorkspaceManager(本文件):解释“哪些对象属于同一个 work、谁能改、
|
|
7
|
+
* 版本是多少、什么时候过期”,并生成可给 UI/生命周期管理读取的 catalog。
|
|
8
|
+
*
|
|
9
|
+
* 同一个 runtime 内的多个会话共享同一个 work;不同 runtime 通过 namespace
|
|
10
|
+
* token 隔离。新建文件自动归入当前 work 的 manifest,不会串到别的 runtime。
|
|
11
|
+
*/
|
|
12
|
+
import crypto from 'node:crypto'
|
|
13
|
+
import fs from 'node:fs'
|
|
14
|
+
import path from 'node:path'
|
|
15
|
+
import { BlobStore } from '../store/blob-store.mjs'
|
|
16
|
+
import { timingSafeEqualText } from '../util/http.mjs'
|
|
17
|
+
import { readJson, withFileLock, writeJsonAtomic } from '../util/fs-lock.mjs'
|
|
18
|
+
import { tuning } from '../tuning.mjs'
|
|
19
|
+
|
|
20
|
+
const ID_RE = /^[a-z0-9][a-z0-9._-]{0,63}$/
|
|
21
|
+
const KEY_RE = /^(?!\/)(?!.*(?:^|\/)\.\.(?:\/|$))[A-Za-z0-9._@/+:-]{1,512}$/
|
|
22
|
+
|
|
23
|
+
export class WorkspaceConflictError extends Error {
|
|
24
|
+
constructor(message = '内容版本冲突') {
|
|
25
|
+
super(message)
|
|
26
|
+
this.name = 'WorkspaceConflictError'
|
|
27
|
+
this.code = 'ESTALE'
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export class WorkspaceAccessError extends Error {
|
|
32
|
+
constructor(message = '没有访问该 runtime namespace 的权限') {
|
|
33
|
+
super(message)
|
|
34
|
+
this.name = 'WorkspaceAccessError'
|
|
35
|
+
this.code = 'EACCES'
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function assertId(value, label) {
|
|
40
|
+
if (typeof value !== 'string' || !ID_RE.test(value)) {
|
|
41
|
+
throw new Error(`${label} 必须是 1-64 位小写字母/数字/._-: ${value}`)
|
|
42
|
+
}
|
|
43
|
+
return value
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function assertKey(key) {
|
|
47
|
+
if (typeof key !== 'string' || !KEY_RE.test(key)) throw new Error(`对象 key 非法: ${key}`)
|
|
48
|
+
if (key === 'manifest.json') throw new Error('manifest.json 是中间层保留 key')
|
|
49
|
+
return key
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function hashToken(token) {
|
|
53
|
+
return crypto.createHash('sha256').update(String(token)).digest('hex')
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function safeEqualHex(left, right) {
|
|
57
|
+
return timingSafeEqualText(left, right)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export class NamespaceRegistry {
|
|
61
|
+
constructor({ storeRoot }) {
|
|
62
|
+
this.storeRoot = path.resolve(storeRoot)
|
|
63
|
+
this.dir = path.join(this.storeRoot, 'namespaces')
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
file(runtimeId) {
|
|
67
|
+
return path.join(this.dir, `${assertId(runtimeId, 'runtimeId')}.json`)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
create(runtimeId, { token, ttlSec = 0, quotaBytes = 0, meta = {} } = {}) {
|
|
71
|
+
assertId(runtimeId, 'runtimeId')
|
|
72
|
+
fs.mkdirSync(this.dir, { recursive: true })
|
|
73
|
+
const secret = token || crypto.randomBytes(32).toString('hex')
|
|
74
|
+
const now = new Date().toISOString()
|
|
75
|
+
const record = {
|
|
76
|
+
schemaVersion: 1,
|
|
77
|
+
runtimeId,
|
|
78
|
+
tokenHash: hashToken(secret),
|
|
79
|
+
status: 'active',
|
|
80
|
+
createdAt: now,
|
|
81
|
+
lastAccessAt: now,
|
|
82
|
+
ttlSec: Number(ttlSec) || 0,
|
|
83
|
+
quotaBytes: Number(quotaBytes) || 0,
|
|
84
|
+
meta: meta && typeof meta === 'object' ? meta : {},
|
|
85
|
+
}
|
|
86
|
+
writeJsonAtomic(this.file(runtimeId), record)
|
|
87
|
+
return { runtimeId, token: secret, record }
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
read(runtimeId) {
|
|
91
|
+
return readJson(this.file(runtimeId), null)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
verify(runtimeId, token) {
|
|
95
|
+
const record = this.read(runtimeId)
|
|
96
|
+
if (!record || record.status !== 'active') throw new WorkspaceAccessError()
|
|
97
|
+
if (!safeEqualHex(record.tokenHash, hashToken(token))) throw new WorkspaceAccessError()
|
|
98
|
+
if (record.ttlSec > 0) {
|
|
99
|
+
const last = Date.parse(record.lastAccessAt || record.createdAt)
|
|
100
|
+
if (Date.now() - last > record.ttlSec * 1000) throw new WorkspaceAccessError('运行时 namespace 已过期')
|
|
101
|
+
}
|
|
102
|
+
return record
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
touch(runtimeId) {
|
|
106
|
+
const record = this.read(runtimeId)
|
|
107
|
+
if (!record) return
|
|
108
|
+
record.lastAccessAt = new Date().toISOString()
|
|
109
|
+
writeJsonAtomic(this.file(runtimeId), record)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
remove(runtimeId) {
|
|
113
|
+
fs.rmSync(this.file(runtimeId), { force: true })
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export class WorkspaceManager {
|
|
118
|
+
/* journalMaxBytes 默认 512KB:与 JournalStore / FileStateBackend 的进化固化值
|
|
119
|
+
* 保持一致(同构机制:原子 state + journal 轮转),尾读更快、磁盘更省。 */
|
|
120
|
+
constructor({ storeRoot, blobStore = null, journalMaxBytes = 512 * 1024 }) {
|
|
121
|
+
if (!storeRoot) throw new Error('WorkspaceManager 需要 storeRoot')
|
|
122
|
+
this.storeRoot = path.resolve(storeRoot)
|
|
123
|
+
this.blobs = blobStore || new BlobStore({ root: this.storeRoot }).init()
|
|
124
|
+
this.namespaces = new NamespaceRegistry({ storeRoot: this.storeRoot })
|
|
125
|
+
this.worksRoot = path.join(this.storeRoot, 'workspaces')
|
|
126
|
+
this.catalogFile = path.join(this.storeRoot, 'catalog', 'works.json')
|
|
127
|
+
this.locksRoot = path.join(this.storeRoot, 'locks')
|
|
128
|
+
this.journalMaxBytes = Math.max(64 * 1024, Number(journalMaxBytes) || 512 * 1024)
|
|
129
|
+
this._catalogTouched = new Map()
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
init() {
|
|
133
|
+
fs.mkdirSync(this.worksRoot, { recursive: true })
|
|
134
|
+
fs.mkdirSync(path.join(this.storeRoot, 'catalog'), { recursive: true })
|
|
135
|
+
fs.mkdirSync(this.locksRoot, { recursive: true })
|
|
136
|
+
return this
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
workDir(runtimeId, workId) {
|
|
140
|
+
return path.join(this.worksRoot, assertId(runtimeId, 'runtimeId'), assertId(workId, 'workId'))
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
manifestFile(runtimeId, workId) {
|
|
144
|
+
return path.join(this.workDir(runtimeId, workId), 'manifest.json')
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
lockFile(kind, runtimeId, workId = '') {
|
|
148
|
+
const parts = [assertId(runtimeId, 'runtimeId'), workId ? assertId(workId, 'workId') : ''].filter(Boolean)
|
|
149
|
+
return path.join(this.locksRoot, kind, ...parts) + '.lock'
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
emptyManifest(runtimeId, workId, title = '') {
|
|
153
|
+
const now = new Date().toISOString()
|
|
154
|
+
return {
|
|
155
|
+
schemaVersion: 1,
|
|
156
|
+
runtimeId,
|
|
157
|
+
workId,
|
|
158
|
+
title: title || workId,
|
|
159
|
+
createdAt: now,
|
|
160
|
+
updatedAt: now,
|
|
161
|
+
version: 0,
|
|
162
|
+
/* 中间层声明:这个 work 管哪些逻辑文件;allowNew 控制新 key 是否自动归属。 */
|
|
163
|
+
declaration: {
|
|
164
|
+
files: ['**'],
|
|
165
|
+
allowNew: true,
|
|
166
|
+
updatedAt: now,
|
|
167
|
+
},
|
|
168
|
+
files: {},
|
|
169
|
+
meta: {},
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* 中间层声明一个 work 的文件范围。
|
|
175
|
+
* files 支持精确 key、目录前缀(以 / 结尾)和 /** 前缀通配。
|
|
176
|
+
* 声明本身不增加内容版本号;内容写入才增加 version。
|
|
177
|
+
*/
|
|
178
|
+
declareWork(runtimeId, workId, { files = ['**'], allowNew = true, title = '', meta = {} } = {}) {
|
|
179
|
+
assertId(runtimeId, 'runtimeId')
|
|
180
|
+
assertId(workId, 'workId')
|
|
181
|
+
if (!Array.isArray(files) || files.length === 0 || files.some((item) => typeof item !== 'string' || !item)) {
|
|
182
|
+
throw new Error('declaration.files 必须是非空字符串数组')
|
|
183
|
+
}
|
|
184
|
+
return withFileLock(this.lockFile('works', runtimeId, workId), () => {
|
|
185
|
+
const manifest = this.readManifest(runtimeId, workId) || this.emptyManifest(runtimeId, workId, title)
|
|
186
|
+
manifest.title = title || manifest.title || workId
|
|
187
|
+
manifest.declaration = {
|
|
188
|
+
files: [...new Set(files)],
|
|
189
|
+
allowNew: !!allowNew,
|
|
190
|
+
updatedAt: new Date().toISOString(),
|
|
191
|
+
}
|
|
192
|
+
if (meta && typeof meta === 'object') manifest.meta = { ...(manifest.meta || {}), ...meta }
|
|
193
|
+
manifest.updatedAt = new Date().toISOString()
|
|
194
|
+
this.writeManifest(manifest, { catalog: true })
|
|
195
|
+
return manifest
|
|
196
|
+
})
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
assertDeclared(manifest, key) {
|
|
200
|
+
const declaration = manifest?.declaration
|
|
201
|
+
if (!declaration || !Array.isArray(declaration.files) || declaration.files.length === 0) return true
|
|
202
|
+
const matched = declaration.files.some((pattern) => {
|
|
203
|
+
if (pattern === '*' || pattern === '**') return true
|
|
204
|
+
if (pattern.endsWith('/**')) return key.startsWith(pattern.slice(0, -2))
|
|
205
|
+
if (pattern.endsWith('/')) return key.startsWith(pattern)
|
|
206
|
+
return key === pattern
|
|
207
|
+
})
|
|
208
|
+
if (matched) return true
|
|
209
|
+
if (declaration.allowNew) return true
|
|
210
|
+
throw new WorkspaceAccessError(`文件 ${key} 不在 work ${manifest.workId} 的声明范围内`)
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
readManifest(runtimeId, workId) {
|
|
214
|
+
return readJson(this.manifestFile(runtimeId, workId), null)
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
writeManifest(manifest, { catalog = false } = {}) {
|
|
218
|
+
writeJsonAtomic(this.manifestFile(manifest.runtimeId, manifest.workId), manifest)
|
|
219
|
+
const key = `${manifest.runtimeId}/${manifest.workId}`
|
|
220
|
+
const last = this._catalogTouched.get(key) || 0
|
|
221
|
+
/* catalog 是展示/生命周期索引,不是热路径事务日志:按节流间隔写一次,
|
|
222
|
+
* 或在少数版本节点/显式操作时刷新,避免每次 state 保存都抢全局 catalog 锁。 */
|
|
223
|
+
if (catalog || manifest.version <= 5 || manifest.version % 50 === 0 || Date.now() - last > tuning().catalogThrottleMs) {
|
|
224
|
+
this.updateCatalog(manifest)
|
|
225
|
+
this._catalogTouched.set(key, Date.now())
|
|
226
|
+
}
|
|
227
|
+
return manifest
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** catalog 损坏时按磁盘 manifest 重建,绝不能把坏文件当成空库覆盖。 */
|
|
231
|
+
_readCatalogForUpdate() {
|
|
232
|
+
try {
|
|
233
|
+
const parsed = JSON.parse(fs.readFileSync(this.catalogFile, 'utf8'))
|
|
234
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) return parsed
|
|
235
|
+
} catch (error) {
|
|
236
|
+
if (error.code !== 'ENOENT') {
|
|
237
|
+
const quarantine = `${this.catalogFile}.corrupt-${Date.now()}`
|
|
238
|
+
try { fs.renameSync(this.catalogFile, quarantine) } catch { /* 忽略 */ }
|
|
239
|
+
console.error(`[workspace] catalog 损坏,已隔离到 ${quarantine},按 manifest 重建`)
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
const works = {}
|
|
243
|
+
let runtimes = []
|
|
244
|
+
try { runtimes = fs.readdirSync(this.worksRoot, { withFileTypes: true }).filter((e) => e.isDirectory()) } catch { /* 空库 */ }
|
|
245
|
+
for (const runtime of runtimes) {
|
|
246
|
+
let entries = []
|
|
247
|
+
try { entries = fs.readdirSync(path.join(this.worksRoot, runtime.name), { withFileTypes: true }) } catch { continue }
|
|
248
|
+
for (const entry of entries) {
|
|
249
|
+
if (!entry.isDirectory()) continue
|
|
250
|
+
const manifest = this.readManifest(runtime.name, entry.name)
|
|
251
|
+
if (!manifest) continue
|
|
252
|
+
const total = Object.values(manifest.files || {}).reduce((sum, item) => sum + (Number(item.size) || 0), 0)
|
|
253
|
+
works[`${manifest.runtimeId}/${manifest.workId}`] = {
|
|
254
|
+
runtimeId: manifest.runtimeId,
|
|
255
|
+
workId: manifest.workId,
|
|
256
|
+
title: manifest.title || '',
|
|
257
|
+
version: manifest.version || 0,
|
|
258
|
+
files: Object.keys(manifest.files || {}).length,
|
|
259
|
+
size: total,
|
|
260
|
+
createdAt: manifest.createdAt,
|
|
261
|
+
updatedAt: manifest.updatedAt,
|
|
262
|
+
declaration: manifest.declaration || null,
|
|
263
|
+
meta: manifest.meta || {},
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
return { schemaVersion: 1, updatedAt: '', works }
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
updateCatalog(manifest) {
|
|
271
|
+
withFileLock(path.join(this.locksRoot, 'catalog.lock'), () => {
|
|
272
|
+
const catalog = this._readCatalogForUpdate()
|
|
273
|
+
const total = Object.values(manifest.files || {}).reduce((sum, item) => sum + (Number(item.size) || 0), 0)
|
|
274
|
+
catalog.works ||= {}
|
|
275
|
+
catalog.works[`${manifest.runtimeId}/${manifest.workId}`] = {
|
|
276
|
+
runtimeId: manifest.runtimeId,
|
|
277
|
+
workId: manifest.workId,
|
|
278
|
+
title: manifest.title || '',
|
|
279
|
+
version: manifest.version || 0,
|
|
280
|
+
files: Object.keys(manifest.files || {}).length,
|
|
281
|
+
size: total,
|
|
282
|
+
createdAt: manifest.createdAt,
|
|
283
|
+
updatedAt: manifest.updatedAt,
|
|
284
|
+
declaration: manifest.declaration || null,
|
|
285
|
+
meta: manifest.meta || {},
|
|
286
|
+
}
|
|
287
|
+
catalog.updatedAt = new Date().toISOString()
|
|
288
|
+
writeJsonAtomic(this.catalogFile, catalog)
|
|
289
|
+
})
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
ensureWork(runtimeId, workId, { title = '', meta = {} } = {}) {
|
|
293
|
+
assertId(runtimeId, 'runtimeId')
|
|
294
|
+
assertId(workId, 'workId')
|
|
295
|
+
const file = this.manifestFile(runtimeId, workId)
|
|
296
|
+
if (fs.existsSync(file)) return this.readManifest(runtimeId, workId)
|
|
297
|
+
return withFileLock(this.lockFile('works', runtimeId, workId), () => {
|
|
298
|
+
/* 双重检查:两个实例同时初始化同一 work 时只允许一个写 v0。 */
|
|
299
|
+
if (fs.existsSync(file)) return this.readManifest(runtimeId, workId)
|
|
300
|
+
const manifest = this.emptyManifest(runtimeId, workId, title)
|
|
301
|
+
manifest.meta = meta && typeof meta === 'object' ? meta : {}
|
|
302
|
+
return this.writeManifest(manifest, { catalog: true })
|
|
303
|
+
})
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/** 中间层解释逻辑 key → 对象 hash;仓库只收到字节。 */
|
|
307
|
+
put(runtimeId, workId, key, data, { expectedVersion = null, contentType = 'application/octet-stream', title = '' } = {}) {
|
|
308
|
+
assertKey(key)
|
|
309
|
+
this.ensureWork(runtimeId, workId, { title })
|
|
310
|
+
return withFileLock(this.lockFile('works', runtimeId, workId), () => {
|
|
311
|
+
const manifest = this.readManifest(runtimeId, workId) || this.emptyManifest(runtimeId, workId, title)
|
|
312
|
+
if (expectedVersion != null && Number(expectedVersion) !== manifest.version) {
|
|
313
|
+
throw new WorkspaceConflictError(`版本冲突: 当前 ${manifest.version},期望 ${expectedVersion}`)
|
|
314
|
+
}
|
|
315
|
+
this.assertDeclared(manifest, key)
|
|
316
|
+
const blob = this.blobs.put(data)
|
|
317
|
+
const now = new Date().toISOString()
|
|
318
|
+
manifest.files[key] = {
|
|
319
|
+
blob: blob.hash,
|
|
320
|
+
size: blob.size,
|
|
321
|
+
contentType,
|
|
322
|
+
updatedAt: now,
|
|
323
|
+
}
|
|
324
|
+
manifest.version = (manifest.version | 0) + 1
|
|
325
|
+
manifest.updatedAt = now
|
|
326
|
+
if (title) manifest.title = title
|
|
327
|
+
this.writeManifest(manifest)
|
|
328
|
+
return { key, blob: blob.hash, size: blob.size, version: manifest.version }
|
|
329
|
+
})
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
get(runtimeId, workId, key, fallback = undefined) {
|
|
333
|
+
assertKey(key)
|
|
334
|
+
const manifest = this.readManifest(runtimeId, workId)
|
|
335
|
+
if (!manifest || !manifest.files[key]) {
|
|
336
|
+
if (fallback !== undefined) return fallback
|
|
337
|
+
throw new Error(`对象不存在: ${runtimeId}/${workId}/${key}`)
|
|
338
|
+
}
|
|
339
|
+
return this.blobs.get(manifest.files[key].blob)
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
list(runtimeId, workId) {
|
|
343
|
+
const manifest = this.readManifest(runtimeId, workId)
|
|
344
|
+
return manifest ? Object.entries(manifest.files).map(([key, item]) => ({ key, ...item })) : []
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
delete(runtimeId, workId, key, { expectedVersion = null } = {}) {
|
|
348
|
+
assertKey(key)
|
|
349
|
+
return withFileLock(this.lockFile('works', runtimeId, workId), () => {
|
|
350
|
+
const manifest = this.readManifest(runtimeId, workId)
|
|
351
|
+
if (!manifest) throw new Error(`work 不存在: ${runtimeId}/${workId}`)
|
|
352
|
+
if (expectedVersion != null && Number(expectedVersion) !== manifest.version) {
|
|
353
|
+
throw new WorkspaceConflictError(`版本冲突: 当前 ${manifest.version},期望 ${expectedVersion}`)
|
|
354
|
+
}
|
|
355
|
+
this.assertDeclared(manifest, key)
|
|
356
|
+
delete manifest.files[key]
|
|
357
|
+
manifest.version = (manifest.version | 0) + 1
|
|
358
|
+
manifest.updatedAt = new Date().toISOString()
|
|
359
|
+
this.writeManifest(manifest, { catalog: true })
|
|
360
|
+
return { key, version: manifest.version }
|
|
361
|
+
})
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
append(runtimeId, workId, key, text) {
|
|
365
|
+
assertKey(key)
|
|
366
|
+
return withFileLock(this.lockFile('works', runtimeId, workId), () => {
|
|
367
|
+
const manifest = this.readManifest(runtimeId, workId) || this.emptyManifest(runtimeId, workId)
|
|
368
|
+
this.assertDeclared(manifest, key)
|
|
369
|
+
const now = new Date().toISOString()
|
|
370
|
+
let current = Buffer.alloc(0)
|
|
371
|
+
if (manifest.files[key]) current = this.blobs.get(manifest.files[key].blob)
|
|
372
|
+
const extra = Buffer.from(text)
|
|
373
|
+
/* journal 单文件超过阈值时轮转到 .1,避免每次 append 重写无上限增长的历史。 */
|
|
374
|
+
if (key === 'journal.jsonl' && current.length && current.length + extra.length > this.journalMaxBytes) {
|
|
375
|
+
const rotated = this.blobs.put(current)
|
|
376
|
+
manifest.files['journal.jsonl.1'] = {
|
|
377
|
+
blob: rotated.hash,
|
|
378
|
+
size: rotated.size,
|
|
379
|
+
contentType: 'text/plain; charset=utf-8',
|
|
380
|
+
updatedAt: now,
|
|
381
|
+
}
|
|
382
|
+
current = Buffer.alloc(0)
|
|
383
|
+
}
|
|
384
|
+
const blob = this.blobs.put(Buffer.concat([current, extra]))
|
|
385
|
+
manifest.files[key] = {
|
|
386
|
+
blob: blob.hash,
|
|
387
|
+
size: blob.size,
|
|
388
|
+
contentType: 'text/plain; charset=utf-8',
|
|
389
|
+
updatedAt: now,
|
|
390
|
+
}
|
|
391
|
+
manifest.version = (manifest.version | 0) + 1
|
|
392
|
+
manifest.updatedAt = now
|
|
393
|
+
this.writeManifest(manifest)
|
|
394
|
+
return { key, blob: blob.hash, size: blob.size, version: manifest.version }
|
|
395
|
+
})
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
tail(runtimeId, workId, key, limit = 8) {
|
|
399
|
+
try {
|
|
400
|
+
const text = this.get(runtimeId, workId, key).toString('utf8').trim()
|
|
401
|
+
if (!text) return []
|
|
402
|
+
return text.split(/\r?\n/).filter(Boolean).slice(-limit).map((line) => {
|
|
403
|
+
try { return JSON.parse(line) } catch { return { type: 'invalid', raw: line.slice(0, 120) } }
|
|
404
|
+
})
|
|
405
|
+
} catch {
|
|
406
|
+
return []
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/** 从磁盘 manifest 重建 catalog;用于 CLI/UI 读取前刷新最终一致性索引。 */
|
|
411
|
+
refreshCatalog({ runtimeId = '' } = {}) {
|
|
412
|
+
const works = []
|
|
413
|
+
let runtimes = []
|
|
414
|
+
try { runtimes = fs.readdirSync(this.worksRoot, { withFileTypes: true }).filter((e) => e.isDirectory()) } catch { return works }
|
|
415
|
+
for (const runtime of runtimes) {
|
|
416
|
+
if (runtimeId && runtime.name !== runtimeId) continue
|
|
417
|
+
let entries = []
|
|
418
|
+
try { entries = fs.readdirSync(path.join(this.worksRoot, runtime.name), { withFileTypes: true }) } catch { continue }
|
|
419
|
+
for (const entry of entries) {
|
|
420
|
+
if (!entry.isDirectory()) continue
|
|
421
|
+
const manifest = this.readManifest(runtime.name, entry.name)
|
|
422
|
+
if (!manifest) continue
|
|
423
|
+
this.updateCatalog(manifest)
|
|
424
|
+
works.push(manifest)
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
return works
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
listWorks({ runtimeId = '' } = {}) {
|
|
431
|
+
const catalog = readJson(this.catalogFile, null)
|
|
432
|
+
if (catalog && catalog.works) {
|
|
433
|
+
return Object.values(catalog.works)
|
|
434
|
+
.filter((item) => !runtimeId || item.runtimeId === runtimeId)
|
|
435
|
+
.sort((a, b) => String(b.updatedAt).localeCompare(String(a.updatedAt)))
|
|
436
|
+
}
|
|
437
|
+
const works = []
|
|
438
|
+
let runtimes = []
|
|
439
|
+
try { runtimes = fs.readdirSync(this.worksRoot, { withFileTypes: true }).filter((e) => e.isDirectory()) } catch { /* 空库 */ }
|
|
440
|
+
for (const runtime of runtimes) {
|
|
441
|
+
if (runtimeId && runtime.name !== runtimeId) continue
|
|
442
|
+
let entries = []
|
|
443
|
+
try { entries = fs.readdirSync(path.join(this.worksRoot, runtime.name), { withFileTypes: true }) } catch { /* 忽略 */ }
|
|
444
|
+
for (const entry of entries) {
|
|
445
|
+
if (!entry.isDirectory()) continue
|
|
446
|
+
const manifest = this.readManifest(runtime.name, entry.name)
|
|
447
|
+
if (manifest) works.push(manifest)
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
return works
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
referencedHashes() {
|
|
454
|
+
const referenced = new Set()
|
|
455
|
+
for (const summary of this.listWorks()) {
|
|
456
|
+
const manifest = this.readManifest(summary.runtimeId, summary.workId)
|
|
457
|
+
for (const item of Object.values(manifest?.files || {})) if (item?.blob) referenced.add(item.blob)
|
|
458
|
+
}
|
|
459
|
+
return referenced
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
gc({ minAgeMs = 60000 } = {}) {
|
|
463
|
+
return withFileLock(path.join(this.locksRoot, 'gc.lock'), () => {
|
|
464
|
+
/* 刚写入的 blob 可能还没写进 manifest;留出宽限期防止 GC 与 put 竞态。 */
|
|
465
|
+
return this.blobs.gc(this.referencedHashes(), { minAgeMs })
|
|
466
|
+
})
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
removeWork(runtimeId, workId) {
|
|
470
|
+
fs.rmSync(this.workDir(runtimeId, workId), { recursive: true, force: true })
|
|
471
|
+
withFileLock(path.join(this.locksRoot, 'catalog.lock'), () => {
|
|
472
|
+
const catalog = this._readCatalogForUpdate()
|
|
473
|
+
delete catalog.works?.[`${runtimeId}/${workId}`]
|
|
474
|
+
catalog.updatedAt = new Date().toISOString()
|
|
475
|
+
writeJsonAtomic(this.catalogFile, catalog)
|
|
476
|
+
})
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
removeRuntime(runtimeId) {
|
|
480
|
+
assertId(runtimeId, 'runtimeId')
|
|
481
|
+
fs.rmSync(path.join(this.worksRoot, runtimeId), { recursive: true, force: true })
|
|
482
|
+
this.namespaces.remove(runtimeId)
|
|
483
|
+
withFileLock(path.join(this.locksRoot, 'catalog.lock'), () => {
|
|
484
|
+
const catalog = this._readCatalogForUpdate()
|
|
485
|
+
for (const key of Object.keys(catalog.works || {})) {
|
|
486
|
+
if (key.startsWith(`${runtimeId}/`)) delete catalog.works[key]
|
|
487
|
+
}
|
|
488
|
+
catalog.updatedAt = new Date().toISOString()
|
|
489
|
+
writeJsonAtomic(this.catalogFile, catalog)
|
|
490
|
+
})
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
/** 绑定到单个 runtime / work 的客户端;每次操作校验 namespace token。 */
|
|
495
|
+
export class WorkspaceClient {
|
|
496
|
+
constructor({ manager, runtimeId, token, workId = 'main' } = {}) {
|
|
497
|
+
/* 结构化契约:允许同版本 kit 快照跨包提供 manager,不依赖类身份。 */
|
|
498
|
+
if (!manager || typeof manager.put !== 'function' || typeof manager.readManifest !== 'function') {
|
|
499
|
+
throw new Error('WorkspaceClient 需要 WorkspaceManager 兼容实现')
|
|
500
|
+
}
|
|
501
|
+
this.manager = manager
|
|
502
|
+
this.runtimeId = assertId(runtimeId, 'runtimeId')
|
|
503
|
+
this.token = token
|
|
504
|
+
this.workId = assertId(workId, 'workId')
|
|
505
|
+
this._verifiedAt = 0
|
|
506
|
+
this._verify(true)
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
_verify(force = false) {
|
|
510
|
+
const now = Date.now()
|
|
511
|
+
if (!force && this._verifiedAt && now - this._verifiedAt < tuning().tokenVerifyCacheMs) return
|
|
512
|
+
this.manager.namespaces.verify(this.runtimeId, this.token)
|
|
513
|
+
this.manager.namespaces.touch(this.runtimeId)
|
|
514
|
+
this._verifiedAt = now
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
ensureWork(workId = this.workId, options = {}) {
|
|
518
|
+
this._verify()
|
|
519
|
+
return this.manager.ensureWork(this.runtimeId, workId, options)
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
put(workId, key, data, options = {}) {
|
|
523
|
+
this._verify()
|
|
524
|
+
return this.manager.put(this.runtimeId, workId, key, data, options)
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
putJson(workId, key, value, options = {}) {
|
|
528
|
+
return this.put(workId, key, Buffer.from(JSON.stringify(value)), {
|
|
529
|
+
contentType: 'application/json; charset=utf-8',
|
|
530
|
+
...options,
|
|
531
|
+
})
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
get(workId, key, fallback = undefined) {
|
|
535
|
+
this._verify()
|
|
536
|
+
return this.manager.get(this.runtimeId, workId, key, fallback)
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
getJson(workId, key, fallback = undefined) {
|
|
540
|
+
const data = this.get(workId, key, fallback === undefined ? undefined : Buffer.from(JSON.stringify(fallback)))
|
|
541
|
+
if (data === undefined) return undefined
|
|
542
|
+
try { return JSON.parse(data.toString('utf8')) } catch { return fallback }
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
list(workId) {
|
|
546
|
+
this._verify()
|
|
547
|
+
return this.manager.list(this.runtimeId, workId)
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
delete(workId, key, options = {}) {
|
|
551
|
+
this._verify()
|
|
552
|
+
return this.manager.delete(this.runtimeId, workId, key, options)
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
append(workId, key, text) {
|
|
556
|
+
this._verify()
|
|
557
|
+
return this.manager.append(this.runtimeId, workId, key, text)
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
tail(workId, key, limit = 8) {
|
|
561
|
+
this._verify()
|
|
562
|
+
return this.manager.tail(this.runtimeId, workId, key, limit)
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
manifest(workId = this.workId) {
|
|
566
|
+
this._verify()
|
|
567
|
+
return this.manager.readManifest(this.runtimeId, workId)
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
listWorks() {
|
|
571
|
+
this._verify()
|
|
572
|
+
return this.manager.listWorks({ runtimeId: this.runtimeId })
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
/** 插件的 JournalStore 持久化接口 → 中间层 workspace。 */
|
|
577
|
+
export class WorkspaceBackend {
|
|
578
|
+
constructor({ client, workId = 'main', journalPath = null }) {
|
|
579
|
+
/* 结构化契约:workspace-service 可能来自另一份 kit 快照。 */
|
|
580
|
+
if (!client || typeof client.put !== 'function' || typeof client.getJson !== 'function') {
|
|
581
|
+
throw new Error('WorkspaceBackend 需要 WorkspaceClient 兼容实现')
|
|
582
|
+
}
|
|
583
|
+
this.client = client
|
|
584
|
+
this.workId = workId
|
|
585
|
+
this.journalPath = journalPath || null
|
|
586
|
+
this.stateKey = 'state.json'
|
|
587
|
+
this.journalKey = 'journal.jsonl'
|
|
588
|
+
this.checkpointPrefix = 'checkpoints/'
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
readState() {
|
|
592
|
+
return this.client.getJson(this.workId, this.stateKey, null)
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
writeState(doc) {
|
|
596
|
+
const result = this.client.putJson(this.workId, this.stateKey, doc)
|
|
597
|
+
return { ...result, stateKey: this.stateKey }
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
appendJournal(event) {
|
|
601
|
+
try {
|
|
602
|
+
this.client.append(this.workId, this.journalKey, JSON.stringify({ ...event, ts: Date.now() / 1000 }) + '\n')
|
|
603
|
+
} catch { /* journal 失败不阻塞主状态 */ }
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
journalTail(limit = 8) {
|
|
607
|
+
const parse = (text) => String(text || '').trim().split(/\r?\n/).filter(Boolean)
|
|
608
|
+
const lines = []
|
|
609
|
+
for (const key of ['journal.jsonl.1', 'journal.jsonl']) {
|
|
610
|
+
try {
|
|
611
|
+
const data = this.client.get(this.workId, key, null)
|
|
612
|
+
if (data) lines.push(...parse(data.toString('utf8')))
|
|
613
|
+
} catch { /* 轮转文件可能不存在 */ }
|
|
614
|
+
}
|
|
615
|
+
return lines.slice(-limit).map((line) => {
|
|
616
|
+
try { return JSON.parse(line) } catch { return { type: 'invalid', raw: line.slice(0, 120) } }
|
|
617
|
+
})
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
writeCheckpoint(name, payload) {
|
|
621
|
+
const key = `${this.checkpointPrefix}${name}.json`
|
|
622
|
+
this.client.putJson(this.workId, key, payload)
|
|
623
|
+
this.appendJournal({ type: 'checkpoint', name })
|
|
624
|
+
return { name, createdAt: payload.createdAt, meta: payload.meta || {} }
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
listCheckpoints() {
|
|
628
|
+
return this.client.list(this.workId)
|
|
629
|
+
.filter((item) => item.key.startsWith(this.checkpointPrefix) && item.key.endsWith('.json'))
|
|
630
|
+
.map((item) => {
|
|
631
|
+
try {
|
|
632
|
+
const payload = this.client.getJson(this.workId, item.key)
|
|
633
|
+
if (!payload) return null
|
|
634
|
+
return {
|
|
635
|
+
name: payload.name,
|
|
636
|
+
seq: payload.seq,
|
|
637
|
+
appliedSeq: payload.appliedSeq,
|
|
638
|
+
pending: !!payload.pending,
|
|
639
|
+
title: payload.title,
|
|
640
|
+
slides: payload.slides,
|
|
641
|
+
createdAt: payload.createdAt,
|
|
642
|
+
meta: payload.meta || {},
|
|
643
|
+
}
|
|
644
|
+
} catch { return null }
|
|
645
|
+
})
|
|
646
|
+
.filter(Boolean)
|
|
647
|
+
.sort((a, b) => String(b.createdAt).localeCompare(String(a.createdAt)))
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
readCheckpoint(name) {
|
|
651
|
+
const key = `${this.checkpointPrefix}${name}.json`
|
|
652
|
+
const payload = this.client.getJson(this.workId, key, null)
|
|
653
|
+
if (!payload || !payload.deck) throw new Error('checkpoint 内容损坏: ' + name)
|
|
654
|
+
return payload
|
|
655
|
+
}
|
|
656
|
+
}
|