carrick 0.3.156 → 0.3.158
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/dist/cli.d.ts +7 -0
- package/dist/cli.js +4 -0
- package/dist/cli.js.map +1 -1
- package/dist/contract.d.ts +8 -1
- package/dist/contract.js.map +1 -1
- package/dist/engine-ask.d.ts +21 -0
- package/dist/engine-ask.js +50 -0
- package/dist/engine-ask.js.map +1 -0
- package/dist/facts/diff.d.ts +14 -1
- package/dist/facts/diff.js +21 -8
- package/dist/facts/diff.js.map +1 -1
- package/dist/facts/enabled.d.ts +6 -0
- package/dist/facts/enabled.js +8 -0
- package/dist/facts/enabled.js.map +1 -1
- package/dist/facts/fetch.d.ts +7 -0
- package/dist/facts/fetch.js +24 -2
- package/dist/facts/fetch.js.map +1 -1
- package/dist/facts/lines.d.ts +22 -4
- package/dist/facts/lines.js +31 -9
- package/dist/facts/lines.js.map +1 -1
- package/dist/facts/peers.d.ts +13 -4
- package/dist/facts/peers.js +17 -15
- package/dist/facts/peers.js.map +1 -1
- package/dist/facts/rules/packages.js +3 -1
- package/dist/facts/rules/packages.js.map +1 -1
- package/dist/facts/rules/same-name.js +1 -1
- package/dist/facts/rules/same-name.js.map +1 -1
- package/dist/facts/store.d.ts +15 -0
- package/dist/facts/store.js +30 -0
- package/dist/facts/store.js.map +1 -1
- package/dist/held/backoff.d.ts +8 -0
- package/dist/held/backoff.js +43 -0
- package/dist/held/backoff.js.map +1 -0
- package/dist/held/build.d.ts +17 -0
- package/dist/held/build.js +62 -0
- package/dist/held/build.js.map +1 -0
- package/dist/held/client.d.ts +43 -0
- package/dist/held/client.js +200 -0
- package/dist/held/client.js.map +1 -0
- package/dist/held/daemon.d.ts +151 -0
- package/dist/held/daemon.js +399 -0
- package/dist/held/daemon.js.map +1 -0
- package/dist/held/early.d.ts +28 -0
- package/dist/held/early.js +115 -0
- package/dist/held/early.js.map +1 -0
- package/dist/held/engine.d.ts +50 -0
- package/dist/held/engine.js +166 -0
- package/dist/held/engine.js.map +1 -0
- package/dist/held/paths.d.ts +15 -0
- package/dist/held/paths.js +44 -0
- package/dist/held/paths.js.map +1 -0
- package/dist/held/place.d.ts +130 -0
- package/dist/held/place.js +236 -0
- package/dist/held/place.js.map +1 -0
- package/dist/held/registry.d.ts +22 -0
- package/dist/held/registry.js +72 -0
- package/dist/held/registry.js.map +1 -0
- package/dist/held/run.d.ts +2 -0
- package/dist/held/run.js +78 -0
- package/dist/held/run.js.map +1 -0
- package/dist/held/runtime.d.ts +22 -0
- package/dist/held/runtime.js +612 -0
- package/dist/held/runtime.js.map +1 -0
- package/dist/held/shadow.d.ts +33 -0
- package/dist/held/shadow.js +68 -0
- package/dist/held/shadow.js.map +1 -0
- package/dist/held/steps.d.ts +11 -0
- package/dist/held/steps.js +29 -0
- package/dist/held/steps.js.map +1 -0
- package/dist/hook/bash-targets.d.ts +7 -2
- package/dist/hook/bash-targets.js +82 -27
- package/dist/hook/bash-targets.js.map +1 -1
- package/dist/hook/confirm.d.ts +79 -0
- package/dist/hook/confirm.js +220 -0
- package/dist/hook/confirm.js.map +1 -0
- package/dist/hook/edit-flow.d.ts +14 -3
- package/dist/hook/edit-flow.js +113 -33
- package/dist/hook/edit-flow.js.map +1 -1
- package/dist/hook/generation.d.ts +19 -0
- package/dist/hook/generation.js +75 -0
- package/dist/hook/generation.js.map +1 -0
- package/dist/hook/late.d.ts +50 -9
- package/dist/hook/late.js +104 -24
- package/dist/hook/late.js.map +1 -1
- package/dist/hook/lock.d.ts +26 -0
- package/dist/hook/lock.js +122 -0
- package/dist/hook/lock.js.map +1 -0
- package/dist/hook/post-bash.js +17 -8
- package/dist/hook/post-bash.js.map +1 -1
- package/dist/hook/post-edit.js +2 -2
- package/dist/hook/post-edit.js.map +1 -1
- package/dist/hook/post-read.js +25 -3
- package/dist/hook/post-read.js.map +1 -1
- package/dist/hook/post-search.js +1 -1
- package/dist/hook/post-search.js.map +1 -1
- package/dist/hook/probe.js +1 -0
- package/dist/hook/probe.js.map +1 -1
- package/dist/hook/read-answer.d.ts +5 -0
- package/dist/hook/read-answer.js +8 -4
- package/dist/hook/read-answer.js.map +1 -1
- package/dist/hook/rechecks.d.ts +59 -2
- package/dist/hook/rechecks.js +129 -119
- package/dist/hook/rechecks.js.map +1 -1
- package/dist/hook/session-start.d.ts +1 -1
- package/dist/hook/session-start.js +19 -5
- package/dist/hook/session-start.js.map +1 -1
- package/dist/hook/similar.d.ts +1 -1
- package/dist/hook/similar.js +21 -8
- package/dist/hook/similar.js.map +1 -1
- package/dist/hook/stop-wait.js +35 -16
- package/dist/hook/stop-wait.js.map +1 -1
- package/dist/hook/timings.d.ts +30 -2
- package/dist/hook/timings.js +8 -2
- package/dist/hook/timings.js.map +1 -1
- package/dist/hook/user-prompt.js +2 -2
- package/dist/hook/user-prompt.js.map +1 -1
- package/dist/hosted-snapshot.d.ts +27 -0
- package/dist/hosted-snapshot.js +32 -0
- package/dist/hosted-snapshot.js.map +1 -1
- package/dist/init/hosted.js +2 -9
- package/dist/init/hosted.js.map +1 -1
- package/dist/lsp-frame.d.ts +20 -0
- package/dist/lsp-frame.js +47 -0
- package/dist/lsp-frame.js.map +1 -0
- package/dist/render.d.ts +15 -1
- package/dist/render.js +50 -4
- package/dist/render.js.map +1 -1
- package/dist/server.js +5 -29
- package/dist/server.js.map +1 -1
- package/package.json +6 -6
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/sidecar/dist/src/capture/anchors.d.ts +8 -0
- package/sidecar/dist/src/capture/anchors.js +3 -2
- package/sidecar/dist/src/capture/api.d.ts +98 -1
- package/sidecar/dist/src/capture/check-classify.d.ts +7 -0
- package/sidecar/dist/src/capture/check-classify.js +24 -0
- package/sidecar/dist/src/capture/check-probe.d.ts +86 -11
- package/sidecar/dist/src/capture/check-probe.js +175 -22
- package/sidecar/dist/src/capture/check.js +13 -1
- package/sidecar/dist/src/capture/graphql-leaves.d.ts +46 -0
- package/sidecar/dist/src/capture/graphql-leaves.js +142 -0
- package/sidecar/dist/src/capture/index.d.ts +12 -3
- package/sidecar/dist/src/capture/index.js +11 -2
- package/sidecar/dist/src/capture/result-label.js +3 -1
- package/sidecar/dist/src/capture/type-reasons.json +78 -0
- package/sidecar/dist/src/definition-resolver.d.ts +6 -5
- package/sidecar/dist/src/definition-resolver.js +20 -15
- package/sidecar/dist/src/engine-stamp.json +1 -0
- package/sidecar/dist/src/held-shadow.d.ts +70 -0
- package/sidecar/dist/src/held-shadow.js +222 -0
- package/sidecar/dist/src/index.js +65 -2
- package/sidecar/dist/src/library-claims.d.ts +3 -1
- package/sidecar/dist/src/library-claims.js +105 -6
- package/sidecar/dist/src/retype.d.ts +47 -0
- package/sidecar/dist/src/retype.js +274 -18
- package/sidecar/dist/src/site-find.d.ts +27 -0
- package/sidecar/dist/src/site-find.js +109 -0
- package/sidecar/dist/src/type-home.d.ts +12 -0
- package/sidecar/dist/src/type-home.js +41 -1
- package/sidecar/dist/src/type-inferrer.d.ts +13 -3
- package/sidecar/dist/src/type-inferrer.js +44 -22
- package/sidecar/dist/src/type-structural-expander.d.ts +11 -11
- package/sidecar/dist/src/type-structural-expander.js +73 -4
- package/sidecar/dist/src/types.d.ts +91 -5
- package/sidecar/dist/src/validators.d.ts +621 -254
- package/sidecar/dist/src/validators.js +37 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Which index each part of the hooks reads (carrick#3434). The fact lines
|
|
2
|
+
// (part 1) read the fact file, which is the hosted index; the re-check, Read,
|
|
3
|
+
// uses and search lines (part 2) read this machine's copy. When the two name
|
|
4
|
+
// different commits for a repo, the first part-2 line of a session says so
|
|
5
|
+
// once, and the session start says so in its first line. The comparison is
|
|
6
|
+
// `generationGap` (`hosted-snapshot.ts`), the one answer; this file reads the
|
|
7
|
+
// fact file and keeps the said-once key.
|
|
8
|
+
import { createLogger } from "../log.js";
|
|
9
|
+
import { generationGap } from "../hosted-snapshot.js";
|
|
10
|
+
import { commitsOf } from "../facts/peers.js";
|
|
11
|
+
import { openFacts } from "../facts/store.js";
|
|
12
|
+
import { generationSentence } from "../render.js";
|
|
13
|
+
import { markTold, wasTold } from "./reuse.js";
|
|
14
|
+
const log = createLogger("carrick-generation");
|
|
15
|
+
/** The stamp one `check` answer carries for its own repo, or null when it names none. */
|
|
16
|
+
export function stampOf(result) {
|
|
17
|
+
if (!result.repo || !result.index_commit)
|
|
18
|
+
return null;
|
|
19
|
+
return { repo: result.repo, commit: result.index_commit, ...(result.indexed_at ? { indexedAt: result.indexed_at } : {}) };
|
|
20
|
+
}
|
|
21
|
+
/** One stamp per repo of `carrick status`: its commit when its services agree on one, else none. */
|
|
22
|
+
export function stampsOfStatus(services) {
|
|
23
|
+
const byRepo = new Map();
|
|
24
|
+
for (const service of services)
|
|
25
|
+
byRepo.set(service.repo, [...(byRepo.get(service.repo) ?? []), service]);
|
|
26
|
+
return [...byRepo].map(([repo, rows]) => {
|
|
27
|
+
const commits = new Set(rows.map((row) => row.index_commit));
|
|
28
|
+
const commit = commits.size === 1 ? rows[0].index_commit : null;
|
|
29
|
+
const indexedAt = rows.find((row) => row.indexed_at)?.indexed_at;
|
|
30
|
+
return { repo, commit, ...(indexedAt ? { indexedAt } : {}) };
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/** The gaps between the fact file under `root` and `local`, with the fact file's build time. Never throws. */
|
|
34
|
+
export async function gapsAgainstFacts(root, local) {
|
|
35
|
+
if (local.length === 0)
|
|
36
|
+
return { gaps: [], builtAt: null };
|
|
37
|
+
try {
|
|
38
|
+
const store = await openFacts(root);
|
|
39
|
+
if (store === null)
|
|
40
|
+
return { gaps: [], builtAt: null };
|
|
41
|
+
try {
|
|
42
|
+
return { gaps: generationGap(commitsOf(store.meta), store.repos, local), builtAt: store.meta["built_at"] ?? null };
|
|
43
|
+
}
|
|
44
|
+
finally {
|
|
45
|
+
store.close();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
log("generation read failed", String(error));
|
|
50
|
+
return { gaps: [], builtAt: null };
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/** The session start's sentence: the gap between the fact file and `carrick status`, or null. */
|
|
54
|
+
export async function sessionGenerationSentence(root, services, now) {
|
|
55
|
+
const { gaps, builtAt } = await gapsAgainstFacts(root, stampsOfStatus(services));
|
|
56
|
+
return generationSentence(gaps, builtAt, now);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The sentence for the first part-2 line of a session while the gap stands,
|
|
60
|
+
* from the answers' own stamps (no extra call). Said once per session under
|
|
61
|
+
* `generation::<sorted local commits>`: a new local commit is a new gap.
|
|
62
|
+
*/
|
|
63
|
+
export async function firstLineGeneration(root, session, stamps, now = Date.now(), home) {
|
|
64
|
+
if (!session || stamps.length === 0)
|
|
65
|
+
return null;
|
|
66
|
+
const { gaps, builtAt } = await gapsAgainstFacts(root, stamps);
|
|
67
|
+
if (gaps.length === 0)
|
|
68
|
+
return null;
|
|
69
|
+
const key = `generation::${gaps.map((gap) => gap.local).sort().join(",")}`;
|
|
70
|
+
if (wasTold(session, key, home))
|
|
71
|
+
return null;
|
|
72
|
+
markTold(session, [key], home);
|
|
73
|
+
return generationSentence(gaps, builtAt, now);
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=generation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generation.js","sourceRoot":"","sources":["../../src/hook/generation.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,8EAA8E;AAC9E,6EAA6E;AAC7E,2EAA2E;AAC3E,2EAA2E;AAC3E,8EAA8E;AAC9E,yCAAyC;AAEzC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEtD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9C,OAAO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GAAW;IAC3G,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,MAAM,gBAAgB,CAAC,IAAI,EAAE,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC;IACjF,OAAO,kBAAkB,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;AAChD,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,IAAY,EACZ,OAA2B,EAC3B,MAA6B,EAC7B,MAAc,IAAI,CAAC,GAAG,EAAE,EACxB,IAAa;IAEb,IAAI,CAAC,OAAO,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACjD,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,MAAM,gBAAgB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC/D,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACnC,MAAM,GAAG,GAAG,eAAe,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;IAC3E,IAAI,OAAO,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAC7C,QAAQ,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,CAAC;IAC/B,OAAO,kBAAkB,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;AAChD,CAAC"}
|
package/dist/hook/late.d.ts
CHANGED
|
@@ -1,13 +1,41 @@
|
|
|
1
|
-
import type { Answer } from "./rechecks.ts";
|
|
1
|
+
import type { Answer, EarlyAnswer } from "./rechecks.ts";
|
|
2
|
+
import type { LocalStamp } from "../hosted-snapshot.ts";
|
|
2
3
|
/** The words for one finished answer, or null when there is nothing to say. */
|
|
3
4
|
export declare function lateContext(answer: Answer, uses: boolean): string | null;
|
|
5
|
+
/**
|
|
6
|
+
* The full answer as a carrier prints it once its entry's early answer has
|
|
7
|
+
* spoken (part 3, B1, P10): without the breaks the early rows already stated
|
|
8
|
+
* and their mirror call rows, and one correction line for each early break the
|
|
9
|
+
* full re-check found compatible. An entry with no early answer, or whose early
|
|
10
|
+
* answer was never printed, is printed as it stands: an early break part 2 did
|
|
11
|
+
* not judge is then printed by its own carrier (`deliverEarly`).
|
|
12
|
+
*/
|
|
13
|
+
export declare function confirmAnswer(answer: Answer, home?: string): {
|
|
14
|
+
answer: Answer;
|
|
15
|
+
corrections: string[];
|
|
16
|
+
};
|
|
4
17
|
/**
|
|
5
18
|
* What a carrier prints for one finished answer it has claimed, oldest first:
|
|
6
|
-
* its similar-function blocks, then its words (`lateContext`),
|
|
7
|
-
*
|
|
8
|
-
*
|
|
19
|
+
* its similar-function blocks, then its words (`lateContext`), then any
|
|
20
|
+
* correction of its early answer, with the uses-count and lead keys marked as
|
|
21
|
+
* told. Shared by `deliverLate` and by the Stop hook for an answer queued in
|
|
22
|
+
* place of the probe (R46.2), so both print it the same way.
|
|
23
|
+
*/
|
|
24
|
+
export declare function deliverOne(session: string, raw: Answer, home?: string): string[];
|
|
25
|
+
/**
|
|
26
|
+
* What a carrier prints for one early answer (part 3, B1) it owes: the breaks
|
|
27
|
+
* not yet printed in this message (`seen`, the rows' keys), through the one
|
|
28
|
+
* renderer, claimed once under `<seq>.early.said` with the keys of every row the
|
|
29
|
+
* message states. When the full answer has already landed, only the rows it did
|
|
30
|
+
* not judge stand and print (R5a); the rest are its to say.
|
|
9
31
|
*/
|
|
10
|
-
export declare function
|
|
32
|
+
export declare function deliverEarly(owner: string, early: EarlyAnswer, seen: Set<string>, options?: {
|
|
33
|
+
home?: string;
|
|
34
|
+
now?: number;
|
|
35
|
+
late?: boolean;
|
|
36
|
+
}): string[];
|
|
37
|
+
/** Every early answer `session` is owed, printed oldest first (`deliverEarly`). */
|
|
38
|
+
export declare function deliverEarlies(session: string, seen: Set<string>, home?: string, now?: number, listing?: readonly string[]): string[];
|
|
11
39
|
/** Whether an answer holds a row to act on: a problem, a moved row, a deletion. */
|
|
12
40
|
export declare function hasFindings(answer: Answer): boolean;
|
|
13
41
|
/**
|
|
@@ -15,18 +43,31 @@ export declare function hasFindings(answer: Answer): boolean;
|
|
|
15
43
|
* the findings alone. No uses-count line and no leads, which a parent with
|
|
16
44
|
* many sub-agents would get once per file it never edited.
|
|
17
45
|
*/
|
|
18
|
-
export declare function adoptedLine(
|
|
46
|
+
export declare function adoptedLine(raw: Answer, home?: string): string | null;
|
|
19
47
|
/**
|
|
20
48
|
* The one reader of a finished `check --changed` answer, for every hook that
|
|
21
49
|
* speaks it (the carriers and Stop): a problem, or the clean line for the set a
|
|
22
50
|
* Stop named, once per set. Null when there is nothing to say.
|
|
23
51
|
*/
|
|
24
52
|
export declare function changedLine(session: string, answer: Answer, home?: string): string | null;
|
|
53
|
+
/** The index a delivered answer was read from, and where in the returned contexts its words start. */
|
|
54
|
+
export type LateStamp = {
|
|
55
|
+
root: string;
|
|
56
|
+
stamp: LocalStamp;
|
|
57
|
+
at: number;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* `deliverLate`, with the sentence saying which index the first part-2 line of
|
|
61
|
+
* the session read when it differs from the fact file's (once per session,
|
|
62
|
+
* `generation.ts`), placed before that line.
|
|
63
|
+
*/
|
|
64
|
+
export declare function deliverLateFirst(session: string | undefined, now?: number, seen?: Set<string>, home?: string): Promise<string[]>;
|
|
25
65
|
/**
|
|
26
66
|
* Claim and render every finished answer this session has not been given.
|
|
27
|
-
* Returns the contexts to print, oldest first. Nothing here throws.
|
|
67
|
+
* Returns the contexts to print, oldest first. Nothing here throws. `seen` are
|
|
68
|
+
* the early rows this message already states (the edit hook's in hand).
|
|
28
69
|
*/
|
|
29
|
-
export declare function deliverLate(session: string | undefined, now?: number): string[];
|
|
70
|
+
export declare function deliverLate(session: string | undefined, now?: number, seen?: Set<string>, home?: string, stamps?: LateStamp[]): string[];
|
|
30
71
|
/** The one JSON object a PostToolUse hook prints (the host attaches it to the tool result), or nothing when there are no lines. */
|
|
31
72
|
export declare function emitPostToolUse(contexts: readonly string[]): void;
|
|
32
73
|
/**
|
|
@@ -34,4 +75,4 @@ export declare function emitPostToolUse(contexts: readonly string[]): void;
|
|
|
34
75
|
* command that names no source file, a search tool): on the hook channel only,
|
|
35
76
|
* and nothing when none has landed.
|
|
36
77
|
*/
|
|
37
|
-
export declare function printLateOnly(session: string | undefined): void
|
|
78
|
+
export declare function printLateOnly(session: string | undefined): Promise<void>;
|
package/dist/hook/late.js
CHANGED
|
@@ -9,11 +9,13 @@
|
|
|
9
9
|
import { resolveChannel } from "../channel.js";
|
|
10
10
|
import { problemItems } from "../contract.js";
|
|
11
11
|
import { createLogger } from "../log.js";
|
|
12
|
-
import { answersTheEdit, changedCleanLine, changedLines, movedLines, renderPostToolUse } from "../render.js";
|
|
13
|
-
import { claimDelivery, isChanged, owedFor } from "./rechecks.js";
|
|
12
|
+
import { answersTheEdit, changedCleanLine, changedLines, correctionLine, movedLines, renderPostToolUse } from "../render.js";
|
|
13
|
+
import { claimDelivery, claimEarly, earlyOwedFor, earlySaid, isChanged, owedFor, readAnswer, readEarly, sessionListing } from "./rechecks.js";
|
|
14
|
+
import { confirmedResult, earlyRows, keepRows, standingEarly } from "./confirm.js";
|
|
14
15
|
import { markLed, markSaid, markTold, toldKey, wasLed, wasSaid, wasTold } from "./reuse.js";
|
|
15
16
|
import { similarLines } from "./similar.js";
|
|
16
17
|
import { needsBackground } from "./probe.js";
|
|
18
|
+
import { firstLineGeneration, stampOf } from "./generation.js";
|
|
17
19
|
const log = createLogger("carrick-late");
|
|
18
20
|
/** The words for one finished answer, or null when there is nothing to say. */
|
|
19
21
|
export function lateContext(answer, uses) {
|
|
@@ -38,13 +40,35 @@ export function lateContext(answer, uses) {
|
|
|
38
40
|
return null;
|
|
39
41
|
return renderPostToolUse(answer.result, answer.relative, { uses, late: true });
|
|
40
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* The full answer as a carrier prints it once its entry's early answer has
|
|
45
|
+
* spoken (part 3, B1, P10): without the breaks the early rows already stated
|
|
46
|
+
* and their mirror call rows, and one correction line for each early break the
|
|
47
|
+
* full re-check found compatible. An entry with no early answer, or whose early
|
|
48
|
+
* answer was never printed, is printed as it stands: an early break part 2 did
|
|
49
|
+
* not judge is then printed by its own carrier (`deliverEarly`).
|
|
50
|
+
*/
|
|
51
|
+
export function confirmAnswer(answer, home) {
|
|
52
|
+
if (isChanged(answer) || !answer.result || answer.result.error)
|
|
53
|
+
return { answer, corrections: [] };
|
|
54
|
+
const early = readEarly(answer.session, answer.seq, home);
|
|
55
|
+
const said = early === null ? null : earlySaid(answer.session, answer.seq, home);
|
|
56
|
+
if (early === null || said === null || said.size === 0)
|
|
57
|
+
return { answer, corrections: [] };
|
|
58
|
+
const { result, corrected } = confirmedResult(answer.result, early.result, said);
|
|
59
|
+
if (result !== answer.result)
|
|
60
|
+
log("late rows dropped: the early answer stated them", answer.relative);
|
|
61
|
+
return { answer: { ...answer, result }, corrections: corrected.map((label) => correctionLine(answer.relative, label)) };
|
|
62
|
+
}
|
|
41
63
|
/**
|
|
42
64
|
* What a carrier prints for one finished answer it has claimed, oldest first:
|
|
43
|
-
* its similar-function blocks, then its words (`lateContext`),
|
|
44
|
-
*
|
|
45
|
-
*
|
|
65
|
+
* its similar-function blocks, then its words (`lateContext`), then any
|
|
66
|
+
* correction of its early answer, with the uses-count and lead keys marked as
|
|
67
|
+
* told. Shared by `deliverLate` and by the Stop hook for an answer queued in
|
|
68
|
+
* place of the probe (R46.2), so both print it the same way.
|
|
46
69
|
*/
|
|
47
|
-
export function deliverOne(session,
|
|
70
|
+
export function deliverOne(session, raw, home) {
|
|
71
|
+
const { answer, corrections } = confirmAnswer(raw, home);
|
|
48
72
|
const contexts = [];
|
|
49
73
|
const key = answer.result ? toldKey(answer.result, answer.relative) : null;
|
|
50
74
|
// As the edit-time answer would have: no uses-count line where the fact
|
|
@@ -54,19 +78,45 @@ export function deliverOne(session, answer, home) {
|
|
|
54
78
|
// A lead the probe already delivered is in `led`; this one is for a file
|
|
55
79
|
// whose probe had no answer (carrick#3249).
|
|
56
80
|
const found = answer.result
|
|
57
|
-
? similarLines(answer.result, answer.relative, (similarKey) => !wasLed(session, similarKey, home), log)
|
|
81
|
+
? similarLines(answer.result, answer.relative, answer.cwd ?? null, (similarKey) => !wasLed(session, similarKey, home), log)
|
|
58
82
|
: null;
|
|
59
83
|
if (found && found.lines.length > 0) {
|
|
60
84
|
contexts.push(...found.lines);
|
|
61
85
|
markLed(session, found.keys, home);
|
|
62
86
|
}
|
|
63
|
-
if (
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
87
|
+
if (context) {
|
|
88
|
+
contexts.push(context);
|
|
89
|
+
if (key !== null && uses && answer.result?.uses_lines?.length)
|
|
90
|
+
markTold(session, [key], home);
|
|
91
|
+
}
|
|
92
|
+
contexts.push(...corrections);
|
|
68
93
|
return contexts;
|
|
69
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* What a carrier prints for one early answer (part 3, B1) it owes: the breaks
|
|
97
|
+
* not yet printed in this message (`seen`, the rows' keys), through the one
|
|
98
|
+
* renderer, claimed once under `<seq>.early.said` with the keys of every row the
|
|
99
|
+
* message states. When the full answer has already landed, only the rows it did
|
|
100
|
+
* not judge stand and print (R5a); the rest are its to say.
|
|
101
|
+
*/
|
|
102
|
+
export function deliverEarly(owner, early, seen, options = {}) {
|
|
103
|
+
const full = readAnswer(owner, early.seq, options.home);
|
|
104
|
+
const view = full?.state === "answered" && full.result && !full.result.error ? standingEarly(early.result, full.result) : early.result;
|
|
105
|
+
const rows = earlyRows(view);
|
|
106
|
+
if (!claimEarly(owner, early.seq, rows.map((row) => row.key), options.home, options.now))
|
|
107
|
+
return [];
|
|
108
|
+
const fresh = keepRows(view, (row) => !seen.has(row.key));
|
|
109
|
+
for (const row of rows)
|
|
110
|
+
seen.add(row.key);
|
|
111
|
+
const text = renderPostToolUse(fresh, early.relative, { early: true, uses: false, late: options.late !== false });
|
|
112
|
+
if (text)
|
|
113
|
+
log(`early answer ${early.relative} delivered ${Math.round(((options.now ?? Date.now()) - Date.parse(early.enqueued_at)) / 1000)} s after the edit`);
|
|
114
|
+
return text ? [text] : [];
|
|
115
|
+
}
|
|
116
|
+
/** Every early answer `session` is owed, printed oldest first (`deliverEarly`). */
|
|
117
|
+
export function deliverEarlies(session, seen, home, now = Date.now(), listing) {
|
|
118
|
+
return earlyOwedFor(session, home, listing).flatMap(({ owner, early }) => deliverEarly(owner, early, seen, { home, now }));
|
|
119
|
+
}
|
|
70
120
|
/**
|
|
71
121
|
* The clean line for a `check --changed` that answered with no problem over
|
|
72
122
|
* files a Stop named as still checking (hook-wording audit decision 1: a
|
|
@@ -97,10 +147,13 @@ export function hasFindings(answer) {
|
|
|
97
147
|
* the findings alone. No uses-count line and no leads, which a parent with
|
|
98
148
|
* many sub-agents would get once per file it never edited.
|
|
99
149
|
*/
|
|
100
|
-
export function adoptedLine(
|
|
101
|
-
if (isChanged(
|
|
102
|
-
return lateContext(
|
|
103
|
-
|
|
150
|
+
export function adoptedLine(raw, home) {
|
|
151
|
+
if (isChanged(raw))
|
|
152
|
+
return lateContext(raw, false);
|
|
153
|
+
const { answer, corrections } = confirmAnswer(raw, home);
|
|
154
|
+
const said = hasFindings(answer) ? lateContext(answer, false) : null;
|
|
155
|
+
const lines = [...(said ? [said] : []), ...corrections];
|
|
156
|
+
return lines.length > 0 ? lines.join("\n\n") : null;
|
|
104
157
|
}
|
|
105
158
|
/**
|
|
106
159
|
* The one reader of a finished `check --changed` answer, for every hook that
|
|
@@ -110,22 +163,44 @@ export function adoptedLine(answer) {
|
|
|
110
163
|
export function changedLine(session, answer, home) {
|
|
111
164
|
return lateContext(answer, false) ?? cleanNamedLine(session, answer, home);
|
|
112
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* `deliverLate`, with the sentence saying which index the first part-2 line of
|
|
168
|
+
* the session read when it differs from the fact file's (once per session,
|
|
169
|
+
* `generation.ts`), placed before that line.
|
|
170
|
+
*/
|
|
171
|
+
export async function deliverLateFirst(session, now = Date.now(), seen = new Set(), home) {
|
|
172
|
+
const stamps = [];
|
|
173
|
+
const contexts = deliverLate(session, now, seen, home, stamps);
|
|
174
|
+
const first = stamps[0];
|
|
175
|
+
if (!first)
|
|
176
|
+
return contexts;
|
|
177
|
+
const line = await firstLineGeneration(first.root, session, stamps.filter((s) => s.root === first.root).map((s) => s.stamp), now, home);
|
|
178
|
+
if (line)
|
|
179
|
+
contexts.splice(first.at, 0, line);
|
|
180
|
+
return contexts;
|
|
181
|
+
}
|
|
113
182
|
/**
|
|
114
183
|
* Claim and render every finished answer this session has not been given.
|
|
115
|
-
* Returns the contexts to print, oldest first. Nothing here throws.
|
|
184
|
+
* Returns the contexts to print, oldest first. Nothing here throws. `seen` are
|
|
185
|
+
* the early rows this message already states (the edit hook's in hand).
|
|
116
186
|
*/
|
|
117
|
-
export function deliverLate(session, now = Date.now()) {
|
|
187
|
+
export function deliverLate(session, now = Date.now(), seen = new Set(), home, stamps) {
|
|
118
188
|
if (!session)
|
|
119
189
|
return [];
|
|
120
190
|
const contexts = [];
|
|
121
191
|
try {
|
|
122
|
-
|
|
123
|
-
|
|
192
|
+
// Early answers first, so a full answer delivered beside its entry's
|
|
193
|
+
// early one is compared with it (`confirmAnswer`), never said twice.
|
|
194
|
+
// One listing of the sessions folder serves both readers.
|
|
195
|
+
const listing = sessionListing(home);
|
|
196
|
+
contexts.push(...deliverEarlies(session, seen, home, now, listing));
|
|
197
|
+
for (const { owner, answer } of owedFor(session, home, listing)) {
|
|
198
|
+
if (!claimDelivery(owner, answer.seq, home, now))
|
|
124
199
|
continue;
|
|
125
200
|
if (answer.failure)
|
|
126
201
|
log("background re-check failed", answer.relative, answer.failure);
|
|
127
202
|
if (owner !== session) {
|
|
128
|
-
const adopted = adoptedLine(answer);
|
|
203
|
+
const adopted = adoptedLine(answer, home);
|
|
129
204
|
log(`late answer ${answer.relative} of an ended sub-agent delivered`);
|
|
130
205
|
if (adopted)
|
|
131
206
|
contexts.push(adopted);
|
|
@@ -133,7 +208,12 @@ export function deliverLate(session, now = Date.now()) {
|
|
|
133
208
|
}
|
|
134
209
|
const seconds = Math.round((now - Date.parse(answer.enqueued_at)) / 1000);
|
|
135
210
|
log(`late answer ${answer.relative} delivered ${seconds} s after the edit`);
|
|
136
|
-
|
|
211
|
+
const said = deliverOne(session, answer, home);
|
|
212
|
+
contexts.push(...said);
|
|
213
|
+
// The index the words came from, for the first-line generation sentence.
|
|
214
|
+
const stamp = said.length > 0 && answer.result ? stampOf(answer.result) : null;
|
|
215
|
+
if (stamp)
|
|
216
|
+
stamps?.push({ root: answer.root, stamp, at: contexts.length - said.length });
|
|
137
217
|
}
|
|
138
218
|
}
|
|
139
219
|
catch (error) {
|
|
@@ -154,11 +234,11 @@ export function emitPostToolUse(contexts) {
|
|
|
154
234
|
* command that names no source file, a search tool): on the hook channel only,
|
|
155
235
|
* and nothing when none has landed.
|
|
156
236
|
*/
|
|
157
|
-
export function printLateOnly(session) {
|
|
237
|
+
export async function printLateOnly(session) {
|
|
158
238
|
if (!session)
|
|
159
239
|
return;
|
|
160
240
|
if (resolveChannel({ hooksInstalled: true }).channel !== "hook")
|
|
161
241
|
return;
|
|
162
|
-
emitPostToolUse(
|
|
242
|
+
emitPostToolUse(await deliverLateFirst(session));
|
|
163
243
|
}
|
|
164
244
|
//# sourceMappingURL=late.js.map
|
package/dist/hook/late.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"late.js","sourceRoot":"","sources":["../../src/hook/late.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,EAAE;AACF,+EAA+E;AAC/E,+EAA+E;AAC/E,6EAA6E;AAC7E,2EAA2E;AAC3E,4EAA4E;AAC5E,uBAAuB;AAEvB,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AM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;YAC/E,IAAI,KAAK;gBAAE,MAAM,EAAE,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,QAAQ,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;QAC3F,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,GAAG,CAAC,sBAAsB,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IAC7C,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,mIAAmI;AACnI,MAAM,UAAU,eAAe,CAAC,QAA2B;IACzD,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO;IAClC,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,IAAI,CAAC,SAAS,CAAC;QACb,kBAAkB,EAAE,EAAE,aAAa,EAAE,aAAa,EAAE,iBAAiB,EAAE,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE;KAC/F,CAAC,CACH,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,OAA2B;IAC7D,IAAI,CAAC,OAAO;QAAE,OAAO;IACrB,IAAI,cAAc,CAAC,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,KAAK,MAAM;QAAE,OAAO;IACxE,eAAe,CAAC,MAAM,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC;AACnD,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** A lock is stale this long after its holder's cap, whatever its pid says. */
|
|
2
|
+
export declare const STALE_SLACK_MS = 60000;
|
|
3
|
+
export type Lock = {
|
|
4
|
+
pid: number;
|
|
5
|
+
started: string;
|
|
6
|
+
touched: string;
|
|
7
|
+
};
|
|
8
|
+
export declare function alive(pid: number): boolean;
|
|
9
|
+
export declare function readJson<T>(file: string): T | null;
|
|
10
|
+
/**
|
|
11
|
+
* Create `file` holding `body`, only if it does not exist yet, and complete
|
|
12
|
+
* when it does: written beside it, then hard-linked into place (the one
|
|
13
|
+
* operation two processes cannot both win).
|
|
14
|
+
*/
|
|
15
|
+
export declare function createExclusive(file: string, body: string): boolean;
|
|
16
|
+
/** Whether the lock's holder is a live process that has touched it lately. */
|
|
17
|
+
export declare function lockHeld(lock: Lock | null, now: number, cap: number): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Take the lock at `file` for `pid`, replacing one nobody holds. The dead lock
|
|
20
|
+
* is re-read before it is removed, so a lock another process just replaced is
|
|
21
|
+
* never unlinked from under it. `takeOver` names the process that started
|
|
22
|
+
* `pid` and holds the lock until `pid` takes it.
|
|
23
|
+
*/
|
|
24
|
+
export declare function takeLock(file: string, pid: number, now: number, cap: number, takeOver?: number): boolean;
|
|
25
|
+
export declare function releaseLock(file: string, pid: number): void;
|
|
26
|
+
export declare function touchLock(file: string, pid: number, now: number): void;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// One lock file for one background process: the re-check runner and the
|
|
2
|
+
// held-compiler daemon both use it. A lock names a pid and the time it was last
|
|
3
|
+
// touched; it is held while that process is alive and has touched it lately.
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { writeAtomic } from "./reuse.js";
|
|
7
|
+
/** A lock is stale this long after its holder's cap, whatever its pid says. */
|
|
8
|
+
export const STALE_SLACK_MS = 60_000;
|
|
9
|
+
let tempCounter = 0;
|
|
10
|
+
export function alive(pid) {
|
|
11
|
+
try {
|
|
12
|
+
process.kill(pid, 0);
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
// EPERM: the process exists and is somebody else's.
|
|
17
|
+
return error.code === "EPERM";
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export function readJson(file) {
|
|
21
|
+
try {
|
|
22
|
+
return JSON.parse(fs.readFileSync(file, "utf8"));
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Create `file` holding `body`, only if it does not exist yet, and complete
|
|
30
|
+
* when it does: written beside it, then hard-linked into place (the one
|
|
31
|
+
* operation two processes cannot both win).
|
|
32
|
+
*/
|
|
33
|
+
export function createExclusive(file, body) {
|
|
34
|
+
tempCounter += 1;
|
|
35
|
+
const temp = `${file}.${process.pid}.${tempCounter}.tmp`;
|
|
36
|
+
try {
|
|
37
|
+
fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
38
|
+
fs.writeFileSync(temp, body, { flag: "wx", mode: 0o600 });
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
fs.linkSync(temp, file);
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
finally {
|
|
51
|
+
try {
|
|
52
|
+
fs.unlinkSync(temp);
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
// Already gone.
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function lockBody(pid, started, now) {
|
|
60
|
+
return `${JSON.stringify({ pid, started, touched: new Date(now).toISOString() })}\n`;
|
|
61
|
+
}
|
|
62
|
+
/** Whether the lock's holder is a live process that has touched it lately. */
|
|
63
|
+
export function lockHeld(lock, now, cap) {
|
|
64
|
+
if (lock === null || typeof lock.pid !== "number")
|
|
65
|
+
return false;
|
|
66
|
+
if (!alive(lock.pid))
|
|
67
|
+
return false;
|
|
68
|
+
const touched = Date.parse(lock.touched);
|
|
69
|
+
return Number.isFinite(touched) && now - touched <= cap + STALE_SLACK_MS;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Take the lock at `file` for `pid`, replacing one nobody holds. The dead lock
|
|
73
|
+
* is re-read before it is removed, so a lock another process just replaced is
|
|
74
|
+
* never unlinked from under it. `takeOver` names the process that started
|
|
75
|
+
* `pid` and holds the lock until `pid` takes it.
|
|
76
|
+
*/
|
|
77
|
+
export function takeLock(file, pid, now, cap, takeOver) {
|
|
78
|
+
const body = lockBody(pid, new Date(now).toISOString(), now);
|
|
79
|
+
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
80
|
+
if (createExclusive(file, body))
|
|
81
|
+
return true;
|
|
82
|
+
const seen = readJson(file);
|
|
83
|
+
if (seen !== null && seen.pid === pid) {
|
|
84
|
+
writeAtomic(file, body);
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
// The process that started this one holds the lock until it takes over.
|
|
88
|
+
if (seen !== null && takeOver !== undefined && seen.pid === takeOver) {
|
|
89
|
+
writeAtomic(file, body);
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
if (lockHeld(seen, now, cap))
|
|
93
|
+
return false;
|
|
94
|
+
const again = readJson(file);
|
|
95
|
+
if ((again?.pid ?? null) !== (seen?.pid ?? null))
|
|
96
|
+
return false;
|
|
97
|
+
try {
|
|
98
|
+
fs.unlinkSync(file);
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
// Another process removed it first; the retry decides between us.
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
export function releaseLock(file, pid) {
|
|
107
|
+
if (readJson(file)?.pid !== pid)
|
|
108
|
+
return;
|
|
109
|
+
try {
|
|
110
|
+
fs.unlinkSync(file);
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
// Already gone.
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
export function touchLock(file, pid, now) {
|
|
117
|
+
const held = readJson(file);
|
|
118
|
+
if (held?.pid !== pid)
|
|
119
|
+
return;
|
|
120
|
+
writeAtomic(file, lockBody(pid, held.started, now));
|
|
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W;IACnD,IAAI,QAAQ,CAAO,IAAI,CAAC,EAAE,GAAG,KAAK,GAAG;QAAE,OAAO;IAC9C,IAAI,CAAC;QACH,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC;IAAC,MAAM,CAAC;QACP,gBAAgB;IAClB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,IAAY,EAAE,GAAW,EAAE,GAAW;IAC9D,MAAM,IAAI,GAAG,QAAQ,CAAO,IAAI,CAAC,CAAC;IAClC,IAAI,IAAI,EAAE,GAAG,KAAK,GAAG;QAAE,OAAO;IAC9B,WAAW,CAAC,IAAI,EAAE,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;AACtD,CAAC"}
|
package/dist/hook/post-bash.js
CHANGED
|
@@ -18,12 +18,15 @@
|
|
|
18
18
|
// starts nothing and prints only the background re-check answers that landed
|
|
19
19
|
// since the last hook spoke (`late.ts`): the Stop hook never waits for them,
|
|
20
20
|
// so this is often the first hook after one lands (hook-wording audit T2).
|
|
21
|
-
//
|
|
21
|
+
// Every run writes one `post-bash` timing row through `timed`, as the other
|
|
22
|
+
// hooks do (carrick#4415). Whatever happens it exits 0 and prints at most the
|
|
23
|
+
// one JSON object.
|
|
22
24
|
import { readStdin } from "./stdin.js";
|
|
23
25
|
import { sessionKey } from "./session-key.js";
|
|
24
26
|
import { factsEnabled } from "../facts/enabled.js";
|
|
25
27
|
import path from "node:path";
|
|
26
28
|
import fs from "node:fs";
|
|
29
|
+
import { timed } from "./timings.js";
|
|
27
30
|
import { bashTargets, MENTIONS_FACT_SOURCE, movesTreeInBulk, searchedNames } from "./bash-targets.js";
|
|
28
31
|
/** At most this many files are asked about for one command. */
|
|
29
32
|
const MAX_FILES = 2;
|
|
@@ -36,9 +39,9 @@ const SEARCH_WORD = /\b(grep|rg|egrep|fgrep)\b/;
|
|
|
36
39
|
/** The late answers alone, through the shared printer (`late.ts`). */
|
|
37
40
|
async function lateOnly(session) {
|
|
38
41
|
const { printLateOnly } = await import("./late.js");
|
|
39
|
-
printLateOnly(session);
|
|
42
|
+
await printLateOnly(session);
|
|
40
43
|
}
|
|
41
|
-
async function main() {
|
|
44
|
+
async function main(timing) {
|
|
42
45
|
let payload;
|
|
43
46
|
try {
|
|
44
47
|
payload = JSON.parse((await readStdin()) || "{}");
|
|
@@ -50,7 +53,7 @@ async function main() {
|
|
|
50
53
|
if (!command || !(MENTIONS_FACT_SOURCE.test(command) || SEARCH_WORD.test(command)))
|
|
51
54
|
return lateOnly(sessionKey(payload));
|
|
52
55
|
const cwd = payload.cwd ?? process.cwd();
|
|
53
|
-
const { reads, writes, factWrites } = bashTargets(command, path.resolve(cwd));
|
|
56
|
+
const { reads, writes, factWrites } = bashTargets(command, path.resolve(cwd), { durationMs: payload.duration_ms });
|
|
54
57
|
const candidates = writes.length + factWrites.length > 0 && !movesTreeInBulk(command, path.resolve(cwd)) ? [...writes, ...factWrites] : [];
|
|
55
58
|
// A search for a function's name: the index sites its output did not print.
|
|
56
59
|
const searched = SEARCH_WORD.test(command) ? searchedNames(command, path.resolve(cwd)) : { names: [], operands: [] };
|
|
@@ -97,7 +100,11 @@ async function main() {
|
|
|
97
100
|
const { answerReads } = await import("./read-answer.js");
|
|
98
101
|
// A command that also writes keeps the binary's read answer (the edit flow's
|
|
99
102
|
// own fact lines share no cap with it).
|
|
103
|
+
const waitStarted = Date.now();
|
|
100
104
|
const read = await answerReads(fresh, payload.cwd, session, { facts: capped.length === 0 });
|
|
105
|
+
timing.waitedMs = Date.now() - waitStarted;
|
|
106
|
+
if (read.factsMs !== undefined)
|
|
107
|
+
timing.factsMs = read.factsMs;
|
|
101
108
|
const answers = [...read.contexts];
|
|
102
109
|
const response = payload.tool_response;
|
|
103
110
|
const output = typeof response === "string" ? response : response?.stdout;
|
|
@@ -124,15 +131,17 @@ async function main() {
|
|
|
124
131
|
changes.set(file, found);
|
|
125
132
|
}
|
|
126
133
|
}
|
|
127
|
-
|
|
134
|
+
// The row names the first written file, as the edit hook's does.
|
|
135
|
+
timing.file = capped[0];
|
|
136
|
+
await editFlow({ cwd: payload.cwd ?? null, session, subAgent: Boolean(payload.agent_id), channel: channel.channel, shell: true, timing, changes, factOnly }, toEdit, answers);
|
|
128
137
|
return;
|
|
129
138
|
}
|
|
130
|
-
const {
|
|
131
|
-
emitPostToolUse([...
|
|
139
|
+
const { deliverLateFirst, emitPostToolUse } = await import("./late.js");
|
|
140
|
+
emitPostToolUse([...(await deliverLateFirst(session)), ...answers]);
|
|
132
141
|
// Claimed only now that the lines are printed.
|
|
133
142
|
if (session)
|
|
134
143
|
reuse.markFacts(session, read.claims);
|
|
135
144
|
}
|
|
136
|
-
await main
|
|
145
|
+
await timed("post-bash", main);
|
|
137
146
|
process.exit(0);
|
|
138
147
|
//# sourceMappingURL=post-bash.js.map
|