@agent-watch-ai/edge 0.6.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +288 -9
- package/README.md +307 -5
- package/dist/billing/billing-mode.d.ts +37 -5
- package/dist/billing/billing-mode.js +28 -19
- package/dist/billing/constants/billing.constants.d.ts +0 -2
- package/dist/billing/constants/billing.constants.js +0 -2
- package/dist/billing/index.d.ts +2 -1
- package/dist/billing/index.js +1 -1
- package/dist/billing/session-billing.d.ts +7 -3
- package/dist/billing/session-billing.js +34 -13
- package/dist/billing/types/billing.types.d.ts +7 -0
- package/dist/capture/capture-env.d.ts +147 -0
- package/dist/capture/capture-env.js +301 -0
- package/dist/capture/captured-step.d.ts +88 -0
- package/dist/capture/captured-step.js +503 -0
- package/dist/capture/constants/capture.constants.d.ts +85 -0
- package/dist/capture/constants/capture.constants.js +87 -0
- package/dist/capture/launched-runs.d.ts +43 -0
- package/dist/capture/launched-runs.js +157 -0
- package/dist/capture/node.cjs +697 -0
- package/dist/capture/node.d.cts +32 -0
- package/dist/capture/python/sitecustomize.py +832 -0
- package/dist/capture/schemas/capture.schema.d.ts +35 -0
- package/dist/capture/schemas/capture.schema.js +31 -0
- package/dist/capture/types/capture.types.d.ts +20 -0
- package/dist/capture/venv-loader.d.ts +68 -0
- package/dist/capture/venv-loader.js +189 -0
- package/dist/cli/constants/cli.constants.d.ts +23 -6
- package/dist/cli/constants/cli.constants.js +24 -7
- package/dist/cli/context.d.ts +19 -22
- package/dist/cli/context.js +23 -54
- package/dist/cli/doctor-run-capture.d.ts +21 -0
- package/dist/cli/doctor-run-capture.js +33 -0
- package/dist/cli/doctor.js +21 -68
- package/dist/cli/hook-check.d.ts +7 -2
- package/dist/cli/hook-check.js +30 -15
- package/dist/cli/hook.d.ts +14 -0
- package/dist/cli/hook.js +82 -1
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +1 -1
- package/dist/cli/misc.js +10 -2
- package/dist/cli/npm-global.d.ts +24 -0
- package/dist/cli/npm-global.js +77 -0
- package/dist/cli/npx-install.js +22 -6
- package/dist/cli/replay.d.ts +33 -0
- package/dist/cli/replay.js +228 -0
- package/dist/cli/setup.d.ts +10 -2
- package/dist/cli/setup.js +200 -31
- package/dist/cli/status.js +45 -5
- package/dist/cli/toggle.js +10 -0
- package/dist/cli/types/cli.types.d.ts +15 -1
- package/dist/cli/uninstall.js +42 -23
- package/dist/cli/update.js +3 -2
- package/dist/cli.js +104 -17
- package/dist/config/config-store.d.ts +15 -4
- package/dist/config/config-store.js +31 -7
- package/dist/config/config.d.ts +0 -2
- package/dist/config/config.js +0 -1
- package/dist/config/constants/config.constants.d.ts +8 -1
- package/dist/config/constants/config.constants.js +10 -1
- package/dist/config/events-transport.d.ts +15 -0
- package/dist/config/events-transport.js +29 -0
- package/dist/config/index.d.ts +2 -1
- package/dist/config/index.js +1 -0
- package/dist/config/root-config.d.ts +12 -0
- package/dist/config/root-config.js +24 -0
- package/dist/config/schemas/config.schema.d.ts +15 -2
- package/dist/config/schemas/config.schema.js +52 -8
- package/dist/config/types/config.types.d.ts +7 -0
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.js +1 -1
- package/dist/core/version.d.ts +9 -0
- package/dist/core/version.js +14 -0
- package/dist/core/which.d.ts +11 -0
- package/dist/core/which.js +18 -0
- package/dist/credentials/cloud-claim.d.ts +34 -0
- package/dist/credentials/cloud-claim.js +61 -0
- package/dist/credentials/constants/credentials.constants.d.ts +16 -1
- package/dist/credentials/constants/credentials.constants.js +17 -2
- package/dist/credentials/credential-status.js +1 -1
- package/dist/credentials/credentials.d.ts +3 -3
- package/dist/credentials/credentials.js +26 -12
- package/dist/credentials/device-api.d.ts +15 -1
- package/dist/credentials/device-api.js +12 -1
- package/dist/credentials/identity.d.ts +2 -2
- package/dist/credentials/identity.js +2 -2
- package/dist/credentials/install-key.d.ts +31 -0
- package/dist/credentials/install-key.js +58 -0
- package/dist/credentials/migration.d.ts +9 -7
- package/dist/credentials/migration.js +58 -18
- package/dist/credentials/secret-store.d.ts +12 -0
- package/dist/credentials/secret-store.js +18 -1
- package/dist/credentials/sign-in.d.ts +27 -0
- package/dist/credentials/sign-in.js +31 -1
- package/dist/credentials/token-refresher.d.ts +5 -1
- package/dist/credentials/token-refresher.js +10 -2
- package/dist/enforcement/enforcement.js +1 -1
- package/dist/events/constants/events.constants.d.ts +5 -2
- package/dist/events/constants/events.constants.js +4 -1
- package/dist/events/enrich.d.ts +14 -0
- package/dist/events/enrich.js +1 -1
- package/dist/events/index.d.ts +1 -0
- package/dist/events/product-event.d.ts +6 -3
- package/dist/events/types/events.types.d.ts +6 -0
- package/dist/events/types/replay-progress.types.d.ts +26 -0
- package/dist/events/types/replay-progress.types.js +1 -0
- package/dist/events/types/repo-tree.types.d.ts +2 -1
- package/dist/feature/ticket-candidates.d.ts +1 -1
- package/dist/git/checkout-root.d.ts +15 -0
- package/dist/git/checkout-root.js +18 -0
- package/dist/git/code-state.d.ts +2 -16
- package/dist/git/code-state.js +11 -12
- package/dist/git/constants/git.constants.d.ts +33 -11
- package/dist/git/constants/git.constants.js +45 -12
- package/dist/git/fingerprint.d.ts +3 -6
- package/dist/git/fingerprint.js +5 -8
- package/dist/git/git-context.js +5 -1
- package/dist/git/index.d.ts +1 -2
- package/dist/git/index.js +1 -1
- package/dist/git/repo-snapshot.d.ts +13 -4
- package/dist/git/repo-snapshot.js +53 -9
- package/dist/git/types/snapshot.types.d.ts +6 -0
- package/dist/pipeline/constants/pipeline.constants.d.ts +3 -0
- package/dist/pipeline/constants/pipeline.constants.js +3 -0
- package/dist/pipeline/hook-pipeline.js +82 -57
- package/dist/privacy/product-capture.js +2 -0
- package/dist/providers/antigravity/antigravity.capture.d.ts +2 -0
- package/dist/providers/antigravity/antigravity.capture.js +5 -0
- package/dist/providers/antigravity/antigravity.detect.js +8 -22
- package/dist/providers/antigravity/antigravity.provider.js +10 -3
- package/dist/providers/antigravity/constants/antigravity.constants.d.ts +1 -0
- package/dist/providers/antigravity/constants/antigravity.constants.js +1 -0
- package/dist/providers/claude/claude.adapter.js +9 -6
- package/dist/providers/claude/claude.detect.js +2 -17
- package/dist/providers/claude/claude.otel.d.ts +21 -3
- package/dist/providers/claude/claude.otel.js +216 -61
- package/dist/providers/claude/claude.provider.js +21 -1
- package/dist/providers/claude/claude.version.d.ts +9 -0
- package/dist/providers/claude/claude.version.js +28 -0
- package/dist/providers/claude/constants/claude.constants.d.ts +27 -0
- package/dist/providers/claude/constants/claude.constants.js +27 -0
- package/dist/providers/claude/constants/claude.otel.constants.d.ts +27 -0
- package/dist/providers/claude/constants/claude.otel.constants.js +45 -5
- package/dist/providers/claude/types/claude.types.d.ts +13 -0
- package/dist/providers/codex/codex.capture.d.ts +76 -0
- package/dist/providers/codex/codex.capture.js +454 -0
- package/dist/providers/codex/codex.detect.js +2 -4
- package/dist/providers/codex/codex.otel.d.ts +38 -2
- package/dist/providers/codex/codex.otel.js +50 -6
- package/dist/providers/codex/codex.provider.js +8 -0
- package/dist/providers/codex/codex.surface.d.ts +9 -0
- package/dist/{turns/codex-originator.js → providers/codex/codex.surface.js} +17 -3
- package/dist/providers/codex/codex.titles.d.ts +14 -0
- package/dist/providers/codex/codex.titles.js +35 -0
- package/dist/providers/codex/constants/codex.constants.d.ts +4 -0
- package/dist/providers/codex/constants/codex.constants.js +4 -0
- package/dist/providers/cursor/constants/cursor.constants.d.ts +17 -4
- package/dist/providers/cursor/constants/cursor.constants.js +25 -5
- package/dist/providers/cursor/cursor-mcp-memo.d.ts +34 -0
- package/dist/providers/cursor/cursor-mcp-memo.js +94 -0
- package/dist/providers/cursor/cursor.adapter.js +20 -82
- package/dist/providers/cursor/cursor.capture.d.ts +1 -0
- package/dist/providers/cursor/cursor.capture.js +4 -0
- package/dist/providers/cursor/cursor.detect.d.ts +5 -1
- package/dist/providers/cursor/cursor.detect.js +11 -26
- package/dist/providers/cursor/cursor.hooks.js +2 -2
- package/dist/providers/cursor/cursor.provider.js +16 -7
- package/dist/providers/cursor/cursor.titles.d.ts +14 -0
- package/dist/providers/cursor/cursor.titles.js +20 -0
- package/dist/providers/cursor/schemas/cursor.schema.d.ts +3 -3
- package/dist/providers/cursor/schemas/cursor.schema.js +5 -3
- package/dist/providers/gemini/constants/gemini.constants.d.ts +16 -0
- package/dist/providers/gemini/constants/gemini.constants.js +17 -0
- package/dist/providers/gemini/gemini.capture.d.ts +81 -0
- package/dist/providers/gemini/gemini.capture.js +210 -0
- package/dist/providers/gemini/gemini.detect.js +57 -24
- package/dist/providers/gemini/gemini.otel.d.ts +38 -2
- package/dist/providers/gemini/gemini.otel.js +56 -125
- package/dist/providers/gemini/gemini.provider.js +5 -0
- package/dist/providers/index.d.ts +1 -0
- package/dist/providers/index.js +1 -0
- package/dist/providers/provider.d.ts +8 -0
- package/dist/providers/provider.js +9 -0
- package/dist/providers/registry.d.ts +14 -0
- package/dist/providers/registry.js +14 -0
- package/dist/providers/shared/constants/hook-config.constants.d.ts +2 -0
- package/dist/providers/shared/constants/hook-config.constants.js +2 -0
- package/dist/providers/shared/constants/terminal-capture.constants.d.ts +6 -0
- package/dist/providers/shared/constants/terminal-capture.constants.js +6 -0
- package/dist/providers/shared/editor-paths.d.ts +8 -0
- package/dist/providers/shared/editor-paths.js +18 -0
- package/dist/providers/shared/hook-config.d.ts +5 -0
- package/dist/providers/shared/hook-config.js +39 -1
- package/dist/providers/shared/hooks-marker.d.ts +14 -0
- package/dist/providers/shared/hooks-marker.js +23 -0
- package/dist/providers/shared/install-record.d.ts +29 -0
- package/dist/providers/shared/install-record.js +52 -0
- package/dist/providers/shared/session-title-store.d.ts +23 -0
- package/dist/providers/shared/session-title-store.js +50 -0
- package/dist/providers/shared/terminal-capture.d.ts +41 -0
- package/dist/providers/shared/terminal-capture.js +109 -0
- package/dist/providers/shared/tooling.d.ts +21 -0
- package/dist/providers/shared/tooling.js +36 -1
- package/dist/providers/types/provider.types.d.ts +57 -4
- package/dist/replay/checkout-resolver.d.ts +56 -0
- package/dist/replay/checkout-resolver.js +173 -0
- package/dist/replay/codex-turns.d.ts +24 -0
- package/dist/replay/codex-turns.js +221 -0
- package/dist/replay/constants/replay.constants.d.ts +99 -0
- package/dist/replay/constants/replay.constants.js +102 -0
- package/dist/replay/describe.d.ts +10 -0
- package/dist/replay/describe.js +31 -0
- package/dist/replay/gemini-turns.d.ts +36 -0
- package/dist/replay/gemini-turns.js +192 -0
- package/dist/replay/machine.d.ts +34 -0
- package/dist/replay/machine.js +68 -0
- package/dist/replay/progress-event.d.ts +21 -0
- package/dist/replay/progress-event.js +45 -0
- package/dist/replay/replay-runner.d.ts +60 -0
- package/dist/replay/replay-runner.js +581 -0
- package/dist/replay/replay-scan.d.ts +84 -0
- package/dist/replay/replay-scan.js +182 -0
- package/dist/replay/replay-state.d.ts +108 -0
- package/dist/replay/replay-state.js +199 -0
- package/dist/replay/resume.d.ts +18 -0
- package/dist/replay/resume.js +34 -0
- package/dist/replay/start.d.ts +23 -0
- package/dist/replay/start.js +39 -0
- package/dist/replay/throttle.d.ts +36 -0
- package/dist/replay/throttle.js +44 -0
- package/dist/replay/transcript-turns.d.ts +35 -0
- package/dist/replay/transcript-turns.js +241 -0
- package/dist/replay/turn-event.d.ts +40 -0
- package/dist/replay/turn-event.js +127 -0
- package/dist/replay/types/replay.types.d.ts +198 -0
- package/dist/replay/types/replay.types.js +1 -0
- package/dist/replay/window.d.ts +28 -0
- package/dist/replay/window.js +41 -0
- package/dist/replay/worktree-map.d.ts +42 -0
- package/dist/replay/worktree-map.js +134 -0
- package/dist/snapshot/branch-selection.d.ts +40 -23
- package/dist/snapshot/branch-selection.js +71 -41
- package/dist/snapshot/constants/snapshot-stages.constants.d.ts +3 -1
- package/dist/snapshot/constants/snapshot-stages.constants.js +3 -1
- package/dist/snapshot/constants/snapshot.constants.d.ts +34 -7
- package/dist/snapshot/constants/snapshot.constants.js +34 -7
- package/dist/snapshot/index.d.ts +2 -2
- package/dist/snapshot/index.js +1 -1
- package/dist/snapshot/snapshot-pipeline.js +100 -26
- package/dist/snapshot/snapshot-state.js +6 -2
- package/dist/snapshot/tree-pipeline.d.ts +1 -1
- package/dist/snapshot/tree-pipeline.js +34 -15
- package/dist/snapshot/types/snapshot.types.d.ts +22 -3
- package/dist/storage/schemas/storage.schema.d.ts +2 -0
- package/dist/storage/schemas/storage.schema.js +6 -0
- package/dist/transport/delivery-stats.d.ts +13 -1
- package/dist/transport/delivery-stats.js +18 -2
- package/dist/transport/delivery.d.ts +4 -3
- package/dist/transport/delivery.js +21 -7
- package/dist/transport/identity-delivery.d.ts +20 -0
- package/dist/transport/identity-delivery.js +41 -0
- package/dist/transport/index.d.ts +2 -0
- package/dist/transport/index.js +1 -0
- package/dist/transport/types/delivery-flow.types.d.ts +7 -0
- package/dist/turns/claude-transcript.js +4 -12
- package/dist/turns/codex-transcript.d.ts +9 -0
- package/dist/turns/codex-transcript.js +27 -19
- package/dist/turns/constants/turns.constants.d.ts +29 -12
- package/dist/turns/constants/turns.constants.js +31 -19
- package/dist/turns/gemini-transcript.d.ts +19 -1
- package/dist/turns/gemini-transcript.js +29 -18
- package/dist/turns/index.d.ts +3 -4
- package/dist/turns/index.js +2 -3
- package/dist/turns/run-state.d.ts +71 -0
- package/dist/turns/run-state.js +114 -0
- package/dist/turns/tool-events.d.ts +11 -1
- package/dist/turns/tool-events.js +32 -9
- package/dist/turns/transcript.d.ts +15 -14
- package/dist/turns/transcript.js +23 -4
- package/dist/turns/turn-state.d.ts +82 -7
- package/dist/turns/turn-state.js +157 -10
- package/dist/turns/turn-summary.js +7 -2
- package/dist/turns/turn-tracker.d.ts +9 -16
- package/dist/turns/turn-tracker.js +163 -87
- package/dist/turns/types/transcript.types.d.ts +11 -1
- package/dist/turns/types/turn-provider.types.d.ts +33 -0
- package/dist/turns/types/turn-provider.types.js +1 -0
- package/dist/turns/types/turn-state.types.d.ts +9 -0
- package/dist/turns/types/turn-summary.types.d.ts +17 -1
- package/dist/turns/types/turn-tracker.types.d.ts +3 -1
- package/dist/turns/work-checkout.js +1 -2
- package/docs/AUDIT_PROMPT.md +10 -0
- package/docs/DATA_HANDLING.md +201 -13
- package/docs/ENTERPRISE_DEPLOYMENT.md +3 -3
- package/docs/PERFORMANCE.md +10 -0
- package/package.json +3 -2
- package/dist/events/canonical-event.d.ts +0 -10
- package/dist/events/canonical-event.js +0 -9
- package/dist/git/repository-root.d.ts +0 -39
- package/dist/git/repository-root.js +0 -131
- package/dist/git/types/repository-root.types.d.ts +0 -11
- package/dist/transport/transport.d.ts +0 -6
- package/dist/turns/codex-originator.d.ts +0 -11
- package/dist/turns/cursor-transcript.d.ts +0 -21
- package/dist/turns/cursor-transcript.js +0 -66
- package/dist/turns/native-session-titles.d.ts +0 -26
- package/dist/turns/native-session-titles.js +0 -102
- /package/dist/{git/types/repository-root.types.js → billing/types/billing.types.js} +0 -0
- /package/dist/{transport/transport.js → capture/types/capture.types.js} +0 -0
|
@@ -1,71 +1,101 @@
|
|
|
1
|
-
import { SNAPSHOT_REFRESH_MS } from './constants/snapshot.constants.js';
|
|
1
|
+
import { SNAPSHOT_BRANCH_COUNT, SNAPSHOT_REFRESH_MS } from './constants/snapshot.constants.js';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* The branches the snapshot walks, newest commit first, and which of them are due.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
5
|
+
* A branch already found on the trunk, at the same head and against the same
|
|
6
|
+
* base, is left out without a git process: merged stays merged, and that is
|
|
7
|
+
* what lets the walk pass the dozens of finished branches a busy repository
|
|
8
|
+
* keeps to reach the live ones behind them. Every other branch is a candidate,
|
|
9
|
+
* due when one of these holds — and each one is a bug if it is missing:
|
|
6
10
|
*
|
|
7
|
-
* - the branch is new — nothing has ever been
|
|
8
|
-
* - its head moved — the obvious one
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* - the branch is new — nothing has ever been checked about it;
|
|
12
|
+
* - its head moved — the obvious one, and how a merged branch with new work
|
|
13
|
+
* comes back;
|
|
14
|
+
* - the default branch changed since it was checked, because its delta and its
|
|
15
|
+
* verdict were computed against the wrong base and no head has to move for
|
|
16
|
+
* that to be true;
|
|
17
|
+
* - it was last sent longer ago than the heartbeat, which is the only thing
|
|
18
|
+
* that ever re-offers a finished branch to a tracker connected after the fact.
|
|
14
19
|
*
|
|
15
|
-
* @param input - The refs git reported and what was last
|
|
16
|
-
* @returns The
|
|
20
|
+
* @param input - The refs git reported and what was last recorded.
|
|
21
|
+
* @returns The candidates in walk order.
|
|
17
22
|
*/
|
|
18
|
-
export function
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
if (rebased)
|
|
22
|
-
return true;
|
|
23
|
+
export function snapshotCandidates(input) {
|
|
24
|
+
const candidates = [];
|
|
25
|
+
for (const ref of input.refs) {
|
|
23
26
|
const entry = input.stored.branches[ref.name];
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
const current = entry !== undefined && entry.headSha === ref.headSha && entryBase(entry, input.stored) === input.defaultBranch;
|
|
28
|
+
if (current && entry.merged)
|
|
29
|
+
continue;
|
|
30
|
+
candidates.push({ ref, due: !current || input.now - entry.lastSentAt >= SNAPSHOT_REFRESH_MS });
|
|
31
|
+
}
|
|
32
|
+
return candidates;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Whether the walk would reach a due branch before the window is full.
|
|
36
|
+
*
|
|
37
|
+
* The cheap exit on an ordinary closing turn: the first ten live branches are
|
|
38
|
+
* all as they were sent, so no git process runs and nothing is queued.
|
|
39
|
+
*
|
|
40
|
+
* @param candidates - The walk, from {@link snapshotCandidates}.
|
|
41
|
+
* @returns True when something has to be checked.
|
|
42
|
+
*/
|
|
43
|
+
export function anyDue(candidates) {
|
|
44
|
+
const reached = candidates.slice(0, SNAPSHOT_BRANCH_COUNT);
|
|
45
|
+
return reached.some((candidate) => candidate.due);
|
|
30
46
|
}
|
|
31
47
|
/**
|
|
32
48
|
* The state to store once a snapshot has been queued.
|
|
33
49
|
*
|
|
34
|
-
* A branch is recorded
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* later.
|
|
50
|
+
* A branch is recorded only if it was actually checked. The cache is a record
|
|
51
|
+
* of what the platform has been told, not of what git said: a branch whose head
|
|
52
|
+
* moved and which then fell outside the budget must keep its *old* head here,
|
|
53
|
+
* or the next turn compares the new head against the new head, finds them
|
|
54
|
+
* equal, and the work disappears until the heartbeat six hours later.
|
|
40
55
|
*
|
|
41
|
-
* A branch
|
|
42
|
-
*
|
|
56
|
+
* A branch found on the trunk is recorded as merged: the platform has been told
|
|
57
|
+
* all there is, and the verdict is what keeps every later turn from checking it
|
|
58
|
+
* again. Each entry carries the base it was checked against, so a trunk change
|
|
59
|
+
* re-checks branch by branch and a budget cut part-way loses nothing.
|
|
43
60
|
*
|
|
44
61
|
* @param input - Refs, previous state and the send's own clock.
|
|
45
|
-
* @param sent - The branches this snapshot
|
|
62
|
+
* @param sent - The live branches this snapshot described.
|
|
63
|
+
* @param merged - The branches it found already on the trunk.
|
|
46
64
|
* @returns The state to write.
|
|
47
65
|
*/
|
|
48
|
-
export function nextSnapshotState(input, sent) {
|
|
66
|
+
export function nextSnapshotState(input, sent, merged = []) {
|
|
49
67
|
const sentNames = new Set(sent.map((ref) => ref.name));
|
|
68
|
+
const mergedNames = new Set(merged.map((ref) => ref.name));
|
|
50
69
|
const branches = {};
|
|
51
70
|
for (const ref of input.refs) {
|
|
52
71
|
if (sentNames.has(ref.name)) {
|
|
53
|
-
branches[ref.name] = { headSha: ref.headSha, lastSentAt: input.now };
|
|
72
|
+
branches[ref.name] = { headSha: ref.headSha, lastSentAt: input.now, base: input.defaultBranch };
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (mergedNames.has(ref.name)) {
|
|
76
|
+
branches[ref.name] = { headSha: ref.headSha, lastSentAt: input.now, base: input.defaultBranch, merged: true };
|
|
54
77
|
continue;
|
|
55
78
|
}
|
|
56
79
|
const previous = input.stored.branches[ref.name];
|
|
80
|
+
// An entry from before bases were per branch takes the repository's, so
|
|
81
|
+
// the recorded default branch below can move without re-dating it.
|
|
57
82
|
if (previous)
|
|
58
|
-
branches[ref.name] = previous;
|
|
83
|
+
branches[ref.name] = { ...previous, base: entryBase(previous, input.stored) };
|
|
59
84
|
}
|
|
60
|
-
// The recorded base only moves once every branch has been described against
|
|
61
|
-
// it. Recording it early would end the `rebased` selection for branches whose
|
|
62
|
-
// deltas were never recomputed, and they would sit on the wrong base until
|
|
63
|
-
// their heads happened to move.
|
|
64
|
-
const described = input.refs.every((ref) => sentNames.has(ref.name));
|
|
65
85
|
// The tree is the tree flow's to write; a branch send carries it over untouched.
|
|
66
86
|
return {
|
|
67
|
-
defaultBranch:
|
|
87
|
+
defaultBranch: input.defaultBranch,
|
|
68
88
|
branches,
|
|
69
89
|
...(input.stored.tree ? { tree: input.stored.tree } : {})
|
|
70
90
|
};
|
|
71
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* The base an entry was checked against.
|
|
94
|
+
*
|
|
95
|
+
* @param entry - One stored branch.
|
|
96
|
+
* @param stored - Its state, whose default branch an older entry inherits.
|
|
97
|
+
* @returns The base name, or undefined when there was none.
|
|
98
|
+
*/
|
|
99
|
+
function entryBase(entry, stored) {
|
|
100
|
+
return entry.base ?? stored.defaultBranch;
|
|
101
|
+
}
|
|
@@ -7,13 +7,15 @@ export declare const STAGE_ENQUEUE = "enqueue";
|
|
|
7
7
|
/** Reasons a stage ends the flow early. */
|
|
8
8
|
export declare const STOP_NOT_A_REPOSITORY = "no branches: not a repository, or it has none";
|
|
9
9
|
export declare const STOP_NOTHING_CHANGED = "no branch moved and none is due a refresh";
|
|
10
|
+
export declare const STOP_ALL_ON_TRUNK = "every checked branch is already on the trunk";
|
|
10
11
|
export declare const STOP_BUDGET_SPENT = "snapshot budget spent";
|
|
11
12
|
export declare const STOP_NO_EVENT = "no snapshot event was built";
|
|
12
13
|
/** The tree flow's stages and stops. */
|
|
13
14
|
export declare const STAGE_TREE_DUE = "tree-due";
|
|
14
15
|
export declare const STAGE_TREE_RESOLVE = "tree-resolve";
|
|
16
|
+
export declare const STAGE_TREE_CHANGED = "tree-changed";
|
|
15
17
|
export declare const STAGE_TREE_COLLECT = "tree-collect";
|
|
16
|
-
export declare const STOP_TREE_SENT = "tree already sent for this repository and identity";
|
|
18
|
+
export declare const STOP_TREE_SENT = "trunk tree already sent for this repository and identity";
|
|
17
19
|
export declare const STOP_TREE_NOT_DUE = "tree attempt failed within the last hour";
|
|
18
20
|
export declare const STOP_TREE_NO_TRUNK = "no default branch tree to list";
|
|
19
21
|
export declare const STOP_TREE_UNLISTED = "tree could not be listed";
|
|
@@ -7,13 +7,15 @@ export const STAGE_ENQUEUE = 'enqueue';
|
|
|
7
7
|
/** Reasons a stage ends the flow early. */
|
|
8
8
|
export const STOP_NOT_A_REPOSITORY = 'no branches: not a repository, or it has none';
|
|
9
9
|
export const STOP_NOTHING_CHANGED = 'no branch moved and none is due a refresh';
|
|
10
|
+
export const STOP_ALL_ON_TRUNK = 'every checked branch is already on the trunk';
|
|
10
11
|
export const STOP_BUDGET_SPENT = 'snapshot budget spent';
|
|
11
12
|
export const STOP_NO_EVENT = 'no snapshot event was built';
|
|
12
13
|
/** The tree flow's stages and stops. */
|
|
13
14
|
export const STAGE_TREE_DUE = 'tree-due';
|
|
14
15
|
export const STAGE_TREE_RESOLVE = 'tree-resolve';
|
|
16
|
+
export const STAGE_TREE_CHANGED = 'tree-changed';
|
|
15
17
|
export const STAGE_TREE_COLLECT = 'tree-collect';
|
|
16
|
-
export const STOP_TREE_SENT = 'tree already sent for this repository and identity';
|
|
18
|
+
export const STOP_TREE_SENT = 'trunk tree already sent for this repository and identity';
|
|
17
19
|
export const STOP_TREE_NOT_DUE = 'tree attempt failed within the last hour';
|
|
18
20
|
export const STOP_TREE_NO_TRUNK = 'no default branch tree to list';
|
|
19
21
|
export const STOP_TREE_UNLISTED = 'tree could not be listed';
|
|
@@ -1,11 +1,37 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* How many branches one snapshot describes.
|
|
2
|
+
* How many live branches one snapshot describes.
|
|
3
3
|
*
|
|
4
|
-
* The ten most recently committed
|
|
5
|
-
* working on, few enough that the
|
|
6
|
-
*
|
|
4
|
+
* The ten most recently committed that are not already on the trunk: enough to
|
|
5
|
+
* cover what anyone is actually working on, few enough that the backend's
|
|
6
|
+
* per-branch transaction count stays bounded.
|
|
7
7
|
*/
|
|
8
8
|
export declare const SNAPSHOT_BRANCH_COUNT = 10;
|
|
9
|
+
/**
|
|
10
|
+
* How many branches the listing reads, newest commit first, to find those ten.
|
|
11
|
+
*
|
|
12
|
+
* Merged branches are passed over, so the ten live ones can sit deep: 46 down
|
|
13
|
+
* on agent-watch-core (294 local branches, October 2026). Still one process —
|
|
14
|
+
* all 294 list in ~40 ms — and the bound keeps the state file small.
|
|
15
|
+
*/
|
|
16
|
+
export declare const SNAPSHOT_SCAN_COUNT = 100;
|
|
17
|
+
/**
|
|
18
|
+
* How many branches one snapshot may check with git.
|
|
19
|
+
*
|
|
20
|
+
* A check is the delta log plus, when it has commits, a merge-tree and a tree
|
|
21
|
+
* read: ~70 ms on agent-watch-core. Finding its ten live branches from an empty
|
|
22
|
+
* cache took 18 checks (27 more were passed for a gone upstream at no cost); the
|
|
23
|
+
* budget usually ends a first snapshot before this does, and verdicts are
|
|
24
|
+
* remembered, so the next turn continues where it stopped.
|
|
25
|
+
*/
|
|
26
|
+
export declare const SNAPSHOT_MAX_CHECKS = 20;
|
|
27
|
+
/**
|
|
28
|
+
* Budget the checks leave for queueing the event and writing the state.
|
|
29
|
+
*
|
|
30
|
+
* Without it a walk that ran to the deadline would queue nothing and record
|
|
31
|
+
* nothing, and on a repository that always needs more than the budget no turn
|
|
32
|
+
* would ever make progress.
|
|
33
|
+
*/
|
|
34
|
+
export declare const SNAPSHOT_WRITE_RESERVE_MS = 100;
|
|
9
35
|
/**
|
|
10
36
|
* How many of a branch's own commits travel with it.
|
|
11
37
|
*
|
|
@@ -87,8 +113,9 @@ export declare const SNAPSHOT_RE_CONTROL_CHARACTER: RegExp;
|
|
|
87
113
|
/** Hex characters kept from the repository digest that names a state file. */
|
|
88
114
|
export declare const SNAPSHOT_STATE_HASH_LENGTH = 32;
|
|
89
115
|
/**
|
|
90
|
-
* How long a repository
|
|
91
|
-
* failed, budget spent)
|
|
92
|
-
*
|
|
116
|
+
* How long a repository waits between `repo.tree` checks: after a failed
|
|
117
|
+
* attempt (no trunk, listing failed, budget spent), and between comparisons of
|
|
118
|
+
* the trunk's tree oid with the one already sent. Bounds the git cost to one
|
|
119
|
+
* oid lookup an hour per repository.
|
|
93
120
|
*/
|
|
94
121
|
export declare const TREE_RETRY_INTERVAL_MS: number;
|
|
@@ -1,11 +1,37 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* How many branches one snapshot describes.
|
|
2
|
+
* How many live branches one snapshot describes.
|
|
3
3
|
*
|
|
4
|
-
* The ten most recently committed
|
|
5
|
-
* working on, few enough that the
|
|
6
|
-
*
|
|
4
|
+
* The ten most recently committed that are not already on the trunk: enough to
|
|
5
|
+
* cover what anyone is actually working on, few enough that the backend's
|
|
6
|
+
* per-branch transaction count stays bounded.
|
|
7
7
|
*/
|
|
8
8
|
export const SNAPSHOT_BRANCH_COUNT = 10;
|
|
9
|
+
/**
|
|
10
|
+
* How many branches the listing reads, newest commit first, to find those ten.
|
|
11
|
+
*
|
|
12
|
+
* Merged branches are passed over, so the ten live ones can sit deep: 46 down
|
|
13
|
+
* on agent-watch-core (294 local branches, October 2026). Still one process —
|
|
14
|
+
* all 294 list in ~40 ms — and the bound keeps the state file small.
|
|
15
|
+
*/
|
|
16
|
+
export const SNAPSHOT_SCAN_COUNT = 100;
|
|
17
|
+
/**
|
|
18
|
+
* How many branches one snapshot may check with git.
|
|
19
|
+
*
|
|
20
|
+
* A check is the delta log plus, when it has commits, a merge-tree and a tree
|
|
21
|
+
* read: ~70 ms on agent-watch-core. Finding its ten live branches from an empty
|
|
22
|
+
* cache took 18 checks (27 more were passed for a gone upstream at no cost); the
|
|
23
|
+
* budget usually ends a first snapshot before this does, and verdicts are
|
|
24
|
+
* remembered, so the next turn continues where it stopped.
|
|
25
|
+
*/
|
|
26
|
+
export const SNAPSHOT_MAX_CHECKS = 20;
|
|
27
|
+
/**
|
|
28
|
+
* Budget the checks leave for queueing the event and writing the state.
|
|
29
|
+
*
|
|
30
|
+
* Without it a walk that ran to the deadline would queue nothing and record
|
|
31
|
+
* nothing, and on a repository that always needs more than the budget no turn
|
|
32
|
+
* would ever make progress.
|
|
33
|
+
*/
|
|
34
|
+
export const SNAPSHOT_WRITE_RESERVE_MS = 100;
|
|
9
35
|
/**
|
|
10
36
|
* How many of a branch's own commits travel with it.
|
|
11
37
|
*
|
|
@@ -88,8 +114,9 @@ export const SNAPSHOT_RE_CONTROL_CHARACTER = /[\x00-\x1f\x7f]/;
|
|
|
88
114
|
/** Hex characters kept from the repository digest that names a state file. */
|
|
89
115
|
export const SNAPSHOT_STATE_HASH_LENGTH = 32;
|
|
90
116
|
/**
|
|
91
|
-
* How long a repository
|
|
92
|
-
* failed, budget spent)
|
|
93
|
-
*
|
|
117
|
+
* How long a repository waits between `repo.tree` checks: after a failed
|
|
118
|
+
* attempt (no trunk, listing failed, budget spent), and between comparisons of
|
|
119
|
+
* the trunk's tree oid with the one already sent. Bounds the git cost to one
|
|
120
|
+
* oid lookup an hour per repository.
|
|
94
121
|
*/
|
|
95
122
|
export const TREE_RETRY_INTERVAL_MS = 60 * 60 * 1000;
|
package/dist/snapshot/index.d.ts
CHANGED
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
* of work exists at all.
|
|
9
9
|
*
|
|
10
10
|
* The tree flow beside it sends the trunk's source paths and declaration names
|
|
11
|
-
* (`repo.tree`)
|
|
11
|
+
* (`repo.tree`) per repository and identity, again when the trunk's tree changes, for a tenant whose code nothing may clone.
|
|
12
12
|
*/
|
|
13
13
|
export type { BuildSnapshotInput, SelectionInput, SnapshotFlowInput, SnapshotFlowState, SnapshotIdentity, SnapshotPipelineInput, SnapshotQueue, SnapshotState, SnapshotStateEntry, SnapshotStateReader } from './types/snapshot.types.js';
|
|
14
14
|
export { SNAPSHOT_BRANCH_COUNT, SNAPSHOT_BUDGET_MS, SNAPSHOT_COMMITS_PER_BRANCH, SNAPSHOT_REFRESH_MS } from './constants/snapshot.constants.js';
|
|
15
|
-
export { nextSnapshotState,
|
|
15
|
+
export { anyDue, nextSnapshotState, snapshotCandidates } from './branch-selection.js';
|
|
16
16
|
export { budgetedRunner, remainingMs, withinBudget } from './budget.js';
|
|
17
17
|
export { buildRepoSnapshot } from './snapshot-event.js';
|
|
18
18
|
export { runSnapshotPipeline } from './snapshot-pipeline.js';
|
package/dist/snapshot/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { SNAPSHOT_BRANCH_COUNT, SNAPSHOT_BUDGET_MS, SNAPSHOT_COMMITS_PER_BRANCH, SNAPSHOT_REFRESH_MS } from './constants/snapshot.constants.js';
|
|
2
|
-
export { nextSnapshotState,
|
|
2
|
+
export { anyDue, nextSnapshotState, snapshotCandidates } from './branch-selection.js';
|
|
3
3
|
export { budgetedRunner, remainingMs, withinBudget } from './budget.js';
|
|
4
4
|
export { buildRepoSnapshot } from './snapshot-event.js';
|
|
5
5
|
export { runSnapshotPipeline } from './snapshot-pipeline.js';
|
|
@@ -2,12 +2,12 @@ import { debugLog } from '../core/logger.js';
|
|
|
2
2
|
import { next, runFlow, step, stop } from '../core/pipe.js';
|
|
3
3
|
import { collectBranchCommits, collectBranchRefs, resolveDefaultBranch } from '../git/repo-snapshot.js';
|
|
4
4
|
import { sanitizeValue } from '../privacy/sanitizer.js';
|
|
5
|
-
import { nextSnapshotState,
|
|
5
|
+
import { anyDue, nextSnapshotState, snapshotCandidates } from './branch-selection.js';
|
|
6
6
|
import { budgetedRunner, remainingMs, withinBudget } from './budget.js';
|
|
7
7
|
import { buildRepoSnapshot } from './snapshot-event.js';
|
|
8
8
|
import { emptyState } from './snapshot-state.js';
|
|
9
|
-
import { SNAPSHOT_BRANCH_COUNT, SNAPSHOT_COMMITS_PER_BRANCH } from './constants/snapshot.constants.js';
|
|
10
|
-
import { STAGE_COLLECT_COMMITS, STAGE_COLLECT_REFS, STAGE_ENQUEUE, STAGE_SANITIZE, STAGE_SELECT_CHANGED, STOP_BUDGET_SPENT, STOP_NOTHING_CHANGED, STOP_NO_EVENT, STOP_NOT_A_REPOSITORY } from './constants/snapshot-stages.constants.js';
|
|
9
|
+
import { SNAPSHOT_BRANCH_COUNT, SNAPSHOT_COMMITS_PER_BRANCH, SNAPSHOT_MAX_CHECKS, SNAPSHOT_SCAN_COUNT, SNAPSHOT_WRITE_RESERVE_MS } from './constants/snapshot.constants.js';
|
|
10
|
+
import { STAGE_COLLECT_COMMITS, STAGE_COLLECT_REFS, STAGE_ENQUEUE, STAGE_SANITIZE, STAGE_SELECT_CHANGED, STOP_ALL_ON_TRUNK, STOP_BUDGET_SPENT, STOP_NOTHING_CHANGED, STOP_NO_EVENT, STOP_NOT_A_REPOSITORY } from './constants/snapshot-stages.constants.js';
|
|
11
11
|
/**
|
|
12
12
|
* The snapshot flow, as the list of stages it is.
|
|
13
13
|
*
|
|
@@ -43,7 +43,8 @@ export function runSnapshotPipeline(pipeline) {
|
|
|
43
43
|
// sequential seconds of the hook's answer if nothing bounds them.
|
|
44
44
|
run: budgetedRunner(pipeline.input.run, pipeline.input.deadline),
|
|
45
45
|
refs: [],
|
|
46
|
-
|
|
46
|
+
candidates: [],
|
|
47
|
+
merged: [],
|
|
47
48
|
branches: []
|
|
48
49
|
};
|
|
49
50
|
return runFlow(SNAPSHOT_STAGES, initial, (trace) => {
|
|
@@ -60,48 +61,103 @@ export function runSnapshotPipeline(pipeline) {
|
|
|
60
61
|
*/
|
|
61
62
|
async function collectRefs(state) {
|
|
62
63
|
const { cwd } = state.input;
|
|
63
|
-
const refs = await collectBranchRefs({ cwd, branchCount:
|
|
64
|
+
const refs = await collectBranchRefs({ cwd, branchCount: SNAPSHOT_SCAN_COUNT, ...(state.input.requiredBranches ? { requiredBranches: state.input.requiredBranches } : {}) }, state.run);
|
|
64
65
|
if (refs.length === 0)
|
|
65
66
|
return stop(state, STOP_NOT_A_REPOSITORY);
|
|
66
67
|
const defaultBranch = await resolveDefaultBranch(cwd, state.run);
|
|
67
68
|
return next({ ...state, refs, defaultBranch });
|
|
68
69
|
}
|
|
69
70
|
/**
|
|
70
|
-
* Compare the heads against what was last
|
|
71
|
+
* Compare the heads against what was last recorded.
|
|
71
72
|
*
|
|
72
73
|
* @param state - Current flow state.
|
|
73
|
-
* @returns The state with its
|
|
74
|
+
* @returns The state with its walk, or a stop when nothing in reach is due.
|
|
74
75
|
*/
|
|
75
76
|
async function selectChanged(state) {
|
|
76
77
|
const stored = await state.store.read(state.input.repository);
|
|
77
|
-
const selected =
|
|
78
|
-
|
|
78
|
+
const selected = snapshotCandidates(selectionInput({ ...state, stored }));
|
|
79
|
+
const required = new Set(state.input.requiredBranches);
|
|
80
|
+
const candidates = [
|
|
81
|
+
...state.refs.filter((ref) => required.has(ref.name)).map((ref) => ({ ref, due: true })),
|
|
82
|
+
...selected.filter(({ ref }) => !required.has(ref.name))
|
|
83
|
+
];
|
|
84
|
+
if (!anyDue(candidates))
|
|
79
85
|
return stop({ ...state, stored }, STOP_NOTHING_CHANGED);
|
|
80
|
-
return next({ ...state, stored,
|
|
86
|
+
return next({ ...state, stored, candidates });
|
|
81
87
|
}
|
|
82
88
|
/**
|
|
83
|
-
*
|
|
89
|
+
* Walk the branches newest first until ten live ones are in hand.
|
|
84
90
|
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
* described
|
|
91
|
+
* A branch found already on the trunk does not count toward the ten, so the
|
|
92
|
+
* window fills from the next-newest live branches instead of shrinking. One
|
|
93
|
+
* that was described and has not moved counts without a git process. The walk
|
|
94
|
+
* ends at ten, at {@link SNAPSHOT_MAX_CHECKS} checks, or when the checks have
|
|
95
|
+
* spent all but the reserve the queue write needs; what it did not reach keeps
|
|
96
|
+
* its old entry and is checked on a later turn.
|
|
97
|
+
*
|
|
98
|
+
* A gone upstream is a verdict without a git process, but only for a branch
|
|
99
|
+
* the cache has never recorded: once one is recorded, a moved head or a
|
|
100
|
+
* heartbeat means a real check, so commits made after its pull request merged
|
|
101
|
+
* are seen as the new work they are, on this turn and every later one.
|
|
88
102
|
*
|
|
89
103
|
* @param state - Current flow state.
|
|
90
|
-
* @returns The state with its branches, or a stop when the
|
|
91
|
-
* before any branch was
|
|
104
|
+
* @returns The state with its live and merged branches, or a stop when the
|
|
105
|
+
* budget ran out before any branch was checked.
|
|
92
106
|
*/
|
|
93
107
|
async function collectCommits(state) {
|
|
94
|
-
const
|
|
108
|
+
const checkDeadline = state.input.deadline - SNAPSHOT_WRITE_RESERVE_MS;
|
|
109
|
+
const run = budgetedRunner(state.run, checkDeadline);
|
|
110
|
+
const merged = [];
|
|
95
111
|
const branches = [];
|
|
96
|
-
|
|
97
|
-
|
|
112
|
+
let live = 0;
|
|
113
|
+
let checks = 0;
|
|
114
|
+
for (const { ref, due } of state.candidates) {
|
|
115
|
+
if (live >= SNAPSHOT_BRANCH_COUNT)
|
|
116
|
+
break;
|
|
117
|
+
if (!due) {
|
|
118
|
+
live += 1;
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
if (!state.input.requiredBranches?.includes(ref.name) && ref.upstreamGone && !state.stored?.branches[ref.name]) {
|
|
122
|
+
merged.push(ref);
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
if (checks >= SNAPSHOT_MAX_CHECKS || remainingMs(checkDeadline) === 0)
|
|
98
126
|
break;
|
|
99
|
-
|
|
127
|
+
checks += 1;
|
|
128
|
+
const commits = await checkBranch(ref, state, run);
|
|
129
|
+
// A check the budget cut short is unknown, not live: its merge test may
|
|
130
|
+
// have been the call that was skipped, and failing open there would send
|
|
131
|
+
// a merged branch.
|
|
132
|
+
if (remainingMs(checkDeadline) === 0)
|
|
133
|
+
break;
|
|
134
|
+
if (!commits) {
|
|
135
|
+
merged.push(ref);
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
live += 1;
|
|
100
139
|
branches.push({ ...ref, commits });
|
|
101
140
|
}
|
|
102
|
-
if (branches.length === 0)
|
|
141
|
+
if (merged.length === 0 && branches.length === 0)
|
|
103
142
|
return stop(state, STOP_BUDGET_SPENT);
|
|
104
|
-
return next({ ...state, branches });
|
|
143
|
+
return next({ ...state, merged, branches });
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* One branch's delta, or undefined when its work is already on the trunk.
|
|
147
|
+
*
|
|
148
|
+
* @param ref - The branch.
|
|
149
|
+
* @param state - Current flow state.
|
|
150
|
+
* @param run - The checks' budgeted runner.
|
|
151
|
+
* @returns What {@link collectBranchCommits} says.
|
|
152
|
+
*/
|
|
153
|
+
function checkBranch(ref, state, run) {
|
|
154
|
+
return collectBranchCommits(ref.name, {
|
|
155
|
+
cwd: state.input.cwd,
|
|
156
|
+
defaultBranch: state.defaultBranch,
|
|
157
|
+
commitCount: SNAPSHOT_COMMITS_PER_BRANCH,
|
|
158
|
+
withFiles: state.input.files,
|
|
159
|
+
includeMerged: state.input.requiredBranches?.includes(ref.name)
|
|
160
|
+
}, run);
|
|
105
161
|
}
|
|
106
162
|
/**
|
|
107
163
|
* Build the event and put it through the same scrubber prompt text gets.
|
|
@@ -114,6 +170,8 @@ async function collectCommits(state) {
|
|
|
114
170
|
* @returns The state carrying the event to send.
|
|
115
171
|
*/
|
|
116
172
|
async function sanitize(state) {
|
|
173
|
+
if (state.branches.length === 0)
|
|
174
|
+
return next(state);
|
|
117
175
|
const event = buildRepoSnapshot({
|
|
118
176
|
identity: state.input,
|
|
119
177
|
defaultBranch: state.defaultBranch,
|
|
@@ -122,27 +180,43 @@ async function sanitize(state) {
|
|
|
122
180
|
return next({ ...state, event: sanitizeValue(event) });
|
|
123
181
|
}
|
|
124
182
|
/**
|
|
125
|
-
* Queue the event, then record what was
|
|
183
|
+
* Queue the event, then record what was checked.
|
|
126
184
|
*
|
|
127
185
|
* The cache is written only after the queue accepted the event. Written first,
|
|
128
186
|
* a failed enqueue would mark the branches as reported and nothing would ever
|
|
129
187
|
* offer them again.
|
|
130
188
|
*
|
|
189
|
+
* Branches already on the trunk are recorded too, as merged, with nothing
|
|
190
|
+
* queued when they are all there is: otherwise every turn would check them
|
|
191
|
+
* again. Their heads are what is recorded, so new commits select them again.
|
|
192
|
+
*
|
|
131
193
|
* @param state - Current flow state.
|
|
132
194
|
* @returns The state, unchanged.
|
|
133
195
|
*/
|
|
134
196
|
async function enqueue(state) {
|
|
197
|
+
if (state.branches.length === 0) {
|
|
198
|
+
await record(state);
|
|
199
|
+
return stop(state, STOP_ALL_ON_TRUNK);
|
|
200
|
+
}
|
|
135
201
|
if (!state.event)
|
|
136
202
|
return stop(state, STOP_NO_EVENT);
|
|
137
|
-
const
|
|
138
|
-
const queued = await withinBudget(state.queue.enqueue([state.event]), deadline);
|
|
203
|
+
const queued = await withinBudget(state.queue.enqueue([state.event]), state.input.deadline);
|
|
139
204
|
// Recording a send that may not have happened is the one thing this flow must
|
|
140
205
|
// never do: the branches would be marked reported and never offered again.
|
|
141
206
|
if (!queued)
|
|
142
207
|
return stop(state, STOP_BUDGET_SPENT);
|
|
143
|
-
await
|
|
208
|
+
await record(state);
|
|
144
209
|
return next(state);
|
|
145
210
|
}
|
|
211
|
+
/**
|
|
212
|
+
* Write the checked branches to the cache, within the budget.
|
|
213
|
+
*
|
|
214
|
+
* @param state - Current flow state.
|
|
215
|
+
* @returns Nothing; an abandoned write only means the branches are offered again.
|
|
216
|
+
*/
|
|
217
|
+
async function record(state) {
|
|
218
|
+
await withinBudget(state.store.write(state.input.repository, nextSnapshotState(selectionInput(state), state.branches, state.merged)), state.input.deadline);
|
|
219
|
+
}
|
|
146
220
|
/**
|
|
147
221
|
* The selection's view of this flow.
|
|
148
222
|
*
|
|
@@ -86,7 +86,9 @@ function readEntries(value) {
|
|
|
86
86
|
continue;
|
|
87
87
|
entries[name] = {
|
|
88
88
|
headSha: entry.headSha,
|
|
89
|
-
lastSentAt: typeof entry.lastSentAt === 'number' ? entry.lastSentAt : 0
|
|
89
|
+
lastSentAt: typeof entry.lastSentAt === 'number' ? entry.lastSentAt : 0,
|
|
90
|
+
...(typeof entry.base === 'string' ? { base: entry.base } : {}),
|
|
91
|
+
...(entry.merged === true ? { merged: true } : {})
|
|
90
92
|
};
|
|
91
93
|
}
|
|
92
94
|
return entries;
|
|
@@ -105,7 +107,9 @@ function readTree(value) {
|
|
|
105
107
|
sha: typeof record.sha === 'string' ? record.sha : undefined,
|
|
106
108
|
sentAt: typeof record.sentAt === 'number' ? record.sentAt : undefined,
|
|
107
109
|
sentFor: typeof record.sentFor === 'string' ? record.sentFor : undefined,
|
|
108
|
-
|
|
110
|
+
checkedAt: typeof record.checkedAt === 'number' ? record.checkedAt : undefined,
|
|
111
|
+
triedAt: typeof record.triedAt === 'number' ? record.triedAt : undefined,
|
|
112
|
+
triedFor: typeof record.triedFor === 'string' ? record.triedFor : undefined
|
|
109
113
|
};
|
|
110
114
|
}
|
|
111
115
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { FlowResult } from '../core/types/core.types.js';
|
|
2
2
|
import type { TreeFlowState, TreePipelineInput } from './types/snapshot.types.js';
|
|
3
3
|
/**
|
|
4
|
-
* Send the default branch's source paths and declaration names,
|
|
4
|
+
* Send the default branch's source paths and declaration names, and again whenever the trunk's tree changes.
|
|
5
5
|
*
|
|
6
6
|
* Shares the snapshot's deadline and never outlives it: an overrun stops
|
|
7
7
|
* without recording anything, so the next turn tries again. Never throws.
|