@capyclaw/publisher 0.1.3 → 0.1.4
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/package.json +3 -11
- package/server/archive.mjs +69 -35
- package/server/drop.mjs +9 -3
- package/server/impl.mjs +133 -97
- package/server/tools.mjs +1 -1
- package/node_modules/@capyclaw/foundation/README.md +0 -51
- package/node_modules/@capyclaw/foundation/abi/bridge.mjs +0 -86
- package/node_modules/@capyclaw/foundation/abi/errors.mjs +0 -63
- package/node_modules/@capyclaw/foundation/abi/index.mjs +0 -35
- package/node_modules/@capyclaw/foundation/abi/kinds.mjs +0 -271
- package/node_modules/@capyclaw/foundation/abi/loader.mjs +0 -345
- package/node_modules/@capyclaw/foundation/abi/schema.mjs +0 -98
- package/node_modules/@capyclaw/foundation/abi/spec.mjs +0 -255
- package/node_modules/@capyclaw/foundation/abi/validate.mjs +0 -24
- package/node_modules/@capyclaw/foundation/abi/version.mjs +0 -82
- package/node_modules/@capyclaw/foundation/cordis.patch.yml +0 -5
- package/node_modules/@capyclaw/foundation/kit/index.mjs +0 -6
- package/node_modules/@capyclaw/foundation/lib/adapters/client-panel.mjs +0 -98
- package/node_modules/@capyclaw/foundation/lib/adapters/host-event.mjs +0 -35
- package/node_modules/@capyclaw/foundation/lib/adapters/http-router.mjs +0 -69
- package/node_modules/@capyclaw/foundation/lib/adapters/lifecycle-hook.mjs +0 -55
- package/node_modules/@capyclaw/foundation/lib/adapters/own-server.mjs +0 -113
- package/node_modules/@capyclaw/foundation/lib/adapters/raw.mjs +0 -68
- package/node_modules/@capyclaw/foundation/lib/adapters/runtime-driver.mjs +0 -113
- package/node_modules/@capyclaw/foundation/lib/adapters/service-provider.mjs +0 -77
- package/node_modules/@capyclaw/foundation/lib/adapters/skill-provider.mjs +0 -56
- package/node_modules/@capyclaw/foundation/lib/adapters/tool-provider.mjs +0 -50
- package/node_modules/@capyclaw/foundation/lib/adapters/ui-panel.mjs +0 -64
- package/node_modules/@capyclaw/foundation/lib/ctx-service.mjs +0 -42
- package/node_modules/@capyclaw/foundation/lib/host/caps.mjs +0 -34
- package/node_modules/@capyclaw/foundation/lib/host/contract.mjs +0 -85
- package/node_modules/@capyclaw/foundation/lib/host/dsh.mjs +0 -50
- package/node_modules/@capyclaw/foundation/lib/host/memory.mjs +0 -160
- package/node_modules/@capyclaw/foundation/lib/host.mjs +0 -23
- package/node_modules/@capyclaw/foundation/lib/kernel.mjs +0 -185
- package/node_modules/@capyclaw/foundation/lib/skill/scan.mjs +0 -87
- package/node_modules/@capyclaw/foundation/lib/subsystems/events.mjs +0 -60
- package/node_modules/@capyclaw/foundation/lib/subsystems/log.mjs +0 -51
- package/node_modules/@capyclaw/foundation/lib/subsystems/net.mjs +0 -188
- package/node_modules/@capyclaw/foundation/package.json +0 -53
- package/node_modules/@capyclaw/foundation/runtime/index.mjs +0 -20
- package/node_modules/@capyclaw/plugin-kit/INTEGRATION.md +0 -100
- package/node_modules/@capyclaw/plugin-kit/README.md +0 -70
- package/node_modules/@capyclaw/plugin-kit/bin/sync.mjs +0 -103
- package/node_modules/@capyclaw/plugin-kit/package.json +0 -69
- package/node_modules/@capyclaw/plugin-kit/src/cli.mjs +0 -56
- package/node_modules/@capyclaw/plugin-kit/src/config.mjs +0 -142
- package/node_modules/@capyclaw/plugin-kit/src/editor/heartbeat-worker.js +0 -129
- package/node_modules/@capyclaw/plugin-kit/src/editor/lease.mjs +0 -139
- package/node_modules/@capyclaw/plugin-kit/src/editor/shadow.mjs +0 -219
- package/node_modules/@capyclaw/plugin-kit/src/editor/transport.js +0 -13
- package/node_modules/@capyclaw/plugin-kit/src/index.mjs +0 -13
- package/node_modules/@capyclaw/plugin-kit/src/pack.mjs +0 -230
- package/node_modules/@capyclaw/plugin-kit/src/runtime/context.mjs +0 -128
- package/node_modules/@capyclaw/plugin-kit/src/self-contained.mjs +0 -307
- package/node_modules/@capyclaw/plugin-kit/src/service/api.mjs +0 -45
- package/node_modules/@capyclaw/plugin-kit/src/service/http.mjs +0 -113
- package/node_modules/@capyclaw/plugin-kit/src/service/mcp-http.mjs +0 -150
- package/node_modules/@capyclaw/plugin-kit/src/service/server.mjs +0 -131
- package/node_modules/@capyclaw/plugin-kit/src/skills/provider.mjs +0 -82
- package/node_modules/@capyclaw/plugin-kit/src/store/blob-store.mjs +0 -109
- package/node_modules/@capyclaw/plugin-kit/src/store/content-store.mjs +0 -17
- package/node_modules/@capyclaw/plugin-kit/src/store/journal-store.mjs +0 -89
- package/node_modules/@capyclaw/plugin-kit/src/tools/result.mjs +0 -57
- package/node_modules/@capyclaw/plugin-kit/src/tools/validate.mjs +0 -150
- package/node_modules/@capyclaw/plugin-kit/src/tuning.mjs +0 -82
- package/node_modules/@capyclaw/plugin-kit/src/util/fs-lock.mjs +0 -132
- package/node_modules/@capyclaw/plugin-kit/src/util/http.mjs +0 -130
- package/node_modules/@capyclaw/plugin-kit/src/workspace/manager.mjs +0 -656
- package/node_modules/@capyclaw/plugin-kit/src/zip.mjs +0 -181
- package/node_modules/@capyclaw/plugin-validator/bin/cli.mjs +0 -49
- package/node_modules/@capyclaw/plugin-validator/lib/index.mjs +0 -303
- package/node_modules/@capyclaw/plugin-validator/package.json +0 -28
- package/node_modules/@capyclaw/tool-host/README.md +0 -56
- package/node_modules/@capyclaw/tool-host/cordis.patch.yml +0 -4
- package/node_modules/@capyclaw/tool-host/dsh-suite.json +0 -30
- package/node_modules/@capyclaw/tool-host/lib/host.mjs +0 -16
- package/node_modules/@capyclaw/tool-host/package.json +0 -59
- package/node_modules/@capyclaw/tool-host/src/descriptors.mjs +0 -166
- package/node_modules/@capyclaw/tool-host/src/index.mjs +0 -416
- package/node_modules/semver/LICENSE +0 -15
- package/node_modules/semver/README.md +0 -680
- package/node_modules/semver/bin/semver.js +0 -195
- package/node_modules/semver/classes/comparator.js +0 -143
- package/node_modules/semver/classes/index.js +0 -7
- package/node_modules/semver/classes/range.js +0 -577
- package/node_modules/semver/classes/semver.js +0 -350
- package/node_modules/semver/functions/clean.js +0 -8
- package/node_modules/semver/functions/cmp.js +0 -54
- package/node_modules/semver/functions/coerce.js +0 -62
- package/node_modules/semver/functions/compare-build.js +0 -9
- package/node_modules/semver/functions/compare-loose.js +0 -5
- package/node_modules/semver/functions/compare.js +0 -7
- package/node_modules/semver/functions/diff.js +0 -60
- package/node_modules/semver/functions/eq.js +0 -5
- package/node_modules/semver/functions/gt.js +0 -5
- package/node_modules/semver/functions/gte.js +0 -5
- package/node_modules/semver/functions/inc.js +0 -21
- package/node_modules/semver/functions/lt.js +0 -5
- package/node_modules/semver/functions/lte.js +0 -5
- package/node_modules/semver/functions/major.js +0 -5
- package/node_modules/semver/functions/minor.js +0 -5
- package/node_modules/semver/functions/neq.js +0 -5
- package/node_modules/semver/functions/parse.js +0 -18
- package/node_modules/semver/functions/patch.js +0 -5
- package/node_modules/semver/functions/prerelease.js +0 -8
- package/node_modules/semver/functions/rcompare.js +0 -5
- package/node_modules/semver/functions/rsort.js +0 -5
- package/node_modules/semver/functions/satisfies.js +0 -12
- package/node_modules/semver/functions/sort.js +0 -5
- package/node_modules/semver/functions/truncate.js +0 -48
- package/node_modules/semver/functions/valid.js +0 -8
- package/node_modules/semver/index.js +0 -93
- package/node_modules/semver/internal/constants.js +0 -67
- package/node_modules/semver/internal/debug.js +0 -11
- package/node_modules/semver/internal/identifiers.js +0 -29
- package/node_modules/semver/internal/lrucache.js +0 -42
- package/node_modules/semver/internal/parse-options.js +0 -17
- package/node_modules/semver/internal/re.js +0 -223
- package/node_modules/semver/internal/trim-comparator-whitespace.js +0 -438
- package/node_modules/semver/package.json +0 -78
- package/node_modules/semver/preload.js +0 -4
- package/node_modules/semver/range.bnf +0 -17
- package/node_modules/semver/ranges/gtr.js +0 -6
- package/node_modules/semver/ranges/intersects.js +0 -9
- package/node_modules/semver/ranges/ltr.js +0 -6
- package/node_modules/semver/ranges/max-satisfying.js +0 -27
- package/node_modules/semver/ranges/min-satisfying.js +0 -26
- package/node_modules/semver/ranges/min-version.js +0 -63
- package/node_modules/semver/ranges/outside.js +0 -82
- package/node_modules/semver/ranges/simplify.js +0 -49
- package/node_modules/semver/ranges/subset.js +0 -249
- package/node_modules/semver/ranges/to-comparators.js +0 -10
- package/node_modules/semver/ranges/valid.js +0 -13
- package/node_modules/yaml/LICENSE +0 -13
- package/node_modules/yaml/README.md +0 -172
- package/node_modules/yaml/bin.mjs +0 -11
- package/node_modules/yaml/browser/dist/compose/compose-collection.js +0 -88
- package/node_modules/yaml/browser/dist/compose/compose-doc.js +0 -43
- package/node_modules/yaml/browser/dist/compose/compose-node.js +0 -109
- package/node_modules/yaml/browser/dist/compose/compose-scalar.js +0 -86
- package/node_modules/yaml/browser/dist/compose/composer.js +0 -219
- package/node_modules/yaml/browser/dist/compose/resolve-block-map.js +0 -115
- package/node_modules/yaml/browser/dist/compose/resolve-block-scalar.js +0 -198
- package/node_modules/yaml/browser/dist/compose/resolve-block-seq.js +0 -49
- package/node_modules/yaml/browser/dist/compose/resolve-end.js +0 -37
- package/node_modules/yaml/browser/dist/compose/resolve-flow-collection.js +0 -207
- package/node_modules/yaml/browser/dist/compose/resolve-flow-scalar.js +0 -226
- package/node_modules/yaml/browser/dist/compose/resolve-props.js +0 -146
- package/node_modules/yaml/browser/dist/compose/util-contains-newline.js +0 -34
- package/node_modules/yaml/browser/dist/compose/util-empty-scalar-position.js +0 -26
- package/node_modules/yaml/browser/dist/compose/util-flow-indent-check.js +0 -15
- package/node_modules/yaml/browser/dist/compose/util-map-includes.js +0 -13
- package/node_modules/yaml/browser/dist/doc/Document.js +0 -335
- package/node_modules/yaml/browser/dist/doc/anchors.js +0 -71
- package/node_modules/yaml/browser/dist/doc/applyReviver.js +0 -55
- package/node_modules/yaml/browser/dist/doc/createNode.js +0 -88
- package/node_modules/yaml/browser/dist/doc/directives.js +0 -176
- package/node_modules/yaml/browser/dist/errors.js +0 -57
- package/node_modules/yaml/browser/dist/index.js +0 -17
- package/node_modules/yaml/browser/dist/log.js +0 -11
- package/node_modules/yaml/browser/dist/nodes/Alias.js +0 -118
- package/node_modules/yaml/browser/dist/nodes/Collection.js +0 -147
- package/node_modules/yaml/browser/dist/nodes/Node.js +0 -38
- package/node_modules/yaml/browser/dist/nodes/Pair.js +0 -36
- package/node_modules/yaml/browser/dist/nodes/Scalar.js +0 -24
- package/node_modules/yaml/browser/dist/nodes/YAMLMap.js +0 -144
- package/node_modules/yaml/browser/dist/nodes/YAMLSeq.js +0 -113
- package/node_modules/yaml/browser/dist/nodes/addPairToJSMap.js +0 -63
- package/node_modules/yaml/browser/dist/nodes/identity.js +0 -36
- package/node_modules/yaml/browser/dist/nodes/toJS.js +0 -37
- package/node_modules/yaml/browser/dist/parse/cst-scalar.js +0 -214
- package/node_modules/yaml/browser/dist/parse/cst-stringify.js +0 -61
- package/node_modules/yaml/browser/dist/parse/cst-visit.js +0 -97
- package/node_modules/yaml/browser/dist/parse/cst.js +0 -98
- package/node_modules/yaml/browser/dist/parse/lexer.js +0 -721
- package/node_modules/yaml/browser/dist/parse/line-counter.js +0 -39
- package/node_modules/yaml/browser/dist/parse/parser.js +0 -975
- package/node_modules/yaml/browser/dist/public-api.js +0 -102
- package/node_modules/yaml/browser/dist/schema/Schema.js +0 -37
- package/node_modules/yaml/browser/dist/schema/common/map.js +0 -17
- package/node_modules/yaml/browser/dist/schema/common/null.js +0 -15
- package/node_modules/yaml/browser/dist/schema/common/seq.js +0 -17
- package/node_modules/yaml/browser/dist/schema/common/string.js +0 -14
- package/node_modules/yaml/browser/dist/schema/core/bool.js +0 -19
- package/node_modules/yaml/browser/dist/schema/core/float.js +0 -43
- package/node_modules/yaml/browser/dist/schema/core/int.js +0 -38
- package/node_modules/yaml/browser/dist/schema/core/schema.js +0 -23
- package/node_modules/yaml/browser/dist/schema/json/schema.js +0 -62
- package/node_modules/yaml/browser/dist/schema/tags.js +0 -96
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/binary.js +0 -58
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/bool.js +0 -26
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/float.js +0 -46
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/int.js +0 -71
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/merge.js +0 -67
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/omap.js +0 -74
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/pairs.js +0 -78
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/schema.js +0 -39
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/set.js +0 -93
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/timestamp.js +0 -101
- package/node_modules/yaml/browser/dist/stringify/foldFlowLines.js +0 -146
- package/node_modules/yaml/browser/dist/stringify/stringify.js +0 -129
- package/node_modules/yaml/browser/dist/stringify/stringifyCollection.js +0 -153
- package/node_modules/yaml/browser/dist/stringify/stringifyComment.js +0 -20
- package/node_modules/yaml/browser/dist/stringify/stringifyDocument.js +0 -85
- package/node_modules/yaml/browser/dist/stringify/stringifyNumber.js +0 -25
- package/node_modules/yaml/browser/dist/stringify/stringifyPair.js +0 -150
- package/node_modules/yaml/browser/dist/stringify/stringifyString.js +0 -336
- package/node_modules/yaml/browser/dist/util.js +0 -11
- package/node_modules/yaml/browser/dist/visit.js +0 -233
- package/node_modules/yaml/browser/index.js +0 -5
- package/node_modules/yaml/browser/package.json +0 -3
- package/node_modules/yaml/dist/cli.d.ts +0 -8
- package/node_modules/yaml/dist/cli.mjs +0 -201
- package/node_modules/yaml/dist/compose/compose-collection.d.ts +0 -11
- package/node_modules/yaml/dist/compose/compose-collection.js +0 -90
- package/node_modules/yaml/dist/compose/compose-doc.d.ts +0 -7
- package/node_modules/yaml/dist/compose/compose-doc.js +0 -45
- package/node_modules/yaml/dist/compose/compose-node.d.ts +0 -29
- package/node_modules/yaml/dist/compose/compose-node.js +0 -112
- package/node_modules/yaml/dist/compose/compose-scalar.d.ts +0 -5
- package/node_modules/yaml/dist/compose/compose-scalar.js +0 -88
- package/node_modules/yaml/dist/compose/composer.d.ts +0 -63
- package/node_modules/yaml/dist/compose/composer.js +0 -224
- package/node_modules/yaml/dist/compose/resolve-block-map.d.ts +0 -6
- package/node_modules/yaml/dist/compose/resolve-block-map.js +0 -117
- package/node_modules/yaml/dist/compose/resolve-block-scalar.d.ts +0 -11
- package/node_modules/yaml/dist/compose/resolve-block-scalar.js +0 -200
- package/node_modules/yaml/dist/compose/resolve-block-seq.d.ts +0 -6
- package/node_modules/yaml/dist/compose/resolve-block-seq.js +0 -51
- package/node_modules/yaml/dist/compose/resolve-end.d.ts +0 -6
- package/node_modules/yaml/dist/compose/resolve-end.js +0 -39
- package/node_modules/yaml/dist/compose/resolve-flow-collection.d.ts +0 -7
- package/node_modules/yaml/dist/compose/resolve-flow-collection.js +0 -209
- package/node_modules/yaml/dist/compose/resolve-flow-scalar.d.ts +0 -10
- package/node_modules/yaml/dist/compose/resolve-flow-scalar.js +0 -228
- package/node_modules/yaml/dist/compose/resolve-props.d.ts +0 -23
- package/node_modules/yaml/dist/compose/resolve-props.js +0 -148
- package/node_modules/yaml/dist/compose/util-contains-newline.d.ts +0 -2
- package/node_modules/yaml/dist/compose/util-contains-newline.js +0 -36
- package/node_modules/yaml/dist/compose/util-empty-scalar-position.d.ts +0 -2
- package/node_modules/yaml/dist/compose/util-empty-scalar-position.js +0 -28
- package/node_modules/yaml/dist/compose/util-flow-indent-check.d.ts +0 -3
- package/node_modules/yaml/dist/compose/util-flow-indent-check.js +0 -17
- package/node_modules/yaml/dist/compose/util-map-includes.d.ts +0 -4
- package/node_modules/yaml/dist/compose/util-map-includes.js +0 -15
- package/node_modules/yaml/dist/doc/Document.d.ts +0 -141
- package/node_modules/yaml/dist/doc/Document.js +0 -337
- package/node_modules/yaml/dist/doc/anchors.d.ts +0 -24
- package/node_modules/yaml/dist/doc/anchors.js +0 -76
- package/node_modules/yaml/dist/doc/applyReviver.d.ts +0 -9
- package/node_modules/yaml/dist/doc/applyReviver.js +0 -57
- package/node_modules/yaml/dist/doc/createNode.d.ts +0 -17
- package/node_modules/yaml/dist/doc/createNode.js +0 -90
- package/node_modules/yaml/dist/doc/directives.d.ts +0 -49
- package/node_modules/yaml/dist/doc/directives.js +0 -178
- package/node_modules/yaml/dist/errors.d.ts +0 -21
- package/node_modules/yaml/dist/errors.js +0 -62
- package/node_modules/yaml/dist/index.d.ts +0 -25
- package/node_modules/yaml/dist/index.js +0 -50
- package/node_modules/yaml/dist/log.d.ts +0 -3
- package/node_modules/yaml/dist/log.js +0 -19
- package/node_modules/yaml/dist/nodes/Alias.d.ts +0 -29
- package/node_modules/yaml/dist/nodes/Alias.js +0 -120
- package/node_modules/yaml/dist/nodes/Collection.d.ts +0 -73
- package/node_modules/yaml/dist/nodes/Collection.js +0 -151
- package/node_modules/yaml/dist/nodes/Node.d.ts +0 -53
- package/node_modules/yaml/dist/nodes/Node.js +0 -40
- package/node_modules/yaml/dist/nodes/Pair.d.ts +0 -22
- package/node_modules/yaml/dist/nodes/Pair.js +0 -39
- package/node_modules/yaml/dist/nodes/Scalar.d.ts +0 -47
- package/node_modules/yaml/dist/nodes/Scalar.js +0 -27
- package/node_modules/yaml/dist/nodes/YAMLMap.d.ts +0 -53
- package/node_modules/yaml/dist/nodes/YAMLMap.js +0 -147
- package/node_modules/yaml/dist/nodes/YAMLSeq.d.ts +0 -60
- package/node_modules/yaml/dist/nodes/YAMLSeq.js +0 -115
- package/node_modules/yaml/dist/nodes/addPairToJSMap.d.ts +0 -4
- package/node_modules/yaml/dist/nodes/addPairToJSMap.js +0 -65
- package/node_modules/yaml/dist/nodes/identity.d.ts +0 -23
- package/node_modules/yaml/dist/nodes/identity.js +0 -53
- package/node_modules/yaml/dist/nodes/toJS.d.ts +0 -29
- package/node_modules/yaml/dist/nodes/toJS.js +0 -39
- package/node_modules/yaml/dist/options.d.ts +0 -350
- package/node_modules/yaml/dist/parse/cst-scalar.d.ts +0 -64
- package/node_modules/yaml/dist/parse/cst-scalar.js +0 -218
- package/node_modules/yaml/dist/parse/cst-stringify.d.ts +0 -8
- package/node_modules/yaml/dist/parse/cst-stringify.js +0 -63
- package/node_modules/yaml/dist/parse/cst-visit.d.ts +0 -39
- package/node_modules/yaml/dist/parse/cst-visit.js +0 -99
- package/node_modules/yaml/dist/parse/cst.d.ts +0 -109
- package/node_modules/yaml/dist/parse/cst.js +0 -112
- package/node_modules/yaml/dist/parse/lexer.d.ts +0 -87
- package/node_modules/yaml/dist/parse/lexer.js +0 -723
- package/node_modules/yaml/dist/parse/line-counter.d.ts +0 -22
- package/node_modules/yaml/dist/parse/line-counter.js +0 -41
- package/node_modules/yaml/dist/parse/parser.d.ts +0 -84
- package/node_modules/yaml/dist/parse/parser.js +0 -980
- package/node_modules/yaml/dist/public-api.d.ts +0 -44
- package/node_modules/yaml/dist/public-api.js +0 -107
- package/node_modules/yaml/dist/schema/Schema.d.ts +0 -17
- package/node_modules/yaml/dist/schema/Schema.js +0 -39
- package/node_modules/yaml/dist/schema/common/map.d.ts +0 -2
- package/node_modules/yaml/dist/schema/common/map.js +0 -19
- package/node_modules/yaml/dist/schema/common/null.d.ts +0 -4
- package/node_modules/yaml/dist/schema/common/null.js +0 -17
- package/node_modules/yaml/dist/schema/common/seq.d.ts +0 -2
- package/node_modules/yaml/dist/schema/common/seq.js +0 -19
- package/node_modules/yaml/dist/schema/common/string.d.ts +0 -2
- package/node_modules/yaml/dist/schema/common/string.js +0 -16
- package/node_modules/yaml/dist/schema/core/bool.d.ts +0 -4
- package/node_modules/yaml/dist/schema/core/bool.js +0 -21
- package/node_modules/yaml/dist/schema/core/float.d.ts +0 -4
- package/node_modules/yaml/dist/schema/core/float.js +0 -47
- package/node_modules/yaml/dist/schema/core/int.d.ts +0 -4
- package/node_modules/yaml/dist/schema/core/int.js +0 -42
- package/node_modules/yaml/dist/schema/core/schema.d.ts +0 -1
- package/node_modules/yaml/dist/schema/core/schema.js +0 -25
- package/node_modules/yaml/dist/schema/json/schema.d.ts +0 -2
- package/node_modules/yaml/dist/schema/json/schema.js +0 -64
- package/node_modules/yaml/dist/schema/json-schema.d.ts +0 -69
- package/node_modules/yaml/dist/schema/tags.d.ts +0 -48
- package/node_modules/yaml/dist/schema/tags.js +0 -99
- package/node_modules/yaml/dist/schema/types.d.ts +0 -92
- package/node_modules/yaml/dist/schema/yaml-1.1/binary.d.ts +0 -2
- package/node_modules/yaml/dist/schema/yaml-1.1/binary.js +0 -70
- package/node_modules/yaml/dist/schema/yaml-1.1/bool.d.ts +0 -7
- package/node_modules/yaml/dist/schema/yaml-1.1/bool.js +0 -29
- package/node_modules/yaml/dist/schema/yaml-1.1/float.d.ts +0 -4
- package/node_modules/yaml/dist/schema/yaml-1.1/float.js +0 -50
- package/node_modules/yaml/dist/schema/yaml-1.1/int.d.ts +0 -5
- package/node_modules/yaml/dist/schema/yaml-1.1/int.js +0 -76
- package/node_modules/yaml/dist/schema/yaml-1.1/merge.d.ts +0 -9
- package/node_modules/yaml/dist/schema/yaml-1.1/merge.js +0 -71
- package/node_modules/yaml/dist/schema/yaml-1.1/omap.d.ts +0 -22
- package/node_modules/yaml/dist/schema/yaml-1.1/omap.js +0 -77
- package/node_modules/yaml/dist/schema/yaml-1.1/pairs.d.ts +0 -10
- package/node_modules/yaml/dist/schema/yaml-1.1/pairs.js +0 -82
- package/node_modules/yaml/dist/schema/yaml-1.1/schema.d.ts +0 -1
- package/node_modules/yaml/dist/schema/yaml-1.1/schema.js +0 -41
- package/node_modules/yaml/dist/schema/yaml-1.1/set.d.ts +0 -28
- package/node_modules/yaml/dist/schema/yaml-1.1/set.js +0 -96
- package/node_modules/yaml/dist/schema/yaml-1.1/timestamp.d.ts +0 -6
- package/node_modules/yaml/dist/schema/yaml-1.1/timestamp.js +0 -105
- package/node_modules/yaml/dist/stringify/foldFlowLines.d.ts +0 -34
- package/node_modules/yaml/dist/stringify/foldFlowLines.js +0 -151
- package/node_modules/yaml/dist/stringify/stringify.d.ts +0 -21
- package/node_modules/yaml/dist/stringify/stringify.js +0 -132
- package/node_modules/yaml/dist/stringify/stringifyCollection.d.ts +0 -17
- package/node_modules/yaml/dist/stringify/stringifyCollection.js +0 -155
- package/node_modules/yaml/dist/stringify/stringifyComment.d.ts +0 -10
- package/node_modules/yaml/dist/stringify/stringifyComment.js +0 -24
- package/node_modules/yaml/dist/stringify/stringifyDocument.d.ts +0 -4
- package/node_modules/yaml/dist/stringify/stringifyDocument.js +0 -87
- package/node_modules/yaml/dist/stringify/stringifyNumber.d.ts +0 -2
- package/node_modules/yaml/dist/stringify/stringifyNumber.js +0 -27
- package/node_modules/yaml/dist/stringify/stringifyPair.d.ts +0 -3
- package/node_modules/yaml/dist/stringify/stringifyPair.js +0 -152
- package/node_modules/yaml/dist/stringify/stringifyString.d.ts +0 -9
- package/node_modules/yaml/dist/stringify/stringifyString.js +0 -338
- package/node_modules/yaml/dist/test-events.d.ts +0 -4
- package/node_modules/yaml/dist/test-events.js +0 -134
- package/node_modules/yaml/dist/util.d.ts +0 -16
- package/node_modules/yaml/dist/util.js +0 -28
- package/node_modules/yaml/dist/visit.d.ts +0 -102
- package/node_modules/yaml/dist/visit.js +0 -236
- package/node_modules/yaml/package.json +0 -97
- package/node_modules/yaml/util.js +0 -2
|
@@ -1,656 +0,0 @@
|
|
|
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
|
-
}
|