@ambystech/ambykit 1.3.1 → 1.5.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/CHANGELOG.md +95 -1
- package/README.md +8 -0
- package/dist/cli/activity.d.ts +5 -1
- package/dist/cli/activity.js +22 -8
- package/dist/cli/activity.js.map +1 -1
- package/dist/cli/add.js +12 -5
- package/dist/cli/add.js.map +1 -1
- package/dist/cli/analyze.js +68 -4
- package/dist/cli/analyze.js.map +1 -1
- package/dist/cli/base-command.js +6 -0
- package/dist/cli/base-command.js.map +1 -1
- package/dist/cli/check.js +18 -3
- package/dist/cli/check.js.map +1 -1
- package/dist/cli/dashboard.js +3 -1
- package/dist/cli/dashboard.js.map +1 -1
- package/dist/cli/directive.d.ts +7 -0
- package/dist/cli/directive.js +43 -0
- package/dist/cli/directive.js.map +1 -0
- package/dist/cli/fleet.d.ts +16 -0
- package/dist/cli/fleet.js +472 -0
- package/dist/cli/fleet.js.map +1 -0
- package/dist/cli/graph.d.ts +13 -0
- package/dist/cli/graph.js +40 -0
- package/dist/cli/graph.js.map +1 -0
- package/dist/cli/index.js +10 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/io/fsops.d.ts +4 -0
- package/dist/cli/io/fsops.js +62 -0
- package/dist/cli/io/fsops.js.map +1 -1
- package/dist/cli/mcp.d.ts +21 -0
- package/dist/cli/mcp.js +27 -0
- package/dist/cli/mcp.js.map +1 -0
- package/dist/cli/sync.d.ts +2 -0
- package/dist/cli/sync.js +31 -5
- package/dist/cli/sync.js.map +1 -1
- package/dist/cli/trace.d.ts +14 -0
- package/dist/cli/trace.js +89 -0
- package/dist/cli/trace.js.map +1 -0
- package/dist/cli/ui/dashboard/feature-chart.js +15 -2
- package/dist/cli/ui/dashboard/feature-chart.js.map +1 -1
- package/dist/cli/ui/dashboard/feature-view.js +11 -1
- package/dist/cli/ui/dashboard/feature-view.js.map +1 -1
- package/dist/cli/ui/dashboard/graph-view.d.ts +44 -0
- package/dist/cli/ui/dashboard/graph-view.js +78 -0
- package/dist/cli/ui/dashboard/graph-view.js.map +1 -0
- package/dist/cli/ui/dashboard/help-overlay.d.ts +1 -1
- package/dist/cli/ui/dashboard/help-overlay.js +9 -0
- package/dist/cli/ui/dashboard/help-overlay.js.map +1 -1
- package/dist/cli/ui/dashboard/quality-view.d.ts +8 -0
- package/dist/cli/ui/dashboard/quality-view.js +31 -0
- package/dist/cli/ui/dashboard/quality-view.js.map +1 -0
- package/dist/cli/ui/dashboard/story-detail.d.ts +1 -1
- package/dist/cli/ui/dashboard/story-detail.js +10 -3
- package/dist/cli/ui/dashboard/story-detail.js.map +1 -1
- package/dist/cli/ui/dashboard/tokens.d.ts +26 -0
- package/dist/cli/ui/dashboard/tokens.js +26 -0
- package/dist/cli/ui/dashboard/tokens.js.map +1 -1
- package/dist/cli/ui/interactive/overview.d.ts +13 -1
- package/dist/cli/ui/interactive/overview.js +62 -0
- package/dist/cli/ui/interactive/overview.js.map +1 -1
- package/dist/cli/ui/tool-options.d.ts +3 -2
- package/dist/cli/ui/tool-options.js +3 -3
- package/dist/cli/ui/tool-options.js.map +1 -1
- package/dist/cli/update.d.ts +1 -1
- package/dist/cli/update.js +8 -3
- package/dist/cli/update.js.map +1 -1
- package/dist/core/activity.d.ts +15 -2
- package/dist/core/activity.js +19 -4
- package/dist/core/activity.js.map +1 -1
- package/dist/core/analyze.d.ts +80 -2
- package/dist/core/analyze.js +200 -61
- package/dist/core/analyze.js.map +1 -1
- package/dist/core/checkouts.js +2 -0
- package/dist/core/checkouts.js.map +1 -1
- package/dist/core/config.d.ts +28 -1
- package/dist/core/config.js +44 -0
- package/dist/core/config.js.map +1 -1
- package/dist/core/dashboard.d.ts +4 -0
- package/dist/core/dashboard.js +5 -3
- package/dist/core/dashboard.js.map +1 -1
- package/dist/core/decisions.d.ts +60 -0
- package/dist/core/decisions.js +231 -0
- package/dist/core/decisions.js.map +1 -0
- package/dist/core/emit.d.ts +16 -1
- package/dist/core/emit.js +49 -5
- package/dist/core/emit.js.map +1 -1
- package/dist/core/features.js +6 -1
- package/dist/core/features.js.map +1 -1
- package/dist/core/fleet/claims.d.ts +45 -0
- package/dist/core/fleet/claims.js +85 -0
- package/dist/core/fleet/claims.js.map +1 -0
- package/dist/core/fleet/directives.d.ts +56 -0
- package/dist/core/fleet/directives.js +99 -0
- package/dist/core/fleet/directives.js.map +1 -0
- package/dist/core/fleet/flow-input.d.ts +6 -0
- package/dist/core/fleet/flow-input.js +35 -0
- package/dist/core/fleet/flow-input.js.map +1 -0
- package/dist/core/fleet/index.d.ts +9 -0
- package/dist/core/fleet/index.js +10 -0
- package/dist/core/fleet/index.js.map +1 -0
- package/dist/core/fleet/lane-status.d.ts +39 -0
- package/dist/core/fleet/lane-status.js +63 -0
- package/dist/core/fleet/lane-status.js.map +1 -0
- package/dist/core/fleet/lock.d.ts +23 -0
- package/dist/core/fleet/lock.js +103 -0
- package/dist/core/fleet/lock.js.map +1 -0
- package/dist/core/fleet/notes.d.ts +31 -0
- package/dist/core/fleet/notes.js +56 -0
- package/dist/core/fleet/notes.js.map +1 -0
- package/dist/core/fleet/run-flow.d.ts +157 -0
- package/dist/core/fleet/run-flow.js +205 -0
- package/dist/core/fleet/run-flow.js.map +1 -0
- package/dist/core/fleet/runs.d.ts +46 -0
- package/dist/core/fleet/runs.js +182 -0
- package/dist/core/fleet/runs.js.map +1 -0
- package/dist/core/fleet/types.d.ts +63 -0
- package/dist/core/fleet/types.js +11 -0
- package/dist/core/fleet/types.js.map +1 -0
- package/dist/core/graph-format.d.ts +51 -0
- package/dist/core/graph-format.js +99 -0
- package/dist/core/graph-format.js.map +1 -0
- package/dist/core/graph-paths.d.ts +27 -0
- package/dist/core/graph-paths.js +94 -0
- package/dist/core/graph-paths.js.map +1 -0
- package/dist/core/graph-scope.d.ts +7 -0
- package/dist/core/graph-scope.js +31 -0
- package/dist/core/graph-scope.js.map +1 -0
- package/dist/core/graph-types.d.ts +55 -0
- package/dist/core/graph-types.js +6 -0
- package/dist/core/graph-types.js.map +1 -0
- package/dist/core/graph.d.ts +14 -0
- package/dist/core/graph.js +144 -0
- package/dist/core/graph.js.map +1 -0
- package/dist/core/index.d.ts +13 -0
- package/dist/core/index.js +13 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/markers.d.ts +44 -0
- package/dist/core/markers.js +139 -0
- package/dist/core/markers.js.map +1 -0
- package/dist/core/merge-json.d.ts +15 -0
- package/dist/core/merge-json.js +46 -0
- package/dist/core/merge-json.js.map +1 -0
- package/dist/core/moved-targets.d.ts +23 -0
- package/dist/core/moved-targets.js +23 -0
- package/dist/core/moved-targets.js.map +1 -0
- package/dist/core/overview-types.d.ts +27 -1
- package/dist/core/overview-types.js.map +1 -1
- package/dist/core/overview.d.ts +1 -1
- package/dist/core/overview.js +91 -74
- package/dist/core/overview.js.map +1 -1
- package/dist/core/path-guard.d.ts +5 -0
- package/dist/core/path-guard.js +9 -0
- package/dist/core/path-guard.js.map +1 -0
- package/dist/core/paths.d.ts +2 -0
- package/dist/core/paths.js +4 -0
- package/dist/core/paths.js.map +1 -1
- package/dist/core/query.d.ts +91 -0
- package/dist/core/query.js +197 -0
- package/dist/core/query.js.map +1 -0
- package/dist/core/report.d.ts +36 -0
- package/dist/core/report.js +62 -0
- package/dist/core/report.js.map +1 -0
- package/dist/core/rules.js +3 -0
- package/dist/core/rules.js.map +1 -1
- package/dist/core/scaffold.d.ts +2 -2
- package/dist/core/scaffold.js +3 -1
- package/dist/core/scaffold.js.map +1 -1
- package/dist/core/subagents.d.ts +29 -0
- package/dist/core/subagents.js +52 -0
- package/dist/core/subagents.js.map +1 -0
- package/dist/core/tasks-edit.d.ts +34 -0
- package/dist/core/tasks-edit.js +115 -0
- package/dist/core/tasks-edit.js.map +1 -0
- package/dist/core/test-design.d.ts +94 -0
- package/dist/core/test-design.js +325 -0
- package/dist/core/test-design.js.map +1 -0
- package/dist/core/trace-cite.d.ts +16 -0
- package/dist/core/trace-cite.js +24 -0
- package/dist/core/trace-cite.js.map +1 -0
- package/dist/core/trace-coverage.d.ts +8 -0
- package/dist/core/trace-coverage.js +40 -0
- package/dist/core/trace-coverage.js.map +1 -0
- package/dist/core/trace-design.d.ts +6 -0
- package/dist/core/trace-design.js +16 -0
- package/dist/core/trace-design.js.map +1 -0
- package/dist/core/trace-io.d.ts +14 -0
- package/dist/core/trace-io.js +97 -0
- package/dist/core/trace-io.js.map +1 -0
- package/dist/core/trace-requirements.d.ts +9 -0
- package/dist/core/trace-requirements.js +27 -0
- package/dist/core/trace-requirements.js.map +1 -0
- package/dist/core/trace-tests.d.ts +7 -0
- package/dist/core/trace-tests.js +27 -0
- package/dist/core/trace-tests.js.map +1 -0
- package/dist/core/trace-types.d.ts +81 -0
- package/dist/core/trace-types.js +3 -0
- package/dist/core/trace-types.js.map +1 -0
- package/dist/core/trace.d.ts +18 -0
- package/dist/core/trace.js +109 -0
- package/dist/core/trace.js.map +1 -0
- package/dist/core/types.d.ts +43 -1
- package/dist/emitters/antigravity-cli.d.ts +4 -0
- package/dist/emitters/antigravity-cli.js +8 -0
- package/dist/emitters/antigravity-cli.js.map +1 -1
- package/dist/emitters/antigravity.d.ts +6 -0
- package/dist/emitters/antigravity.js +8 -0
- package/dist/emitters/antigravity.js.map +1 -1
- package/dist/emitters/base-emitter.d.ts +28 -0
- package/dist/emitters/base-emitter.js +41 -1
- package/dist/emitters/base-emitter.js.map +1 -1
- package/dist/emitters/claude.d.ts +12 -2
- package/dist/emitters/claude.js +34 -5
- package/dist/emitters/claude.js.map +1 -1
- package/dist/emitters/copilot-cli.d.ts +7 -1
- package/dist/emitters/copilot-cli.js +9 -0
- package/dist/emitters/copilot-cli.js.map +1 -1
- package/dist/emitters/copilot.d.ts +5 -0
- package/dist/emitters/copilot.js +23 -1
- package/dist/emitters/copilot.js.map +1 -1
- package/dist/emitters/cursor.d.ts +3 -0
- package/dist/emitters/cursor.js +8 -1
- package/dist/emitters/cursor.js.map +1 -1
- package/dist/emitters/index.d.ts +10 -3
- package/dist/emitters/index.js +6 -6
- package/dist/emitters/index.js.map +1 -1
- package/dist/emitters/opencode.d.ts +8 -0
- package/dist/emitters/opencode.js +23 -0
- package/dist/emitters/opencode.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/mcp/protocol.d.ts +44 -0
- package/dist/mcp/protocol.js +114 -0
- package/dist/mcp/protocol.js.map +1 -0
- package/dist/mcp/registry.d.ts +40 -0
- package/dist/mcp/registry.js +44 -0
- package/dist/mcp/registry.js.map +1 -0
- package/dist/mcp/server.d.ts +7 -0
- package/dist/mcp/server.js +14 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/mcp/tools/common.d.ts +12 -0
- package/dist/mcp/tools/common.js +12 -0
- package/dist/mcp/tools/common.js.map +1 -0
- package/dist/mcp/tools/fleet.d.ts +10 -0
- package/dist/mcp/tools/fleet.js +102 -0
- package/dist/mcp/tools/fleet.js.map +1 -0
- package/dist/mcp/tools/index.d.ts +3 -0
- package/dist/mcp/tools/index.js +13 -0
- package/dist/mcp/tools/index.js.map +1 -0
- package/dist/mcp/tools/read.d.ts +6 -0
- package/dist/mcp/tools/read.js +62 -0
- package/dist/mcp/tools/read.js.map +1 -0
- package/dist/mcp/tools/write.d.ts +6 -0
- package/dist/mcp/tools/write.js +34 -0
- package/dist/mcp/tools/write.js.map +1 -0
- package/dist/plugins/api.d.ts +39 -0
- package/dist/plugins/api.js +28 -0
- package/dist/plugins/api.js.map +1 -0
- package/dist/plugins/index.d.ts +11 -0
- package/dist/plugins/index.js +9 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/plugins/loader.d.ts +35 -0
- package/dist/plugins/loader.js +117 -0
- package/dist/plugins/loader.js.map +1 -0
- package/dist/plugins/manifest.d.ts +21 -0
- package/dist/plugins/manifest.js +53 -0
- package/dist/plugins/manifest.js.map +1 -0
- package/dist/plugins/registry.d.ts +36 -0
- package/dist/plugins/registry.js +30 -0
- package/dist/plugins/registry.js.map +1 -0
- package/dist/plugins/report.d.ts +9 -0
- package/dist/plugins/report.js +19 -0
- package/dist/plugins/report.js.map +1 -0
- package/dist/plugins/semver.d.ts +23 -0
- package/dist/plugins/semver.js +106 -0
- package/dist/plugins/semver.js.map +1 -0
- package/dist/plugins/session.d.ts +18 -0
- package/dist/plugins/session.js +22 -0
- package/dist/plugins/session.js.map +1 -0
- package/dist/testkit/contract.d.ts +33 -0
- package/dist/testkit/contract.js +118 -0
- package/dist/testkit/contract.js.map +1 -0
- package/dist/testkit/index.d.ts +15 -0
- package/dist/testkit/index.js +15 -0
- package/dist/testkit/index.js.map +1 -0
- package/docs/architecture.md +33 -5
- package/docs/artifacts/decision-record.md +54 -0
- package/docs/artifacts/tasks.md +37 -0
- package/docs/artifacts/tests.md +43 -0
- package/docs/cli-reference.md +178 -5
- package/docs/concepts/mcp-server.md +93 -0
- package/docs/contributing.md +9 -0
- package/docs/index.md +1 -1
- package/docs/plugin-api.md +124 -0
- package/docs/plugin-split.md +55 -0
- package/docs/plugin-trust.md +51 -0
- package/docs/tool-compatibility.md +54 -6
- package/docs/workflow.md +37 -5
- package/package.json +5 -2
- package/src/agents/worker.md +37 -0
- package/src/prompts/converge.md +8 -3
- package/src/prompts/decide.md +31 -0
- package/src/prompts/implement.md +15 -7
- package/src/prompts/revise.md +4 -2
- package/src/prompts/run.md +100 -0
- package/src/prompts/tasks.md +13 -3
- package/src/roles/security.md +17 -0
- package/src/templates/adr.md +29 -0
- package/src/templates/tasks.md +6 -0
- package/src/templates/tests.md +29 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { type ActivityMarker } from "../activity.js";
|
|
2
|
+
import { type Directive, type DirectiveAction, type DirectiveStatus } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Directives (feature 025, US-3 and US-7): one per lane at `.amby/fleet/<run>/directives/<lane>.json`
|
|
5
|
+
* in the primary checkout, `{ action, at }`. The last write wins and a missing file means continue
|
|
6
|
+
* (FR-010, FR-011). The file name uses the short lane form `lane-<p>-<k>`. This module holds the reader, the
|
|
7
|
+
* derived status and the single writer, `writeDirective`, that 019's wrapper, 028, 029 and `ambykit directive`
|
|
8
|
+
* all call (FR-023).
|
|
9
|
+
*/
|
|
10
|
+
export declare function directivesDir(root: string, run: string): string;
|
|
11
|
+
export declare function directivePath(root: string, run: string, lane: string): string;
|
|
12
|
+
/** The lane's directive, or null (missing, unreadable or malformed: all mean "continue"). */
|
|
13
|
+
export declare function readDirective(root: string, run: string, lane: string): Directive | null;
|
|
14
|
+
/** What a worker should do: the directive's action, `continue` when there is none. */
|
|
15
|
+
export declare function directiveAction(directive: Directive | null): Directive["action"];
|
|
16
|
+
/**
|
|
17
|
+
* Derived directive status, never stored (FR-022), from the directive and the lane's latest report:
|
|
18
|
+
*
|
|
19
|
+
* - no directive → `none`;
|
|
20
|
+
* - a `pause` directive: `paused` while the lane's state is paused, else `pause requested` (this also covers
|
|
21
|
+
* the moment before the lane's next report, when the directive has not been seen yet);
|
|
22
|
+
* - any other directive: `pending` while it is newer than the lane's latest report (or there is none),
|
|
23
|
+
* then `obeyed` once the lane has reported after it.
|
|
24
|
+
*
|
|
25
|
+
* A report dated exactly at the directive counts as before it (the directive was written after the worker
|
|
26
|
+
* last looked), so a tie reads `pending`.
|
|
27
|
+
*/
|
|
28
|
+
export declare function directiveStatus(directive: Directive | null, latest: Pick<ActivityMarker, "at" | "state"> | null): DirectiveStatus;
|
|
29
|
+
export type WriteDirectiveResult = {
|
|
30
|
+
ok: true;
|
|
31
|
+
run: string;
|
|
32
|
+
lane: string;
|
|
33
|
+
directive: Directive;
|
|
34
|
+
} | {
|
|
35
|
+
ok: false;
|
|
36
|
+
error: string;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* The lanes a directive may name: the run's recorded lanes plus the lane checkouts that exist for the
|
|
40
|
+
* feature. A lane in neither does not exist (FR-023).
|
|
41
|
+
*/
|
|
42
|
+
export declare function knownLanes(root: string, feature: string, runLanes: {
|
|
43
|
+
lane: string;
|
|
44
|
+
}[]): string[];
|
|
45
|
+
/**
|
|
46
|
+
* Write a lane's directive, the single writer (FR-023). Validates the lane against the run, writes
|
|
47
|
+
* `{ action, at }` atomically under a lock, and the last write wins (FR-011). `resume` is not an action:
|
|
48
|
+
* callers write `continue`.
|
|
49
|
+
*/
|
|
50
|
+
export declare function writeDirective(root: string, input: {
|
|
51
|
+
feature: string;
|
|
52
|
+
lane: string;
|
|
53
|
+
action: DirectiveAction;
|
|
54
|
+
run?: string;
|
|
55
|
+
now?: Date;
|
|
56
|
+
}): WriteDirectiveResult;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { shortLane } from "../activity.js";
|
|
4
|
+
import { laneRefs } from "../query.js";
|
|
5
|
+
import { withLock, writeFileAtomic } from "./lock.js";
|
|
6
|
+
import { resolveRun, runDir } from "./runs.js";
|
|
7
|
+
import { DIRECTIVE_ACTIONS } from "./types.js";
|
|
8
|
+
/**
|
|
9
|
+
* Directives (feature 025, US-3 and US-7): one per lane at `.amby/fleet/<run>/directives/<lane>.json`
|
|
10
|
+
* in the primary checkout, `{ action, at }`. The last write wins and a missing file means continue
|
|
11
|
+
* (FR-010, FR-011). The file name uses the short lane form `lane-<p>-<k>`. This module holds the reader, the
|
|
12
|
+
* derived status and the single writer, `writeDirective`, that 019's wrapper, 028, 029 and `ambykit directive`
|
|
13
|
+
* all call (FR-023).
|
|
14
|
+
*/
|
|
15
|
+
export function directivesDir(root, run) {
|
|
16
|
+
return join(runDir(root, run), "directives");
|
|
17
|
+
}
|
|
18
|
+
export function directivePath(root, run, lane) {
|
|
19
|
+
return join(directivesDir(root, run), `${shortLane(lane)}.json`);
|
|
20
|
+
}
|
|
21
|
+
/** The lane's directive, or null (missing, unreadable or malformed: all mean "continue"). */
|
|
22
|
+
export function readDirective(root, run, lane) {
|
|
23
|
+
const path = directivePath(root, run, lane);
|
|
24
|
+
if (!existsSync(path))
|
|
25
|
+
return null;
|
|
26
|
+
try {
|
|
27
|
+
const raw = JSON.parse(readFileSync(path, "utf8"));
|
|
28
|
+
if (!raw || typeof raw.at !== "string" || Number.isNaN(Date.parse(raw.at)))
|
|
29
|
+
return null;
|
|
30
|
+
if (!DIRECTIVE_ACTIONS.includes(raw.action))
|
|
31
|
+
return null;
|
|
32
|
+
return { action: raw.action, at: raw.at };
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/** What a worker should do: the directive's action, `continue` when there is none. */
|
|
39
|
+
export function directiveAction(directive) {
|
|
40
|
+
return directive?.action ?? "continue";
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Derived directive status, never stored (FR-022), from the directive and the lane's latest report:
|
|
44
|
+
*
|
|
45
|
+
* - no directive → `none`;
|
|
46
|
+
* - a `pause` directive: `paused` while the lane's state is paused, else `pause requested` (this also covers
|
|
47
|
+
* the moment before the lane's next report, when the directive has not been seen yet);
|
|
48
|
+
* - any other directive: `pending` while it is newer than the lane's latest report (or there is none),
|
|
49
|
+
* then `obeyed` once the lane has reported after it.
|
|
50
|
+
*
|
|
51
|
+
* A report dated exactly at the directive counts as before it (the directive was written after the worker
|
|
52
|
+
* last looked), so a tie reads `pending`.
|
|
53
|
+
*/
|
|
54
|
+
export function directiveStatus(directive, latest) {
|
|
55
|
+
if (!directive)
|
|
56
|
+
return "none";
|
|
57
|
+
const reportedAfter = latest !== null && Date.parse(latest.at) > Date.parse(directive.at);
|
|
58
|
+
if (directive.action === "pause") {
|
|
59
|
+
return latest?.state === "paused" ? "paused" : "pause requested";
|
|
60
|
+
}
|
|
61
|
+
return reportedAfter ? "obeyed" : "pending";
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The lanes a directive may name: the run's recorded lanes plus the lane checkouts that exist for the
|
|
65
|
+
* feature. A lane in neither does not exist (FR-023).
|
|
66
|
+
*/
|
|
67
|
+
export function knownLanes(root, feature, runLanes) {
|
|
68
|
+
const names = new Set();
|
|
69
|
+
for (const l of runLanes)
|
|
70
|
+
names.add(shortLane(l.lane));
|
|
71
|
+
for (const l of laneRefs(root, feature))
|
|
72
|
+
names.add(l.short);
|
|
73
|
+
return [...names].sort();
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Write a lane's directive, the single writer (FR-023). Validates the lane against the run, writes
|
|
77
|
+
* `{ action, at }` atomically under a lock, and the last write wins (FR-011). `resume` is not an action:
|
|
78
|
+
* callers write `continue`.
|
|
79
|
+
*/
|
|
80
|
+
export function writeDirective(root, input) {
|
|
81
|
+
if (!DIRECTIVE_ACTIONS.includes(input.action)) {
|
|
82
|
+
return { ok: false, error: `invalid action '${input.action}'; allowed: ${DIRECTIVE_ACTIONS.join(", ")}` };
|
|
83
|
+
}
|
|
84
|
+
const resolved = resolveRun(root, input.feature, input.run);
|
|
85
|
+
if (!resolved.ok)
|
|
86
|
+
return { ok: false, error: resolved.warning };
|
|
87
|
+
const run = resolved.run.run;
|
|
88
|
+
const short = shortLane(input.lane.includes(".lane-") || input.lane.startsWith("lane-") ? input.lane : `lane-${input.lane}`);
|
|
89
|
+
const known = knownLanes(root, input.feature, resolved.run.lanes);
|
|
90
|
+
if (!known.includes(short)) {
|
|
91
|
+
return { ok: false, error: `lane '${input.lane}' not found in run ${run}${known.length ? `; lanes: ${known.join(", ")}` : "; the run has no lanes"}` };
|
|
92
|
+
}
|
|
93
|
+
const directive = { action: input.action, at: (input.now ?? new Date()).toISOString() };
|
|
94
|
+
const locked = withLock(root, `directive-${run}-${short}`, () => writeFileAtomic(directivePath(root, run, short), JSON.stringify(directive) + "\n"));
|
|
95
|
+
if (!locked.ok)
|
|
96
|
+
return { ok: false, error: locked.warning };
|
|
97
|
+
return { ok: true, run, lane: short, directive };
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=directives.js.map
|
|
@@ -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AE,CAAC;QAC3B,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,KAAK,CAAC,IAAI,sBAAsB,GAAG,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,YAAY,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,wBAAwB,EAAE,EAAE,CAAC;IACzJ,CAAC;IACD,MAAM,SAAS,GAAc,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,IAAI,IAAI,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC;IACnG,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,EAAE,aAAa,GAAG,IAAI,KAAK,EAAE,EAAE,GAAG,EAAE,CAAC,eAAe,CAAC,aAAa,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;IACrJ,IAAI,CAAC,MAAM,CAAC,EAAE;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC;IAC5D,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;AACnD,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { FlowInput } from "./run-flow.js";
|
|
2
|
+
/**
|
|
3
|
+
* Read a feature's artifacts into the pure `FlowInput` (feature 019). The only file access of the run-flow
|
|
4
|
+
* family besides 025's store; `run-flow.ts` itself stays pure. `root` is the checkout whose `specs/` is read.
|
|
5
|
+
*/
|
|
6
|
+
export declare function readFlowInput(root: string, feature: string): FlowInput;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import matter from "gray-matter";
|
|
4
|
+
import { parseTasks } from "../dashboard.js";
|
|
5
|
+
import { parsePhases } from "../markers.js";
|
|
6
|
+
/**
|
|
7
|
+
* Read a feature's artifacts into the pure `FlowInput` (feature 019). The only file access of the run-flow
|
|
8
|
+
* family besides 025's store; `run-flow.ts` itself stays pure. `root` is the checkout whose `specs/` is read.
|
|
9
|
+
*/
|
|
10
|
+
export function readFlowInput(root, feature) {
|
|
11
|
+
const dir = join(root, "specs", feature);
|
|
12
|
+
const specFile = join(dir, "spec.md");
|
|
13
|
+
let specStatus = null;
|
|
14
|
+
if (existsSync(specFile)) {
|
|
15
|
+
const status = matter(readFileSync(specFile, "utf8")).data.status;
|
|
16
|
+
specStatus = typeof status === "string" && status.trim() !== "" ? status.trim() : "draft";
|
|
17
|
+
}
|
|
18
|
+
const tasksFile = join(dir, "tasks.md");
|
|
19
|
+
const hasTasks = existsSync(tasksFile);
|
|
20
|
+
const text = hasTasks ? readFileSync(tasksFile, "utf8") : "";
|
|
21
|
+
return {
|
|
22
|
+
feature,
|
|
23
|
+
specStatus,
|
|
24
|
+
hasPlan: existsSync(join(dir, "plan.md")),
|
|
25
|
+
hasTasks,
|
|
26
|
+
tasks: parseTasks(text).map((t) => ({ id: t.id, done: t.done, phase: t.phase, ...(t.blocked !== undefined ? { blocked: t.blocked } : {}) })),
|
|
27
|
+
phases: parsePhases(text).map((p) => ({
|
|
28
|
+
phase: p.phase,
|
|
29
|
+
title: p.title,
|
|
30
|
+
...(p.check !== undefined ? { check: p.check } : {}),
|
|
31
|
+
...(p.result ? { result: p.result } : {}),
|
|
32
|
+
})),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=flow-input.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flow-input.js","sourceRoot":"","sources":["../../../src/core/fleet/flow-input.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,M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E,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;QAC5I,MAAM,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YACpC,KAAK,EAAE,CAAC,CAAC,KAAK;YACd,KAAK,EAAE,CAAC,CAAC,KAAK;YACd,GAAG,CAAC,CAAC,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACpD,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC1C,CAAC,CAAC;KACJ,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./types.js";
|
|
2
|
+
export * from "./lock.js";
|
|
3
|
+
export * from "./runs.js";
|
|
4
|
+
export * from "./directives.js";
|
|
5
|
+
export * from "./claims.js";
|
|
6
|
+
export * from "./notes.js";
|
|
7
|
+
export * from "./lane-status.js";
|
|
8
|
+
export * from "./run-flow.js";
|
|
9
|
+
export * from "./flow-input.js";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./types.js";
|
|
2
|
+
export * from "./lock.js";
|
|
3
|
+
export * from "./runs.js";
|
|
4
|
+
export * from "./directives.js";
|
|
5
|
+
export * from "./claims.js";
|
|
6
|
+
export * from "./notes.js";
|
|
7
|
+
export * from "./lane-status.js";
|
|
8
|
+
export * from "./run-flow.js";
|
|
9
|
+
export * from "./flow-input.js";
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/fleet/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type ActivityMarker, type LaneState } from "../activity.js";
|
|
2
|
+
import { type Failed } from "../query.js";
|
|
3
|
+
import type { DirectiveAction, DirectiveStatus } from "./types.js";
|
|
4
|
+
/**
|
|
5
|
+
* `laneStatus` — the single per-lane stall implementation (feature 025, US-5, batch B step 1). 019, 028 and
|
|
6
|
+
* 029 call it and keep no stall logic of their own. A lane is **stalled** when its state is `working` and
|
|
7
|
+
* neither a report nor a change to its `tasks.md` has happened for `fleet.stallMinutes` (default 15). The limit
|
|
8
|
+
* is the fleet's, independent of the dashboard's idle limit (FR-014). Waiting, blocked, paused and done lanes
|
|
9
|
+
* never stall: they are not supposed to be producing reports.
|
|
10
|
+
*/
|
|
11
|
+
export interface LaneStatus {
|
|
12
|
+
/** Short lane name `lane-p-k`. */
|
|
13
|
+
lane: string;
|
|
14
|
+
/** The lane's last reported state; `unreported` when it has not reported at all. */
|
|
15
|
+
state: LaneState | "unreported";
|
|
16
|
+
stalled: boolean;
|
|
17
|
+
/** ISO time of the lane's latest report. */
|
|
18
|
+
lastReportAt?: string;
|
|
19
|
+
/** Whole minutes since the later of the last report and the last `tasks.md` change; absent without either. */
|
|
20
|
+
idleMinutes?: number;
|
|
21
|
+
/** The stall limit in force, in minutes. */
|
|
22
|
+
stallMinutes: number;
|
|
23
|
+
directive: {
|
|
24
|
+
action: DirectiveAction;
|
|
25
|
+
status: DirectiveStatus;
|
|
26
|
+
};
|
|
27
|
+
run?: string;
|
|
28
|
+
}
|
|
29
|
+
/** The latest marker of a lane, looked for in the lane's own checkout, the given checkout and the primary one. */
|
|
30
|
+
export declare function latestLaneMarker(root: string, feature: string, lane: string): {
|
|
31
|
+
marker: ActivityMarker;
|
|
32
|
+
at: number;
|
|
33
|
+
} | null;
|
|
34
|
+
export declare function laneStatus(root: string, input: {
|
|
35
|
+
feature: string;
|
|
36
|
+
lane?: string;
|
|
37
|
+
run?: string;
|
|
38
|
+
now?: number;
|
|
39
|
+
}): LaneStatus | Failed;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { readMarkers, shortLane, tasksMtime } from "../activity.js";
|
|
3
|
+
import { primaryRoot } from "../checkouts.js";
|
|
4
|
+
import { fleetSettings, loadConfig } from "../config.js";
|
|
5
|
+
import { failed, laneRefs, resolveLane, isFailed } from "../query.js";
|
|
6
|
+
import { WORKTREES_DIR } from "../worktree.js";
|
|
7
|
+
import { directiveAction, directiveStatus, knownLanes, readDirective } from "./directives.js";
|
|
8
|
+
import { resolveRun } from "./runs.js";
|
|
9
|
+
/** The latest marker of a lane, looked for in the lane's own checkout, the given checkout and the primary one. */
|
|
10
|
+
export function latestLaneMarker(root, feature, lane) {
|
|
11
|
+
const short = shortLane(lane);
|
|
12
|
+
const roots = new Set([root, primaryRoot(root), ...laneRefs(root, feature).filter((l) => l.short === short).map((l) => l.root)]);
|
|
13
|
+
let best = null;
|
|
14
|
+
for (const r of roots) {
|
|
15
|
+
for (const m of readMarkers(r)) {
|
|
16
|
+
if (m.feature !== feature || !m.lane || shortLane(m.lane) !== short)
|
|
17
|
+
continue;
|
|
18
|
+
const at = Date.parse(m.at);
|
|
19
|
+
if (!best || at > best.at)
|
|
20
|
+
best = { marker: m, at };
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return best;
|
|
24
|
+
}
|
|
25
|
+
export function laneStatus(root, input) {
|
|
26
|
+
const now = input.now ?? Date.now();
|
|
27
|
+
const settings = fleetSettings(loadConfig(primaryRoot(root)));
|
|
28
|
+
const resolved = resolveLane(root, input.feature, input.lane);
|
|
29
|
+
if (isFailed(resolved)) {
|
|
30
|
+
// A lane with no checkout can still be a lane of the run (a worker not started yet): fall through when named.
|
|
31
|
+
if (!input.lane)
|
|
32
|
+
return resolved;
|
|
33
|
+
}
|
|
34
|
+
const lane = !isFailed(resolved) && resolved ? resolved.short : input.lane ? shortLane(input.lane.startsWith("lane-") || input.lane.includes(".lane-") ? input.lane : `lane-${input.lane}`) : null;
|
|
35
|
+
if (!lane)
|
|
36
|
+
return failed(`no lane given for ${input.feature} and this server is not running in a lane`);
|
|
37
|
+
const run = resolveRun(root, input.feature, input.run);
|
|
38
|
+
const known = knownLanes(root, input.feature, run.ok ? run.run.lanes : []);
|
|
39
|
+
const found = latestLaneMarker(root, input.feature, lane);
|
|
40
|
+
if (!known.includes(lane) && !found) {
|
|
41
|
+
return failed(`lane '${input.lane ?? lane}' not found for ${input.feature}${known.length ? `; lanes: ${known.join(", ")}` : "; it has no lanes"}`);
|
|
42
|
+
}
|
|
43
|
+
const laneRoot = join(primaryRoot(root), WORKTREES_DIR, `${input.feature}.${lane}`);
|
|
44
|
+
const touched = tasksMtime(laneRoot, input.feature);
|
|
45
|
+
const lastReport = found?.at ?? null;
|
|
46
|
+
const activity = Math.max(lastReport ?? 0, touched ?? 0, 0);
|
|
47
|
+
const state = found ? (found.marker.state ?? "working") : "unreported";
|
|
48
|
+
const idleMs = activity > 0 ? Math.max(0, now - Math.min(activity, now)) : null;
|
|
49
|
+
const stalled = state === "working" && idleMs !== null && idleMs > settings.stallMinutes * 60_000;
|
|
50
|
+
const directive = run.ok ? readDirective(root, run.run.run, lane) : null;
|
|
51
|
+
const status = directiveStatus(directive, found ? { at: found.marker.at, state: found.marker.state } : null);
|
|
52
|
+
return {
|
|
53
|
+
lane,
|
|
54
|
+
state,
|
|
55
|
+
stalled,
|
|
56
|
+
...(found ? { lastReportAt: found.marker.at } : {}),
|
|
57
|
+
...(idleMs !== null ? { idleMinutes: Math.floor(idleMs / 60_000) } : {}),
|
|
58
|
+
stallMinutes: settings.stallMinutes,
|
|
59
|
+
directive: { action: directiveAction(directive), status },
|
|
60
|
+
...(run.ok ? { run: run.run.run } : {}),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=lane-status.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lane-status.js","sourceRoot":"","sources":["../../../src/core/fleet/lane-status.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAuC,MAAM,gBAAgB,CAAC;AACzG,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAe,MAAM,aAAa,CAAC;AACnF,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC9F,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AA2BvC,kHAAkH;AAClH,MAAM,UAAU,gBAAgB,CAAC,IAAY,EAAE,OAAe,EAAE,IAAY;IAC1E,MAAM,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;IAC9B,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,EAAE,WAAW,CAAC,IAAI,CAAC,EAAE,GAAG,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,C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AC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACnD,GAAG,CAAC,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACxE,YAAY,EAAE,QAAQ,CAAC,YAAY;QACnC,SAAS,EAAE,EAAE,MAAM,EAAE,eAAe,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE;QACzD,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACxC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lockfiles and atomic writes (feature 025, data-model "Locks"). `.amby/locks/<name>.lock` is created
|
|
3
|
+
* exclusively with the owner's pid and time; a lock older than 30 s is stale and taken over. Callers
|
|
4
|
+
* retry briefly and then get a warning: a lock never hangs the agent (FR-012).
|
|
5
|
+
*/
|
|
6
|
+
export declare const LOCK_DIR: string;
|
|
7
|
+
export declare const STALE_LOCK_MS = 30000;
|
|
8
|
+
export type Locked<T> = {
|
|
9
|
+
ok: true;
|
|
10
|
+
value: T;
|
|
11
|
+
} | {
|
|
12
|
+
ok: false;
|
|
13
|
+
warning: string;
|
|
14
|
+
};
|
|
15
|
+
/** File-name-safe lock name for an arbitrary path or id. */
|
|
16
|
+
export declare function lockName(raw: string): string;
|
|
17
|
+
/** Run `fn` while holding `<root>/.amby/locks/<name>.lock`. */
|
|
18
|
+
export declare function withLock<T>(root: string, name: string, fn: () => T, opts?: {
|
|
19
|
+
waitMs?: number;
|
|
20
|
+
staleMs?: number;
|
|
21
|
+
}): Locked<T>;
|
|
22
|
+
/** Write to a temp file and rename it over `path`, so a reader never sees half a file. */
|
|
23
|
+
export declare function writeFileAtomic(path: string, data: string): void;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { closeSync, existsSync, mkdirSync, openSync, readFileSync, renameSync, rmSync, statSync, writeFileSync, writeSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
/**
|
|
4
|
+
* Lockfiles and atomic writes (feature 025, data-model "Locks"). `.amby/locks/<name>.lock` is created
|
|
5
|
+
* exclusively with the owner's pid and time; a lock older than 30 s is stale and taken over. Callers
|
|
6
|
+
* retry briefly and then get a warning: a lock never hangs the agent (FR-012).
|
|
7
|
+
*/
|
|
8
|
+
export const LOCK_DIR = join(".amby", "locks");
|
|
9
|
+
export const STALE_LOCK_MS = 30_000;
|
|
10
|
+
const RETRY_MS = 15;
|
|
11
|
+
const WAIT_MS = 2_000;
|
|
12
|
+
function sleep(ms) {
|
|
13
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
14
|
+
}
|
|
15
|
+
/** File-name-safe lock name for an arbitrary path or id. */
|
|
16
|
+
export function lockName(raw) {
|
|
17
|
+
return raw.replace(/[^a-z0-9._-]+/gi, "_").slice(-120) || "lock";
|
|
18
|
+
}
|
|
19
|
+
/** Run `fn` while holding `<root>/.amby/locks/<name>.lock`. */
|
|
20
|
+
export function withLock(root, name, fn, opts = {}) {
|
|
21
|
+
const dir = join(root, LOCK_DIR);
|
|
22
|
+
mkdirSync(dir, { recursive: true });
|
|
23
|
+
const ignore = join(dir, ".gitignore");
|
|
24
|
+
if (!existsSync(ignore)) {
|
|
25
|
+
try {
|
|
26
|
+
writeFileSync(ignore, "# AmbyKit lock files (local only)\n*\n", "utf8");
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
/* another writer won the race */
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const path = join(dir, `${lockName(name)}.lock`);
|
|
33
|
+
const deadline = Date.now() + (opts.waitMs ?? WAIT_MS);
|
|
34
|
+
const staleMs = opts.staleMs ?? STALE_LOCK_MS;
|
|
35
|
+
for (;;) {
|
|
36
|
+
try {
|
|
37
|
+
const fd = openSync(path, "wx");
|
|
38
|
+
try {
|
|
39
|
+
writeSync(fd, JSON.stringify({ pid: process.pid, at: new Date().toISOString() }));
|
|
40
|
+
}
|
|
41
|
+
finally {
|
|
42
|
+
closeSync(fd);
|
|
43
|
+
}
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
if (err.code !== "EEXIST")
|
|
48
|
+
return { ok: false, warning: `could not lock ${name}: ${err.message}` };
|
|
49
|
+
if (isStale(path, staleMs)) {
|
|
50
|
+
rmSync(path, { force: true });
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (Date.now() >= deadline)
|
|
54
|
+
return { ok: false, warning: `${name} is busy (locked by another writer); try again` };
|
|
55
|
+
sleep(RETRY_MS);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
return { ok: true, value: fn() };
|
|
60
|
+
}
|
|
61
|
+
finally {
|
|
62
|
+
rmSync(path, { force: true });
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function isStale(path, staleMs) {
|
|
66
|
+
try {
|
|
67
|
+
const body = JSON.parse(readFileSync(path, "utf8"));
|
|
68
|
+
const at = body.at ? Date.parse(body.at) : NaN;
|
|
69
|
+
if (!Number.isNaN(at))
|
|
70
|
+
return Date.now() - at > staleMs;
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
/* unreadable or half-written: fall through to the file's own age */
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
return Date.now() - statSync(path).mtimeMs > staleMs;
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
return false; // vanished: the next exclusive create decides
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/** Write to a temp file and rename it over `path`, so a reader never sees half a file. */
|
|
83
|
+
export function writeFileAtomic(path, data) {
|
|
84
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
85
|
+
const tmp = `${path}.${process.pid}.${Date.now().toString(36)}.tmp`;
|
|
86
|
+
writeFileSync(tmp, data, "utf8");
|
|
87
|
+
for (let attempt = 0;; attempt++) {
|
|
88
|
+
try {
|
|
89
|
+
renameSync(tmp, path);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
const code = err.code;
|
|
94
|
+
if (attempt < 5 && (code === "EPERM" || code === "EBUSY" || code === "EACCES")) {
|
|
95
|
+
sleep(10 * (attempt + 1)); // Windows: a reader may briefly hold the target
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
rmSync(tmp, { force: true });
|
|
99
|
+
throw err;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=lock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lock.js","sourceRoot":"","sources":["../../../src/core/fleet/lock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAC3I,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE1C;;;;GAIG;AAEH,MAAM,CAAC,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAC/C,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC;AACpC,MAAM,QAAQ,GAAG,EAAE,CAAC;AACpB,MAAM,OAAO,GAAG,KAAK,CAAC;AAItB,SAAS,KAAK,CAAC,EAAU;IACvB,OAAO,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,IAAI,iBAAiB,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC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Z,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The notes board (feature 025, US-4): `.amby/fleet/<run>/notes.log`, one line per note,
|
|
3
|
+
* `T### | <comma-separated files or -> | <text>`. This is the only notes file and format; a line that does
|
|
4
|
+
* not match is refused (FR-016). 019's `fleet note` wraps `postNote`.
|
|
5
|
+
*/
|
|
6
|
+
export interface Note {
|
|
7
|
+
task: string;
|
|
8
|
+
files: string[];
|
|
9
|
+
text: string;
|
|
10
|
+
}
|
|
11
|
+
export declare const NOTE_MAX_TEXT = 500;
|
|
12
|
+
export declare function notesPath(root: string, run: string): string;
|
|
13
|
+
/** One note as its line. */
|
|
14
|
+
export declare function formatNote(n: Note): string;
|
|
15
|
+
/** Parse one line; null when it is not in the form. */
|
|
16
|
+
export declare function parseNote(line: string): Note | null;
|
|
17
|
+
export type NoteResult = {
|
|
18
|
+
ok: true;
|
|
19
|
+
line: string;
|
|
20
|
+
} | {
|
|
21
|
+
ok: false;
|
|
22
|
+
error: string;
|
|
23
|
+
};
|
|
24
|
+
/** Validate and append one note. Refuses a missing or malformed task id, empty text and any newline. */
|
|
25
|
+
export declare function postNote(root: string, run: string, input: {
|
|
26
|
+
task: string;
|
|
27
|
+
files: string[];
|
|
28
|
+
text: string;
|
|
29
|
+
}): NoteResult;
|
|
30
|
+
/** Every well-formed note, oldest first; malformed lines are ignored. */
|
|
31
|
+
export declare function readNotes(root: string, run: string): Note[];
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { appendFileSync, existsSync, mkdirSync, readFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { withLock } from "./lock.js";
|
|
4
|
+
import { runDir } from "./runs.js";
|
|
5
|
+
export const NOTE_MAX_TEXT = 500;
|
|
6
|
+
const TASK = /^T\d+$/;
|
|
7
|
+
export function notesPath(root, run) {
|
|
8
|
+
return join(runDir(root, run), "notes.log");
|
|
9
|
+
}
|
|
10
|
+
/** One note as its line. */
|
|
11
|
+
export function formatNote(n) {
|
|
12
|
+
return `${n.task} | ${n.files.length ? n.files.join(", ") : "-"} | ${n.text}`;
|
|
13
|
+
}
|
|
14
|
+
/** Parse one line; null when it is not in the form. */
|
|
15
|
+
export function parseNote(line) {
|
|
16
|
+
const m = /^(T\d+) \| ([^|\n]+?) \| (.+)$/.exec(line);
|
|
17
|
+
if (!m)
|
|
18
|
+
return null;
|
|
19
|
+
const files = m[2] === "-" ? [] : m[2].split(",").map((f) => f.trim());
|
|
20
|
+
if (files.some((f) => f === ""))
|
|
21
|
+
return null;
|
|
22
|
+
return { task: m[1], files, text: m[3] };
|
|
23
|
+
}
|
|
24
|
+
/** Validate and append one note. Refuses a missing or malformed task id, empty text and any newline. */
|
|
25
|
+
export function postNote(root, run, input) {
|
|
26
|
+
if (!TASK.test(input.task))
|
|
27
|
+
return { ok: false, error: `a note needs a task id like T012, got '${input.task}'` };
|
|
28
|
+
const text = input.text;
|
|
29
|
+
if (/[\r\n]/.test(text) || input.files.some((f) => /[\r\n|,]/.test(f)))
|
|
30
|
+
return { ok: false, error: "a note is one line: no newline in the text, and no newline, comma or | in a file name" };
|
|
31
|
+
if (text.trim() === "")
|
|
32
|
+
return { ok: false, error: "a note needs some text" };
|
|
33
|
+
if (text.length > NOTE_MAX_TEXT)
|
|
34
|
+
return { ok: false, error: `a note is at most ${NOTE_MAX_TEXT} characters (got ${text.length})` };
|
|
35
|
+
const files = input.files.map((f) => f.trim()).filter(Boolean);
|
|
36
|
+
const line = formatNote({ task: input.task, files, text: text.trim() });
|
|
37
|
+
if (!parseNote(line))
|
|
38
|
+
return { ok: false, error: "that note is not in the form `T### | files | text`" };
|
|
39
|
+
const path = notesPath(root, run);
|
|
40
|
+
const locked = withLock(root, `notes-${run}`, () => {
|
|
41
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
42
|
+
appendFileSync(path, line + "\n", "utf8");
|
|
43
|
+
});
|
|
44
|
+
return locked.ok ? { ok: true, line } : { ok: false, error: locked.warning };
|
|
45
|
+
}
|
|
46
|
+
/** Every well-formed note, oldest first; malformed lines are ignored. */
|
|
47
|
+
export function readNotes(root, run) {
|
|
48
|
+
const path = notesPath(root, run);
|
|
49
|
+
if (!existsSync(path))
|
|
50
|
+
return [];
|
|
51
|
+
return readFileSync(path, "utf8")
|
|
52
|
+
.split(/\r?\n/)
|
|
53
|
+
.map(parseNote)
|
|
54
|
+
.filter((n) => n !== null);
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=notes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notes.js","sourceRoot":"","sources":["../../../src/core/fleet/notes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC9E,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAcnC,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,CAAC;AACjC,MAAM,IAAI,GAAG,QAAQ,CAAC;AAEtB,MAAM,UAAU,SAAS,CAAC,IAAY,EAAE,GAAW;IACjD,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,WAAW,CAAC,CAAC;AAC9C,CAAC;AAED,4BAA4B;AAC5B,MAAM,UAAU,UAAU,CAAC,CAAO;IAChC,OAAO,GAAG,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;AAChF,CAAC;AAED,uDAAuD;AACvD,MAAM,UAAU,SAAS,CA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