toolstile 0.2.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +71 -15
- package/dist/agents.d.ts +7 -0
- package/dist/agents.js +20 -6
- package/dist/api.d.ts +2 -0
- package/dist/checks.d.ts +23 -1
- package/dist/checks.js +25 -5
- package/dist/cli.js +46 -3
- package/dist/commands.d.ts +2 -0
- package/dist/commands.js +28 -3
- package/dist/fix.d.ts +126 -0
- package/dist/fix.js +622 -0
- package/dist/prompt.d.ts +2 -2
- package/dist/prompt.js +15 -4
- package/dist/report.d.ts +3 -1
- package/dist/report.js +105 -23
- package/dist/sources.js +15 -10
- package/dist/state.d.ts +5 -1
- package/dist/state.js +19 -2
- package/dist/types.d.ts +8 -0
- package/package.json +2 -1
package/dist/fix.d.ts
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { type Style } from "./report.js";
|
|
2
|
+
import { type ScanOptions } from "./sources.js";
|
|
3
|
+
import type { Severity } from "./types.js";
|
|
4
|
+
type Key = string | number;
|
|
5
|
+
/** One edit to a config file. TOML edits rewrite the server's table from the edited data. */
|
|
6
|
+
/** `was` is the value the plan saw; a file changed since then is left alone. */
|
|
7
|
+
type Op = {
|
|
8
|
+
type: "set";
|
|
9
|
+
file: string;
|
|
10
|
+
path: Key[];
|
|
11
|
+
value: unknown;
|
|
12
|
+
was?: unknown;
|
|
13
|
+
} | {
|
|
14
|
+
type: "remove";
|
|
15
|
+
file: string;
|
|
16
|
+
path: Key[];
|
|
17
|
+
was?: unknown;
|
|
18
|
+
}
|
|
19
|
+
/** Removes a string from an array, wherever it sits by the time the edit runs. */
|
|
20
|
+
| {
|
|
21
|
+
type: "remove-item";
|
|
22
|
+
file: string;
|
|
23
|
+
path: Key[];
|
|
24
|
+
value: string;
|
|
25
|
+
}
|
|
26
|
+
/** Adds a string to an array (created when missing) unless it is already there. */
|
|
27
|
+
| {
|
|
28
|
+
type: "append";
|
|
29
|
+
file: string;
|
|
30
|
+
path: Key[];
|
|
31
|
+
value: string;
|
|
32
|
+
} | {
|
|
33
|
+
type: "chmod";
|
|
34
|
+
file: string;
|
|
35
|
+
mode: number;
|
|
36
|
+
};
|
|
37
|
+
export interface Fix {
|
|
38
|
+
rule: string;
|
|
39
|
+
severity: Severity;
|
|
40
|
+
/** One line for the checklist. */
|
|
41
|
+
label: string;
|
|
42
|
+
file: string;
|
|
43
|
+
/** What changes where. Secret values are shown as •••• and never printed. */
|
|
44
|
+
changes: Change[];
|
|
45
|
+
/** Selected at first; approval changes alter how the agent works, so they start off. */
|
|
46
|
+
checked: boolean;
|
|
47
|
+
ops: Op[];
|
|
48
|
+
/** Variables this fix moves into the secrets file. */
|
|
49
|
+
secrets: {
|
|
50
|
+
name: string;
|
|
51
|
+
value: string;
|
|
52
|
+
}[];
|
|
53
|
+
}
|
|
54
|
+
export interface Change {
|
|
55
|
+
/** Key inside the file, or a description such as `permissions`. */
|
|
56
|
+
where: string;
|
|
57
|
+
from: string;
|
|
58
|
+
to: string;
|
|
59
|
+
}
|
|
60
|
+
export interface ManualFix {
|
|
61
|
+
severity: Severity;
|
|
62
|
+
subject: string;
|
|
63
|
+
reason: string;
|
|
64
|
+
}
|
|
65
|
+
export interface Plan {
|
|
66
|
+
fixes: Fix[];
|
|
67
|
+
manual: ManualFix[];
|
|
68
|
+
secretsFile: string;
|
|
69
|
+
/** The shell file that loads the secrets file, or null where `--fix` cannot load one (Windows). */
|
|
70
|
+
profile: {
|
|
71
|
+
path: string;
|
|
72
|
+
line: string;
|
|
73
|
+
} | null;
|
|
74
|
+
/** Packages whose current version was looked up on npm or PyPI. */
|
|
75
|
+
lookedUp: number;
|
|
76
|
+
}
|
|
77
|
+
export interface PlanOptions extends ScanOptions {
|
|
78
|
+
fetch?: typeof fetch;
|
|
79
|
+
}
|
|
80
|
+
/** The file `--fix` keeps moved secrets in, next to the CLI's credentials. */
|
|
81
|
+
export declare const secretsPath: (opts: {
|
|
82
|
+
home: string;
|
|
83
|
+
env: Record<string, string | undefined>;
|
|
84
|
+
platform: NodeJS.Platform;
|
|
85
|
+
}) => string;
|
|
86
|
+
/** The startup file of the user's shell, and the line that loads the secrets file from it. */
|
|
87
|
+
export declare function profileFor(opts: PlanOptions, secretsFile: string): Plan["profile"];
|
|
88
|
+
/**
|
|
89
|
+
* Works out every change `audit --fix` can make, without making any. Looks up the current
|
|
90
|
+
* version of unpinned npm and PyPI packages; nothing else leaves the machine.
|
|
91
|
+
*/
|
|
92
|
+
export declare function planFixes(opts: PlanOptions): Promise<Plan>;
|
|
93
|
+
export interface ApplyResult {
|
|
94
|
+
applied: Fix[];
|
|
95
|
+
failed: {
|
|
96
|
+
fix: Fix;
|
|
97
|
+
reason: string;
|
|
98
|
+
}[];
|
|
99
|
+
backups: string | null;
|
|
100
|
+
profileAdded: boolean;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Makes the chosen changes. Every edited file is checked in memory first; secrets are saved
|
|
104
|
+
* and the original files backed up before any config is rewritten.
|
|
105
|
+
*/
|
|
106
|
+
export declare function applyFixes(plan: Plan, chosen: Fix[], opts: {
|
|
107
|
+
home: string;
|
|
108
|
+
now?: Date;
|
|
109
|
+
}): ApplyResult;
|
|
110
|
+
export interface FixRun extends PlanOptions {
|
|
111
|
+
stdin: NodeJS.ReadableStream & {
|
|
112
|
+
isTTY?: boolean;
|
|
113
|
+
};
|
|
114
|
+
stdout: NodeJS.WritableStream & {
|
|
115
|
+
isTTY?: boolean;
|
|
116
|
+
columns?: number;
|
|
117
|
+
};
|
|
118
|
+
style: Style;
|
|
119
|
+
/** Apply the changes that start selected, without asking. */
|
|
120
|
+
yes: boolean;
|
|
121
|
+
/** Only show the changes. */
|
|
122
|
+
dryRun: boolean;
|
|
123
|
+
}
|
|
124
|
+
/** `toolstile audit --fix`: shows every change it can make, lets the user pick, then makes them. */
|
|
125
|
+
export declare function runFix(o: FixRun): Promise<number>;
|
|
126
|
+
export {};
|