@incremental/watcher 0.0.0-stage → 0.1.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/README.md +32 -2
- package/dist/src/index.d.ts +6 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +5 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/run.d.ts +18 -0
- package/dist/src/run.d.ts.map +1 -0
- package/dist/src/run.js +181 -0
- package/dist/src/run.js.map +1 -0
- package/dist/src/session.d.ts +58 -0
- package/dist/src/session.d.ts.map +1 -0
- package/dist/src/session.js +259 -0
- package/dist/src/session.js.map +1 -0
- package/dist/src/watch.d.ts +36 -0
- package/dist/src/watch.d.ts.map +1 -0
- package/dist/src/watch.js +180 -0
- package/dist/src/watch.js.map +1 -0
- package/dist/tests/watcher.test.d.ts +2 -0
- package/dist/tests/watcher.test.d.ts.map +1 -0
- package/dist/tests/watcher.test.js +246 -0
- package/dist/tests/watcher.test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +23 -4
- package/src/index.ts +6 -0
- package/src/run.ts +179 -0
- package/src/session.ts +336 -0
- package/src/watch.ts +215 -0
- package/tests/watcher.test.ts +269 -0
- package/tsconfig.json +8 -0
package/README.md
CHANGED
|
@@ -1,3 +1,33 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @frontal-labs/incremental-watcher
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The file-system change source (draft: `spec/adapters/watcher.md`). It turns events under the repository into a ChangeSet since the stored baseline, runs `affected`, runs the selected tasks, and advances only from a complete history. It is a change source, not a recorder, and it never sets the first baseline.
|
|
4
|
+
|
|
5
|
+
## Use
|
|
6
|
+
|
|
7
|
+
incremental-watcher watch --tasks tasks.json [--interval MS] [--cycles N] [--json] [--store DIR] [--root DIR] [--timeout MS]
|
|
8
|
+
|
|
9
|
+
`tasks.json` is a JSON array of `{ "id", "command": [argv...], "inputs": [repo-relative files or directories] }`. Exit codes: 0 every run passed; 1 a task failed; 2 usage or config error; 4 engine or setup error.
|
|
10
|
+
|
|
11
|
+
## How a cycle works
|
|
12
|
+
|
|
13
|
+
1. A session starts a watch window. The window is complete only if the tree equalled the stored baseline B when it started (checked with `incremental-git`). Otherwise the session has no history and the first cycles run everything.
|
|
14
|
+
2. Each cycle: the changes since B (classified against the window's start snapshot) go to `affected`. Plan fallbacks, lost windows and the first cycle of a session run every task.
|
|
15
|
+
3. Selected tasks run, and each is observed with its declared file inputs (hashed). An observation is clean only if the tree is clean at HEAD, the window was complete and no event arrived during the run.
|
|
16
|
+
4. The store advances to HEAD only when all of that holds, the tree is clean and HEAD did not move. Otherwise it does not advance.
|
|
17
|
+
|
|
18
|
+
## Gaps (documented, not hidden)
|
|
19
|
+
|
|
20
|
+
- **Task definitions.** The draft says the watcher has no task. The loop needs tasks to observe, so they come from `tasks.json`. This is a deviation from the draft.
|
|
21
|
+
- **Silent drops are safe.** macOS FSEvents can coalesce or lose events without telling Node. The watcher never reads its changes from events. Events only wake the caller. `state` walks the tree and compares each file's stat with the snapshot taken when the window opened. A file whose mtime is within two seconds of the snapshot (the racy case) is hashed at snapshot time and compared by content. So a dropped event delays a run; it cannot hide a change. The test `an edit with no event delivered is still reported` checks this with no watch open. Recursive `fs.watch` was verified on darwin only.
|
|
22
|
+
- **Cost.** Each check walks the whole tree, linear in the file count: about 10 ms per thousand entries on this machine (measured on this repository). Directory mtimes cannot replace the walk, because an edit changes only its file's mtime. The watch loop therefore waits at least ten times the last walk (`--interval` is a minimum), so the check never takes more than about a tenth of the time.
|
|
23
|
+
- **Baseline.** A window starts only on a tree equal to the stored baseline. Uncommitted edits or a commit made while no watcher ran leave the session without history, so cycles run everything until another adapter (typescript, vitest) advances the store to a clean HEAD.
|
|
24
|
+
- **Git still runs.** The ChangeSet itself comes from events, but the baseline check and the advance use the git change source every cycle. The draft's "without running git" applies only to the ChangeSet.
|
|
25
|
+
- **Ignored directories.** `node_modules`, `.git`, `dist`, `.incremental` and `.toolchain` are never watched. A task input under them is refused with a config error.
|
|
26
|
+
- **Coarse plans.** Context caps are all false, so in balanced mode a change to a path that is not a task input falls back (P6 or P7). This is sound and coarse.
|
|
27
|
+
- **Renames** are reported as `deleted` plus `added` (no `old_path`). Symbolic links are a loss.
|
|
28
|
+
- **Cost.** Each window start walks the whole tree.
|
|
29
|
+
- **Context.** The reserved context keys are constants. The runner is `incremental-watcher@<version>`.
|
|
30
|
+
|
|
31
|
+
## Tests
|
|
32
|
+
|
|
33
|
+
`npm test` builds the client, runs `tsc -b`, and runs `node --test` on the integration tests in `test/watcher.test.ts`. The tests use a scratch git repository and the real engine.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { Watcher, walk, SKIP_DIRS } from "./watch.js";
|
|
2
|
+
export type { WatchState } from "./watch.js";
|
|
3
|
+
export { ConfigError, contextFor, inputsOf, runTask, Session } from "./session.js";
|
|
4
|
+
export type { CycleReport, SessionOptions, TaskDef, TaskRun } from "./session.js";
|
|
5
|
+
export { loadTasks, parseArgs, UsageError } from "./run.js";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACtD,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACnF,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAClF,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// @incremental/watcher: the file-system change source (spec/adapters/watcher.md).
|
|
2
|
+
export { Watcher, walk, SKIP_DIRS } from "./watch.js";
|
|
3
|
+
export { ConfigError, contextFor, inputsOf, runTask, Session } from "./session.js";
|
|
4
|
+
export { loadTasks, parseArgs, UsageError } from "./run.js";
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEtD,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEnF,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { type TaskDef } from "./session.js";
|
|
3
|
+
export interface WatchOptions {
|
|
4
|
+
root: string;
|
|
5
|
+
store: string;
|
|
6
|
+
tasks: TaskDef[];
|
|
7
|
+
intervalMs: number;
|
|
8
|
+
cycles: number;
|
|
9
|
+
timeoutMs: number;
|
|
10
|
+
json: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare class UsageError extends Error {
|
|
13
|
+
constructor(message: string);
|
|
14
|
+
}
|
|
15
|
+
export declare function loadTasks(file: string): TaskDef[];
|
|
16
|
+
export declare function parseArgs(argv: string[]): WatchOptions;
|
|
17
|
+
export declare function main(argv: string[]): Promise<number>;
|
|
18
|
+
//# sourceMappingURL=run.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.d.ts","sources":["../../src/run.ts"],"names":[],"mappings":";AAUA,OAAO,EAA0C,KAAK,OAAO,EAAE,MAAM,cAAc,CAAC;AAEpF,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,OAAO,EAAE,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,OAAO,CAAC;CACf;AAED,qBAAa,UAAW,SAAQ,KAAK;IACnC,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,EAAE,CA6BjD;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,YAAY,CAsDtD;AAoBD,wBAAsB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAsC1D"}
|
package/dist/src/run.js
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// `incremental-watcher watch`: the watcher loop. Runs a cycle every --interval
|
|
3
|
+
// milliseconds (default 1000), --cycles times (default: until interrupted).
|
|
4
|
+
//
|
|
5
|
+
// Exit codes: 0 every run task passed; 1 a task failed; 2 usage error; 4 engine or setup error.
|
|
6
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import { pathToFileURL } from "node:url";
|
|
9
|
+
import { spawnSync } from "node:child_process";
|
|
10
|
+
import { defaultEngine } from "@incremental/client";
|
|
11
|
+
import { ConfigError, Session } from "./session.js";
|
|
12
|
+
export class UsageError extends Error {
|
|
13
|
+
constructor(message) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.name = "UsageError";
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export function loadTasks(file) {
|
|
19
|
+
if (!existsSync(file))
|
|
20
|
+
throw new UsageError(`no task file at ${file}`);
|
|
21
|
+
let raw;
|
|
22
|
+
try {
|
|
23
|
+
raw = JSON.parse(readFileSync(file, "utf8"));
|
|
24
|
+
}
|
|
25
|
+
catch (e) {
|
|
26
|
+
throw new UsageError(`cannot parse ${file}: ${e instanceof Error ? e.message : String(e)}`);
|
|
27
|
+
}
|
|
28
|
+
if (!Array.isArray(raw))
|
|
29
|
+
throw new UsageError(`${file} must hold a JSON array of tasks`);
|
|
30
|
+
const ids = new Set();
|
|
31
|
+
return raw.map((t, i) => {
|
|
32
|
+
const o = t;
|
|
33
|
+
const strings = (v) => Array.isArray(v) && v.every((x) => typeof x === "string");
|
|
34
|
+
if (typeof o.id !== "string" ||
|
|
35
|
+
o.id === "" ||
|
|
36
|
+
!strings(o.command) ||
|
|
37
|
+
o.command.length === 0 ||
|
|
38
|
+
!strings(o.inputs)) {
|
|
39
|
+
throw new UsageError(`task ${i} needs id, command (non-empty string array) and inputs (string array)`);
|
|
40
|
+
}
|
|
41
|
+
if (ids.has(o.id))
|
|
42
|
+
throw new UsageError(`duplicate task id ${o.id}`);
|
|
43
|
+
ids.add(o.id);
|
|
44
|
+
return { id: o.id, command: o.command, inputs: o.inputs };
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
export function parseArgs(argv) {
|
|
48
|
+
const [cmd, ...rest] = argv;
|
|
49
|
+
const usage = "usage: incremental-watcher watch --tasks FILE [--interval MS] [--cycles N] [--json] [--store DIR] [--root DIR] [--timeout MS]";
|
|
50
|
+
if (cmd !== "watch")
|
|
51
|
+
throw new UsageError(usage);
|
|
52
|
+
const opts = {
|
|
53
|
+
root: process.cwd(),
|
|
54
|
+
store: "",
|
|
55
|
+
tasks: [],
|
|
56
|
+
intervalMs: 1000,
|
|
57
|
+
cycles: 0,
|
|
58
|
+
timeoutMs: 600_000,
|
|
59
|
+
json: false,
|
|
60
|
+
};
|
|
61
|
+
let tasksFile = null;
|
|
62
|
+
let storeGiven = false;
|
|
63
|
+
for (let i = 0; i < rest.length; i++) {
|
|
64
|
+
const a = rest[i];
|
|
65
|
+
const value = () => {
|
|
66
|
+
const v = rest[++i];
|
|
67
|
+
if (v === undefined)
|
|
68
|
+
throw new UsageError(`${a} needs a value`);
|
|
69
|
+
return v;
|
|
70
|
+
};
|
|
71
|
+
const int = (min) => {
|
|
72
|
+
const n = Number(value());
|
|
73
|
+
if (!Number.isInteger(n) || n < min)
|
|
74
|
+
throw new UsageError(`${a} needs an integer >= ${min}`);
|
|
75
|
+
return n;
|
|
76
|
+
};
|
|
77
|
+
if (a === "--tasks") {
|
|
78
|
+
tasksFile = value();
|
|
79
|
+
}
|
|
80
|
+
else if (a === "--interval") {
|
|
81
|
+
opts.intervalMs = int(0);
|
|
82
|
+
}
|
|
83
|
+
else if (a === "--cycles") {
|
|
84
|
+
opts.cycles = int(0);
|
|
85
|
+
}
|
|
86
|
+
else if (a === "--timeout") {
|
|
87
|
+
opts.timeoutMs = int(1);
|
|
88
|
+
}
|
|
89
|
+
else if (a === "--json") {
|
|
90
|
+
opts.json = true;
|
|
91
|
+
}
|
|
92
|
+
else if (a === "--store") {
|
|
93
|
+
opts.store = value();
|
|
94
|
+
storeGiven = true;
|
|
95
|
+
}
|
|
96
|
+
else if (a === "--root") {
|
|
97
|
+
opts.root = value();
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
throw new UsageError(`unknown option ${a}`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (tasksFile === null)
|
|
104
|
+
throw new UsageError(usage);
|
|
105
|
+
opts.root = path.resolve(opts.root);
|
|
106
|
+
if (!storeGiven)
|
|
107
|
+
opts.store = process.env.INCREMENTAL_STORE || path.join(opts.root, ".incremental");
|
|
108
|
+
opts.store = path.resolve(opts.store);
|
|
109
|
+
opts.tasks = loadTasks(path.resolve(tasksFile));
|
|
110
|
+
return opts;
|
|
111
|
+
}
|
|
112
|
+
function ensureStore(store) {
|
|
113
|
+
if (existsSync(store))
|
|
114
|
+
return;
|
|
115
|
+
const r = spawnSync(defaultEngine(), ["init", "--store", store], { encoding: "utf8" });
|
|
116
|
+
if (r.status !== 0)
|
|
117
|
+
throw new UsageError(`cannot create the store at ${store}: ${(r.stderr || "").trim()}`);
|
|
118
|
+
}
|
|
119
|
+
function describe(n, r) {
|
|
120
|
+
const counts = { pass: 0, fail: 0, error: 0 };
|
|
121
|
+
for (const t of r.results)
|
|
122
|
+
counts[t.outcome] = (counts[t.outcome] ?? 0) + 1;
|
|
123
|
+
const why = r.reason === null ? "" : ` (${r.reason})`;
|
|
124
|
+
return [
|
|
125
|
+
`cycle ${n}: ${r.mode}${why}, stored ${r.stored ?? "none"}, changes ${r.changes.length}`,
|
|
126
|
+
` selected [${r.selected.join(", ")}]: pass ${counts.pass}, fail ${counts.fail}, error ${counts.error}`,
|
|
127
|
+
` ${r.advanced ? `advanced to ${r.headEnd}` : "not advanced"}`,
|
|
128
|
+
].join("\n");
|
|
129
|
+
}
|
|
130
|
+
export async function main(argv) {
|
|
131
|
+
let opts;
|
|
132
|
+
try {
|
|
133
|
+
opts = parseArgs(argv);
|
|
134
|
+
}
|
|
135
|
+
catch (e) {
|
|
136
|
+
process.stderr.write(`${e instanceof Error ? e.message : String(e)}\n`);
|
|
137
|
+
return 2;
|
|
138
|
+
}
|
|
139
|
+
let code = 0;
|
|
140
|
+
let session = null;
|
|
141
|
+
try {
|
|
142
|
+
ensureStore(opts.store);
|
|
143
|
+
session = new Session({
|
|
144
|
+
root: opts.root,
|
|
145
|
+
store: opts.store,
|
|
146
|
+
tasks: opts.tasks,
|
|
147
|
+
timeoutMs: opts.timeoutMs,
|
|
148
|
+
});
|
|
149
|
+
await session.open();
|
|
150
|
+
for (let n = 1; opts.cycles === 0 || n <= opts.cycles; n++) {
|
|
151
|
+
const report = await session.cycle();
|
|
152
|
+
if (opts.json)
|
|
153
|
+
process.stdout.write(JSON.stringify(report) + "\n");
|
|
154
|
+
else
|
|
155
|
+
process.stdout.write(describe(n, report) + "\n");
|
|
156
|
+
if (report.results.some((t) => t.outcome === "fail"))
|
|
157
|
+
code = 1;
|
|
158
|
+
// Each cycle walks the whole tree, so the wait is at least ten times that
|
|
159
|
+
// walk: the check never takes more than about a tenth of the time, however
|
|
160
|
+
// large the repository. The interval is a minimum, not a fixed rate.
|
|
161
|
+
const wait = Math.max(opts.intervalMs, 10 * session.lastCheckMs());
|
|
162
|
+
if (opts.cycles === 0 || n < opts.cycles)
|
|
163
|
+
await new Promise((res) => setTimeout(res, wait));
|
|
164
|
+
}
|
|
165
|
+
return code;
|
|
166
|
+
}
|
|
167
|
+
catch (e) {
|
|
168
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
169
|
+
process.stderr.write(`incremental watcher: ${message}\n`);
|
|
170
|
+
return e instanceof ConfigError || e instanceof UsageError ? 2 : 4;
|
|
171
|
+
}
|
|
172
|
+
finally {
|
|
173
|
+
await session?.close();
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (process.argv[1] !== undefined && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
177
|
+
main(process.argv.slice(2)).then((code) => {
|
|
178
|
+
process.exitCode = code;
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
//# sourceMappingURL=run.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.js","sources":["../../src/run.ts"],"names":[],"mappings":";AACA,+EAA+E;AAC/E,4EAA4E;AAC5E,EAAE;AACF,gGAAgG;AAChG,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAoB,WAAW,EAAE,OAAO,EAAgB,MAAM,cAAc,CAAC;AAYpF,MAAM,OAAO,UAAW,SAAQ,KAAK;IACnC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;IAC3B,C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CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAC3D,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,wBAAwB,OAAO,IAAI,CAAC,CAAC;QAC1D,OAAO,CAAC,YAAY,WAAW,IAAI,CAAC,YAAY,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACrE,CAAC;YAAS,CAAC;QACT,MAAM,OAAO,EAAE,KAAK,EAAE,CAAC;IACzB,CAAC;AACH,CAAC;AAED,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,SAAS,IAAI,OAAO,IAAI,CAAC,GAAG,KAAK,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAC7F,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE;QACxC,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;IAC1B,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { type Change, type Context, type Input, type Outcome, type Plan } from "@incremental/client";
|
|
2
|
+
export declare class ConfigError extends Error {
|
|
3
|
+
constructor(message: string);
|
|
4
|
+
}
|
|
5
|
+
export interface TaskDef {
|
|
6
|
+
id: string;
|
|
7
|
+
command: string[];
|
|
8
|
+
inputs: string[];
|
|
9
|
+
}
|
|
10
|
+
export interface SessionOptions {
|
|
11
|
+
root: string;
|
|
12
|
+
store: string;
|
|
13
|
+
tasks: TaskDef[];
|
|
14
|
+
timeoutMs: number;
|
|
15
|
+
}
|
|
16
|
+
export interface TaskRun {
|
|
17
|
+
task: string;
|
|
18
|
+
outcome: Outcome;
|
|
19
|
+
durationMs: number;
|
|
20
|
+
}
|
|
21
|
+
export interface CycleReport {
|
|
22
|
+
mode: "full" | "incremental";
|
|
23
|
+
reason: string | null;
|
|
24
|
+
stored: string | null;
|
|
25
|
+
changes: Change[];
|
|
26
|
+
plan: Plan | null;
|
|
27
|
+
selected: string[];
|
|
28
|
+
results: TaskRun[];
|
|
29
|
+
advanced: boolean;
|
|
30
|
+
headEnd: string;
|
|
31
|
+
}
|
|
32
|
+
export declare function contextFor(): Context;
|
|
33
|
+
type FileInput = Extract<Input, {
|
|
34
|
+
kind: "file";
|
|
35
|
+
}>;
|
|
36
|
+
export declare function inputsOf(root: string, task: TaskDef): FileInput[];
|
|
37
|
+
export declare class Session {
|
|
38
|
+
private readonly opts;
|
|
39
|
+
private client;
|
|
40
|
+
private readonly watcher;
|
|
41
|
+
private base;
|
|
42
|
+
private first;
|
|
43
|
+
constructor(opts: SessionOptions);
|
|
44
|
+
open(): Promise<void>;
|
|
45
|
+
close(): Promise<void>;
|
|
46
|
+
lastCheckMs(): number;
|
|
47
|
+
pending(): number;
|
|
48
|
+
reportLoss(reason: string): void;
|
|
49
|
+
private arm;
|
|
50
|
+
private need;
|
|
51
|
+
cycle(): Promise<CycleReport>;
|
|
52
|
+
}
|
|
53
|
+
export declare function runTask(root: string, task: TaskDef, timeoutMs: number): {
|
|
54
|
+
outcome: Outcome;
|
|
55
|
+
durationMs: number;
|
|
56
|
+
};
|
|
57
|
+
export {};
|
|
58
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.d.ts","sources":["../../src/session.ts"],"names":[],"mappings":"AAUA,OAAO,EAKL,KAAK,MAAM,EACX,KAAK,OAAO,EACZ,KAAK,KAAK,EAEV,KAAK,OAAO,EACZ,KAAK,IAAI,EACV,MAAM,qBAAqB,CAAC;AAG7B,qBAAa,WAAY,SAAQ,KAAK;IACpC,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AAID,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB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I,CAAC,CAI3B;IAGD,WAAW,IAAI,MAAM,CAEpB;IAID,OAAO,IAAI,MAAM,CAEhB;IAID,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAE/B;YAIa,GAAG;IAcjB,OAAO,CAAC,IAAI;IAON,KAAK,IAAI,OAAO,CAAC,WAAW,CAAC,CA6FlC;CACF;AAID,wBAAgB,OAAO,CACrB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,OAAO,EACb,SAAS,EAAE,MAAM,GAChB;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAa1C"}
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
// The watcher loop (spec/adapters/watcher.md). A session holds the event history
|
|
2
|
+
// since a store baseline B and turns it into a ChangeSet for `affected`. It mirrors
|
|
3
|
+
// the typescript run loop (PLAN 10.4) for observe and advance, with one difference:
|
|
4
|
+
// the history is only complete if the watch was running and the tree equalled B
|
|
5
|
+
// when it started, so the session advances only from a complete history.
|
|
6
|
+
import { spawnSync } from "node:child_process";
|
|
7
|
+
import { createHash } from "node:crypto";
|
|
8
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
9
|
+
import { createRequire } from "node:module";
|
|
10
|
+
import path from "node:path";
|
|
11
|
+
import { connect, defaultEngine, repoRoot, } from "@incremental/client";
|
|
12
|
+
import { relOf, SKIP_DIRS, Watcher, walk } from "./watch.js";
|
|
13
|
+
export class ConfigError extends Error {
|
|
14
|
+
constructor(message) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.name = "ConfigError";
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const require_ = createRequire(import.meta.url);
|
|
20
|
+
const WATCHER_RUNNER = `incremental-watcher@${require_("../../package.json").version}`;
|
|
21
|
+
function gitSourcePath() {
|
|
22
|
+
return (process.env.INCREMENTAL_GIT ||
|
|
23
|
+
path.join(repoRoot(), "adapters", "git", "dist", "incremental-git"));
|
|
24
|
+
}
|
|
25
|
+
function gitChangeSet(root, ref) {
|
|
26
|
+
const r = spawnSync(gitSourcePath(), ["changes", "--base", ref, "--root", root], {
|
|
27
|
+
encoding: "utf8",
|
|
28
|
+
});
|
|
29
|
+
if (r.error !== undefined)
|
|
30
|
+
throw new Error(`cannot run the git change source: ${r.error.message}`);
|
|
31
|
+
if (r.status !== 0)
|
|
32
|
+
throw new Error(`git change source failed (exit ${r.status}): ${(r.stdout || r.stderr || "").trim()}`);
|
|
33
|
+
return JSON.parse(r.stdout);
|
|
34
|
+
}
|
|
35
|
+
// The context (PLAN 8.4). The watcher observes no tool, lockfile or probe, so the
|
|
36
|
+
// reserved keys are constant and caps are all false. In balanced mode that makes
|
|
37
|
+
// any change to a path that is not a task input a fallback (P6, P7), which is sound.
|
|
38
|
+
export function contextFor() {
|
|
39
|
+
return {
|
|
40
|
+
lockfile: "absent",
|
|
41
|
+
tsconfig: "absent",
|
|
42
|
+
pkgjson: "absent",
|
|
43
|
+
runner: WATCHER_RUNNER,
|
|
44
|
+
node: process.version,
|
|
45
|
+
fmt: 1,
|
|
46
|
+
caps: { probes: false, dirs: false, env: false },
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function sha256(data) {
|
|
50
|
+
return createHash("sha256").update(data).digest("hex");
|
|
51
|
+
}
|
|
52
|
+
// The file inputs of a task: each declared path, directories expanded. Missing
|
|
53
|
+
// paths contribute nothing (a later creation is an added path, which falls back).
|
|
54
|
+
export function inputsOf(root, task) {
|
|
55
|
+
const files = new Map();
|
|
56
|
+
for (const entry of task.inputs) {
|
|
57
|
+
const abs = path.resolve(root, entry);
|
|
58
|
+
const rel = relOf(root, abs);
|
|
59
|
+
if (rel === "" || rel.startsWith("..") || path.isAbsolute(rel)) {
|
|
60
|
+
throw new ConfigError(`task ${task.id}: input ${entry} is outside the repository`);
|
|
61
|
+
}
|
|
62
|
+
if (rel.split("/").some((s) => SKIP_DIRS.has(s))) {
|
|
63
|
+
throw new ConfigError(`task ${task.id}: input ${entry} is under an ignored directory`);
|
|
64
|
+
}
|
|
65
|
+
if (existsSync(abs)) {
|
|
66
|
+
const st = statSync(abs);
|
|
67
|
+
const kinds = st.isDirectory()
|
|
68
|
+
? walk(root, abs)
|
|
69
|
+
: new Map([[rel, "file"]]);
|
|
70
|
+
for (const [child, kind] of kinds) {
|
|
71
|
+
if (kind === "file") {
|
|
72
|
+
files.set(child, {
|
|
73
|
+
kind: "file",
|
|
74
|
+
path: child,
|
|
75
|
+
hash: sha256(readFileSync(path.join(root, child))),
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return [...files.values()].sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
|
|
82
|
+
}
|
|
83
|
+
export class Session {
|
|
84
|
+
opts;
|
|
85
|
+
client = null;
|
|
86
|
+
watcher;
|
|
87
|
+
// The baseline the event history is complete since, or null.
|
|
88
|
+
base = null;
|
|
89
|
+
// The first cycle of a session runs everything: a restart has no history.
|
|
90
|
+
first = true;
|
|
91
|
+
constructor(opts) {
|
|
92
|
+
this.opts = opts;
|
|
93
|
+
this.watcher = new Watcher(opts.root);
|
|
94
|
+
}
|
|
95
|
+
// Connects to the store and opens a watch window against the stored baseline.
|
|
96
|
+
async open() {
|
|
97
|
+
this.client = await connect({
|
|
98
|
+
store: this.opts.store,
|
|
99
|
+
root: this.opts.root,
|
|
100
|
+
command: [defaultEngine(), "serve"],
|
|
101
|
+
timeoutMs: 60_000,
|
|
102
|
+
});
|
|
103
|
+
await this.arm();
|
|
104
|
+
}
|
|
105
|
+
async close() {
|
|
106
|
+
this.watcher.stop();
|
|
107
|
+
await this.client?.close();
|
|
108
|
+
this.client = null;
|
|
109
|
+
}
|
|
110
|
+
// Duration of the last full check of the tree, in milliseconds.
|
|
111
|
+
lastCheckMs() {
|
|
112
|
+
return this.watcher.lastWalkMs;
|
|
113
|
+
}
|
|
114
|
+
// Events the watcher has recorded since the window started, for callers that
|
|
115
|
+
// want to know whether a cycle has work to do.
|
|
116
|
+
pending() {
|
|
117
|
+
return this.watcher.state().changes.length;
|
|
118
|
+
}
|
|
119
|
+
// Reports an event loss from outside the watcher (for example a dropped
|
|
120
|
+
// notification). The next cycle runs everything.
|
|
121
|
+
reportLoss(reason) {
|
|
122
|
+
this.watcher.loss(reason);
|
|
123
|
+
}
|
|
124
|
+
// Starts a new window. The history is complete only if the tree equalled the
|
|
125
|
+
// stored baseline when the window started, and the window is then the baseline.
|
|
126
|
+
async arm() {
|
|
127
|
+
this.watcher.start();
|
|
128
|
+
const stored = (await this.need().baseline()).baseline;
|
|
129
|
+
this.base = null;
|
|
130
|
+
if (stored === null)
|
|
131
|
+
return;
|
|
132
|
+
let cs;
|
|
133
|
+
try {
|
|
134
|
+
cs = gitChangeSet(this.opts.root, stored);
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (cs.baseline === stored && cs.changes.length === 0 && !cs.dirty)
|
|
140
|
+
this.base = stored;
|
|
141
|
+
}
|
|
142
|
+
need() {
|
|
143
|
+
if (this.client === null)
|
|
144
|
+
throw new Error("the session is not open");
|
|
145
|
+
return this.client;
|
|
146
|
+
}
|
|
147
|
+
// One cycle: the ChangeSet since the stored baseline, `affected`, the selected
|
|
148
|
+
// tasks run and observed, then advance if the history was complete.
|
|
149
|
+
async cycle() {
|
|
150
|
+
const client = this.need();
|
|
151
|
+
const { root } = this.opts;
|
|
152
|
+
const stored = (await client.baseline()).baseline;
|
|
153
|
+
const startHead = gitChangeSet(root, "HEAD").head;
|
|
154
|
+
const gen = this.watcher.generation;
|
|
155
|
+
const state = this.watcher.state();
|
|
156
|
+
const complete = this.base !== null && this.base === stored && state.lost === null;
|
|
157
|
+
let reason = null;
|
|
158
|
+
if (this.first)
|
|
159
|
+
reason = "no_history";
|
|
160
|
+
else if (this.base === null)
|
|
161
|
+
reason = "not_watching_since_baseline";
|
|
162
|
+
else if (this.base !== stored)
|
|
163
|
+
reason = "baseline_moved";
|
|
164
|
+
else if (state.lost !== null)
|
|
165
|
+
reason = `watcher_lost: ${state.lost}`;
|
|
166
|
+
let plan = null;
|
|
167
|
+
if (reason === null && stored !== null) {
|
|
168
|
+
plan = await client.affected({ baseline: stored, changes: state.changes }, {
|
|
169
|
+
baseline: stored,
|
|
170
|
+
context: contextFor(),
|
|
171
|
+
declared_tasks: this.opts.tasks.map((t) => t.id),
|
|
172
|
+
verify: false,
|
|
173
|
+
policy: "balanced",
|
|
174
|
+
});
|
|
175
|
+
if (plan.fallback !== null)
|
|
176
|
+
reason = `${plan.fallback.reason}`;
|
|
177
|
+
const declared = new Set(this.opts.tasks.map((t) => t.id));
|
|
178
|
+
if (reason === null && plan.tasks.some((t) => !declared.has(t.id)))
|
|
179
|
+
reason = "plan_unknown_task";
|
|
180
|
+
}
|
|
181
|
+
const full = reason !== null || stored === null;
|
|
182
|
+
const selectedIds = full
|
|
183
|
+
? this.opts.tasks.map((t) => t.id)
|
|
184
|
+
: (plan?.tasks ?? []).map((t) => t.id);
|
|
185
|
+
const selected = this.opts.tasks.filter((t) => selectedIds.includes(t.id));
|
|
186
|
+
const results = [];
|
|
187
|
+
const observations = [];
|
|
188
|
+
const obsBaseline = stored ?? startHead;
|
|
189
|
+
for (const task of selected) {
|
|
190
|
+
const inputs = inputsOf(root, task);
|
|
191
|
+
const run = runTask(root, task, this.opts.timeoutMs);
|
|
192
|
+
results.push({ task: task.id, ...run });
|
|
193
|
+
observations.push({
|
|
194
|
+
task: task.id,
|
|
195
|
+
baseline: obsBaseline,
|
|
196
|
+
dirty: true,
|
|
197
|
+
context: contextFor(),
|
|
198
|
+
inputs,
|
|
199
|
+
outputs: [],
|
|
200
|
+
outcome: run.outcome,
|
|
201
|
+
duration_ms: run.durationMs,
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
const end = gitChangeSet(root, "HEAD");
|
|
205
|
+
// The tree is clean at HEAD, the window covered the baseline, and no event
|
|
206
|
+
// arrived during the run: the runs saw exactly the tree that the baseline names.
|
|
207
|
+
const treeClean = complete && !end.dirty && end.head === startHead && this.watcher.generation === gen;
|
|
208
|
+
// Observations are reusable only from a clean tree (dirty ones are never trusted).
|
|
209
|
+
for (const o of observations)
|
|
210
|
+
o.dirty = !treeClean;
|
|
211
|
+
if (observations.length > 0)
|
|
212
|
+
await client.observeMany(observations);
|
|
213
|
+
const allRan = results.every((r) => r.outcome !== "error");
|
|
214
|
+
const canAdvance = treeClean && stored !== null && allRan;
|
|
215
|
+
let advanced = false;
|
|
216
|
+
if (canAdvance && end.head !== stored) {
|
|
217
|
+
await client.advance(end.head, stored);
|
|
218
|
+
advanced = true;
|
|
219
|
+
this.base = end.head;
|
|
220
|
+
this.watcher.rebase();
|
|
221
|
+
}
|
|
222
|
+
// A full cycle that did not advance starts a new window, so the next cycle can
|
|
223
|
+
// be incremental again if the tree equals the stored baseline.
|
|
224
|
+
if (full && !advanced)
|
|
225
|
+
await this.arm();
|
|
226
|
+
const report = {
|
|
227
|
+
mode: full ? "full" : "incremental",
|
|
228
|
+
reason,
|
|
229
|
+
stored,
|
|
230
|
+
changes: state.changes,
|
|
231
|
+
plan,
|
|
232
|
+
selected: selected.map((t) => t.id),
|
|
233
|
+
results,
|
|
234
|
+
advanced,
|
|
235
|
+
headEnd: end.head,
|
|
236
|
+
};
|
|
237
|
+
this.first = false;
|
|
238
|
+
return report;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
// Runs one task command in the repository. A command that cannot start, or is
|
|
242
|
+
// killed, is an error, never a pass.
|
|
243
|
+
export function runTask(root, task, timeoutMs) {
|
|
244
|
+
const started = Date.now();
|
|
245
|
+
const [cmd, ...args] = task.command;
|
|
246
|
+
if (cmd === undefined)
|
|
247
|
+
throw new ConfigError(`task ${task.id}: empty command`);
|
|
248
|
+
const r = spawnSync(cmd, args, {
|
|
249
|
+
cwd: root,
|
|
250
|
+
encoding: "utf8",
|
|
251
|
+
timeout: timeoutMs,
|
|
252
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
253
|
+
});
|
|
254
|
+
const durationMs = Date.now() - started;
|
|
255
|
+
if (r.error !== undefined || r.signal !== null)
|
|
256
|
+
return { outcome: "error", durationMs };
|
|
257
|
+
return { outcome: r.status === 0 ? "pass" : "fail", durationMs };
|
|
258
|
+
}
|
|
259
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.js","sources":["../../src/session.ts"],"names":[],"mappings":"AAAA,iFAAiF;AACjF,oFAAoF;AACpF,oFAAoF;AACpF,gFAAgF;AAChF,yEAAyE;AACzE,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EACL,OAAO,EACP,aAAa,EACb,QAAQ,GAQT,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAE7D,MAAM,OAAO,WAAY,SAAQ,KAAK;IACpC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC5B,CAAC;CACF;AAqCD,MAAM,QAAQ,GAAG,aAAa,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;AAChD,MAAM,cAAc,GAAG,uBAAwB,QAAQ,CAAC,oBAAoB,CAAyB,CAAC,OAAO,EAAE,CAAC;AAEhH,SAAS,aAAa;IACpB,OAAO,CACL,OAAO,CAAC,GAAG,CAAC,eAAe;QAC3B,IAAI,CAAC,IAAI,C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C,OAAO,CAAC;IACpC,IAAI,GAAG,KAAK,SAAS;QAAE,MAAM,IAAI,WAAW,CAAC,QAAQ,IAAI,CAAC,EAAE,iBAAiB,CAAC,CAAC;IAC/E,MAAM,CAAC,GAAG,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE;QAC7B,GAAG,EAAE,IAAI;QACT,QAAQ,EAAE,MAAM;QAChB,OAAO,EAAE,SAAS;QAClB,SAAS,EAAE,EAAE,GAAG,IAAI,GAAG,IAAI;KAC5B,CAAC,CAAC;IACH,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC;IACxC,IAAI,CAAC,CAAC,KAAK,KAAK,SAAS,IAAI,CAAC,CAAC,MAAM,KAAK,IAAI;QAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC;IACxF,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC;AACnE,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Change } from "@incremental/client";
|
|
2
|
+
export declare const SKIP_DIRS: Set<string>;
|
|
3
|
+
type Kind = "file" | "dir" | "other";
|
|
4
|
+
export interface WatchState {
|
|
5
|
+
changes: Change[];
|
|
6
|
+
lost: string | null;
|
|
7
|
+
}
|
|
8
|
+
export declare function relOf(root: string, abs: string): string;
|
|
9
|
+
export interface Entry {
|
|
10
|
+
kind: Kind;
|
|
11
|
+
size: number;
|
|
12
|
+
mtimeMs: number;
|
|
13
|
+
ino: number;
|
|
14
|
+
hash?: string;
|
|
15
|
+
}
|
|
16
|
+
export declare function statWalk(root: string, dir: string, out?: Map<string, Entry>): Map<string, Entry>;
|
|
17
|
+
export declare function walk(root: string, dir: string, out?: Map<string, Kind>): Map<string, Kind>;
|
|
18
|
+
export declare class Watcher {
|
|
19
|
+
readonly root: string;
|
|
20
|
+
private handle;
|
|
21
|
+
private base;
|
|
22
|
+
private baseTime;
|
|
23
|
+
lastWalkMs: number;
|
|
24
|
+
private lostReason;
|
|
25
|
+
generation: number;
|
|
26
|
+
constructor(root: string);
|
|
27
|
+
start(): void;
|
|
28
|
+
rebase(): void;
|
|
29
|
+
stop(): void;
|
|
30
|
+
loss(reason: string): void;
|
|
31
|
+
private onEvent;
|
|
32
|
+
state(): WatchState;
|
|
33
|
+
private racyAt;
|
|
34
|
+
}
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=watch.d.ts.map
|