owenloop 0.4.1 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +71 -0
- package/README.md +182 -53
- package/bin/owenloop.mjs +50 -2
- package/dist/packages/work/src/agent/brief.d.ts +176 -0
- package/dist/packages/work/src/agent/brief.js +197 -0
- package/dist/packages/work/src/agent/loop.d.ts +141 -0
- package/dist/packages/work/src/agent/loop.js +669 -0
- package/dist/packages/work/src/agent/model-policy.d.ts +49 -0
- package/dist/packages/work/src/agent/model-policy.js +138 -0
- package/dist/packages/work/src/agent/workdir.d.ts +210 -0
- package/dist/packages/work/src/agent/workdir.js +319 -0
- package/dist/packages/work/src/bundle/cache.d.ts +92 -0
- package/dist/packages/work/src/bundle/cache.js +338 -0
- package/dist/packages/work/src/bundle/fetch.d.ts +87 -0
- package/dist/packages/work/src/bundle/fetch.js +345 -0
- package/dist/packages/work/src/bundle/types.d.ts +164 -0
- package/dist/packages/work/src/bundle/types.js +1 -0
- package/dist/packages/work/src/consumed-verifier.d.ts +45 -0
- package/dist/packages/work/src/consumed-verifier.js +205 -0
- package/dist/packages/work/src/credentials/owenloop.d.ts +11 -0
- package/dist/packages/work/src/credentials/owenloop.js +28 -0
- package/dist/packages/work/src/credentials/reader.d.ts +36 -0
- package/dist/packages/work/src/credentials/reader.js +32 -0
- package/dist/packages/work/src/credentials/resolve.d.ts +19 -0
- package/dist/packages/work/src/credentials/resolve.js +56 -0
- package/dist/packages/work/src/exec/instructions.d.ts +99 -0
- package/dist/packages/work/src/exec/instructions.js +323 -0
- package/dist/packages/work/src/exec/loop.d.ts +40 -0
- package/dist/packages/work/src/exec/loop.js +332 -0
- package/dist/packages/work/src/exec/payload.d.ts +29 -0
- package/dist/packages/work/src/exec/payload.js +54 -0
- package/dist/packages/work/src/exec/receipt.d.ts +41 -0
- package/dist/packages/work/src/exec/receipt.js +32 -0
- package/dist/packages/work/src/exec/runner.d.ts +71 -0
- package/dist/packages/work/src/exec/runner.js +256 -0
- package/dist/packages/work/src/harness/child-env.d.ts +100 -0
- package/dist/packages/work/src/harness/child-env.js +134 -0
- package/dist/packages/work/src/harness/claude.d.ts +140 -0
- package/dist/packages/work/src/harness/claude.js +837 -0
- package/dist/packages/work/src/harness/codex.d.ts +111 -0
- package/dist/packages/work/src/harness/codex.js +1024 -0
- package/dist/packages/work/src/harness/contract.d.ts +308 -0
- package/dist/packages/work/src/harness/contract.js +32 -0
- package/dist/packages/work/src/harness/fake.d.ts +59 -0
- package/dist/packages/work/src/harness/fake.js +91 -0
- package/dist/packages/work/src/harness/jsonrpc-stdio.d.ts +108 -0
- package/dist/packages/work/src/harness/jsonrpc-stdio.js +351 -0
- package/dist/packages/work/src/harness/permissions.d.ts +75 -0
- package/dist/packages/work/src/harness/permissions.js +182 -0
- package/dist/packages/work/src/harness/registry.d.ts +47 -0
- package/dist/packages/work/src/harness/registry.js +45 -0
- package/dist/packages/work/src/harness/session-store.d.ts +181 -0
- package/dist/packages/work/src/harness/session-store.js +523 -0
- package/dist/packages/work/src/harness/types.d.ts +29 -0
- package/dist/packages/work/src/harness/types.js +14 -0
- package/dist/packages/work/src/harnesses.d.ts +38 -0
- package/dist/packages/work/src/harnesses.js +38 -0
- package/dist/packages/work/src/hold/loop.d.ts +36 -0
- package/dist/packages/work/src/hold/loop.js +23 -0
- package/dist/packages/work/src/hold/mcp.d.ts +75 -0
- package/dist/packages/work/src/hold/mcp.js +264 -0
- package/dist/packages/work/src/hub/client.d.ts +23 -0
- package/dist/packages/work/src/hub/client.js +91 -0
- package/dist/packages/work/src/hub/types.d.ts +326 -0
- package/dist/packages/work/src/hub/types.js +26 -0
- package/dist/packages/work/src/lease/loop.d.ts +94 -0
- package/dist/packages/work/src/lease/loop.js +277 -0
- package/dist/packages/work/src/main.d.ts +1 -0
- package/dist/packages/work/src/main.js +48 -0
- package/dist/packages/work/src/mcp/server.d.ts +125 -0
- package/dist/packages/work/src/mcp/server.js +320 -0
- package/dist/packages/work/src/owenloop-bin.d.ts +1 -0
- package/dist/packages/work/src/owenloop-bin.js +18 -0
- package/dist/packages/work/src/roles/agent-run.d.ts +124 -0
- package/dist/packages/work/src/roles/agent-run.js +529 -0
- package/dist/packages/work/src/roles/exec.d.ts +48 -0
- package/dist/packages/work/src/roles/exec.js +228 -0
- package/dist/packages/work/src/roles/hold.d.ts +72 -0
- package/dist/packages/work/src/roles/hold.js +363 -0
- package/dist/packages/work/src/roles/join.d.ts +18 -0
- package/dist/packages/work/src/roles/join.js +204 -0
- package/dist/packages/work/src/roles/lint.d.ts +58 -0
- package/dist/packages/work/src/roles/lint.js +234 -0
- package/dist/packages/work/src/roles/prepare.d.ts +1 -0
- package/dist/packages/work/src/roles/prepare.js +249 -0
- package/dist/packages/work/src/roles/release.d.ts +48 -0
- package/dist/packages/work/src/roles/release.js +137 -0
- package/dist/packages/work/src/roles/sessions.d.ts +61 -0
- package/dist/packages/work/src/roles/sessions.js +180 -0
- package/dist/packages/work/src/roles/settings.d.ts +6 -0
- package/dist/packages/work/src/roles/settings.js +71 -0
- package/dist/packages/work/src/roles/shift.d.ts +13 -0
- package/dist/packages/work/src/roles/shift.js +250 -0
- package/dist/packages/work/src/roles/signals.d.ts +55 -0
- package/dist/packages/work/src/roles/signals.js +62 -0
- package/dist/packages/work/src/settings/provision.d.ts +21 -0
- package/dist/packages/work/src/settings/provision.js +47 -0
- package/dist/packages/work/src/settings/settings.d.ts +136 -0
- package/dist/packages/work/src/settings/settings.js +155 -0
- package/dist/packages/work/src/shift/client.d.ts +24 -0
- package/dist/packages/work/src/shift/client.js +124 -0
- package/dist/packages/work/src/shift/loop.d.ts +131 -0
- package/dist/packages/work/src/shift/loop.js +751 -0
- package/dist/packages/work/src/shift/protocol.d.ts +95 -0
- package/dist/packages/work/src/shift/protocol.js +24 -0
- package/dist/packages/work/src/shift/routing.d.ts +35 -0
- package/dist/packages/work/src/shift/routing.js +50 -0
- package/dist/packages/work/src/shift/runtime.d.ts +45 -0
- package/dist/packages/work/src/shift/runtime.js +337 -0
- package/dist/packages/work/src/shift/server.d.ts +23 -0
- package/dist/packages/work/src/shift/server.js +716 -0
- package/dist/packages/work/src/shift/spawn.d.ts +109 -0
- package/dist/packages/work/src/shift/spawn.js +158 -0
- package/dist/packages/work/src/shift/state.d.ts +79 -0
- package/dist/packages/work/src/shift/state.js +385 -0
- package/dist/packages/work/src/submit-proof.d.ts +36 -0
- package/dist/packages/work/src/submit-proof.js +93 -0
- package/dist/packages/work/src/usage.d.ts +6 -0
- package/dist/packages/work/src/usage.js +175 -0
- package/dist/src/add.d.ts +189 -0
- package/dist/src/add.js +300 -0
- package/dist/src/archive.d.ts +97 -0
- package/dist/src/archive.js +591 -0
- package/dist/src/bundle/index.d.ts +64 -0
- package/dist/src/bundle/index.js +508 -0
- package/dist/src/bundle/manifest.d.ts +50 -0
- package/dist/src/bundle/manifest.js +435 -0
- package/dist/src/bundle/runtime.d.ts +26 -0
- package/dist/src/bundle/runtime.js +64 -0
- package/dist/src/bundle/tar.d.ts +62 -0
- package/dist/src/bundle/tar.js +238 -0
- package/dist/src/bundle/types.d.ts +105 -0
- package/dist/src/bundle/types.js +21 -0
- package/dist/{cli.d.ts → src/cli.d.ts} +92 -7
- package/dist/src/cli.js +5968 -0
- package/dist/{credentials.d.ts → src/credentials.d.ts} +22 -15
- package/dist/{credentials.js → src/credentials.js} +35 -31
- package/dist/src/crypto/allowed-signers.d.ts +68 -0
- package/dist/src/crypto/allowed-signers.js +307 -0
- package/dist/src/crypto/canonical.d.ts +8 -0
- package/dist/src/crypto/canonical.js +92 -0
- package/dist/src/crypto/chain.d.ts +65 -0
- package/dist/src/crypto/chain.js +377 -0
- package/dist/src/crypto/dsse.d.ts +209 -0
- package/dist/src/crypto/dsse.js +282 -0
- package/dist/src/crypto/enrollment.d.ts +78 -0
- package/dist/src/crypto/enrollment.js +186 -0
- package/dist/src/crypto/index.d.ts +48 -0
- package/dist/src/crypto/index.js +44 -0
- package/dist/src/crypto/keys.d.ts +258 -0
- package/dist/src/crypto/keys.js +908 -0
- package/dist/src/crypto/org-root.d.ts +33 -0
- package/dist/src/crypto/org-root.js +78 -0
- package/dist/src/crypto/origin-rules.d.ts +56 -0
- package/dist/src/crypto/origin-rules.js +143 -0
- package/dist/src/crypto/policy-floor.d.ts +98 -0
- package/dist/src/crypto/policy-floor.js +353 -0
- package/dist/src/crypto/records.d.ts +316 -0
- package/dist/src/crypto/records.js +157 -0
- package/dist/src/crypto/scope.d.ts +49 -0
- package/dist/src/crypto/scope.js +83 -0
- package/dist/src/crypto/ssh.d.ts +171 -0
- package/dist/src/crypto/ssh.js +396 -0
- package/dist/src/crypto/submission.d.ts +33 -0
- package/dist/src/crypto/submission.js +47 -0
- package/dist/src/crypto/trust-roots.d.ts +29 -0
- package/dist/src/crypto/trust-roots.js +39 -0
- package/dist/src/crypto/verify-consumed.d.ts +67 -0
- package/dist/src/crypto/verify-consumed.js +259 -0
- package/dist/src/crypto/verify-origin.d.ts +50 -0
- package/dist/src/crypto/verify-origin.js +151 -0
- package/dist/src/crypto/verify-publication.d.ts +60 -0
- package/dist/src/crypto/verify-publication.js +150 -0
- package/dist/{defs.d.ts → src/defs.d.ts} +24 -1
- package/dist/{defs.js → src/defs.js} +181 -61
- package/dist/{engine.d.ts → src/engine.d.ts} +105 -9
- package/dist/{engine.js → src/engine.js} +251 -47
- package/dist/{factory.d.ts → src/factory.d.ts} +16 -0
- package/dist/{factory.js → src/factory.js} +16 -4
- package/dist/src/global-config.d.ts +59 -0
- package/dist/src/global-config.js +84 -0
- package/dist/{hub.d.ts → src/hub.d.ts} +280 -31
- package/dist/{hub.js → src/hub.js} +493 -52
- package/dist/src/index.d.ts +47 -0
- package/dist/src/index.js +41 -0
- package/dist/src/install.d.ts +538 -0
- package/dist/src/install.js +1981 -0
- package/dist/src/lock.d.ts +38 -0
- package/dist/src/lock.js +325 -0
- package/dist/src/mcp/serve.d.ts +109 -0
- package/dist/{mcp → src/mcp}/serve.js +335 -75
- package/dist/{mcp → src/mcp}/server.d.ts +6 -9
- package/dist/{mcp → src/mcp}/server.js +18 -10
- package/dist/{model.d.ts → src/model.d.ts} +15 -0
- package/dist/{model.js → src/model.js} +112 -2
- package/dist/src/order-resolver.d.ts +184 -0
- package/dist/src/order-resolver.js +252 -0
- package/dist/src/package-version.d.ts +10 -0
- package/dist/src/package-version.js +42 -0
- package/dist/{paths.d.ts → src/paths.d.ts} +14 -1
- package/dist/{paths.js → src/paths.js} +18 -0
- package/dist/src/schemas/enrollment-grant.v1.schema.json +90 -0
- package/dist/src/schemas/index.d.ts +1416 -0
- package/dist/src/schemas/index.js +31 -0
- package/dist/src/schemas/order.v1.schema.json +106 -0
- package/dist/src/schemas/origin.v1.schema.json +68 -0
- package/dist/src/schemas/policy-floor.v1.schema.json +29 -0
- package/dist/src/schemas/publication.v1.schema.json +31 -0
- package/dist/src/schemas/revocation.v1.schema.json +39 -0
- package/dist/src/schemas/submission.v1.schema.json +61 -0
- package/dist/src/store/def-source.d.ts +52 -0
- package/dist/src/store/def-source.js +335 -0
- package/dist/src/store/index-file.d.ts +69 -0
- package/dist/src/store/index-file.js +151 -0
- package/dist/src/store/index.d.ts +27 -0
- package/dist/src/store/index.js +22 -0
- package/dist/src/store/ingestor.d.ts +43 -0
- package/dist/src/store/ingestor.js +211 -0
- package/dist/src/store/install.d.ts +228 -0
- package/dist/src/store/install.js +555 -0
- package/dist/src/store/instruction-source.d.ts +49 -0
- package/dist/src/store/instruction-source.js +298 -0
- package/dist/src/store/origin-evidence.d.ts +21 -0
- package/dist/src/store/origin-evidence.js +66 -0
- package/dist/src/store/pre-commit-verifier.d.ts +68 -0
- package/dist/src/store/pre-commit-verifier.js +418 -0
- package/dist/src/store/resolve.d.ts +138 -0
- package/dist/src/store/resolve.js +363 -0
- package/dist/src/store/types.d.ts +288 -0
- package/dist/src/store/types.js +356 -0
- package/dist/{types.d.ts → src/types.d.ts} +58 -24
- package/dist/{untar.d.ts → src/untar.d.ts} +8 -23
- package/dist/src/untar.js +38 -0
- package/dist/{util.d.ts → src/util.d.ts} +3 -2
- package/dist/{util.js → src/util.js} +3 -2
- package/dist/{owenwork.d.ts → src/work-settings.d.ts} +22 -22
- package/dist/{owenwork.js → src/work-settings.js} +27 -27
- package/docs/agent-runner.md +86 -0
- package/docs/authoring.md +150 -59
- package/docs/bundles.md +250 -0
- package/docs/cli.md +1758 -163
- package/docs/crypto.md +816 -0
- package/docs/design.md +374 -52
- package/docs/embedding.md +135 -27
- package/docs/wire-contracts.md +380 -0
- package/examples/workflows/{command-worker.yaml → command-executor.yaml} +15 -15
- package/examples/workflows/compile-dev-playbook.yaml +338 -0
- package/examples/workflows/judges/gate-sharpness.md +39 -0
- package/examples/workflows/judges/security.md +34 -0
- package/package.json +22 -8
- package/plugins/claude-code/.claude-plugin/marketplace.json +14 -0
- package/plugins/claude-code/plugin/.claude-plugin/plugin.json +8 -0
- package/plugins/claude-code/plugin/.mcp.json +14 -0
- package/plugins/claude-code/plugin/hooks/hooks.json +26 -0
- package/plugins/claude-code/plugin/hooks/session-end.sh +40 -0
- package/plugins/claude-code/plugin/hooks/session-start.sh +52 -0
- package/plugins/claude-code/plugin/skills/author/SKILL.md +181 -0
- package/plugins/claude-code/plugin/skills/conduct/SKILL.md +106 -0
- package/plugins/claude-code/plugin/skills/shift/SKILL.md +105 -0
- package/plugins/codex/.agents/plugins/marketplace.json +21 -0
- package/plugins/codex/plugins/owenloop/.codex-plugin/plugin.json +7 -0
- package/plugins/codex/plugins/owenloop/.mcp.json +20 -0
- package/plugins/codex/plugins/owenloop/hooks/hooks.json +26 -0
- package/plugins/codex/plugins/owenloop/hooks/session-end.sh +40 -0
- package/plugins/codex/plugins/owenloop/hooks/session-start.sh +52 -0
- package/plugins/codex/plugins/owenloop/skills/author/SKILL.md +181 -0
- package/plugins/codex/plugins/owenloop/skills/conduct/SKILL.md +106 -0
- package/plugins/codex/plugins/owenloop/skills/shift/SKILL.md +105 -0
- package/dist/add.d.ts +0 -384
- package/dist/add.js +0 -834
- package/dist/cli.js +0 -3270
- package/dist/index.d.ts +0 -32
- package/dist/index.js +0 -23
- package/dist/lock.d.ts +0 -80
- package/dist/lock.js +0 -217
- package/dist/mcp/serve.d.ts +0 -84
- package/dist/untar.js +0 -164
- /package/dist/{schema.d.ts → src/schema.d.ts} +0 -0
- /package/dist/{schema.js → src/schema.js} +0 -0
- /package/dist/{store.d.ts → src/store.d.ts} +0 -0
- /package/dist/{store.js → src/store.js} +0 -0
- /package/dist/{types.js → src/types.js} +0 -0
package/dist/index.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* owenloop — a generic dataflow workflow engine.
|
|
3
|
-
*
|
|
4
|
-
* Steps owe and consume artifacts; a step's eligibility to run is a pure
|
|
5
|
-
* function of artifact state (debts + dependency satisfaction), not a status
|
|
6
|
-
* enum. Rejection carries a reason thread; a forward cascade keeps the graph
|
|
7
|
-
* honest ("an artifact is green only while every artifact it consumed is
|
|
8
|
-
* green"); a commit-fingerprint CAS makes concurrent advancement safe.
|
|
9
|
-
*
|
|
10
|
-
* This is the public API. The engine is domain-neutral: a *wiring* (a set of
|
|
11
|
-
* workflow definitions + a worker that executes orders) layers a concrete
|
|
12
|
-
* process — software delivery, research, triage — on top of it.
|
|
13
|
-
*/
|
|
14
|
-
export { Engine } from './engine.ts';
|
|
15
|
-
export type { CommitResult, CreateOpts, DefResolver, DeferredFiring, DeferredReason, EmitResult, EngineEvent, EngineListener, EngineWorkflowStatus, Order, ReapDetail, ReapReason, TickResult, } from './engine.ts';
|
|
16
|
-
export { createEngine } from './factory.ts';
|
|
17
|
-
export type { CreateEngineOpts, CreatedEngine } from './factory.ts';
|
|
18
|
-
export { Store, openStore, StoreVersionError } from './store.ts';
|
|
19
|
-
export type { ArtifactRow, RunRow, TaskRow, WorkflowRow } from './store.ts';
|
|
20
|
-
export { buildDef, DefError, expandIncludes, finalizeDefs, hashDef, lintDef, loadDefFile, loadDefs, loadDefsRaw, parseDef, SUPPORTED_ENGINE_VERSION, validateDef } from './defs.ts';
|
|
21
|
-
export { credentialSlot, hashDefForHub, keychainServiceFor, normalizeOrigin, readStoredCredential } from './hub.ts';
|
|
22
|
-
export type { Credential, CredentialSlotSelector, Keychain, ReadStoredCredentialOpts } from './hub.ts';
|
|
23
|
-
export type { DefLoadFailure } from './defs.ts';
|
|
24
|
-
export { deleteCredential, ensureFreshOAuth, storeCredential } from './credentials.ts';
|
|
25
|
-
export type { CredentialIO } from './credentials.ts';
|
|
26
|
-
export { buildGraph, buildTrace, eligibleFirings, graphToDot, graphToMermaid, isStalled, modelCheck, workflowStatus, } from './model.ts';
|
|
27
|
-
export type { ArtifactMap, Blocker, Firing, TimeFacts, WorkflowStatus } from './model.ts';
|
|
28
|
-
export { parseConsume, parseProduce, } from './paths.ts';
|
|
29
|
-
export { assertValidSchema, summarizeIssues, validateValue } from './schema.ts';
|
|
30
|
-
export type { SchemaCheck, SchemaIssue } from './schema.ts';
|
|
31
|
-
export { DEBT_STATES, SETTLED_STATES } from './types.ts';
|
|
32
|
-
export type { Acceptance, ArtifactBiography, ArtifactData, Author, CheckFinding, CheckOptions, CheckReport, CheckStep, ConsumePattern, FiringTrigger, Fingerprint, GraphEdge, GraphNode, GraphNodeState, InputDef, InvariantDef, InvariantPredicate, InvariantViolation, JsonSchema, StepDef, ProducePattern, ReasonEntry, RejectKind, RunData, TaskData, TimelineEvent, WorkflowDef, WorkflowGraph, WorkflowTrace, } from './types.ts';
|
package/dist/index.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* owenloop — a generic dataflow workflow engine.
|
|
3
|
-
*
|
|
4
|
-
* Steps owe and consume artifacts; a step's eligibility to run is a pure
|
|
5
|
-
* function of artifact state (debts + dependency satisfaction), not a status
|
|
6
|
-
* enum. Rejection carries a reason thread; a forward cascade keeps the graph
|
|
7
|
-
* honest ("an artifact is green only while every artifact it consumed is
|
|
8
|
-
* green"); a commit-fingerprint CAS makes concurrent advancement safe.
|
|
9
|
-
*
|
|
10
|
-
* This is the public API. The engine is domain-neutral: a *wiring* (a set of
|
|
11
|
-
* workflow definitions + a worker that executes orders) layers a concrete
|
|
12
|
-
* process — software delivery, research, triage — on top of it.
|
|
13
|
-
*/
|
|
14
|
-
export { Engine } from "./engine.js";
|
|
15
|
-
export { createEngine } from "./factory.js";
|
|
16
|
-
export { Store, openStore, StoreVersionError } from "./store.js";
|
|
17
|
-
export { buildDef, DefError, expandIncludes, finalizeDefs, hashDef, lintDef, loadDefFile, loadDefs, loadDefsRaw, parseDef, SUPPORTED_ENGINE_VERSION, validateDef } from "./defs.js";
|
|
18
|
-
export { credentialSlot, hashDefForHub, keychainServiceFor, normalizeOrigin, readStoredCredential } from "./hub.js";
|
|
19
|
-
export { deleteCredential, ensureFreshOAuth, storeCredential } from "./credentials.js";
|
|
20
|
-
export { buildGraph, buildTrace, eligibleFirings, graphToDot, graphToMermaid, isStalled, modelCheck, workflowStatus, } from "./model.js";
|
|
21
|
-
export { parseConsume, parseProduce, } from "./paths.js";
|
|
22
|
-
export { assertValidSchema, summarizeIssues, validateValue } from "./schema.js";
|
|
23
|
-
export { DEBT_STATES, SETTLED_STATES } from "./types.js";
|
package/dist/lock.d.ts
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generic advisory FILE LOCK — an exclusive-create lockfile with liveness-aware
|
|
3
|
-
* staleness, used to serialize a filesystem critical section across owenloop
|
|
4
|
-
* processes.
|
|
5
|
-
*
|
|
6
|
-
* Extracted verbatim (logic-identical) from `src/add.ts`'s per-project install
|
|
7
|
-
* lock: `add.ts` now consumes it through thin `acquireInstallLock` /
|
|
8
|
-
* `releaseInstallLock` wrappers that preserve the old names, types, and the
|
|
9
|
-
* "owenloop add" timeout wording; `src/credentials.ts` uses it to serialize the
|
|
10
|
-
* OAuth refresh-and-persist critical section (`credentials.lock`). The only
|
|
11
|
-
* behavioral addition during the move is the optional `label` (used in the
|
|
12
|
-
* timeout message) so each caller names itself.
|
|
13
|
-
*
|
|
14
|
-
* Depends only on node builtins so the library barrel (`src/index.ts` →
|
|
15
|
-
* `credentials.ts` → here) never drags the `add`/`untar` graph into its runtime
|
|
16
|
-
* closure.
|
|
17
|
-
*/
|
|
18
|
-
export interface FileLockHandle {
|
|
19
|
-
lockPath: string;
|
|
20
|
-
acquired: boolean;
|
|
21
|
-
/** Per-acquisition ownership token — present when `acquired`; proof of ownership for release. */
|
|
22
|
-
token?: string;
|
|
23
|
-
}
|
|
24
|
-
export interface AcquireFileLockOpts {
|
|
25
|
-
/** Max time to wait for a live lock before failing cleanly (default 10s). */
|
|
26
|
-
waitMs?: number;
|
|
27
|
-
/**
|
|
28
|
-
* Age (by mtime) past which an *unparseable/abandoned* lock may be reclaimed
|
|
29
|
-
* (default 10m). Age NEVER reclaims a lock whose recorded pid is alive on
|
|
30
|
-
* this host — it only governs the fail-closed fallback for a lock we cannot
|
|
31
|
-
* attribute to a live owner (unparseable payload, or one without a pid).
|
|
32
|
-
*/
|
|
33
|
-
staleMs?: number;
|
|
34
|
-
/** Poll interval while waiting on a live lock (default 100ms). */
|
|
35
|
-
pollMs?: number;
|
|
36
|
-
/** Liveness probe for the holder pid — injectable so tests are deterministic. */
|
|
37
|
-
isPidAlive?: (pid: number) => boolean;
|
|
38
|
-
/** Clock — injectable so tests are deterministic. */
|
|
39
|
-
now?: () => number;
|
|
40
|
-
/** Current hostname — injectable so cross-host tests are deterministic (default `os.hostname`). */
|
|
41
|
-
hostname?: () => string;
|
|
42
|
-
/**
|
|
43
|
-
* Names the holder in the timeout message ("another ${label} is in
|
|
44
|
-
* progress …"). Defaults to a generic phrase; `add` passes "owenloop add" so
|
|
45
|
-
* its existing wording is byte-identical.
|
|
46
|
-
*/
|
|
47
|
-
label?: string;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Thrown by `acquireFileLock` when it gives up after `waitMs` on a lock a live
|
|
51
|
-
* owner still holds. A subclass of `Error` (not a plain `Error`) so a caller can
|
|
52
|
-
* `instanceof`-distinguish a clean timeout from a real filesystem failure (an
|
|
53
|
-
* EACCES/EROFS from the exclusive create) and map only the timeout to its own
|
|
54
|
-
* domain error — while `.message` stays byte-identical to the pre-extraction
|
|
55
|
-
* plain-`Error` message the `add` tests assert on.
|
|
56
|
-
*/
|
|
57
|
-
export declare class FileLockTimeoutError extends Error {
|
|
58
|
-
readonly lockPath: string;
|
|
59
|
-
readonly holderPid: number | undefined;
|
|
60
|
-
readonly waitMs: number;
|
|
61
|
-
constructor(message: string, lockPath: string, holderPid: number | undefined, waitMs: number);
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Acquire the file lock at `lockPath` (an exclusive-create of the file,
|
|
65
|
-
* `openSync(..,'wx')` — the O_EXCL create is the real serialization point). The
|
|
66
|
-
* payload carries an ownership token, the owner pid, a start timestamp, and the
|
|
67
|
-
* host. If another process holds it: reclaim it only when liveness-aware
|
|
68
|
-
* staleness says its owner is gone (see `lockIsStale`), otherwise poll until it
|
|
69
|
-
* frees, and if it does not free within `waitMs` throw a `FileLockTimeoutError`.
|
|
70
|
-
* Always pair with `releaseFileLock` in a `finally`.
|
|
71
|
-
*/
|
|
72
|
-
export declare function acquireFileLock(lockPath: string, opts?: AcquireFileLockOpts): Promise<FileLockHandle>;
|
|
73
|
-
/**
|
|
74
|
-
* Release a lock acquired by `acquireFileLock`. Token-checked and best-effort: a
|
|
75
|
-
* no-op if not acquired, if the lock is already gone/unparseable, or if its
|
|
76
|
-
* token no longer matches this handle (someone else legitimately re-acquired it
|
|
77
|
-
* — deleting would steal *their* lock). Never throws; it runs in a `finally` and
|
|
78
|
-
* must not mask the real error.
|
|
79
|
-
*/
|
|
80
|
-
export declare function releaseFileLock(handle: FileLockHandle): void;
|
package/dist/lock.js
DELETED
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generic advisory FILE LOCK — an exclusive-create lockfile with liveness-aware
|
|
3
|
-
* staleness, used to serialize a filesystem critical section across owenloop
|
|
4
|
-
* processes.
|
|
5
|
-
*
|
|
6
|
-
* Extracted verbatim (logic-identical) from `src/add.ts`'s per-project install
|
|
7
|
-
* lock: `add.ts` now consumes it through thin `acquireInstallLock` /
|
|
8
|
-
* `releaseInstallLock` wrappers that preserve the old names, types, and the
|
|
9
|
-
* "owenloop add" timeout wording; `src/credentials.ts` uses it to serialize the
|
|
10
|
-
* OAuth refresh-and-persist critical section (`credentials.lock`). The only
|
|
11
|
-
* behavioral addition during the move is the optional `label` (used in the
|
|
12
|
-
* timeout message) so each caller names itself.
|
|
13
|
-
*
|
|
14
|
-
* Depends only on node builtins so the library barrel (`src/index.ts` →
|
|
15
|
-
* `credentials.ts` → here) never drags the `add`/`untar` graph into its runtime
|
|
16
|
-
* closure.
|
|
17
|
-
*/
|
|
18
|
-
import { closeSync, mkdirSync, openSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
19
|
-
import { dirname } from 'node:path';
|
|
20
|
-
import { randomBytes } from 'node:crypto';
|
|
21
|
-
import { hostname } from 'node:os';
|
|
22
|
-
import { setTimeout as sleep } from 'node:timers/promises';
|
|
23
|
-
/** Default wait/stale/poll timings for a file lock (overridable per acquire). */
|
|
24
|
-
const LOCK_WAIT_MS = 10_000;
|
|
25
|
-
const LOCK_STALE_MS = 10 * 60_000;
|
|
26
|
-
const LOCK_POLL_MS = 100;
|
|
27
|
-
/**
|
|
28
|
-
* Thrown by `acquireFileLock` when it gives up after `waitMs` on a lock a live
|
|
29
|
-
* owner still holds. A subclass of `Error` (not a plain `Error`) so a caller can
|
|
30
|
-
* `instanceof`-distinguish a clean timeout from a real filesystem failure (an
|
|
31
|
-
* EACCES/EROFS from the exclusive create) and map only the timeout to its own
|
|
32
|
-
* domain error — while `.message` stays byte-identical to the pre-extraction
|
|
33
|
-
* plain-`Error` message the `add` tests assert on.
|
|
34
|
-
*/
|
|
35
|
-
export class FileLockTimeoutError extends Error {
|
|
36
|
-
lockPath;
|
|
37
|
-
holderPid;
|
|
38
|
-
waitMs;
|
|
39
|
-
constructor(message, lockPath, holderPid, waitMs) {
|
|
40
|
-
super(message);
|
|
41
|
-
this.name = 'FileLockTimeoutError';
|
|
42
|
-
this.lockPath = lockPath;
|
|
43
|
-
this.holderPid = holderPid;
|
|
44
|
-
this.waitMs = waitMs;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
/** `true` if a process with `pid` exists (signal 0 probes without delivering). */
|
|
48
|
-
function defaultIsPidAlive(pid) {
|
|
49
|
-
try {
|
|
50
|
-
process.kill(pid, 0);
|
|
51
|
-
return true;
|
|
52
|
-
}
|
|
53
|
-
catch (e) {
|
|
54
|
-
// EPERM: the process exists but we may not signal it — treat as alive.
|
|
55
|
-
// ESRCH (and anything else): no such process — dead.
|
|
56
|
-
return e.code === 'EPERM';
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
/** Read the lock file's raw bytes, or `null` if it is gone/unreadable. */
|
|
60
|
-
function readLockRaw(lockPath) {
|
|
61
|
-
try {
|
|
62
|
-
return readFileSync(lockPath, 'utf8');
|
|
63
|
-
}
|
|
64
|
-
catch {
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
/** Parse raw lock bytes into a holder, or `null` if absent/unparseable. */
|
|
69
|
-
function parseLockHolder(raw) {
|
|
70
|
-
if (raw === null)
|
|
71
|
-
return null;
|
|
72
|
-
try {
|
|
73
|
-
return JSON.parse(raw);
|
|
74
|
-
}
|
|
75
|
-
catch {
|
|
76
|
-
return null;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
/** Read + parse the lock file in one step (fresh read). Used off the hot loop. */
|
|
80
|
-
function readLockHolder(lockPath) {
|
|
81
|
-
return parseLockHolder(readLockRaw(lockPath));
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Decide whether the lock described by `holder` (parsed from a raw read) may be
|
|
85
|
-
* reclaimed, given the current host. Liveness-aware, not age-based:
|
|
86
|
-
*
|
|
87
|
-
* 1. `statSync` fails — the lock vanished mid-judgment → treat as reclaimable
|
|
88
|
-
* (the acquire loop re-verifies and simply retries the exclusive create).
|
|
89
|
-
* 2. Holder records a `host` that differs from ours → NOT stale, ever. A
|
|
90
|
-
* foreign PID space means `process.kill(pid, 0)` proves nothing; a shared
|
|
91
|
-
* filesystem could be locked by another machine. Held; caller refuses.
|
|
92
|
-
* 3. Holder has a numeric `pid` and either matches our host or omits `host`
|
|
93
|
-
* (a legacy same-machine payload) → stale iff that pid is dead. Age never
|
|
94
|
-
* reclaims a live-pid lock — this is the core safety policy.
|
|
95
|
-
* 4. Unparseable, or parses without a numeric pid → fail closed: held until
|
|
96
|
-
* `now() - mtimeMs > staleMs` (age is the only abandonment signal left).
|
|
97
|
-
*/
|
|
98
|
-
function lockIsStale(lockPath, holder, staleMs, isPidAlive, now, currentHost) {
|
|
99
|
-
let mtimeMs;
|
|
100
|
-
try {
|
|
101
|
-
mtimeMs = statSync(lockPath).mtimeMs;
|
|
102
|
-
}
|
|
103
|
-
catch {
|
|
104
|
-
// Vanished between the EEXIST and here — someone else reclaimed it; retry.
|
|
105
|
-
return true;
|
|
106
|
-
}
|
|
107
|
-
// Case 2: recorded on a different host — its pid tells us nothing. Held.
|
|
108
|
-
if (holder && typeof holder.host === 'string' && holder.host !== currentHost) {
|
|
109
|
-
return false;
|
|
110
|
-
}
|
|
111
|
-
// Case 3: same host (or legacy no-host payload) with a numeric pid — liveness decides.
|
|
112
|
-
if (holder && typeof holder.pid === 'number') {
|
|
113
|
-
return !isPidAlive(holder.pid);
|
|
114
|
-
}
|
|
115
|
-
// Case 4: no attributable live owner — age is the only abandonment signal.
|
|
116
|
-
return now() - mtimeMs > staleMs;
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Acquire the file lock at `lockPath` (an exclusive-create of the file,
|
|
120
|
-
* `openSync(..,'wx')` — the O_EXCL create is the real serialization point). The
|
|
121
|
-
* payload carries an ownership token, the owner pid, a start timestamp, and the
|
|
122
|
-
* host. If another process holds it: reclaim it only when liveness-aware
|
|
123
|
-
* staleness says its owner is gone (see `lockIsStale`), otherwise poll until it
|
|
124
|
-
* frees, and if it does not free within `waitMs` throw a `FileLockTimeoutError`.
|
|
125
|
-
* Always pair with `releaseFileLock` in a `finally`.
|
|
126
|
-
*/
|
|
127
|
-
export async function acquireFileLock(lockPath, opts = {}) {
|
|
128
|
-
const waitMs = opts.waitMs ?? LOCK_WAIT_MS;
|
|
129
|
-
const staleMs = opts.staleMs ?? LOCK_STALE_MS;
|
|
130
|
-
const pollMs = opts.pollMs ?? LOCK_POLL_MS;
|
|
131
|
-
const isPidAlive = opts.isPidAlive ?? defaultIsPidAlive;
|
|
132
|
-
const now = opts.now ?? Date.now;
|
|
133
|
-
const host = (opts.hostname ?? hostname)();
|
|
134
|
-
const label = opts.label ?? 'owenloop process';
|
|
135
|
-
mkdirSync(dirname(lockPath), { recursive: true });
|
|
136
|
-
const deadline = now() + waitMs;
|
|
137
|
-
for (;;) {
|
|
138
|
-
try {
|
|
139
|
-
const fd = openSync(lockPath, 'wx');
|
|
140
|
-
const token = randomBytes(16).toString('hex');
|
|
141
|
-
try {
|
|
142
|
-
writeFileSync(fd, JSON.stringify({ pid: process.pid, startedAt: now(), token, host }));
|
|
143
|
-
}
|
|
144
|
-
finally {
|
|
145
|
-
closeSync(fd);
|
|
146
|
-
}
|
|
147
|
-
return { lockPath, acquired: true, token };
|
|
148
|
-
}
|
|
149
|
-
catch (e) {
|
|
150
|
-
if (e.code !== 'EEXIST')
|
|
151
|
-
throw e;
|
|
152
|
-
}
|
|
153
|
-
// Judge staleness from a single captured raw read...
|
|
154
|
-
const raw = readLockRaw(lockPath);
|
|
155
|
-
const holder = parseLockHolder(raw);
|
|
156
|
-
if (lockIsStale(lockPath, holder, staleMs, isPidAlive, now, host)) {
|
|
157
|
-
// ...then re-verify the bytes are unchanged immediately before deleting.
|
|
158
|
-
// Between judging stale and rmSync a third process could reclaim and
|
|
159
|
-
// re-create the lock; deleting then would destroy a *fresh* owner's lock.
|
|
160
|
-
// Residual window is a few syscalls (read-compare-delete) rather than the
|
|
161
|
-
// poll interval — and the `wx` create below is the true arbiter: if two
|
|
162
|
-
// reclaimers race, one wins the create and the other loops on EEXIST. A
|
|
163
|
-
// rename-based reclaim was rejected: POSIX rename clobbers its target, so
|
|
164
|
-
// any "rename back on mismatch" arm can itself destroy a newer lock.
|
|
165
|
-
const raw2 = readLockRaw(lockPath);
|
|
166
|
-
if (raw2 !== null && raw2 === raw) {
|
|
167
|
-
rmSync(lockPath, { force: true });
|
|
168
|
-
continue; // reclaimed — retry the exclusive create
|
|
169
|
-
}
|
|
170
|
-
// Bytes changed under us, or the lock is stat-able but unreadable (a
|
|
171
|
-
// root-owned 0600 lock: statSync needs only dir perms, readFileSync
|
|
172
|
-
// EACCES → raw/raw2 null). Do NOT delete — fall through to the deadline
|
|
173
|
-
// check and poll sleep below. Never `continue` here: with an unreadable,
|
|
174
|
-
// backdated lock this branch would otherwise spin sleeplessly, starving
|
|
175
|
-
// the event loop and never enforcing `waitMs`.
|
|
176
|
-
}
|
|
177
|
-
if (now() >= deadline) {
|
|
178
|
-
throw new FileLockTimeoutError(inProgressMessage(lockPath, holder, waitMs, label), lockPath, typeof holder?.pid === 'number' ? holder.pid : undefined, waitMs);
|
|
179
|
-
}
|
|
180
|
-
await sleep(pollMs);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
/** Build the clear "another … is in progress" timeout error text, with graceful fallbacks. */
|
|
184
|
-
function inProgressMessage(lockPath, holder, waitMs, label) {
|
|
185
|
-
const who = typeof holder?.pid === 'number' ? `pid ${holder.pid}` : 'another process';
|
|
186
|
-
// Lock content is untrusted input: a finite `startedAt` outside the ECMAScript
|
|
187
|
-
// Date range (|t| > 8.64e15 ms) makes `new Date(t).toISOString()` throw
|
|
188
|
-
// RangeError. Only render held-since when the value is a valid time value;
|
|
189
|
-
// otherwise omit it (same graceful fallback as an absent startedAt).
|
|
190
|
-
const heldSince = typeof holder?.startedAt === 'number' &&
|
|
191
|
-
Number.isFinite(holder.startedAt) &&
|
|
192
|
-
Math.abs(holder.startedAt) <= 8.64e15
|
|
193
|
-
? `, held since ${new Date(holder.startedAt).toISOString()}`
|
|
194
|
-
: '';
|
|
195
|
-
const s = Math.round(waitMs / 1000);
|
|
196
|
-
return `another ${label} is in progress (${who}${heldSince}) — holds ${lockPath}; timed out waiting after ${s}s`;
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* Release a lock acquired by `acquireFileLock`. Token-checked and best-effort: a
|
|
200
|
-
* no-op if not acquired, if the lock is already gone/unparseable, or if its
|
|
201
|
-
* token no longer matches this handle (someone else legitimately re-acquired it
|
|
202
|
-
* — deleting would steal *their* lock). Never throws; it runs in a `finally` and
|
|
203
|
-
* must not mask the real error.
|
|
204
|
-
*/
|
|
205
|
-
export function releaseFileLock(handle) {
|
|
206
|
-
if (!handle.acquired)
|
|
207
|
-
return;
|
|
208
|
-
try {
|
|
209
|
-
const holder = readLockHolder(handle.lockPath);
|
|
210
|
-
if (!holder || holder.token !== handle.token)
|
|
211
|
-
return;
|
|
212
|
-
rmSync(handle.lockPath, { force: true });
|
|
213
|
-
}
|
|
214
|
-
catch {
|
|
215
|
-
// Already reclaimed/replaced, or an unexpected fs error — swallow.
|
|
216
|
-
}
|
|
217
|
-
}
|
package/dist/mcp/serve.d.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `owenloop mcp` — the owenloop-cli-mcp stdio control-plane surface (O2).
|
|
3
|
-
*
|
|
4
|
-
* TWO-PLANE MODEL (identity-and-setup-model doc, §5/§6/§8, in the
|
|
5
|
-
* owenloop-service repo): owenloop runs two distinct planes. The HUMAN control
|
|
6
|
-
* plane is the everyday operator surface — starting runs, answering gates,
|
|
7
|
-
* pushing defs — and it authenticates as the logged-in human. The AGENT plane
|
|
8
|
-
* is what a delivery-line worker uses with its own `olp_` bearer. This module
|
|
9
|
-
* serves the HUMAN plane to a local MCP host (Claude Code) over stdio: it reads
|
|
10
|
-
* newline-delimited JSON-RPC 2.0 on stdin, translates each `tools/call` into one
|
|
11
|
-
* authenticated HTTPS request to the hub's `/api/*` REST mirror, and writes the
|
|
12
|
-
* JSON-RPC reply on stdout. It is spawned by hosts, never run by a human at a
|
|
13
|
-
* prompt.
|
|
14
|
-
*
|
|
15
|
-
* The model doc's cardinal rule (§6): the MODEL must never see a live token.
|
|
16
|
-
* Two consequences are load-bearing here:
|
|
17
|
-
* 1. Every hub call reads the stored `human` credential fresh and refreshes it
|
|
18
|
-
* through O1's locked path (`ensureFreshOAuth`/`refreshOAuth` in
|
|
19
|
-
* `src/credentials.ts`); the bearer only ever rides the `Authorization`
|
|
20
|
-
* header, never a tool result. The server holds NO credential state between
|
|
21
|
-
* calls — its only state is the resolved origin and the fixed tool list.
|
|
22
|
-
* 2. `create_agent` MINTS an `olp_` agent token and writes it straight to the
|
|
23
|
-
* local store (`storeCredential`, slot `agent:<name>`, scopes `['work']`);
|
|
24
|
-
* the token is NEVER returned in a tool result, printed, or logged. The
|
|
25
|
-
* mint response body carries the plaintext in TWO fields (`data.token` AND
|
|
26
|
-
* the human `text` "Store this secret now…"), so the handler builds its
|
|
27
|
-
* result object FROM SCRATCH (`{name, pools, stored:true}`) and never
|
|
28
|
-
* passes any field of the raw body outbound.
|
|
29
|
-
*
|
|
30
|
-
* The transport core is in `./server.ts` (a copy of owenwork's; see its header).
|
|
31
|
-
* Everything owenloop-specific — origin resolution, the authenticated hub
|
|
32
|
-
* client, the tool registrations, the enrollment capability gate, and the
|
|
33
|
-
* command body — lives here.
|
|
34
|
-
*/
|
|
35
|
-
import type { CredentialIO } from '../credentials.ts';
|
|
36
|
-
import type { LineStream } from './server.ts';
|
|
37
|
-
/**
|
|
38
|
-
* The IO surface `runMcpCommand` needs — a strict subset of the CLI's `CliIO`,
|
|
39
|
-
* which structurally satisfies it, so `dispatchMcp` passes its `io` unchanged.
|
|
40
|
-
* `stdinStream` is the injectable transport (tests feed a `PassThrough`; the
|
|
41
|
-
* command falls back to `process.stdin`).
|
|
42
|
-
*/
|
|
43
|
-
export interface McpIo extends CredentialIO {
|
|
44
|
-
out: (line: string) => void;
|
|
45
|
-
err: (line: string) => void;
|
|
46
|
-
stdinStream?: LineStream;
|
|
47
|
-
}
|
|
48
|
-
/** The exit-2 ambiguity outcome; the caller prints `message` to stderr and returns 2. */
|
|
49
|
-
type OriginResolution = {
|
|
50
|
-
origin: string;
|
|
51
|
-
} | {
|
|
52
|
-
exitCode: 2;
|
|
53
|
-
message: string;
|
|
54
|
-
};
|
|
55
|
-
/**
|
|
56
|
-
* Resolve the hub origin this server binds to, precedence:
|
|
57
|
-
* 1. `--hub <origin>` flag,
|
|
58
|
-
* 2. `OWENLOOP_HUB` env,
|
|
59
|
-
* 3. if the FILE credential backend holds exactly ONE hub with a valid `human`
|
|
60
|
-
* slot, use it,
|
|
61
|
-
* 4. else exit 2 with a message naming BOTH remedies.
|
|
62
|
-
*
|
|
63
|
-
* Rungs 1–2 normalize the origin (a malformed value throws a `CliError` → the
|
|
64
|
-
* command's exit-1 path via `mainAsync`'s catch, matching every other command).
|
|
65
|
-
* Rung 3 is file-backend-only because only the file backend can enumerate
|
|
66
|
-
* (`listStoredHubOrigins`); `null` (cannot enumerate — keychain/external), `[]`
|
|
67
|
-
* (nothing stored), and length>1 (ambiguous) each get a tailored exit-2 message.
|
|
68
|
-
*
|
|
69
|
-
* DELIBERATELY there is NO silent production fallback (the CLI's `resolveHub`
|
|
70
|
-
* `DEFAULT_HUB` rung): a control-plane server must never bind to a hub the
|
|
71
|
-
* operator did not name.
|
|
72
|
-
*/
|
|
73
|
-
export declare function resolveMcpOrigin(io: McpIo, hubFlag: string | undefined): OriginResolution;
|
|
74
|
-
/**
|
|
75
|
-
* Run the `owenloop mcp` command: resolve the origin, decide the enrollment
|
|
76
|
-
* gate, build the tool list, construct the JSON-RPC server, and pump stdin until
|
|
77
|
-
* EOF. Returns the process exit code: 2 on an origin-ambiguity (message to
|
|
78
|
-
* stderr, nothing to stdout — stdout is the protocol channel), else 0 on stdin
|
|
79
|
-
* EOF. A malformed `--hub`/`OWENLOOP_HUB` throws a `CliError` (exit-1 path).
|
|
80
|
-
*/
|
|
81
|
-
export declare function runMcpCommand(io: McpIo, opts: {
|
|
82
|
-
hubFlag?: string;
|
|
83
|
-
}): Promise<number>;
|
|
84
|
-
export {};
|
package/dist/untar.js
DELETED
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Minimal, dependency-free `.tar.gz` reader for GitHub codeload tarballs.
|
|
3
|
-
*
|
|
4
|
-
* GitHub's tarball endpoint (`/repos/:owner/:repo/tarball/:ref`) emits a
|
|
5
|
-
* gzipped USTAR/pax stream: short ASCII paths as plain USTAR headers, and
|
|
6
|
-
* paths over 100 chars as a pax extended header (typeflag `'x'`) followed by
|
|
7
|
-
* the real entry. GitHub does NOT emit GNU longname (`'L'`) entries — this
|
|
8
|
-
* reader does not implement that typeflag; a repo path that happens to need
|
|
9
|
-
* it would be silently skipped (unrepresentable, not corrupt).
|
|
10
|
-
*
|
|
11
|
-
* This is intentionally narrow: just enough tar to unpack a GitHub tarball,
|
|
12
|
-
* not a general-purpose tar library.
|
|
13
|
-
*/
|
|
14
|
-
import { gunzipSync } from 'node:zlib';
|
|
15
|
-
const BLOCK = 512;
|
|
16
|
-
export const DEFAULT_TAR_LIMITS = {
|
|
17
|
-
maxCompressedBytes: 256 * 1024 * 1024,
|
|
18
|
-
maxExpandedBytes: 1024 * 1024 * 1024,
|
|
19
|
-
maxFileCount: 50_000,
|
|
20
|
-
maxFileBytes: 100 * 1024 * 1024,
|
|
21
|
-
maxPathLength: 1024,
|
|
22
|
-
};
|
|
23
|
-
/** Parse a NUL/space-padded octal field (tar's numeric encoding) into a number. */
|
|
24
|
-
function parseOctal(bytes) {
|
|
25
|
-
let s = '';
|
|
26
|
-
for (const b of bytes) {
|
|
27
|
-
if (b === 0 || b === 32 /* space */)
|
|
28
|
-
continue;
|
|
29
|
-
s += String.fromCharCode(b);
|
|
30
|
-
}
|
|
31
|
-
return s.length ? parseInt(s, 8) : 0;
|
|
32
|
-
}
|
|
33
|
-
function readCString(bytes) {
|
|
34
|
-
const nul = bytes.indexOf(0);
|
|
35
|
-
const slice = nul >= 0 ? bytes.subarray(0, nul) : bytes;
|
|
36
|
-
return Buffer.from(slice).toString('utf8');
|
|
37
|
-
}
|
|
38
|
-
/** Parse a pax extended-header data block's `key=value` records, e.g. `path=...`. */
|
|
39
|
-
function parsePaxRecords(data) {
|
|
40
|
-
const text = Buffer.from(data).toString('utf8');
|
|
41
|
-
const out = new Map();
|
|
42
|
-
let i = 0;
|
|
43
|
-
while (i < text.length) {
|
|
44
|
-
// Each record is "<len> <key>=<value>\n", <len> counts the whole record
|
|
45
|
-
// (including the length prefix itself and the trailing newline).
|
|
46
|
-
const spaceIdx = text.indexOf(' ', i);
|
|
47
|
-
if (spaceIdx < 0)
|
|
48
|
-
break;
|
|
49
|
-
const len = parseInt(text.slice(i, spaceIdx), 10);
|
|
50
|
-
if (!Number.isFinite(len) || len <= 0)
|
|
51
|
-
break;
|
|
52
|
-
const record = text.slice(i, i + len);
|
|
53
|
-
const eq = record.indexOf('=', spaceIdx - i + 1);
|
|
54
|
-
if (eq >= 0) {
|
|
55
|
-
const key = record.slice(spaceIdx - i + 1, eq);
|
|
56
|
-
// record.slice(eq + 1) still has the trailing '\n' the pax format
|
|
57
|
-
// mandates — strip it to get the bare value.
|
|
58
|
-
const value = record.slice(eq + 1).replace(/\n$/, '');
|
|
59
|
-
out.set(key, value);
|
|
60
|
-
}
|
|
61
|
-
i += len;
|
|
62
|
-
}
|
|
63
|
-
return out;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Extract a gzipped tar archive into a flat map of in-archive path → file
|
|
67
|
-
* bytes. Directory entries are dropped; only regular files are kept. Pax
|
|
68
|
-
* extended headers (typeflag 'x') are honored for long paths; pax global
|
|
69
|
-
* headers (typeflag 'g') are skipped. Any other typeflag is skipped (its
|
|
70
|
-
* data block(s) consumed and discarded so the stream stays in sync).
|
|
71
|
-
*
|
|
72
|
-
* Returns keys as the raw in-archive paths, including the leading
|
|
73
|
-
* `<owner>-<repo>-<sha>/` root-dir component GitHub tarballs always have —
|
|
74
|
-
* callers strip that themselves.
|
|
75
|
-
*/
|
|
76
|
-
export function extractTarGz(bytes, limits = {}) {
|
|
77
|
-
const lim = { ...DEFAULT_TAR_LIMITS, ...limits };
|
|
78
|
-
if (bytes.length > lim.maxCompressedBytes) {
|
|
79
|
-
throw new Error(`compressed archive size ${bytes.length} exceeds limit of ${lim.maxCompressedBytes} bytes`);
|
|
80
|
-
}
|
|
81
|
-
let tar;
|
|
82
|
-
try {
|
|
83
|
-
// maxOutputLength caps the inflated size — a gzip bomb aborts here with
|
|
84
|
-
// ERR_BUFFER_TOO_LARGE rather than exhausting memory.
|
|
85
|
-
tar = gunzipSync(bytes, { maxOutputLength: lim.maxExpandedBytes });
|
|
86
|
-
}
|
|
87
|
-
catch (e) {
|
|
88
|
-
if (e.code === 'ERR_BUFFER_TOO_LARGE') {
|
|
89
|
-
throw new Error(`expanded archive size exceeds limit of ${lim.maxExpandedBytes} bytes`);
|
|
90
|
-
}
|
|
91
|
-
throw e;
|
|
92
|
-
}
|
|
93
|
-
const out = new Map();
|
|
94
|
-
let offset = 0;
|
|
95
|
-
let fileCount = 0;
|
|
96
|
-
let pendingLongPath;
|
|
97
|
-
while (offset + BLOCK <= tar.length) {
|
|
98
|
-
const header = tar.subarray(offset, offset + BLOCK);
|
|
99
|
-
// Two consecutive all-zero blocks mark the end of the archive.
|
|
100
|
-
if (header.every((b) => b === 0))
|
|
101
|
-
break;
|
|
102
|
-
const nameField = readCString(header.subarray(0, 100));
|
|
103
|
-
const sizeField = parseOctal(header.subarray(124, 136));
|
|
104
|
-
const typeflag = String.fromCharCode(header[156] ?? 0);
|
|
105
|
-
const prefixField = readCString(header.subarray(345, 500));
|
|
106
|
-
// parseOctal on a corrupt size field can yield NaN; a valid entry is a
|
|
107
|
-
// non-negative integer.
|
|
108
|
-
if (!Number.isInteger(sizeField) || sizeField < 0) {
|
|
109
|
-
throw new Error(`corrupt tar header: invalid size field (got ${sizeField})`);
|
|
110
|
-
}
|
|
111
|
-
offset += BLOCK;
|
|
112
|
-
const dataStart = offset;
|
|
113
|
-
const dataEnd = dataStart + sizeField;
|
|
114
|
-
// subarray silently clamps a past-the-end range, so a truncated archive
|
|
115
|
-
// would otherwise yield a short read instead of an error — guard it.
|
|
116
|
-
if (dataEnd > tar.length) {
|
|
117
|
-
throw new Error(`corrupt tar archive: entry data (${sizeField} bytes) extends past end of archive`);
|
|
118
|
-
}
|
|
119
|
-
const data = tar.subarray(dataStart, dataEnd);
|
|
120
|
-
// Data is padded up to the next 512-byte boundary.
|
|
121
|
-
offset += Math.ceil(sizeField / BLOCK) * BLOCK;
|
|
122
|
-
if (typeflag === '5') {
|
|
123
|
-
// directory — nothing to keep
|
|
124
|
-
continue;
|
|
125
|
-
}
|
|
126
|
-
if (typeflag === 'g') {
|
|
127
|
-
// pax global extended header — applies to the whole archive; we don't
|
|
128
|
-
// need any of its records (uid/gid/etc), just skip its data.
|
|
129
|
-
continue;
|
|
130
|
-
}
|
|
131
|
-
if (typeflag === 'x') {
|
|
132
|
-
// pax extended header for the NEXT entry — currently only 'path' matters.
|
|
133
|
-
const records = parsePaxRecords(data);
|
|
134
|
-
const p = records.get('path');
|
|
135
|
-
if (p !== undefined)
|
|
136
|
-
pendingLongPath = p;
|
|
137
|
-
continue;
|
|
138
|
-
}
|
|
139
|
-
if (typeflag !== '0' && typeflag !== '\0') {
|
|
140
|
-
// unsupported typeflag (symlink, hardlink, GNU longname, ...) — skip.
|
|
141
|
-
pendingLongPath = undefined;
|
|
142
|
-
continue;
|
|
143
|
-
}
|
|
144
|
-
// Regular file.
|
|
145
|
-
if (sizeField > lim.maxFileBytes) {
|
|
146
|
-
throw new Error(`archive entry exceeds per-file size limit of ${lim.maxFileBytes} bytes (${sizeField} bytes)`);
|
|
147
|
-
}
|
|
148
|
-
// Validate the FINAL, fully-resolved name (pax 'path' override or USTAR
|
|
149
|
-
// prefix+name), not the raw 100-byte field — that is what a caller joins.
|
|
150
|
-
const name = pendingLongPath ?? (prefixField ? `${prefixField}/${nameField}` : nameField);
|
|
151
|
-
pendingLongPath = undefined;
|
|
152
|
-
if (name) {
|
|
153
|
-
if (name.length > lim.maxPathLength) {
|
|
154
|
-
throw new Error(`archive entry path length ${name.length} exceeds limit of ${lim.maxPathLength} chars`);
|
|
155
|
-
}
|
|
156
|
-
fileCount += 1;
|
|
157
|
-
if (fileCount > lim.maxFileCount) {
|
|
158
|
-
throw new Error(`archive file count exceeds limit of ${lim.maxFileCount}`);
|
|
159
|
-
}
|
|
160
|
-
out.set(name, new Uint8Array(data));
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
return out;
|
|
164
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|