@warpgogol/forge 9.7.0 → 10.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +50 -27
- package/CHANGELOG.md +52 -0
- package/bin/cli.js +0 -0
- package/dist/os/adr/handlers/archive.d.ts.map +1 -1
- package/dist/os/adr/handlers/archive.js +3 -7
- package/dist/os/adr/handlers/archive.js.map +1 -1
- package/dist/os/adr/handlers/list-create.d.ts.map +1 -1
- package/dist/os/adr/handlers/list-create.js +8 -6
- package/dist/os/adr/handlers/list-create.js.map +1 -1
- package/dist/os/audit/handlers/archive.d.ts.map +1 -1
- package/dist/os/audit/handlers/archive.js +3 -7
- package/dist/os/audit/handlers/archive.js.map +1 -1
- package/dist/os/codebase/handlers/codebase-measure-symbols.d.ts.map +1 -1
- package/dist/os/codebase/handlers/codebase-measure-symbols.js +35 -4
- package/dist/os/codebase/handlers/codebase-measure-symbols.js.map +1 -1
- package/dist/os/core/archive-regen.d.ts +1 -0
- package/dist/os/core/archive-regen.d.ts.map +1 -1
- package/dist/os/core/archive-regen.js +31 -6
- package/dist/os/core/archive-regen.js.map +1 -1
- package/dist/os/core/core.module.d.ts.map +1 -1
- package/dist/os/core/core.module.js +6 -69
- package/dist/os/core/core.module.js.map +1 -1
- package/dist/os/core/handlers/assets-helpers.d.ts.map +1 -1
- package/dist/os/core/handlers/assets-helpers.js +2 -3
- package/dist/os/core/handlers/assets-helpers.js.map +1 -1
- package/dist/os/core/handlers/determinism-check.d.ts.map +1 -1
- package/dist/os/core/handlers/determinism-check.js +2 -3
- package/dist/os/core/handlers/determinism-check.js.map +1 -1
- package/dist/os/core/handlers/pinned-check.d.ts +13 -0
- package/dist/os/core/handlers/pinned-check.d.ts.map +1 -1
- package/dist/os/core/handlers/pinned-check.js +25 -0
- package/dist/os/core/handlers/pinned-check.js.map +1 -1
- package/dist/os/core/handlers/pinned-types.d.ts +7 -0
- package/dist/os/core/handlers/pinned-types.d.ts.map +1 -1
- package/dist/os/core/handlers/pinned-validate.d.ts.map +1 -1
- package/dist/os/core/handlers/pinned-validate.js +24 -1
- package/dist/os/core/handlers/pinned-validate.js.map +1 -1
- package/dist/os/core/handlers/release-prepare.d.ts.map +1 -1
- package/dist/os/core/handlers/release-prepare.js +2 -4
- package/dist/os/core/handlers/release-prepare.js.map +1 -1
- package/dist/os/flow/digest.d.ts +73 -1
- package/dist/os/flow/digest.d.ts.map +1 -1
- package/dist/os/flow/digest.js +344 -92
- package/dist/os/flow/digest.js.map +1 -1
- package/dist/os/flow/evidence-lock.d.ts +36 -0
- package/dist/os/flow/evidence-lock.d.ts.map +1 -0
- package/dist/os/flow/evidence-lock.js +156 -0
- package/dist/os/flow/evidence-lock.js.map +1 -0
- package/dist/os/flow/flow.module.d.ts.map +1 -1
- package/dist/os/flow/flow.module.js +36 -14
- package/dist/os/flow/flow.module.js.map +1 -1
- package/dist/os/flow/git.d.ts +50 -3
- package/dist/os/flow/git.d.ts.map +1 -1
- package/dist/os/flow/git.js +144 -12
- package/dist/os/flow/git.js.map +1 -1
- package/dist/os/flow/handlers/flow-digest.d.ts.map +1 -1
- package/dist/os/flow/handlers/flow-digest.js +3 -5
- package/dist/os/flow/handlers/flow-digest.js.map +1 -1
- package/dist/os/flow/handlers/flow-peers.js +1 -1
- package/dist/os/flow/handlers/flow-peers.js.map +1 -1
- package/dist/os/flow/handlers/flow-push.d.ts +81 -0
- package/dist/os/flow/handlers/flow-push.d.ts.map +1 -1
- package/dist/os/flow/handlers/flow-push.js +642 -138
- package/dist/os/flow/handlers/flow-push.js.map +1 -1
- package/dist/os/flow/locks.d.ts +8 -0
- package/dist/os/flow/locks.d.ts.map +1 -1
- package/dist/os/flow/locks.js +6 -3
- package/dist/os/flow/locks.js.map +1 -1
- package/dist/os/{mission → flow}/open-missions.d.ts +1 -2
- package/dist/os/flow/open-missions.d.ts.map +1 -0
- package/dist/os/flow/open-missions.js +37 -0
- package/dist/os/flow/open-missions.js.map +1 -0
- package/dist/os/flow/preflight.d.ts.map +1 -1
- package/dist/os/flow/preflight.js +5 -3
- package/dist/os/flow/preflight.js.map +1 -1
- package/dist/os/flow/registry.d.ts +9 -5
- package/dist/os/flow/registry.d.ts.map +1 -1
- package/dist/os/flow/registry.js +2 -2
- package/dist/os/flow/registry.js.map +1 -1
- package/dist/os/friction/friction.module.d.ts.map +1 -1
- package/dist/os/friction/friction.module.js +30 -5
- package/dist/os/friction/friction.module.js.map +1 -1
- package/dist/os/friction/handlers/friction-add.d.ts.map +1 -1
- package/dist/os/friction/handlers/friction-add.js +10 -17
- package/dist/os/friction/handlers/friction-add.js.map +1 -1
- package/dist/os/friction/handlers/friction-migrate.d.ts.map +1 -1
- package/dist/os/friction/handlers/friction-migrate.js +188 -2
- package/dist/os/friction/handlers/friction-migrate.js.map +1 -1
- package/dist/os/friction/store.d.ts +4 -0
- package/dist/os/friction/store.d.ts.map +1 -1
- package/dist/os/friction/store.js +20 -0
- package/dist/os/friction/store.js.map +1 -1
- package/dist/os/friction/types.d.ts +12 -0
- package/dist/os/friction/types.d.ts.map +1 -1
- package/dist/os/friction/types.js +8 -0
- package/dist/os/friction/types.js.map +1 -1
- package/dist/os/gate/handlers/gate-probe-catalog.d.ts.map +1 -1
- package/dist/os/gate/handlers/gate-probe-catalog.js +38 -5
- package/dist/os/gate/handlers/gate-probe-catalog.js.map +1 -1
- package/dist/os/plan/handlers/archive.d.ts.map +1 -1
- package/dist/os/plan/handlers/archive.js +3 -7
- package/dist/os/plan/handlers/archive.js.map +1 -1
- package/dist/os/rfc/handlers/archive.d.ts.map +1 -1
- package/dist/os/rfc/handlers/archive.js +3 -7
- package/dist/os/rfc/handlers/archive.js.map +1 -1
- package/dist/os/rfc/handlers/list-create.d.ts.map +1 -1
- package/dist/os/rfc/handlers/list-create.js +15 -7
- package/dist/os/rfc/handlers/list-create.js.map +1 -1
- package/dist/os/session/handlers/archive.d.ts.map +1 -1
- package/dist/os/session/handlers/archive.js +3 -7
- package/dist/os/session/handlers/archive.js.map +1 -1
- package/dist/os/system/handlers/system-product-register.d.ts +24 -0
- package/dist/os/system/handlers/system-product-register.d.ts.map +1 -0
- package/dist/os/system/handlers/system-product-register.js +322 -0
- package/dist/os/system/handlers/system-product-register.js.map +1 -0
- package/dist/os/system/handlers/system-products-status.d.ts +23 -0
- package/dist/os/system/handlers/system-products-status.d.ts.map +1 -0
- package/dist/os/system/handlers/system-products-status.js +235 -0
- package/dist/os/system/handlers/system-products-status.js.map +1 -0
- package/dist/os/system/schemas.d.ts +13 -0
- package/dist/os/system/schemas.d.ts.map +1 -1
- package/dist/os/system/schemas.js +15 -0
- package/dist/os/system/schemas.js.map +1 -1
- package/dist/os/system/system.module.d.ts.map +1 -1
- package/dist/os/system/system.module.js +113 -3
- package/dist/os/system/system.module.js.map +1 -1
- package/dist/src/command-modules.d.ts.map +1 -1
- package/dist/src/command-modules.js +0 -2
- package/dist/src/command-modules.js.map +1 -1
- package/dist/src/config/forge-config.d.ts +2 -0
- package/dist/src/config/forge-config.d.ts.map +1 -1
- package/dist/src/config/forge-config.js +11 -10
- package/dist/src/config/forge-config.js.map +1 -1
- package/dist/src/index.d.ts +0 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +0 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/onboarding/create.d.ts.map +1 -1
- package/dist/src/onboarding/create.js +27 -2
- package/dist/src/onboarding/create.js.map +1 -1
- package/dist/src/onboarding/doctor.d.ts +0 -5
- package/dist/src/onboarding/doctor.d.ts.map +1 -1
- package/dist/src/onboarding/doctor.js +6 -79
- package/dist/src/onboarding/doctor.js.map +1 -1
- package/dist/src/onboarding/npm-token-check.d.ts +1 -1
- package/dist/src/onboarding/npm-token-check.d.ts.map +1 -1
- package/dist/src/onboarding/npm-token-check.js +2 -2
- package/dist/src/onboarding/npm-token-check.js.map +1 -1
- package/dist/src/profiles/stack-profile.js +2 -2
- package/dist/src/types.js +2 -2
- package/dist/src/utils/hash.d.ts +1 -0
- package/dist/src/utils/hash.d.ts.map +1 -1
- package/dist/src/utils/hash.js +4 -0
- package/dist/src/utils/hash.js.map +1 -1
- package/dist/{os/mission → src/utils}/lockfile.d.ts +1 -18
- package/dist/src/utils/lockfile.d.ts.map +1 -0
- package/dist/src/utils/lockfile.js +70 -0
- package/dist/src/utils/lockfile.js.map +1 -0
- package/dist/src/utils/verifier-git.d.ts +27 -1
- package/dist/src/utils/verifier-git.d.ts.map +1 -1
- package/dist/src/utils/verifier-git.js +36 -6
- package/dist/src/utils/verifier-git.js.map +1 -1
- package/docs/reference/system-hub.md +104 -0
- package/os/adr/handlers/archive.ts +3 -11
- package/os/adr/handlers/list-create.test.ts +174 -0
- package/os/adr/handlers/list-create.ts +16 -8
- package/os/audit/handlers/archive.ts +3 -11
- package/os/codebase/handlers/codebase-measure-symbols.ts +32 -4
- package/os/core/archive-regen.ts +33 -7
- package/os/core/core.module.ts +10 -76
- package/os/core/docs-archive.test.ts +25 -0
- package/os/core/handlers/assets-helpers.ts +2 -4
- package/os/core/handlers/determinism-check.ts +2 -3
- package/os/core/handlers/lifecycle-handlers.test.ts +529 -0
- package/os/core/handlers/pinned-check.ts +30 -0
- package/os/core/handlers/pinned-types.ts +7 -0
- package/os/core/handlers/pinned-validate.ts +28 -3
- package/os/core/handlers/release-prepare.ts +2 -4
- package/os/correctness/gate/trust-boundary-cx18.test.ts +1 -1
- package/os/flow/digest.ts +436 -95
- package/os/flow/evidence-lock.ts +184 -0
- package/os/flow/flow.module.ts +37 -14
- package/os/flow/git.ts +206 -11
- package/os/flow/handlers/flow-digest.ts +12 -8
- package/os/flow/handlers/flow-peers.ts +1 -1
- package/os/flow/handlers/flow-push.ts +725 -137
- package/os/flow/locks.ts +24 -7
- package/os/flow/open-missions.ts +45 -0
- package/os/flow/preflight.ts +5 -3
- package/os/flow/registry.ts +7 -3
- package/os/flow/tests/digest-id-inputs.test.ts +106 -0
- package/os/flow/tests/digest-persist.test.ts +243 -0
- package/os/flow/tests/evidence-preflight-surface-skip.test.ts +218 -0
- package/os/flow/tests/flow-push-attest.test.ts +137 -0
- package/os/flow/tests/flow-push-review-baseline.test.ts +339 -0
- package/os/flow/tests/flow-push-verifier-batch.test.ts +134 -0
- package/os/flow/tests/release-lines.test.ts +136 -0
- package/os/flow/tests/state-roots.test.ts +1 -48
- package/os/friction/friction-add.test.ts +42 -0
- package/os/friction/friction-migrate.test.ts +67 -2
- package/os/friction/friction.module.ts +33 -5
- package/os/friction/handlers/friction-add.ts +10 -15
- package/os/friction/handlers/friction-migrate.ts +220 -1
- package/os/friction/store.ts +19 -0
- package/os/friction/types.ts +8 -0
- package/os/gate/handlers/gate-probe-catalog.ts +39 -7
- package/os/gate/handlers/gate-probe-ratchet.test.ts +57 -22
- package/os/plan/handlers/archive.ts +3 -11
- package/os/rfc/handlers/archive.ts +3 -11
- package/os/rfc/handlers/list-create.ts +22 -17
- package/os/rfc/handlers/validate-corpus.test.ts +149 -0
- package/os/rfc/probe-batch.test.ts +253 -0
- package/os/rfc/verifier/rfc-1391/ac10-operating-model-policy.acceptance.test.ts +63 -0
- package/os/session/handlers/archive.ts +3 -11
- package/os/system/handlers/system-product-register.ts +492 -0
- package/os/system/handlers/system-products-status.ts +395 -0
- package/os/system/schemas.ts +17 -0
- package/os/system/system.module.ts +117 -3
- package/os/system/tests/system-product-register.test.ts +304 -0
- package/os/system/tests/system-products-status.test.ts +154 -0
- package/package.json +161 -506
- package/profiles/root-agents-system.md +82 -0
- package/profiles/system.yaml +1 -0
- package/src/command-modules.ts +0 -2
- package/src/config/forge-config.ts +16 -11
- package/src/index.ts +0 -2
- package/src/onboarding/create-superfolder-guard.test.ts +73 -0
- package/src/onboarding/create.ts +28 -2
- package/src/onboarding/doctor.ts +9 -96
- package/src/onboarding/npm-token-check.ts +3 -3
- package/src/profiles/stack-profile.ts +2 -2
- package/src/tests/evidence-consult-serialization.test.ts +202 -0
- package/src/tests/pinned-validate.test.ts +194 -0
- package/src/tests/pkg-health-self-scan.test.ts +29 -0
- package/src/tests/profile-flow-hooks.test.ts +1 -0
- package/src/tests/profile-schema.test.ts +1 -0
- package/src/tests/rfc-evidence-sync.test.ts +369 -0
- package/src/tests/skill-agents-sync.test.ts +192 -0
- package/src/tests/stack-profile.test.ts +1 -0
- package/src/types.ts +2 -2
- package/src/utils/hash.ts +5 -0
- package/src/utils/lockfile.ts +78 -0
- package/src/utils/verifier-git.ts +53 -5
- package/dist/os/core/handlers/forge-autonomy-validate.d.ts +0 -25
- package/dist/os/core/handlers/forge-autonomy-validate.d.ts.map +0 -1
- package/dist/os/core/handlers/forge-autonomy-validate.js +0 -208
- package/dist/os/core/handlers/forge-autonomy-validate.js.map +0 -1
- package/dist/os/mission/handlers/archive.d.ts +0 -4
- package/dist/os/mission/handlers/archive.d.ts.map +0 -1
- package/dist/os/mission/handlers/archive.js +0 -587
- package/dist/os/mission/handlers/archive.js.map +0 -1
- package/dist/os/mission/importer-block.d.ts +0 -19
- package/dist/os/mission/importer-block.d.ts.map +0 -1
- package/dist/os/mission/importer-block.js +0 -124
- package/dist/os/mission/importer-block.js.map +0 -1
- package/dist/os/mission/index.d.ts +0 -2
- package/dist/os/mission/index.d.ts.map +0 -1
- package/dist/os/mission/index.js +0 -15
- package/dist/os/mission/index.js.map +0 -1
- package/dist/os/mission/lockfile.d.ts.map +0 -1
- package/dist/os/mission/lockfile.js +0 -138
- package/dist/os/mission/lockfile.js.map +0 -1
- package/dist/os/mission/mission.module.d.ts +0 -3
- package/dist/os/mission/mission.module.d.ts.map +0 -1
- package/dist/os/mission/mission.module.js +0 -63
- package/dist/os/mission/mission.module.js.map +0 -1
- package/dist/os/mission/open-missions.d.ts.map +0 -1
- package/dist/os/mission/open-missions.js +0 -42
- package/dist/os/mission/open-missions.js.map +0 -1
- package/dist/os/mission/types.d.ts +0 -23
- package/dist/os/mission/types.d.ts.map +0 -1
- package/dist/os/mission/types.js +0 -19
- package/dist/os/mission/types.js.map +0 -1
- package/dist/os/werkstatt/handlers/lock.d.ts +0 -10
- package/dist/os/werkstatt/handlers/lock.d.ts.map +0 -1
- package/dist/os/werkstatt/handlers/lock.js +0 -153
- package/dist/os/werkstatt/handlers/lock.js.map +0 -1
- package/dist/os/werkstatt/handlers/schema.d.ts +0 -33
- package/dist/os/werkstatt/handlers/schema.d.ts.map +0 -1
- package/dist/os/werkstatt/handlers/schema.js +0 -42
- package/dist/os/werkstatt/handlers/schema.js.map +0 -1
- package/dist/os/werkstatt/handlers/werkstatt-lock-recover.d.ts +0 -15
- package/dist/os/werkstatt/handlers/werkstatt-lock-recover.d.ts.map +0 -1
- package/dist/os/werkstatt/handlers/werkstatt-lock-recover.js +0 -171
- package/dist/os/werkstatt/handlers/werkstatt-lock-recover.js.map +0 -1
- package/dist/os/werkstatt/handlers/werkstatt-lock-status.d.ts +0 -18
- package/dist/os/werkstatt/handlers/werkstatt-lock-status.d.ts.map +0 -1
- package/dist/os/werkstatt/handlers/werkstatt-lock-status.js +0 -51
- package/dist/os/werkstatt/handlers/werkstatt-lock-status.js.map +0 -1
- package/dist/os/werkstatt/handlers/werkstatt-operation-validate.d.ts +0 -11
- package/dist/os/werkstatt/handlers/werkstatt-operation-validate.d.ts.map +0 -1
- package/dist/os/werkstatt/handlers/werkstatt-operation-validate.js +0 -86
- package/dist/os/werkstatt/handlers/werkstatt-operation-validate.js.map +0 -1
- package/dist/os/werkstatt/handlers/workspace-deps.d.ts +0 -12
- package/dist/os/werkstatt/handlers/workspace-deps.d.ts.map +0 -1
- package/dist/os/werkstatt/handlers/workspace-deps.js +0 -42
- package/dist/os/werkstatt/handlers/workspace-deps.js.map +0 -1
- package/dist/os/werkstatt/index.d.ts +0 -7
- package/dist/os/werkstatt/index.d.ts.map +0 -1
- package/dist/os/werkstatt/index.js +0 -18
- package/dist/os/werkstatt/index.js.map +0 -1
- package/dist/os/werkstatt/werkstatt.module.d.ts +0 -3
- package/dist/os/werkstatt/werkstatt.module.d.ts.map +0 -1
- package/dist/os/werkstatt/werkstatt.module.js +0 -91
- package/dist/os/werkstatt/werkstatt.module.js.map +0 -1
- package/os/core/handlers/forge-autonomy-validate.ts +0 -276
- package/os/correctness/gate/trust-boundary-cx19.test.ts +0 -514
- package/os/mission/handlers/archive.test.ts +0 -764
- package/os/mission/handlers/archive.ts +0 -719
- package/os/mission/handlers/ship-inflight-degraded.test.ts +0 -105
- package/os/mission/importer-block.ts +0 -119
- package/os/mission/index.ts +0 -15
- package/os/mission/lockfile.ts +0 -152
- package/os/mission/mission.module.ts +0 -68
- package/os/mission/open-missions.ts +0 -50
- package/os/mission/types.ts +0 -42
- package/os/werkstatt/handlers/lock.ts +0 -168
- package/os/werkstatt/handlers/schema.ts +0 -47
- package/os/werkstatt/handlers/werkstatt-lock-recover.ts +0 -206
- package/os/werkstatt/handlers/werkstatt-lock-status.ts +0 -82
- package/os/werkstatt/handlers/werkstatt-operation-validate.ts +0 -112
- package/os/werkstatt/handlers/workspace-deps.ts +0 -56
- package/os/werkstatt/index.ts +0 -39
- package/os/werkstatt/werkstatt.module.ts +0 -95
- package/src/tests/doctor-autonomy.test.ts +0 -246
- package/src/tests/forge-autonomy-validate.test.ts +0 -159
- package/src/tests/werkstatt-lock.test.ts +0 -357
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
<MODULE_CONTRACT>
|
|
3
|
-
<purpose>Werkstatt lock helpers. Moved from @warpgogol/site-kernel-handoff to
|
|
4
|
-
@warpgogol/forge for full autonomous mode (RFC-0556). Provides acquire, release,
|
|
5
|
-
heartbeat, status, and stale-lock removal.</purpose>
|
|
6
|
-
<non-goals>
|
|
7
|
-
<item>Do not implement distributed locks — local process-level only.</item>
|
|
8
|
-
</non-goals>
|
|
9
|
-
</MODULE_CONTRACT>
|
|
10
|
-
<CHANGE_SUMMARY>
|
|
11
|
-
<item>RFC-0362: initial lock helpers (acquire, release, heartbeat, status).</item>
|
|
12
|
-
<item>RFC-0556: moved from @warpgogol/site-kernel-handoff to @warpgogol/forge for autonomous mode.</item>
|
|
13
|
-
</CHANGE_SUMMARY>
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
import { ambientIo as fs } from "../../../src/utils/io.ts";
|
|
17
|
-
import { existsSync } from "../../../src/utils/sync-fs.ts";
|
|
18
|
-
import path from "node:path";
|
|
19
|
-
import { werkstattLockSchema, type WerkstattLock } from "./schema.ts";
|
|
20
|
-
|
|
21
|
-
const LOCKS_DIR = path.join(".werkstatt", "locks");
|
|
22
|
-
const DEFAULT_TIMEOUT_SECONDS = 900;
|
|
23
|
-
|
|
24
|
-
function resolveLocksDir(workspaceRoot: string): string {
|
|
25
|
-
return path.join(workspaceRoot, LOCKS_DIR);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function resolveLockPath(workspaceRoot: string, scope: string): string {
|
|
29
|
-
const safeScope = scope.replace(/[^a-zA-Z0-9:_-]/g, "_");
|
|
30
|
-
return path.join(resolveLocksDir(workspaceRoot), `${safeScope}.lock.json`);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function isProcessAlive(pid: number): boolean {
|
|
34
|
-
try {
|
|
35
|
-
process.kill(pid, 0);
|
|
36
|
-
return true;
|
|
37
|
-
} catch {
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function isLockStale(lock: WerkstattLock, now: Date = new Date()): boolean {
|
|
43
|
-
if (!isProcessAlive(lock.pid)) return true;
|
|
44
|
-
const heartbeatAge = (now.getTime() - new Date(lock.heartbeatAt).getTime()) / 1000;
|
|
45
|
-
return heartbeatAge >= lock.timeoutSeconds;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export async function acquireLock(
|
|
49
|
-
workspaceRoot: string,
|
|
50
|
-
scope: string,
|
|
51
|
-
operationId: string,
|
|
52
|
-
command: string,
|
|
53
|
-
owner: string,
|
|
54
|
-
timeoutSeconds: number = DEFAULT_TIMEOUT_SECONDS,
|
|
55
|
-
): Promise<WerkstattLock> {
|
|
56
|
-
const lockPath = resolveLockPath(workspaceRoot, scope);
|
|
57
|
-
const locksDir = resolveLocksDir(workspaceRoot);
|
|
58
|
-
|
|
59
|
-
if (!existsSync(locksDir)) {
|
|
60
|
-
await fs.mkdir(locksDir);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (existsSync(lockPath)) {
|
|
64
|
-
const raw = await fs.readFile(lockPath);
|
|
65
|
-
try {
|
|
66
|
-
const existing = werkstattLockSchema.parse(JSON.parse(raw));
|
|
67
|
-
if (existing.pid === process.pid && !isLockStale(existing)) {
|
|
68
|
-
const updated = {
|
|
69
|
-
...existing,
|
|
70
|
-
depth: (existing.depth ?? 1) + 1,
|
|
71
|
-
heartbeatAt: new Date().toISOString(),
|
|
72
|
-
};
|
|
73
|
-
werkstattLockSchema.parse(updated);
|
|
74
|
-
await fs.writeFile(lockPath, JSON.stringify(updated, null, 2) + "\n");
|
|
75
|
-
return updated;
|
|
76
|
-
}
|
|
77
|
-
if (!isLockStale(existing)) {
|
|
78
|
-
throw new Error(
|
|
79
|
-
`[werkstatt.lock] lock '${scope}' held by operation '${existing.operationId}' (pid: ${existing.pid})`,
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
} catch (err) {
|
|
83
|
-
if (err instanceof Error && err.message.includes("held by")) throw err;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const now = new Date().toISOString();
|
|
88
|
-
const lock: WerkstattLock = {
|
|
89
|
-
schemaVersion: "1.0.0",
|
|
90
|
-
scope,
|
|
91
|
-
operationId,
|
|
92
|
-
command,
|
|
93
|
-
owner,
|
|
94
|
-
pid: process.pid,
|
|
95
|
-
startedAt: now,
|
|
96
|
-
heartbeatAt: now,
|
|
97
|
-
timeoutSeconds,
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
werkstattLockSchema.parse(lock);
|
|
101
|
-
await fs.writeFile(lockPath, JSON.stringify(lock, null, 2) + "\n");
|
|
102
|
-
return lock;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export async function releaseLock(workspaceRoot: string, scope: string): Promise<void> {
|
|
106
|
-
const lockPath = resolveLockPath(workspaceRoot, scope);
|
|
107
|
-
if (!existsSync(lockPath)) return;
|
|
108
|
-
try {
|
|
109
|
-
const raw = await fs.readFile(lockPath);
|
|
110
|
-
const lock = werkstattLockSchema.parse(JSON.parse(raw));
|
|
111
|
-
if (lock.pid === process.pid && (lock.depth ?? 1) > 1) {
|
|
112
|
-
const decremented = { ...lock, depth: (lock.depth ?? 1) - 1 };
|
|
113
|
-
werkstattLockSchema.parse(decremented);
|
|
114
|
-
await fs.writeFile(lockPath, JSON.stringify(decremented, null, 2) + "\n");
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
await fs.rm(lockPath);
|
|
118
|
-
} catch {
|
|
119
|
-
// corrupt or missing — try direct delete
|
|
120
|
-
try {
|
|
121
|
-
await fs.rm(lockPath);
|
|
122
|
-
} catch {
|
|
123
|
-
/* already gone */
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export async function heartbeatLock(workspaceRoot: string, scope: string): Promise<void> {
|
|
129
|
-
const lockPath = resolveLockPath(workspaceRoot, scope);
|
|
130
|
-
if (!existsSync(lockPath)) return;
|
|
131
|
-
const raw = await fs.readFile(lockPath);
|
|
132
|
-
const lock = werkstattLockSchema.parse(JSON.parse(raw));
|
|
133
|
-
lock.heartbeatAt = new Date().toISOString();
|
|
134
|
-
await fs.writeFile(lockPath, JSON.stringify(lock, null, 2) + "\n");
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
export async function readAllLocks(
|
|
138
|
-
workspaceRoot: string,
|
|
139
|
-
): Promise<Array<WerkstattLock & { stale: boolean }>> {
|
|
140
|
-
const locksDir = resolveLocksDir(workspaceRoot);
|
|
141
|
-
if (!existsSync(locksDir)) return [];
|
|
142
|
-
|
|
143
|
-
const files = (await fs.readdir(locksDir)).map((e) => e.name);
|
|
144
|
-
const locks: Array<WerkstattLock & { stale: boolean }> = [];
|
|
145
|
-
|
|
146
|
-
for (const file of files) {
|
|
147
|
-
if (!file.endsWith(".lock.json")) continue;
|
|
148
|
-
const raw = await fs.readFile(path.join(locksDir, file));
|
|
149
|
-
try {
|
|
150
|
-
const lock = werkstattLockSchema.parse(JSON.parse(raw));
|
|
151
|
-
locks.push({ ...lock, stale: isLockStale(lock) });
|
|
152
|
-
} catch {
|
|
153
|
-
// skip corrupt lock files
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
return locks;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
export async function removeStaleLock(workspaceRoot: string, scope: string): Promise<boolean> {
|
|
161
|
-
const lockPath = resolveLockPath(workspaceRoot, scope);
|
|
162
|
-
if (!existsSync(lockPath)) return false;
|
|
163
|
-
const raw = await fs.readFile(lockPath);
|
|
164
|
-
const lock = werkstattLockSchema.parse(JSON.parse(raw));
|
|
165
|
-
if (!isLockStale(lock)) return false;
|
|
166
|
-
await fs.rm(lockPath);
|
|
167
|
-
return true;
|
|
168
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
<MODULE_CONTRACT>
|
|
3
|
-
<purpose>Werkstatt Zod schemas inlined from @warpgogol/werkstatt-shared/ontology/operations for
|
|
4
|
-
full autonomous mode (RFC-0556). Provides werkstattLockSchema and
|
|
5
|
-
werkstattOperationRecordSchema without a dependency on @warpgogol/ontology.</purpose>
|
|
6
|
-
<non-goals>
|
|
7
|
-
<item>Do not perform file IO — pure shape only.</item>
|
|
8
|
-
<item>Do not define hash-chain Bordbuch format — that is RFC-0276/RFC-0355.</item>
|
|
9
|
-
</non-goals>
|
|
10
|
-
</MODULE_CONTRACT>
|
|
11
|
-
<CHANGE_SUMMARY>
|
|
12
|
-
<item>RFC-0362: initial Werkstatt schemas (WerkstattLock, WerkstattOperationRecord).</item>
|
|
13
|
-
<item>RFC-0556: inlined from @warpgogol/werkstatt-shared/ontology/operations into forge for autonomous mode.</item>
|
|
14
|
-
</CHANGE_SUMMARY>
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import { z } from "zod";
|
|
18
|
-
|
|
19
|
-
export const werkstattLockSchema = z.object({
|
|
20
|
-
schemaVersion: z.literal("1.0.0"),
|
|
21
|
-
scope: z.string().min(1),
|
|
22
|
-
operationId: z.string().min(1),
|
|
23
|
-
command: z.string().min(1),
|
|
24
|
-
owner: z.string().min(1),
|
|
25
|
-
pid: z.number().int(),
|
|
26
|
-
startedAt: z.string().datetime(),
|
|
27
|
-
heartbeatAt: z.string().datetime(),
|
|
28
|
-
timeoutSeconds: z.number().positive(),
|
|
29
|
-
depth: z.number().int().positive().optional(),
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
export const werkstattOperationRecordSchema = z.object({
|
|
33
|
-
schemaVersion: z.literal("1.0.0"),
|
|
34
|
-
operationId: z.string().min(1),
|
|
35
|
-
command: z.string().min(1),
|
|
36
|
-
scopes: z.array(z.string().min(1)),
|
|
37
|
-
state: z.enum(["started", "completed", "failed"]),
|
|
38
|
-
startedAt: z.string().datetime(),
|
|
39
|
-
completedAt: z.string().datetime().nullable(),
|
|
40
|
-
inputHash: z.string().min(1),
|
|
41
|
-
resultHash: z.string().nullable(),
|
|
42
|
-
artifacts: z.array(z.string()),
|
|
43
|
-
error: z.string().nullable(),
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
export type WerkstattLock = z.infer<typeof werkstattLockSchema>;
|
|
47
|
-
export type WerkstattOperationRecord = z.infer<typeof werkstattOperationRecordSchema>;
|
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
<MODULE_CONTRACT>
|
|
3
|
-
<purpose>werkstatt.lock.recover command handler. Moved from
|
|
4
|
-
@warpgogol/site-kernel-handoff to @warpgogol/forge for full autonomous mode (RFC-0556).
|
|
5
|
-
Classifies and cleans stale locks and staging artifacts (RFC-0362 §8).</purpose>
|
|
6
|
-
<non-goals>
|
|
7
|
-
<item>Do not introduce app-specific runtime composition or deployment behavior.</item>
|
|
8
|
-
</non-goals>
|
|
9
|
-
</MODULE_CONTRACT>
|
|
10
|
-
<CHANGE_SUMMARY>
|
|
11
|
-
<item>RFC-0362: initial lock.recover command handler.</item>
|
|
12
|
-
<item>RFC-0556: moved from @warpgogol/site-kernel-handoff to @warpgogol/forge for autonomous mode.</item>
|
|
13
|
-
<item>RFC-1097: step 6 — compass.migrate codemod run
|
|
14
|
-
|
|
15
|
-
Mechanical v1 to v2 header migration across the workspace: 942 files rewritten — CHANGE_SUMMARY windows collapsed into history, forbidden v1 blocks stripped, KEY_DECISIONS seeded from @ai-invariant comments (5 files) or TODO placeholders (103 files), blocks reordered to canonical order.</item>
|
|
16
|
-
<item>RFC-1097: sweep — werkstatt-engine clean
|
|
17
|
-
|
|
18
|
-
Sweep batch 4: 73 Compass headers on headerless engine files (certification, component-runtime, isolation, evolution, testing), real KEY_DECISIONS on 75 files (kernel, cache, dht, swim, gitmesh, runtime), ~80 purpose expansions (CONTRACT-02/PURPOSE-02), non-goals on 13 CONTRACT-03 files, CS-07 history literal fix repo-wide (253 files). Policy: .template.ts/.template.astro excludedPaths. werkstatt-engine now 0 diagnostics.</item>
|
|
19
|
-
<item>RFC-1495: step 1 - forge state roots</item>
|
|
20
|
-
</CHANGE_SUMMARY>
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
import { ambientIo as fs, resolveIo } from "../../../src/utils/io.ts";
|
|
24
|
-
import { existsSync } from "../../../src/utils/sync-fs.ts";
|
|
25
|
-
import path from "node:path";
|
|
26
|
-
import type {
|
|
27
|
-
ForgeCommandInput,
|
|
28
|
-
ForgeCommandResult,
|
|
29
|
-
ForgeRuntimeContext,
|
|
30
|
-
WorkspaceIO,
|
|
31
|
-
} from "../../../src/types.ts";
|
|
32
|
-
import { trashPath } from "../../../src/utils/fs-trash.ts";
|
|
33
|
-
import { readAllLocks, removeStaleLock, acquireLock, releaseLock } from "./lock.ts";
|
|
34
|
-
import { resolveStateRoots } from "../../flow/worktree-path.ts";
|
|
35
|
-
|
|
36
|
-
export interface WerkstattLockRecoverData {
|
|
37
|
-
recovered: Array<{ scope?: string; artifact?: string; action: string }>;
|
|
38
|
-
failed: Array<{ scope?: string; artifact?: string; error: string }>;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function flagString(input: ForgeCommandInput, key: string): string | undefined {
|
|
42
|
-
const v = input.flags[key];
|
|
43
|
-
return typeof v === "string" ? v : undefined;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async function classifyArtifacts(
|
|
47
|
-
workspaceRoot: string,
|
|
48
|
-
purge: boolean,
|
|
49
|
-
io: WorkspaceIO,
|
|
50
|
-
): Promise<{
|
|
51
|
-
recovered: Array<{ artifact: string; action: string }>;
|
|
52
|
-
failed: Array<{ artifact: string; error: string }>;
|
|
53
|
-
}> {
|
|
54
|
-
const recovered: Array<{ artifact: string; action: string }> = [];
|
|
55
|
-
const failed: Array<{ artifact: string; error: string }> = [];
|
|
56
|
-
|
|
57
|
-
// RFC-1495: releases/ is durable state — it lives in the primary checkout;
|
|
58
|
-
// missions/ (open missions) and systems/ stay per-worktree. In a
|
|
59
|
-
// single-worktree repo the roots coincide and the scan is unchanged.
|
|
60
|
-
const stateRoots = await resolveStateRoots(workspaceRoot, io).catch(() => ({
|
|
61
|
-
worktreeRoot: workspaceRoot,
|
|
62
|
-
primaryRoot: workspaceRoot,
|
|
63
|
-
isPrimary: true,
|
|
64
|
-
}));
|
|
65
|
-
const scanRoots: Array<{ name: string; root: string }> = [
|
|
66
|
-
{ name: "systems", root: stateRoots.worktreeRoot },
|
|
67
|
-
{ name: "missions", root: stateRoots.worktreeRoot },
|
|
68
|
-
{ name: "releases", root: stateRoots.primaryRoot },
|
|
69
|
-
];
|
|
70
|
-
for (const { name: root, root: scanRoot } of scanRoots) {
|
|
71
|
-
const rootPath = path.join(scanRoot, root);
|
|
72
|
-
if (!existsSync(rootPath)) continue;
|
|
73
|
-
|
|
74
|
-
let entries: string[];
|
|
75
|
-
try {
|
|
76
|
-
entries = (await fs.readdir(rootPath)).map((e) => e.name);
|
|
77
|
-
} catch {
|
|
78
|
-
continue;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
for (const entry of entries) {
|
|
82
|
-
const entryPath = path.join(rootPath, entry);
|
|
83
|
-
const relPath = `${root}/${entry}`;
|
|
84
|
-
|
|
85
|
-
if (entry.endsWith(".tmp")) {
|
|
86
|
-
if (purge) {
|
|
87
|
-
try {
|
|
88
|
-
await trashPath(entryPath);
|
|
89
|
-
recovered.push({ artifact: relPath, action: "trashed-tmp" });
|
|
90
|
-
} catch (err) {
|
|
91
|
-
failed.push({ artifact: relPath, error: (err as Error).message });
|
|
92
|
-
}
|
|
93
|
-
} else {
|
|
94
|
-
recovered.push({ artifact: relPath, action: "classified-tmp (use --purge to remove)" });
|
|
95
|
-
}
|
|
96
|
-
} else if (entry.includes(".staging-")) {
|
|
97
|
-
if (purge) {
|
|
98
|
-
try {
|
|
99
|
-
await trashPath(entryPath);
|
|
100
|
-
recovered.push({ artifact: relPath, action: "trashed-staging" });
|
|
101
|
-
} catch (err) {
|
|
102
|
-
failed.push({ artifact: relPath, error: (err as Error).message });
|
|
103
|
-
}
|
|
104
|
-
} else {
|
|
105
|
-
recovered.push({
|
|
106
|
-
artifact: relPath,
|
|
107
|
-
action: "classified-staging (use --purge to remove)",
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
} else if (entry.includes(".incomplete")) {
|
|
111
|
-
if (purge) {
|
|
112
|
-
const failedDir = entryPath.replace(".incomplete", `.failed-${Date.now()}`);
|
|
113
|
-
try {
|
|
114
|
-
await fs.rename(entryPath, failedDir);
|
|
115
|
-
recovered.push({ artifact: relPath, action: "renamed-to-failed" });
|
|
116
|
-
} catch (err) {
|
|
117
|
-
failed.push({ artifact: relPath, error: (err as Error).message });
|
|
118
|
-
}
|
|
119
|
-
} else {
|
|
120
|
-
recovered.push({
|
|
121
|
-
artifact: relPath,
|
|
122
|
-
action: "classified-incomplete (use --purge to rename)",
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return { recovered, failed };
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
export async function runWerkstattLockRecover(
|
|
133
|
-
input: ForgeCommandInput,
|
|
134
|
-
context: ForgeRuntimeContext,
|
|
135
|
-
): Promise<ForgeCommandResult<WerkstattLockRecoverData>> {
|
|
136
|
-
const { workspaceRoot, logger } = context;
|
|
137
|
-
const scopeFilter = flagString(input, "scope");
|
|
138
|
-
const purge = input.flags["purge"] === true;
|
|
139
|
-
|
|
140
|
-
const metaOperationId = `recover-${Date.now()}`;
|
|
141
|
-
try {
|
|
142
|
-
await acquireLock(
|
|
143
|
-
workspaceRoot,
|
|
144
|
-
"werkstatt-recovery",
|
|
145
|
-
metaOperationId,
|
|
146
|
-
"werkstatt.lock.recover",
|
|
147
|
-
"system",
|
|
148
|
-
);
|
|
149
|
-
} catch {
|
|
150
|
-
throw new Error("[werkstatt.lock.recover] another recovery operation is in progress");
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
try {
|
|
154
|
-
const locks = await readAllLocks(workspaceRoot);
|
|
155
|
-
const staleLocks = locks.filter((l) => l.stale && (!scopeFilter || l.scope === scopeFilter));
|
|
156
|
-
|
|
157
|
-
const recovered: Array<{ scope?: string; artifact?: string; action: string }> = [];
|
|
158
|
-
const failed: Array<{ scope?: string; artifact?: string; error: string }> = [];
|
|
159
|
-
|
|
160
|
-
for (const lock of staleLocks) {
|
|
161
|
-
try {
|
|
162
|
-
await removeStaleLock(workspaceRoot, lock.scope);
|
|
163
|
-
recovered.push({ scope: lock.scope, action: "removed-stale-lock" });
|
|
164
|
-
logger.info(` [removed] lock '${lock.scope}'`);
|
|
165
|
-
} catch (err) {
|
|
166
|
-
failed.push({ scope: lock.scope, error: (err as Error).message });
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
const { recovered: artifactRecovered, failed: artifactFailed } = await classifyArtifacts(
|
|
171
|
-
workspaceRoot,
|
|
172
|
-
purge,
|
|
173
|
-
resolveIo(context.io),
|
|
174
|
-
);
|
|
175
|
-
for (const r of artifactRecovered) {
|
|
176
|
-
recovered.push({ artifact: r.artifact, action: r.action });
|
|
177
|
-
}
|
|
178
|
-
for (const f of artifactFailed) {
|
|
179
|
-
failed.push({ artifact: f.artifact, error: f.error });
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
if (recovered.length === 0 && failed.length === 0) {
|
|
183
|
-
logger.success("[werkstatt.lock.recover] no stale locks or artifacts found");
|
|
184
|
-
} else {
|
|
185
|
-
logger.success(
|
|
186
|
-
`[werkstatt.lock.recover] ${recovered.length} recovered, ${failed.length} failed`,
|
|
187
|
-
);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
return {
|
|
191
|
-
data: { recovered, failed },
|
|
192
|
-
summary: `[werkstatt.lock.recover] ${recovered.length} artifact${recovered.length === 1 ? "" : "s"} recovered, ${failed.length} failure${failed.length === 1 ? "" : "s"}`,
|
|
193
|
-
nextSteps:
|
|
194
|
-
failed.length > 0
|
|
195
|
-
? [
|
|
196
|
-
{
|
|
197
|
-
action: `Investigate the ${failed.length} failed recovery item(s) above and retry manually`,
|
|
198
|
-
kind: "required",
|
|
199
|
-
},
|
|
200
|
-
]
|
|
201
|
-
: undefined,
|
|
202
|
-
};
|
|
203
|
-
} finally {
|
|
204
|
-
await releaseLock(workspaceRoot, "werkstatt-recovery");
|
|
205
|
-
}
|
|
206
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
<MODULE_CONTRACT>
|
|
3
|
-
<purpose>werkstatt.lock.status command handler. Moved from
|
|
4
|
-
@warpgogol/site-kernel-handoff to @warpgogol/forge for full autonomous mode (RFC-0556).
|
|
5
|
-
Reports all Werkstatt locks, their age, owner, and staleness (RFC-0362).</purpose>
|
|
6
|
-
<non-goals>
|
|
7
|
-
<item>Do not introduce app-specific runtime composition or deployment behavior.</item>
|
|
8
|
-
</non-goals>
|
|
9
|
-
</MODULE_CONTRACT>
|
|
10
|
-
<CHANGE_SUMMARY>
|
|
11
|
-
<item>RFC-0362: initial lock.status command handler.</item>
|
|
12
|
-
<item>RFC-0556: moved from @warpgogol/site-kernel-handoff to @warpgogol/forge for autonomous mode.</item>
|
|
13
|
-
</CHANGE_SUMMARY>
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
import type {
|
|
17
|
-
ForgeCommandInput,
|
|
18
|
-
ForgeCommandResult,
|
|
19
|
-
ForgeRuntimeContext,
|
|
20
|
-
} from "../../../src/types.ts";
|
|
21
|
-
import { readAllLocks } from "./lock.ts";
|
|
22
|
-
|
|
23
|
-
export interface WerkstattLockStatusData {
|
|
24
|
-
locks: Array<{
|
|
25
|
-
scope: string;
|
|
26
|
-
operationId: string;
|
|
27
|
-
command: string;
|
|
28
|
-
owner: string;
|
|
29
|
-
pid: number;
|
|
30
|
-
startedAt: string;
|
|
31
|
-
heartbeatAt: string;
|
|
32
|
-
timeoutSeconds: number;
|
|
33
|
-
stale: boolean;
|
|
34
|
-
}>;
|
|
35
|
-
count: number;
|
|
36
|
-
staleCount: number;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export async function runWerkstattLockStatus(
|
|
40
|
-
_input: ForgeCommandInput,
|
|
41
|
-
context: ForgeRuntimeContext,
|
|
42
|
-
): Promise<ForgeCommandResult<WerkstattLockStatusData>> {
|
|
43
|
-
const { workspaceRoot, logger } = context;
|
|
44
|
-
const locks = await readAllLocks(workspaceRoot);
|
|
45
|
-
|
|
46
|
-
const staleCount = locks.filter((l) => l.stale).length;
|
|
47
|
-
|
|
48
|
-
for (const lock of locks) {
|
|
49
|
-
const status = lock.stale ? "STALE" : "active";
|
|
50
|
-
logger.info(
|
|
51
|
-
` ${lock.scope.padEnd(32)} ${status.padEnd(6)} pid:${lock.pid} op:${lock.operationId}`,
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return {
|
|
56
|
-
data: {
|
|
57
|
-
locks: locks.map((l) => ({
|
|
58
|
-
scope: l.scope,
|
|
59
|
-
operationId: l.operationId,
|
|
60
|
-
command: l.command,
|
|
61
|
-
owner: l.owner,
|
|
62
|
-
pid: l.pid,
|
|
63
|
-
startedAt: l.startedAt,
|
|
64
|
-
heartbeatAt: l.heartbeatAt,
|
|
65
|
-
timeoutSeconds: l.timeoutSeconds,
|
|
66
|
-
stale: l.stale,
|
|
67
|
-
})),
|
|
68
|
-
count: locks.length,
|
|
69
|
-
staleCount,
|
|
70
|
-
},
|
|
71
|
-
summary: `[werkstatt.lock.status] ${locks.length} lock${locks.length === 1 ? "" : "s"}, ${staleCount} stale`,
|
|
72
|
-
nextSteps:
|
|
73
|
-
staleCount > 0
|
|
74
|
-
? [
|
|
75
|
-
{
|
|
76
|
-
action: `Recover stale locks: pnpm exec forge run werkstatt.lock.recover`,
|
|
77
|
-
kind: "optional",
|
|
78
|
-
},
|
|
79
|
-
]
|
|
80
|
-
: undefined,
|
|
81
|
-
};
|
|
82
|
-
}
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
<MODULE_CONTRACT>
|
|
3
|
-
<purpose>werkstatt.operation.validate command handler. Moved from
|
|
4
|
-
@warpgogol/site-kernel-checks to @warpgogol/forge for full autonomous mode (RFC-0556).
|
|
5
|
-
Scans command source files for direct shared-state writes outside the allowlisted
|
|
6
|
-
helper module (RFC-0362 §6).</purpose>
|
|
7
|
-
<non-goals>
|
|
8
|
-
<item>Does not load command implementations — reads source files with regex only.</item>
|
|
9
|
-
<item>Does not scan files outside packages/os/site-kernel-handoff/src/.</item>
|
|
10
|
-
</non-goals>
|
|
11
|
-
</MODULE_CONTRACT>
|
|
12
|
-
<CHANGE_SUMMARY>
|
|
13
|
-
<item>RFC-0362: initial operation.validate command handler.</item>
|
|
14
|
-
<item>RFC-0556: moved from @warpgogol/site-kernel-checks to @warpgogol/forge for autonomous mode. Uses node:fs/promises directly instead of context.io.</item>
|
|
15
|
-
<item>RFC-1248: VITE-CLIENT-DEP-02 lazy-import gate + SCAN-02 validator reads-root existence check (RFC-1248)</item>
|
|
16
|
-
<item>RFC-1493: step 4 — remove per-commit version bump, PC-01..04, version log; one commit path with universal X-RFC/X-ADR trailers</item>
|
|
17
|
-
</CHANGE_SUMMARY>
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
import { basename, join, relative } from "node:path";
|
|
21
|
-
import { resolveIo } from "../../../src/utils/io.ts";
|
|
22
|
-
|
|
23
|
-
import { collectFiles } from "../../../src/utils/fs.ts";
|
|
24
|
-
import type {
|
|
25
|
-
ForgeCommandInput,
|
|
26
|
-
ForgeCommandResult,
|
|
27
|
-
ForgeRuntimeContext,
|
|
28
|
-
} from "../../../src/types.ts";
|
|
29
|
-
|
|
30
|
-
const SCAN_DIR = "packages/werkstatt-engine/src/handoff";
|
|
31
|
-
const ALLOWLIST_DIR = "packages/werkstatt-engine/src/werkstatt";
|
|
32
|
-
|
|
33
|
-
const DIRECT_WRITE_PATTERNS: Array<{ regex: RegExp; label: string }> = [
|
|
34
|
-
{ regex: /\bwriteFile\s*\(/g, label: "writeFile" },
|
|
35
|
-
{ regex: /\bappendFile\s*\(/g, label: "appendFile" },
|
|
36
|
-
{ regex: /\brename\s*\(/g, label: "rename" },
|
|
37
|
-
{ regex: /\bcp\s*\(/g, label: "cp" },
|
|
38
|
-
];
|
|
39
|
-
|
|
40
|
-
export interface WerkstattOperationValidateData {
|
|
41
|
-
scannedFiles: number;
|
|
42
|
-
violations: Array<{ file: string; line: number; pattern: string }>;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export async function runWerkstattOperationValidate(
|
|
46
|
-
_input: ForgeCommandInput,
|
|
47
|
-
context: ForgeRuntimeContext,
|
|
48
|
-
): Promise<ForgeCommandResult<WerkstattOperationValidateData>> {
|
|
49
|
-
const io = resolveIo(context.io);
|
|
50
|
-
const { workspaceRoot, logger } = context;
|
|
51
|
-
const scanPath = join(workspaceRoot, SCAN_DIR);
|
|
52
|
-
const allowlistPath = join(workspaceRoot, ALLOWLIST_DIR);
|
|
53
|
-
|
|
54
|
-
const files = await collectFiles(scanPath, {
|
|
55
|
-
ignore: (name) =>
|
|
56
|
-
name.startsWith(".") || name === "node_modules" || name === "dist" || name === "tests",
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
const violations: Array<{ file: string; line: number; pattern: string }> = [];
|
|
60
|
-
|
|
61
|
-
const PRE_EXISTING_ALLOWLIST = new Set([
|
|
62
|
-
"handoff-pack.ts",
|
|
63
|
-
"materialize.ts",
|
|
64
|
-
"bundle-io.ts",
|
|
65
|
-
]);
|
|
66
|
-
|
|
67
|
-
for (const filePath of files) {
|
|
68
|
-
if (filePath.startsWith(allowlistPath)) continue;
|
|
69
|
-
|
|
70
|
-
const fileName = basename(filePath);
|
|
71
|
-
if (fileName.endsWith(".test.ts") || fileName.endsWith(".spec.ts")) continue;
|
|
72
|
-
if (PRE_EXISTING_ALLOWLIST.has(fileName)) continue;
|
|
73
|
-
|
|
74
|
-
const relPath = relative(workspaceRoot, filePath).replace(/\\/g, "/");
|
|
75
|
-
|
|
76
|
-
let content: string;
|
|
77
|
-
try {
|
|
78
|
-
content = await io.readFile(filePath);
|
|
79
|
-
} catch {
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const lines = content.split("\n");
|
|
84
|
-
for (let i = 0; i < lines.length; i++) {
|
|
85
|
-
const line = lines[i];
|
|
86
|
-
const trimmed = line.trim();
|
|
87
|
-
if (trimmed.startsWith("//") || trimmed.startsWith("*") || trimmed.startsWith("/*")) continue;
|
|
88
|
-
|
|
89
|
-
for (const { regex, label } of DIRECT_WRITE_PATTERNS) {
|
|
90
|
-
const testRegex = new RegExp(regex.source, regex.flags);
|
|
91
|
-
if (testRegex.test(line)) {
|
|
92
|
-
violations.push({ file: relPath, line: i + 1, pattern: label });
|
|
93
|
-
logger.error(
|
|
94
|
-
`${relPath}:${i + 1}: direct ${label} — use the shared atomic-write helper in packages/os/site-kernel-handoff/src/werkstatt/`,
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return {
|
|
102
|
-
data: {
|
|
103
|
-
scannedFiles: files.length,
|
|
104
|
-
violations,
|
|
105
|
-
},
|
|
106
|
-
exitCode: violations.length > 0 ? 1 : 0,
|
|
107
|
-
summary:
|
|
108
|
-
violations.length > 0
|
|
109
|
-
? undefined
|
|
110
|
-
: `[werkstatt.operation.validate] ${files.length} files scanned, 0 violations`,
|
|
111
|
-
};
|
|
112
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
<MODULE_CONTRACT>
|
|
3
|
-
<purpose>Lazy dynamic-import bridge for @warpgogol/werkstatt-shared/node/fs and @warpgogol/werkstatt-shared/fingerprint. These workspace packages are not published to npm — when forge is installed standalone from npm, they are unavailable and handlers that depend on them must degrade gracefully.</purpose>
|
|
4
|
-
<non-goals>
|
|
5
|
-
<item>Do not re-export types from @warpgogol/* — only runtime functions.</item>
|
|
6
|
-
<item>Do not use static imports — that would break npm installs without workspace deps.</item>
|
|
7
|
-
</non-goals>
|
|
8
|
-
</MODULE_CONTRACT>
|
|
9
|
-
<CHANGE_SUMMARY>
|
|
10
|
-
<item>RFC-0682: extract dynamic-import helper so forge publishes without workspace:* deps.</item>
|
|
11
|
-
<item>RFC-0940: moved from os/core/handlers/ to os/werkstatt/handlers/ — this module imports @warpgogol/werkstatt-engine and belongs in the adapter directory.</item>
|
|
12
|
-
</CHANGE_SUMMARY>
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
export type CollectFilesFn = (
|
|
16
|
-
root: string,
|
|
17
|
-
options?: {
|
|
18
|
-
extensions?: string[];
|
|
19
|
-
ignore?: (name: string) => boolean;
|
|
20
|
-
},
|
|
21
|
-
) => Promise<string[]>;
|
|
22
|
-
|
|
23
|
-
export type ByteHashFileFn = (filePath: string) => Promise<string>;
|
|
24
|
-
|
|
25
|
-
interface WorkspaceDeps {
|
|
26
|
-
collectFiles: CollectFilesFn;
|
|
27
|
-
byteHashFile: ByteHashFileFn;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
let cached: WorkspaceDeps | null = null;
|
|
31
|
-
let loadError: string | null = null;
|
|
32
|
-
|
|
33
|
-
export async function loadWorkspaceDeps(): Promise<WorkspaceDeps> {
|
|
34
|
-
if (cached) return cached;
|
|
35
|
-
if (loadError) throw new Error(loadError);
|
|
36
|
-
|
|
37
|
-
try {
|
|
38
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
39
|
-
// @ts-ignore — workspace dep, may not be installed when forge is used standalone from npm
|
|
40
|
-
const shareMod = await import("@warpgogol/werkstatt-shared/node/fs");
|
|
41
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
42
|
-
// @ts-ignore — workspace dep, may not be installed when forge is used standalone from npm
|
|
43
|
-
const fpMod = await import("@warpgogol/werkstatt-shared/fingerprint");
|
|
44
|
-
cached = {
|
|
45
|
-
collectFiles: shareMod.collectFiles as CollectFilesFn,
|
|
46
|
-
byteHashFile: fpMod.byteHashFile as ByteHashFileFn,
|
|
47
|
-
};
|
|
48
|
-
return cached;
|
|
49
|
-
} catch (err) {
|
|
50
|
-
loadError =
|
|
51
|
-
`@warpgogol/werkstatt-shared/fingerprint and @warpgogol/werkstatt-shared/node/fs are required for this command but not installed. ` +
|
|
52
|
-
`When using forge standalone from npm, install them separately or use forge within the warpgogol workspace. ` +
|
|
53
|
-
`Error: ${(err as Error).message}`;
|
|
54
|
-
throw new Error(loadError);
|
|
55
|
-
}
|
|
56
|
-
}
|