agentrinse 0.7.0 → 0.8.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/README.md +29 -11
- package/dist/adapters/codex-database.d.ts.map +1 -1
- package/dist/adapters/codex-database.js +6 -11
- package/dist/adapters/codex-database.js.map +1 -1
- package/dist/adapters/git/adapter.d.ts +10 -0
- package/dist/adapters/git/adapter.d.ts.map +1 -1
- package/dist/adapters/git/adapter.js +105 -20
- package/dist/adapters/git/adapter.js.map +1 -1
- package/dist/adapters/git/refs.d.ts +8 -4
- package/dist/adapters/git/refs.d.ts.map +1 -1
- package/dist/adapters/git/refs.js +35 -18
- package/dist/adapters/git/refs.js.map +1 -1
- package/dist/adapters/registry.d.ts +7 -0
- package/dist/adapters/registry.d.ts.map +1 -1
- package/dist/adapters/registry.js +16 -6
- package/dist/adapters/registry.js.map +1 -1
- package/dist/commands/clean.d.ts +45 -17
- package/dist/commands/clean.d.ts.map +1 -1
- package/dist/commands/clean.js +217 -45
- package/dist/commands/clean.js.map +1 -1
- package/dist/commands/purge.d.ts.map +1 -1
- package/dist/commands/purge.js +12 -8
- package/dist/commands/purge.js.map +1 -1
- package/dist/core/apply.d.ts.map +1 -1
- package/dist/core/apply.js +9 -7
- package/dist/core/apply.js.map +1 -1
- package/dist/core/bounded-command.d.ts +25 -0
- package/dist/core/bounded-command.d.ts.map +1 -0
- package/dist/core/bounded-command.js +91 -0
- package/dist/core/bounded-command.js.map +1 -0
- package/dist/core/process-ownership.d.ts +8 -1
- package/dist/core/process-ownership.d.ts.map +1 -1
- package/dist/core/process-ownership.js +102 -25
- package/dist/core/process-ownership.js.map +1 -1
- package/dist/core/reachability.d.ts +5 -2
- package/dist/core/reachability.d.ts.map +1 -1
- package/dist/core/reachability.js +22 -8
- package/dist/core/reachability.js.map +1 -1
- package/dist/core/worktree-executor.d.ts.map +1 -1
- package/dist/core/worktree-executor.js +12 -9
- package/dist/core/worktree-executor.js.map +1 -1
- package/dist/core/worktree-revalidation.d.ts.map +1 -1
- package/dist/core/worktree-revalidation.js +15 -6
- package/dist/core/worktree-revalidation.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +19 -5
- package/dist/main.js.map +1 -1
- package/dist/state/json-file.d.ts +1 -0
- package/dist/state/json-file.d.ts.map +1 -1
- package/dist/state/json-file.js +90 -27
- package/dist/state/json-file.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +5 -5
|
@@ -1,24 +1,41 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
1
|
+
async function gitRefExists(runGit, gitRef) {
|
|
2
|
+
const refs = (await runGit(["for-each-ref", "--format=%(refname)", "--", gitRef]))
|
|
3
3
|
.split(/\r?\n/u)
|
|
4
4
|
.map((line) => line.trim())
|
|
5
5
|
.filter((line) => line.length > 0);
|
|
6
|
+
if (refs.some((ref) => !ref.startsWith("refs/"))) {
|
|
7
|
+
throw new Error(`invalid Git ref inspection output for ${gitRef}`);
|
|
8
|
+
}
|
|
9
|
+
return refs.includes(gitRef);
|
|
6
10
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
11
|
+
async function gitRefContainsHead(runGit, head, gitRef) {
|
|
12
|
+
if (!(await gitRefExists(runGit, gitRef))) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
if (gitRef.startsWith("refs/tags/")) {
|
|
16
|
+
return (await runGit(["rev-parse", `${gitRef}^{commit}`])).trim() === head;
|
|
17
|
+
}
|
|
18
|
+
return (await runGit(["rev-list", "--max-count=1", head, "--not", gitRef])).trim() === "";
|
|
19
|
+
}
|
|
20
|
+
export async function isPushedHead(runGit, input) {
|
|
21
|
+
if (!input.remoteConfigured || input.detached) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
if (input.upstream === undefined) {
|
|
25
|
+
return ((await runGit(["rev-list", "--max-count=1", input.head, "--not", "--remotes"])).trim() === "");
|
|
26
|
+
}
|
|
27
|
+
const upstream = input.upstream.startsWith("refs/")
|
|
28
|
+
? input.upstream
|
|
29
|
+
: `refs/remotes/${input.upstream}`;
|
|
30
|
+
return input.ahead === 0 && (await gitRefContainsHead(runGit, input.head, upstream));
|
|
31
|
+
}
|
|
32
|
+
export async function matchingGitRefPins(runGit, head, gitRefs) {
|
|
33
|
+
const matches = [];
|
|
34
|
+
for (const gitRef of gitRefs) {
|
|
35
|
+
if (await gitRefContainsHead(runGit, head, gitRef)) {
|
|
36
|
+
matches.push(gitRef);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return matches;
|
|
23
40
|
}
|
|
24
41
|
//# sourceMappingURL=refs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refs.js","sourceRoot":"","sources":["../../../src/adapters/git/refs.ts"],"names":[],"mappings":"AAEA,
|
|
1
|
+
{"version":3,"file":"refs.js","sourceRoot":"","sources":["../../../src/adapters/git/refs.ts"],"names":[],"mappings":"AAEA,KAAK,UAAU,YAAY,CAAC,MAA2B,EAAE,MAAc;IACrE,MAAM,IAAI,GAAG,CAAC,MAAM,MAAM,CAAC,CAAC,cAAc,EAAE,qBAAqB,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;SAC/E,KAAK,CAAC,QAAQ,CAAC;SACf,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;SAC1B,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACrC,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,UAAU,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K,CAAC,QAAQ;QAChB,CAAC,CAAC,gBAAgB,KAAK,CAAC,QAAQ,EAAE,CAAC;IACrC,OAAO,KAAK,CAAC,KAAK,KAAK,CAAC,IAAI,CAAC,MAAM,kBAAkB,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC;AACvF,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,MAA2B,EAC3B,IAAY,EACZ,OAA0B;IAE1B,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,IAAI,MAAM,kBAAkB,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,EAAE,CAAC;YACnD,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
import type { AgentRinseConfig } from "../config/schema.js";
|
|
2
2
|
import type { AuditAdapter } from "../contracts/adapter.js";
|
|
3
|
+
import { type ProcessOwnershipResult } from "../core/process-ownership.js";
|
|
3
4
|
import { ReachabilityIndex, type ReachabilityRoot } from "../core/reachability.js";
|
|
5
|
+
import { type GitWorktreeDependencies } from "./git/adapter.js";
|
|
4
6
|
import { type ProviderAdapterId } from "./provider-specs.js";
|
|
5
7
|
export type AuditAdapterRegistryOptions = {
|
|
6
8
|
providers?: readonly ProviderAdapterId[];
|
|
7
9
|
providerInventory?: boolean;
|
|
8
10
|
roots?: ReachabilityRoot[];
|
|
11
|
+
gitRepositories?: readonly {
|
|
12
|
+
root: string | undefined;
|
|
13
|
+
discovery?: GitWorktreeDependencies["discovery"];
|
|
14
|
+
}[];
|
|
9
15
|
environment?: NodeJS.ProcessEnv;
|
|
10
16
|
reachability?: ReachabilityIndex;
|
|
11
17
|
allowOfflineVacuum?: boolean;
|
|
18
|
+
processProbe?: (path: string) => Promise<ProcessOwnershipResult>;
|
|
12
19
|
};
|
|
13
20
|
export declare function createAuditAdapters(config: AgentRinseConfig, platform?: NodeJS.Platform, options?: AuditAdapterRegistryOptions): AuditAdapter[];
|
|
14
21
|
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/adapters/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAE5D,OAAO,EAAE,iBAAiB,EAAE,KAAK,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/adapters/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAE5D,OAAO,EAEL,KAAK,sBAAsB,EAC5B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,iBAAiB,EAAE,KAAK,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAGnF,OAAO,EAA2B,KAAK,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAEzF,OAAO,EAAgC,KAAK,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAK3F,MAAM,MAAM,2BAA2B,GAAG;IACxC,SAAS,CAAC,EAAE,SAAS,iBAAiB,EAAE,CAAC;IACzC,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,KAAK,CAAC,EAAE,gBAAgB,EAAE,CAAC;IAC3B,eAAe,CAAC,EAAE,SAAS;QACzB,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;QACzB,SAAS,CAAC,EAAE,uBAAuB,CAAC,WAAW,CAAC,CAAC;KAClD,EAAE,CAAC;IACJ,WAAW,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IAChC,YAAY,CAAC,EAAE,iBAAiB,CAAC;IACjC,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,sBAAsB,CAAC,CAAC;CAClE,CAAC;AAqBF,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,gBAAgB,EACxB,QAAQ,GAAE,MAAM,CAAC,QAA2B,EAC5C,OAAO,GAAE,2BAAgC,GACxC,YAAY,EAAE,CAgHhB"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { sha256 } from "../core/digest.js";
|
|
2
|
+
import { createProcessOwnershipProbe, } from "../core/process-ownership.js";
|
|
2
3
|
import { ReachabilityIndex } from "../core/reachability.js";
|
|
3
4
|
import { ArtifactAuditAdapter } from "./artifacts/adapter.js";
|
|
4
5
|
import { DockerAuditAdapter } from "./docker/adapter.js";
|
|
@@ -27,6 +28,9 @@ function validateProviderSelection(providers) {
|
|
|
27
28
|
}
|
|
28
29
|
export function createAuditAdapters(config, platform = process.platform, options = {}) {
|
|
29
30
|
const reachability = options.reachability ?? new ReachabilityIndex();
|
|
31
|
+
// One failed ownership scan protects the rest of this audit without retrying lsof.
|
|
32
|
+
// Revalidation and apply construct fresh probes from current process state.
|
|
33
|
+
const processProbe = options.processProbe ?? createProcessOwnershipProbe({ platform });
|
|
30
34
|
const providerSelection = options.providers === undefined ? undefined : validateProviderSelection(options.providers);
|
|
31
35
|
const exclusiveProviders = providerSelection !== undefined;
|
|
32
36
|
const gitEnabled = !exclusiveProviders && config.adapters.git?.enabled === true;
|
|
@@ -72,17 +76,23 @@ export function createAuditAdapters(config, platform = process.platform, options
|
|
|
72
76
|
return adapters;
|
|
73
77
|
}
|
|
74
78
|
if (gitEnabled) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
79
|
+
const gitRepositories = options.gitRepositories ?? [{ root: config.adapters.git?.root }];
|
|
80
|
+
for (const repository of gitRepositories) {
|
|
81
|
+
adapters.push(new GitWorktreeAuditAdapter(repository.root, undefined, undefined, processProbe, reachability, {
|
|
82
|
+
...config.audit,
|
|
83
|
+
...config.worktrees,
|
|
84
|
+
platform,
|
|
85
|
+
}, {
|
|
86
|
+
isolateRepositoryFailure: options.gitRepositories !== undefined,
|
|
87
|
+
...(repository.discovery === undefined ? {} : { discovery: repository.discovery }),
|
|
88
|
+
}));
|
|
89
|
+
}
|
|
80
90
|
}
|
|
81
91
|
if (config.artifacts.projects.length > 0) {
|
|
82
92
|
adapters.push(new ArtifactAuditAdapter({
|
|
83
93
|
...config.artifacts,
|
|
84
94
|
...config.audit,
|
|
85
|
-
},
|
|
95
|
+
}, processProbe, undefined, reachability));
|
|
86
96
|
}
|
|
87
97
|
if (config.adapters.runtime?.enabled !== false) {
|
|
88
98
|
adapters.push(new RuntimeAuditAdapter({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/adapters/registry.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAyB,MAAM,yBAAyB,CAAC;AACnF,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,uBAAuB,
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/adapters/registry.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EACL,2BAA2B,GAE5B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,iBAAiB,EAAyB,MAAM,yBAAyB,CAAC;AACnF,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AA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AAW,IAAI,OAAO,CAAC,GAAG,CAAC;QACvD,MAAM,eAAe,GAAG,WAAW,CAAC,gBAAgB,CAAC,EAAE,IAAI,EAAE,IAAI,SAAS,CAAC;QAC3E,QAAQ,CAAC,IAAI,CACX,IAAI,kBAAkB,CAAC,SAAS,EAAE;YAChC,eAAe;YACf,WAAW;SACZ,CAAC,CACH,CAAC;IACJ,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
package/dist/commands/clean.d.ts
CHANGED
|
@@ -2,12 +2,10 @@ import { type ActionRisk } from "../contracts/action.js";
|
|
|
2
2
|
import type { CleanupPlan } from "../contracts/plan.js";
|
|
3
3
|
import type { AuditReport } from "../contracts/report.js";
|
|
4
4
|
import type { CleanupRun } from "../contracts/run.js";
|
|
5
|
-
|
|
5
|
+
type CleanCommandBaseOptions = {
|
|
6
6
|
home: string;
|
|
7
7
|
config?: string;
|
|
8
8
|
stateDir?: string;
|
|
9
|
-
profile: "closeout";
|
|
10
|
-
cwd?: string;
|
|
11
9
|
apply: boolean;
|
|
12
10
|
yes: boolean;
|
|
13
11
|
json: boolean;
|
|
@@ -22,42 +20,72 @@ export type CleanCommandOptions = {
|
|
|
22
20
|
}>;
|
|
23
21
|
};
|
|
24
22
|
};
|
|
23
|
+
export type CloseoutCleanCommandOptions = CleanCommandBaseOptions & {
|
|
24
|
+
profile: "closeout";
|
|
25
|
+
cwd?: string;
|
|
26
|
+
};
|
|
27
|
+
export type FleetCleanCommandOptions = CleanCommandBaseOptions & {
|
|
28
|
+
profile: "fleet";
|
|
29
|
+
repos: string[];
|
|
30
|
+
};
|
|
31
|
+
export type CleanCommandOptions = CloseoutCleanCommandOptions | FleetCleanCommandOptions;
|
|
25
32
|
export type MoleHandoff = {
|
|
26
33
|
status: "available" | "absent" | "not-applicable";
|
|
27
34
|
suggestions: string[];
|
|
28
35
|
};
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
36
|
+
type RunSummary = Pick<CleanupRun, "runId" | "status" | "reclaimedBytes"> & {
|
|
37
|
+
journalPath: string;
|
|
38
|
+
quarantinedBytes: number;
|
|
39
|
+
};
|
|
40
|
+
type SavedCleanSummary = {
|
|
33
41
|
auditId: string;
|
|
34
42
|
planId: string;
|
|
35
43
|
auditPath: string;
|
|
36
44
|
planPath: string;
|
|
37
45
|
configPath: string;
|
|
46
|
+
run?: RunSummary;
|
|
47
|
+
};
|
|
48
|
+
export type CloseoutSummary = SavedCleanSummary & {
|
|
49
|
+
profile: "closeout";
|
|
50
|
+
repositoryRoot: string;
|
|
51
|
+
currentWorktree: string;
|
|
38
52
|
worktrees: number;
|
|
39
53
|
protectedWorktrees: number;
|
|
40
54
|
eligibleActions: number;
|
|
41
55
|
expectedReclaimBytes: number;
|
|
42
56
|
pendingQuarantineBytes: number;
|
|
43
57
|
mole: MoleHandoff;
|
|
44
|
-
run?: {
|
|
45
|
-
runId: string;
|
|
46
|
-
status: CleanupRun["status"];
|
|
47
|
-
journalPath: string;
|
|
48
|
-
reclaimedBytes: number;
|
|
49
|
-
quarantinedBytes: number;
|
|
50
|
-
};
|
|
51
58
|
};
|
|
52
|
-
export type
|
|
59
|
+
export type FleetSummary = SavedCleanSummary & {
|
|
60
|
+
profile: "fleet";
|
|
61
|
+
repositoryCount: number;
|
|
62
|
+
riskCeiling: "safe" | "recoverable";
|
|
63
|
+
worktrees: number;
|
|
64
|
+
protectedWorktrees: number;
|
|
65
|
+
candidateActions: number;
|
|
66
|
+
selectedActions: number;
|
|
67
|
+
excludedByRisk: number;
|
|
68
|
+
candidatesByRisk: Record<ActionRisk, number>;
|
|
69
|
+
candidateQuarantineBytes: number;
|
|
70
|
+
selectedQuarantineBytes: number;
|
|
71
|
+
unknownFindings: number;
|
|
72
|
+
topBlockers: {
|
|
73
|
+
code: string;
|
|
74
|
+
count: number;
|
|
75
|
+
}[];
|
|
76
|
+
};
|
|
77
|
+
export type CleanSummary = CloseoutSummary | FleetSummary;
|
|
78
|
+
export type CleanCommandResult<TSummary extends CleanSummary = CleanSummary> = {
|
|
53
79
|
audit: AuditReport;
|
|
54
80
|
plan: CleanupPlan;
|
|
55
81
|
run?: CleanupRun;
|
|
56
82
|
status: "ok" | "degraded" | "failed";
|
|
57
|
-
summary:
|
|
83
|
+
summary: TSummary;
|
|
58
84
|
output: string;
|
|
59
85
|
};
|
|
60
86
|
export declare function cleanCommandExitCode(result: Pick<CleanCommandResult, "run" | "status">): number | undefined;
|
|
61
87
|
export declare function cleanCommandStatus(audit: Pick<AuditReport, "diagnostics" | "probes">, run?: Pick<CleanupRun, "status">): CleanCommandResult["status"];
|
|
62
|
-
export declare function executeCleanCommand(options:
|
|
88
|
+
export declare function executeCleanCommand(options: CloseoutCleanCommandOptions): Promise<CleanCommandResult<CloseoutSummary>>;
|
|
89
|
+
export declare function executeCleanCommand(options: FleetCleanCommandOptions): Promise<CleanCommandResult<FleetSummary>>;
|
|
90
|
+
export {};
|
|
63
91
|
//# sourceMappingURL=clean.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clean.d.ts","sourceRoot":"","sources":["../../src/commands/clean.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"clean.d.ts","sourceRoot":"","sources":["../../src/commands/clean.ts"],"names":[],"mappings":"AAUA,OAAO,EAAoB,KAAK,UAAU,EAAsB,MAAM,wBAAwB,CAAC;AAE/F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAatD,KAAK,uBAAuB,GAAG;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,OAAO,CAAC;IACf,GAAG,EAAE,OAAO,CAAC;IACb,IAAI,EAAE,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ClB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,IAAI,CAAC,kBAAkB,EAAE,KAAK,GAAG,QAAQ,CAAC,GACjD,MAAM,GAAG,SAAS,CAQpB;AAED,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,IAAI,CAAC,WAAW,EAAE,aAAa,GAAG,QAAQ,CAAC,EAClD,GAAG,CAAC,EAAE,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,GAC/B,kBAAkB,CAAC,QAAQ,CAAC,CAO9B;AAkOD,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,2BAA2B,GACnC,OAAO,CAAC,kBAAkB,CAAC,eAAe,CAAC,CAAC,CAAC;AAChD,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,wBAAwB,GAChC,OAAO,CAAC,kBAAkB,CAAC,YAAY,CAAC,CAAC,CAAC"}
|
package/dist/commands/clean.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { execFile } from "node:child_process";
|
|
2
|
+
import { realpath } from "node:fs/promises";
|
|
2
3
|
import { isAbsolute, relative, resolve } from "node:path";
|
|
3
4
|
import { promisify } from "node:util";
|
|
4
5
|
import { parseWorktreePorcelain } from "../adapters/git/porcelain.js";
|
|
@@ -14,6 +15,7 @@ import { createCommandEnvelope, jsonDocument } from "../machine-output.js";
|
|
|
14
15
|
import { writeJsonAtomic } from "../state/json-file.js";
|
|
15
16
|
import { resolveStateRoot, stateLayout } from "../state/layout.js";
|
|
16
17
|
const execFileAsync = promisify(execFile);
|
|
18
|
+
const ACTION_RISKS = ["safe", "recoverable", "destructive", "experimental"];
|
|
17
19
|
export function cleanCommandExitCode(result) {
|
|
18
20
|
if (result.run?.status === "interrupted") {
|
|
19
21
|
return 130;
|
|
@@ -43,18 +45,93 @@ function isInside(root, candidate) {
|
|
|
43
45
|
const result = relative(resolve(root), resolve(candidate));
|
|
44
46
|
return result === "" || (!result.startsWith("..") && !isAbsolute(result));
|
|
45
47
|
}
|
|
46
|
-
function scopedConfig(config,
|
|
48
|
+
function scopedConfig(config, gitRoot, worktrees, maxRisk) {
|
|
47
49
|
const scoped = structuredClone(config);
|
|
48
50
|
for (const id of ["cursor", "copilot", "zed", "opencode", "grok", "runtime", "docker"]) {
|
|
49
51
|
scoped.adapters[id] = { enabled: false };
|
|
50
52
|
}
|
|
51
|
-
scoped.adapters.git = { enabled: true, root:
|
|
53
|
+
scoped.adapters.git = { enabled: true, root: gitRoot };
|
|
52
54
|
scoped.artifacts.projects = scoped.artifacts.projects.filter((project) => worktrees.some((worktree) => isInside(worktree, project.root)));
|
|
53
55
|
if (maxRisk !== undefined) {
|
|
54
56
|
scoped.plan.maxRisk = maxRisk;
|
|
55
57
|
}
|
|
56
58
|
return scoped;
|
|
57
59
|
}
|
|
60
|
+
async function fleetRepositories(repos, runCommand) {
|
|
61
|
+
if (repos.some((repo) => !isAbsolute(repo))) {
|
|
62
|
+
throw new Error("clean --profile fleet requires absolute --repo paths");
|
|
63
|
+
}
|
|
64
|
+
const requested = [...new Set(repos)].sort();
|
|
65
|
+
const valid = new Map();
|
|
66
|
+
const invalid = [];
|
|
67
|
+
const failed = (root, code, error) => ({
|
|
68
|
+
root,
|
|
69
|
+
discovery: {
|
|
70
|
+
diagnostic: {
|
|
71
|
+
severity: "warning",
|
|
72
|
+
code,
|
|
73
|
+
message: error instanceof Error ? error.message : String(error),
|
|
74
|
+
adapter: "git",
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
for (const repo of requested) {
|
|
79
|
+
let commonDir;
|
|
80
|
+
try {
|
|
81
|
+
const commonOutput = (await runCommand("git", [
|
|
82
|
+
"-C",
|
|
83
|
+
repo,
|
|
84
|
+
"rev-parse",
|
|
85
|
+
"--path-format=absolute",
|
|
86
|
+
"--git-common-dir",
|
|
87
|
+
])).stdout.trim();
|
|
88
|
+
commonDir = await realpath(commonOutput);
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
invalid.push(failed(repo, "GIT_PROBE_FAILED", error));
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
if (valid.has(commonDir)) {
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
try {
|
|
98
|
+
const output = (await runCommand("git", ["-C", repo, "worktree", "list", "--porcelain", "-z"])).stdout;
|
|
99
|
+
valid.set(commonDir, {
|
|
100
|
+
root: repo,
|
|
101
|
+
discovery: { records: parseWorktreePorcelain(output) },
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
valid.set(commonDir, failed(repo, "GIT_REPOSITORY_INSPECTION_FAILED", error));
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const repositories = [...valid.entries()]
|
|
109
|
+
.sort(([left], [right]) => left.localeCompare(right))
|
|
110
|
+
.map(([, repository]) => repository)
|
|
111
|
+
.concat(invalid.sort((left, right) => left.root.localeCompare(right.root)));
|
|
112
|
+
const worktrees = new Set();
|
|
113
|
+
for (const repository of valid.values()) {
|
|
114
|
+
for (const record of repository.discovery?.records ?? []) {
|
|
115
|
+
worktrees.add(resolve(record.path));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return { repositories, worktrees: [...worktrees].sort() };
|
|
119
|
+
}
|
|
120
|
+
function quarantineBytes(actions) {
|
|
121
|
+
return actions.reduce((total, action) => total + ("pendingQuarantineBytes" in action ? action.pendingQuarantineBytes : 0), 0);
|
|
122
|
+
}
|
|
123
|
+
function fleetBlockers(audit) {
|
|
124
|
+
const counts = new Map();
|
|
125
|
+
for (const { roots } of audit.findings) {
|
|
126
|
+
for (const { code } of roots) {
|
|
127
|
+
counts.set(code, (counts.get(code) ?? 0) + 1);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return [...counts]
|
|
131
|
+
.map(([code, count]) => ({ code, count }))
|
|
132
|
+
.sort((left, right) => right.count - left.count || left.code.localeCompare(right.code))
|
|
133
|
+
.slice(0, 5);
|
|
134
|
+
}
|
|
58
135
|
async function moleHandoff(platform, runCommand) {
|
|
59
136
|
if (platform !== "darwin") {
|
|
60
137
|
return { status: "not-applicable", suggestions: [] };
|
|
@@ -94,6 +171,34 @@ function renderCloseout(summary) {
|
|
|
94
171
|
}
|
|
95
172
|
return `${lines.join("\n")}\n`;
|
|
96
173
|
}
|
|
174
|
+
function renderFleet(summary, diagnostics) {
|
|
175
|
+
const riskCounts = ACTION_RISKS.map((risk) => `${risk}=${summary.candidatesByRisk[risk]}`).join(", ");
|
|
176
|
+
const lines = [
|
|
177
|
+
"AgentRinse fleet cleanup",
|
|
178
|
+
"",
|
|
179
|
+
`Repositories: ${summary.repositoryCount}`,
|
|
180
|
+
`Worktrees: ${summary.worktrees} (${summary.protectedWorktrees} protected)`,
|
|
181
|
+
`Risk ceiling: ${summary.riskCeiling}`,
|
|
182
|
+
`Candidate actions: ${summary.candidateActions} (${riskCounts})`,
|
|
183
|
+
`Selected actions: ${summary.selectedActions} (${summary.excludedByRisk} excluded by risk)`,
|
|
184
|
+
`Candidate quarantine: ${summary.candidateQuarantineBytes} bytes`,
|
|
185
|
+
`Selected quarantine: ${summary.selectedQuarantineBytes} bytes`,
|
|
186
|
+
`Unknown findings: ${summary.unknownFindings}`,
|
|
187
|
+
`Audit: ${summary.auditPath}`,
|
|
188
|
+
`Plan: ${summary.planPath}`,
|
|
189
|
+
`Config: ${summary.configPath}`,
|
|
190
|
+
];
|
|
191
|
+
if (summary.topBlockers.length > 0) {
|
|
192
|
+
lines.push("", "Top blockers:", ...summary.topBlockers.map((blocker) => ` ${blocker.code}: ${blocker.count}`));
|
|
193
|
+
}
|
|
194
|
+
if (diagnostics.length > 0) {
|
|
195
|
+
lines.push("", "Diagnostics:", ...diagnostics.map((diagnostic) => ` ${diagnostic.code}: ${diagnostic.message}`));
|
|
196
|
+
}
|
|
197
|
+
if (summary.run !== undefined) {
|
|
198
|
+
lines.push("", `Run: ${summary.run.status} (${summary.run.reclaimedBytes} reclaimed, ${summary.run.quarantinedBytes} quarantined bytes)`, `Journal: ${summary.run.journalPath}`);
|
|
199
|
+
}
|
|
200
|
+
return `${lines.join("\n")}\n`;
|
|
201
|
+
}
|
|
97
202
|
function interruptionFrom(signal) {
|
|
98
203
|
if (signal?.aborted !== true) {
|
|
99
204
|
return undefined;
|
|
@@ -103,40 +208,76 @@ function interruptionFrom(signal) {
|
|
|
103
208
|
: new CommandInterruptedError("clean interrupted");
|
|
104
209
|
}
|
|
105
210
|
export async function executeCleanCommand(options) {
|
|
106
|
-
if (options.profile !== "closeout") {
|
|
107
|
-
throw new Error(`unsupported clean profile: ${options.profile}`);
|
|
108
|
-
}
|
|
109
211
|
if (options.json && options.apply && !options.yes) {
|
|
110
212
|
throw new Error("clean --json --apply requires --yes");
|
|
111
213
|
}
|
|
214
|
+
if (options.profile === "fleet") {
|
|
215
|
+
const requirement = options.repos.length === 0
|
|
216
|
+
? "at least one --repo"
|
|
217
|
+
: options.maxRisk === undefined
|
|
218
|
+
? "--max-risk safe or recoverable"
|
|
219
|
+
: undefined;
|
|
220
|
+
if (requirement !== undefined) {
|
|
221
|
+
throw new Error(`clean --profile fleet requires ${requirement}`);
|
|
222
|
+
}
|
|
223
|
+
if (options.maxRisk !== "safe" && options.maxRisk !== "recoverable") {
|
|
224
|
+
throw new Error("clean --profile fleet supports only --max-risk safe or recoverable");
|
|
225
|
+
}
|
|
226
|
+
}
|
|
112
227
|
const runCommand = options.dependencies?.runCommand ?? defaultRunCommand;
|
|
113
228
|
const platform = options.dependencies?.platform ?? process.platform;
|
|
114
229
|
const clock = options.dependencies?.now ?? (() => new Date());
|
|
115
|
-
const cwd = resolve(options.cwd ?? process.cwd());
|
|
116
230
|
const home = resolve(options.home);
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
231
|
+
let repositories;
|
|
232
|
+
let worktrees;
|
|
233
|
+
let currentWorktree;
|
|
234
|
+
let repositoryRoot;
|
|
235
|
+
if (options.profile === "closeout") {
|
|
236
|
+
const cwd = resolve(options.cwd ?? process.cwd());
|
|
237
|
+
currentWorktree = (await runCommand("git", ["-C", cwd, "rev-parse", "--show-toplevel"])).stdout.trim();
|
|
238
|
+
if (currentWorktree === "") {
|
|
239
|
+
throw new Error("closeout requires a Git worktree");
|
|
240
|
+
}
|
|
241
|
+
const worktreeOutput = (await runCommand("git", ["-C", currentWorktree, "worktree", "list", "--porcelain", "-z"])).stdout;
|
|
242
|
+
worktrees = parseWorktreePorcelain(worktreeOutput).map((record) => resolve(record.path));
|
|
243
|
+
repositoryRoot = worktrees[0] ?? currentWorktree;
|
|
244
|
+
repositories = [{ root: currentWorktree }];
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
const fleet = await fleetRepositories(options.repos, runCommand);
|
|
248
|
+
repositories = fleet.repositories;
|
|
249
|
+
worktrees = fleet.worktrees;
|
|
120
250
|
}
|
|
121
|
-
const worktreeOutput = (await runCommand("git", ["-C", currentWorktree, "worktree", "list", "--porcelain", "-z"])).stdout;
|
|
122
|
-
const worktrees = parseWorktreePorcelain(worktreeOutput).map((record) => resolve(record.path));
|
|
123
|
-
const repositoryRoot = worktrees[0] ?? currentWorktree;
|
|
124
251
|
const { config } = await loadConfigForHome(home, options.config);
|
|
125
252
|
const maxRisk = options.maxRisk === undefined ? undefined : actionRiskSchema.parse(options.maxRisk);
|
|
126
|
-
const scoped = scopedConfig(config,
|
|
253
|
+
const scoped = scopedConfig(config, repositories[0].root, worktrees, maxRisk);
|
|
254
|
+
const roots = options.profile === "closeout"
|
|
255
|
+
? [
|
|
256
|
+
{
|
|
257
|
+
path: currentWorktree,
|
|
258
|
+
code: "current-worktree",
|
|
259
|
+
source: "closeout",
|
|
260
|
+
detail: "The worktree running the closeout profile is protected.",
|
|
261
|
+
scope: "exact",
|
|
262
|
+
resourceKinds: ["git-worktree"],
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
path: currentWorktree,
|
|
266
|
+
code: "current-worktree",
|
|
267
|
+
source: "closeout",
|
|
268
|
+
detail: "Artifacts inside the current worktree are protected.",
|
|
269
|
+
scope: "subtree",
|
|
270
|
+
resourceKinds: ["build-artifact"],
|
|
271
|
+
},
|
|
272
|
+
]
|
|
273
|
+
: [];
|
|
127
274
|
const audit = await runAudit({
|
|
128
275
|
home,
|
|
129
276
|
config: scoped,
|
|
130
277
|
adapters: createAuditAdapters(scoped, platform, {
|
|
131
278
|
providerInventory: false,
|
|
132
|
-
roots
|
|
133
|
-
|
|
134
|
-
path: currentWorktree,
|
|
135
|
-
code: "current-worktree",
|
|
136
|
-
source: "closeout",
|
|
137
|
-
detail: "The worktree running the closeout profile is protected.",
|
|
138
|
-
},
|
|
139
|
-
],
|
|
279
|
+
roots,
|
|
280
|
+
...(options.profile === "fleet" ? { gitRepositories: repositories } : {}),
|
|
140
281
|
}),
|
|
141
282
|
now: clock,
|
|
142
283
|
...(options.signal === undefined ? {} : { signal: options.signal }),
|
|
@@ -157,7 +298,7 @@ export async function executeCleanCommand(options) {
|
|
|
157
298
|
});
|
|
158
299
|
let run;
|
|
159
300
|
let journalPath;
|
|
160
|
-
if (options.apply) {
|
|
301
|
+
if (options.apply && plan.actions.length > 0) {
|
|
161
302
|
const interruption = interruptionFrom(options.signal);
|
|
162
303
|
if (interruption !== undefined) {
|
|
163
304
|
throw interruption;
|
|
@@ -172,40 +313,69 @@ export async function executeCleanCommand(options) {
|
|
|
172
313
|
...(options.signal === undefined ? {} : { signal: options.signal }),
|
|
173
314
|
dependencies: {
|
|
174
315
|
clock,
|
|
175
|
-
loadCurrentConfig: async () => (await loadConfigForHome(home, options.config)).config,
|
|
316
|
+
loadCurrentConfig: async () => scopedConfig((await loadConfigForHome(home, options.config)).config, repositories[0].root, worktrees, maxRisk),
|
|
176
317
|
},
|
|
177
318
|
});
|
|
178
319
|
run = result.run;
|
|
179
320
|
journalPath = result.journalPath;
|
|
180
321
|
}
|
|
181
322
|
const gitFindings = audit.findings.filter((finding) => finding.resource.kind === "git-worktree");
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
323
|
+
const runSummary = run === undefined || journalPath === undefined
|
|
324
|
+
? {}
|
|
325
|
+
: {
|
|
326
|
+
run: {
|
|
327
|
+
runId: run.runId,
|
|
328
|
+
status: run.status,
|
|
329
|
+
journalPath,
|
|
330
|
+
reclaimedBytes: run.reclaimedBytes,
|
|
331
|
+
quarantinedBytes: run.quarantinedBytes ?? 0,
|
|
332
|
+
},
|
|
333
|
+
};
|
|
334
|
+
const savedSummary = {
|
|
186
335
|
auditId: audit.auditId,
|
|
187
336
|
planId: plan.planId,
|
|
188
337
|
auditPath,
|
|
189
338
|
planPath,
|
|
190
339
|
configPath,
|
|
191
|
-
|
|
192
|
-
protectedWorktrees: gitFindings.filter((finding) => finding.state !== "eligible").length,
|
|
193
|
-
eligibleActions: plan.actions.length,
|
|
194
|
-
expectedReclaimBytes: plan.expectedReclaimBytes,
|
|
195
|
-
pendingQuarantineBytes: plan.pendingQuarantineBytes ?? 0,
|
|
196
|
-
mole: await moleHandoff(platform, runCommand),
|
|
197
|
-
...(run === undefined || journalPath === undefined
|
|
198
|
-
? {}
|
|
199
|
-
: {
|
|
200
|
-
run: {
|
|
201
|
-
runId: run.runId,
|
|
202
|
-
status: run.status,
|
|
203
|
-
journalPath,
|
|
204
|
-
reclaimedBytes: run.reclaimedBytes,
|
|
205
|
-
quarantinedBytes: run.quarantinedBytes ?? 0,
|
|
206
|
-
},
|
|
207
|
-
}),
|
|
340
|
+
...runSummary,
|
|
208
341
|
};
|
|
342
|
+
const summary = options.profile === "closeout"
|
|
343
|
+
? {
|
|
344
|
+
...savedSummary,
|
|
345
|
+
profile: "closeout",
|
|
346
|
+
repositoryRoot: repositoryRoot,
|
|
347
|
+
currentWorktree: currentWorktree,
|
|
348
|
+
worktrees: gitFindings.length,
|
|
349
|
+
protectedWorktrees: gitFindings.filter((finding) => finding.state !== "eligible").length,
|
|
350
|
+
eligibleActions: plan.actions.length,
|
|
351
|
+
expectedReclaimBytes: plan.expectedReclaimBytes,
|
|
352
|
+
pendingQuarantineBytes: plan.pendingQuarantineBytes ?? 0,
|
|
353
|
+
mole: await moleHandoff(platform, runCommand),
|
|
354
|
+
}
|
|
355
|
+
: (() => {
|
|
356
|
+
const candidates = audit.findings.flatMap((finding) => finding.candidateActions);
|
|
357
|
+
const candidatesByRisk = Object.fromEntries(ACTION_RISKS.map((risk) => [
|
|
358
|
+
risk,
|
|
359
|
+
candidates.filter((action) => action.risk === risk).length,
|
|
360
|
+
]));
|
|
361
|
+
return {
|
|
362
|
+
...savedSummary,
|
|
363
|
+
profile: "fleet",
|
|
364
|
+
repositoryCount: repositories.length,
|
|
365
|
+
riskCeiling: maxRisk,
|
|
366
|
+
worktrees: gitFindings.length,
|
|
367
|
+
protectedWorktrees: gitFindings.filter((finding) => finding.state !== "eligible")
|
|
368
|
+
.length,
|
|
369
|
+
candidateActions: candidates.length,
|
|
370
|
+
selectedActions: plan.actions.length,
|
|
371
|
+
excludedByRisk: candidates.length - plan.actions.length,
|
|
372
|
+
candidatesByRisk,
|
|
373
|
+
candidateQuarantineBytes: quarantineBytes(candidates),
|
|
374
|
+
selectedQuarantineBytes: quarantineBytes(plan.actions),
|
|
375
|
+
unknownFindings: audit.findings.filter((finding) => finding.state === "unknown").length,
|
|
376
|
+
topBlockers: fleetBlockers(audit),
|
|
377
|
+
};
|
|
378
|
+
})();
|
|
209
379
|
const startedAt = audit.startedAt;
|
|
210
380
|
const completedAt = clock().toISOString();
|
|
211
381
|
const status = cleanCommandStatus(audit, run);
|
|
@@ -224,7 +394,9 @@ export async function executeCleanCommand(options) {
|
|
|
224
394
|
data: summary,
|
|
225
395
|
diagnostics: audit.diagnostics,
|
|
226
396
|
}))
|
|
227
|
-
:
|
|
397
|
+
: summary.profile === "closeout"
|
|
398
|
+
? renderCloseout(summary)
|
|
399
|
+
: renderFleet(summary, audit.diagnostics),
|
|
228
400
|
};
|
|
229
401
|
}
|
|
230
402
|
//# sourceMappingURL=clean.js.map
|