@otwld/workflow-cli 0.1.31 → 0.1.32
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/package.json +1 -1
- package/src/audit-github.d.ts +37 -96
- package/src/audit-github.js +91 -294
- package/src/audit-github.js.map +1 -1
- package/src/audit-policy.d.ts +0 -24
- package/src/audit-policy.js +0 -73
- package/src/audit-policy.js.map +1 -1
- package/src/audit-prompt.d.ts +2 -2
- package/src/audit-prompt.js +34 -19
- package/src/audit-prompt.js.map +1 -1
- package/src/audit.d.ts +7 -43
- package/src/audit.js +69 -203
- package/src/audit.js.map +1 -1
- package/src/automation.js +2 -8
- package/src/automation.js.map +1 -1
- package/src/codex-pool.js +15 -4
- package/src/codex-pool.js.map +1 -1
- package/src/codex.js +0 -2
- package/src/codex.js.map +1 -1
package/src/audit-policy.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { parse } from 'yaml';
|
|
2
1
|
/**
|
|
3
2
|
* Validate an object-shaped external value.
|
|
4
3
|
* @param value - External value to validate.
|
|
@@ -44,76 +43,4 @@ export function classifyAudit(code, value) {
|
|
|
44
43
|
return 'technical-error';
|
|
45
44
|
}
|
|
46
45
|
}
|
|
47
|
-
/**
|
|
48
|
-
* Accept repository files needed for remediation without exposing Git metadata.
|
|
49
|
-
* @param path - Repository-relative correction path.
|
|
50
|
-
* @returns Whether the path remains inside the checkout.
|
|
51
|
-
*/
|
|
52
|
-
export function allowedAuditPath(path) {
|
|
53
|
-
return (Boolean(path) &&
|
|
54
|
-
!path.startsWith('/') &&
|
|
55
|
-
!path.includes('\\') &&
|
|
56
|
-
!path
|
|
57
|
-
.split('/')
|
|
58
|
-
.some((part) => part === '..' || part === '.git' || part === '') &&
|
|
59
|
-
!/^[a-z]:/i.test(path));
|
|
60
|
-
}
|
|
61
|
-
function canonical(value) {
|
|
62
|
-
if (Array.isArray(value)) {
|
|
63
|
-
return JSON.stringify(value.map((item) => JSON.parse(canonical(item))));
|
|
64
|
-
}
|
|
65
|
-
if (value && typeof value === 'object') {
|
|
66
|
-
return JSON.stringify(Object.fromEntries(Object.entries(value)
|
|
67
|
-
.sort(([a], [b]) => a.localeCompare(b))
|
|
68
|
-
.map(([key, item]) => [key, JSON.parse(canonical(item))])));
|
|
69
|
-
}
|
|
70
|
-
return JSON.stringify(value);
|
|
71
|
-
}
|
|
72
|
-
function assertAuditSettings(before, after) {
|
|
73
|
-
const old = record(before || {});
|
|
74
|
-
const next = record(after || {});
|
|
75
|
-
for (const key of new Set([...Object.keys(old), ...Object.keys(next)])) {
|
|
76
|
-
const previous = old[key];
|
|
77
|
-
const proposed = next[key];
|
|
78
|
-
// Removing an existing exception strengthens the audit; adding one is not a fix.
|
|
79
|
-
if (key.startsWith('ignore') && Array.isArray(previous)) {
|
|
80
|
-
if (proposed === undefined ||
|
|
81
|
-
(Array.isArray(proposed) &&
|
|
82
|
-
proposed.every((item) => previous.some((entry) => canonical(entry) === canonical(item))))) {
|
|
83
|
-
continue;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
if (canonical(previous) !== canonical(proposed)) {
|
|
87
|
-
throw new Error(`Audit settings changed: ${key}`);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Permit package replacement, new majors and migration scripts while preserving audit settings.
|
|
93
|
-
* @param before - Original package manifest.
|
|
94
|
-
* @param after - Corrected package manifest.
|
|
95
|
-
*/
|
|
96
|
-
export function assertManifest(before, after) {
|
|
97
|
-
const old = record(record(before)['pnpm'] || {});
|
|
98
|
-
const next = record(record(after)['pnpm'] || {});
|
|
99
|
-
assertAuditSettings(old['auditConfig'], next['auditConfig']);
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Allow workspace migrations without adding audit exceptions or weakening its threshold.
|
|
103
|
-
* @param before - Original workspace YAML.
|
|
104
|
-
* @param after - Corrected workspace YAML.
|
|
105
|
-
*/
|
|
106
|
-
export function assertWorkspace(before, after) {
|
|
107
|
-
assertAuditSettings(record(parse(before))['auditConfig'], record(parse(after))['auditConfig']);
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Read the package names affected by the audit report.
|
|
111
|
-
* @param value - External value to validate.
|
|
112
|
-
* @returns The validated operation result.
|
|
113
|
-
*/
|
|
114
|
-
export function auditPackages(value) {
|
|
115
|
-
return [
|
|
116
|
-
...new Set(Object.values(record(record(value)['advisories'])).map((item) => String(record(item)['module_name']))),
|
|
117
|
-
];
|
|
118
|
-
}
|
|
119
46
|
//# sourceMappingURL=audit-policy.js.map
|
package/src/audit-policy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audit-policy.js","sourceRoot":"","sources":["../../../../apps/workflow-cli/src/audit-policy.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"audit-policy.js","sourceRoot":"","sources":["../../../../apps/workflow-cli/src/audit-policy.ts"],"names":[],"mappings":"AACA;;;;;GAKG;AACH,MAAM,UAAU,MAAM,CAAC,KAAc;IACnC,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAChE,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;IACxC,CAAC;IACD,OAAO,KAAa,CAAC;AACvB,CAAC;AACD;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAC3B,IAAmB,EACnB,KAAc;IAEd,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QAC7B,IAAI,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;YACpB,OAAO,iBAAiB,CAAC;QAC3B,CAAC;QACD,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC;QAChD,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC;QACrE,MAAM,MAAM,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,GAAG,CAChE,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CACrB,CAAC;QACF,IACE,CAAC,MAAM,CAAC,KAAK,CACX,CAAC,KAAK,EAAE,EAAE,CACR,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,CACrE,EACD,CAAC;YACD,OAAO,iBAAiB,CAAC;QAC3B,CAAC;QACD,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CACzB,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,EACvC,CAAC,CACF,CAAC;QACF,mFAAmF;QACnF,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC;QAClD,IAAI,IAAI,KAAK,CAAC,IAAI,UAAU,KAAK,CAAC,EAAE,CAAC;YACnC,OAAO,OAAO,CAAC;QACjB,CAAC;QACD,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,UAAU,GAAG,CAAC,EAAE,CAAC;YAC7D,OAAO,YAAY,CAAC;QACtB,CAAC;QACD,OAAO,iBAAiB,CAAC;IAC3B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,iBAAiB,CAAC;IAC3B,CAAC;AACH,CAAC"}
|
package/src/audit-prompt.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/**
|
|
2
|
-
export declare const auditPrompt = "
|
|
1
|
+
/** Dependency remediation, collaboration and publication are owned by the agent. */
|
|
2
|
+
export declare const auditPrompt = "You own this repository's dependency-audit PR and developer communication.\nRead AGENTS.md and relevant domain contexts first. Use pnpm only.\nUse gh and Git normally; GitHub access is configured. Never print credentials.\nRead the supplied audit report. A technical audit error is not evidence of a\nvulnerability: investigate it and report a diagnosis rather than invent a fix.\nFind the existing open audit PR (including older automation/pnpm-audit-* branches)\nand read its description, comments, checks and latest commits. Honor the pause\nlabel. Otherwise check out its current branch and preserve human contributions.\nIf there is no existing PR, create automation/pnpm-audit from the current default\nbranch. Configure Git identity from the authenticated GitHub account when needed\nand use gh auth setup-git to authenticate pushes. Never force-push, rewrite history,\nreset away human work, reopen closed PRs, merge or close a PR automatically.\nInstall repository dependencies before working. Progress from the smallest\nsufficient patch/update through minor upgrades, majors or package replacement.\nNew packages and source/configuration/test migrations are allowed when necessary.\nKeep changes focused. Do not hide findings through audit exceptions, higher audit\nthresholds, disabled CI, removed tests or weakened assertions. Preserve contracts.\nLook for related Renovate PRs and link useful ones; their existence does not block\nyour work. Use judgment rather than a title-matching rule.\nRun focused checks useful for your changes, including pnpm audit. The ordinary PR\nCI owns complete validation; do not duplicate the full CI or wait for it to finish.\nCommit and push useful changes even if the correction is incomplete or checks fail.\nCreate a regular non-draft PR, or update the existing one. Its body must retain the\nsupplied audit marker and explain the changes, broader migrations and limitations.\nOn every attempt, publish context and check results as a PR comment including the\nexact execution URL, even if you made no new commit. Read previous feedback before\nretrying. If the audit was already fixed on the PR, report that and preserve it.\nIf there is no useful change and no PR, create or update one open diagnostic issue\nidentified by the audit marker. Include the execution URL and actionable findings.\nIf a useful unpublished change remains near the deadline, prioritize committing,\npushing and opening/updating its PR over further investigation. A timeout does not\nmake the patch invalid. Finish with a response summarizing changes, checks,\nremaining findings and the PR or issue URL. Never merge automatically.\n";
|
package/src/audit-prompt.js
CHANGED
|
@@ -1,21 +1,36 @@
|
|
|
1
|
-
/**
|
|
2
|
-
export const auditPrompt = `
|
|
3
|
-
Read AGENTS.md and
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
/** Dependency remediation, collaboration and publication are owned by the agent. */
|
|
2
|
+
export const auditPrompt = `You own this repository's dependency-audit PR and developer communication.
|
|
3
|
+
Read AGENTS.md and relevant domain contexts first. Use pnpm only.
|
|
4
|
+
Use gh and Git normally; GitHub access is configured. Never print credentials.
|
|
5
|
+
Read the supplied audit report. A technical audit error is not evidence of a
|
|
6
|
+
vulnerability: investigate it and report a diagnosis rather than invent a fix.
|
|
7
|
+
Find the existing open audit PR (including older automation/pnpm-audit-* branches)
|
|
8
|
+
and read its description, comments, checks and latest commits. Honor the pause
|
|
9
|
+
label. Otherwise check out its current branch and preserve human contributions.
|
|
10
|
+
If there is no existing PR, create automation/pnpm-audit from the current default
|
|
11
|
+
branch. Configure Git identity from the authenticated GitHub account when needed
|
|
12
|
+
and use gh auth setup-git to authenticate pushes. Never force-push, rewrite history,
|
|
13
|
+
reset away human work, reopen closed PRs, merge or close a PR automatically.
|
|
14
|
+
Install repository dependencies before working. Progress from the smallest
|
|
15
|
+
sufficient patch/update through minor upgrades, majors or package replacement.
|
|
16
|
+
New packages and source/configuration/test migrations are allowed when necessary.
|
|
17
|
+
Keep changes focused. Do not hide findings through audit exceptions, higher audit
|
|
18
|
+
thresholds, disabled CI, removed tests or weakened assertions. Preserve contracts.
|
|
19
|
+
Look for related Renovate PRs and link useful ones; their existence does not block
|
|
20
|
+
your work. Use judgment rather than a title-matching rule.
|
|
21
|
+
Run focused checks useful for your changes, including pnpm audit. The ordinary PR
|
|
22
|
+
CI owns complete validation; do not duplicate the full CI or wait for it to finish.
|
|
23
|
+
Commit and push useful changes even if the correction is incomplete or checks fail.
|
|
24
|
+
Create a regular non-draft PR, or update the existing one. Its body must retain the
|
|
25
|
+
supplied audit marker and explain the changes, broader migrations and limitations.
|
|
26
|
+
On every attempt, publish context and check results as a PR comment including the
|
|
27
|
+
exact execution URL, even if you made no new commit. Read previous feedback before
|
|
28
|
+
retrying. If the audit was already fixed on the PR, report that and preserve it.
|
|
29
|
+
If there is no useful change and no PR, create or update one open diagnostic issue
|
|
30
|
+
identified by the audit marker. Include the execution URL and actionable findings.
|
|
31
|
+
If a useful unpublished change remains near the deadline, prioritize committing,
|
|
32
|
+
pushing and opening/updating its PR over further investigation. A timeout does not
|
|
33
|
+
make the patch invalid. Finish with a response summarizing changes, checks,
|
|
34
|
+
remaining findings and the PR or issue URL. Never merge automatically.
|
|
20
35
|
`;
|
|
21
36
|
//# sourceMappingURL=audit-prompt.js.map
|
package/src/audit-prompt.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audit-prompt.js","sourceRoot":"","sources":["../../../../apps/workflow-cli/src/audit-prompt.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"audit-prompt.js","sourceRoot":"","sources":["../../../../apps/workflow-cli/src/audit-prompt.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,MAAM,CAAC,MAAM,WAAW,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiC1B,CAAC"}
|
package/src/audit.d.ts
CHANGED
|
@@ -1,51 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Execute
|
|
3
|
-
* @
|
|
4
|
-
* @
|
|
2
|
+
* Execute the same unfiltered dependency audit as ordinary CI.
|
|
3
|
+
* @returns The report and whether pnpm found actionable vulnerabilities.
|
|
4
|
+
* @throws If the registry or audit command fails technically.
|
|
5
5
|
*/
|
|
6
|
-
export declare function
|
|
7
|
-
/**
|
|
8
|
-
* Write a single-line GitHub Actions output.
|
|
9
|
-
* @param name - Required environment variable name.
|
|
10
|
-
* @param value - External value to validate.
|
|
11
|
-
*/
|
|
12
|
-
export declare function output(name: string, value: string): void;
|
|
13
|
-
/**
|
|
14
|
-
* Resolve a required workflow environment input.
|
|
15
|
-
* @param env - Workflow environment and operation-specific inputs.
|
|
16
|
-
* @param key - Operation input supplied by the calling workflow.
|
|
17
|
-
* @returns The validated operation result.
|
|
18
|
-
* @throws If the input or external operation fails validation.
|
|
19
|
-
*/
|
|
20
|
-
export declare function required(env: NodeJS.ProcessEnv, key: string): string;
|
|
21
|
-
/**
|
|
22
|
-
* Execute the same unfiltered pnpm audit as CI.
|
|
23
|
-
* @param cwd - Directory containing the consumer pnpm workspace.
|
|
24
|
-
* @returns The validated operation result.
|
|
25
|
-
* @throws If the input or external operation fails validation.
|
|
26
|
-
*/
|
|
27
|
-
export declare function audit(cwd?: string): {
|
|
28
|
-
/**
|
|
29
|
-
* The status value used by the workflow contract.
|
|
30
|
-
*/
|
|
6
|
+
export declare function audit(): {
|
|
31
7
|
status: 'clean' | 'vulnerable';
|
|
32
|
-
/**
|
|
33
|
-
* The report value used by the workflow contract.
|
|
34
|
-
*/
|
|
35
8
|
report: unknown;
|
|
36
9
|
};
|
|
37
10
|
/**
|
|
38
|
-
*
|
|
39
|
-
* @param
|
|
40
|
-
* @
|
|
41
|
-
* @throws If the input or external operation fails validation.
|
|
42
|
-
*/
|
|
43
|
-
export declare function verifyAuditPatch(base: string): string;
|
|
44
|
-
/**
|
|
45
|
-
* Execute one dependency-audit workflow phase.
|
|
46
|
-
* @param phase - Audit lifecycle phase to execute.
|
|
47
|
-
* @param env - Workflow environment and operation-specific inputs.
|
|
48
|
-
* @returns The asynchronous operation result.
|
|
49
|
-
* @throws If the input or external operation fails validation.
|
|
11
|
+
* Prepare one prompt-driven mission, or ensure its developer-facing diagnosis.
|
|
12
|
+
* @param phase - Prepare or report.
|
|
13
|
+
* @param env - Workflow environment and optional mission overrides.
|
|
50
14
|
*/
|
|
51
15
|
export declare function runAuditCommand(phase: string, env: NodeJS.ProcessEnv): Promise<void>;
|
package/src/audit.js
CHANGED
|
@@ -1,54 +1,17 @@
|
|
|
1
|
-
import { executable } from './executable.js';
|
|
2
1
|
import { execFileSync, spawnSync } from 'node:child_process';
|
|
3
|
-
import { appendFileSync, existsSync, readFileSync, writeFileSync,
|
|
2
|
+
import { appendFileSync, existsSync, mkdirSync, readFileSync, writeFileSync, } from 'node:fs';
|
|
4
3
|
import { join, resolve } from 'node:path';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { executable } from './executable.js';
|
|
5
|
+
import { classifyAudit } from './audit-policy.js';
|
|
7
6
|
import { auditPrompt } from './audit-prompt.js';
|
|
7
|
+
import { auditMarker, auditPauseLabel, auditPull, auditRunUrl, ensureAuditDiagnostic, } from './audit-github.js';
|
|
8
8
|
/**
|
|
9
|
-
* Execute
|
|
10
|
-
* @
|
|
11
|
-
* @
|
|
12
|
-
*/
|
|
13
|
-
export function git(...args) {
|
|
14
|
-
return execFileSync(executable('git'), args, {
|
|
15
|
-
encoding: 'utf8',
|
|
16
|
-
maxBuffer: 32 * 1024 * 1024,
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Write a single-line GitHub Actions output.
|
|
21
|
-
* @param name - Required environment variable name.
|
|
22
|
-
* @param value - External value to validate.
|
|
23
|
-
*/
|
|
24
|
-
export function output(name, value) {
|
|
25
|
-
if (process.env['GITHUB_OUTPUT']) {
|
|
26
|
-
appendFileSync(process.env['GITHUB_OUTPUT'], `${name}=${value}\n`);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Resolve a required workflow environment input.
|
|
31
|
-
* @param env - Workflow environment and operation-specific inputs.
|
|
32
|
-
* @param key - Operation input supplied by the calling workflow.
|
|
33
|
-
* @returns The validated operation result.
|
|
34
|
-
* @throws If the input or external operation fails validation.
|
|
35
|
-
*/
|
|
36
|
-
export function required(env, key) {
|
|
37
|
-
const value = env[key];
|
|
38
|
-
if (!value) {
|
|
39
|
-
throw new Error(`Missing ${key}`);
|
|
40
|
-
}
|
|
41
|
-
return value;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Execute the same unfiltered pnpm audit as CI.
|
|
45
|
-
* @param cwd - Directory containing the consumer pnpm workspace.
|
|
46
|
-
* @returns The validated operation result.
|
|
47
|
-
* @throws If the input or external operation fails validation.
|
|
9
|
+
* Execute the same unfiltered dependency audit as ordinary CI.
|
|
10
|
+
* @returns The report and whether pnpm found actionable vulnerabilities.
|
|
11
|
+
* @throws If the registry or audit command fails technically.
|
|
48
12
|
*/
|
|
49
|
-
export function audit(
|
|
13
|
+
export function audit() {
|
|
50
14
|
const result = spawnSync(executable('pnpm'), ['audit', '--json'], {
|
|
51
|
-
cwd,
|
|
52
15
|
encoding: 'utf8',
|
|
53
16
|
maxBuffer: 32 * 1024 * 1024,
|
|
54
17
|
});
|
|
@@ -61,183 +24,86 @@ export function audit(cwd = process.cwd()) {
|
|
|
61
24
|
}
|
|
62
25
|
const status = classifyAudit(result.status, report);
|
|
63
26
|
if (status === 'technical-error') {
|
|
64
|
-
throw new Error('Audit failed technically
|
|
27
|
+
throw new Error('Audit failed technically');
|
|
65
28
|
}
|
|
66
29
|
return { status, report };
|
|
67
30
|
}
|
|
68
31
|
/**
|
|
69
|
-
*
|
|
70
|
-
* @param
|
|
71
|
-
* @
|
|
72
|
-
* @throws If the input or external operation fails validation.
|
|
73
|
-
*/
|
|
74
|
-
export function verifyAuditPatch(base) {
|
|
75
|
-
git('add', '--intent-to-add', '.');
|
|
76
|
-
const files = git('diff', '--name-only', '-z', base)
|
|
77
|
-
.split('\0')
|
|
78
|
-
.filter(Boolean);
|
|
79
|
-
if (!files.length) {
|
|
80
|
-
throw new Error('No correction produced');
|
|
81
|
-
}
|
|
82
|
-
for (const file of files) {
|
|
83
|
-
verifyCorrectionFile(base, file);
|
|
84
|
-
}
|
|
85
|
-
return git('diff', '--binary', base);
|
|
86
|
-
}
|
|
87
|
-
function verifyCorrectionFile(base, file) {
|
|
88
|
-
if (!allowedAuditPath(file)) {
|
|
89
|
-
throw new Error(`Disallowed correction: ${file}`);
|
|
90
|
-
}
|
|
91
|
-
if (/120000|160000/.test(git('diff', '--raw', base, '--', file))) {
|
|
92
|
-
throw new Error(`Symlink or submodule: ${file}`);
|
|
93
|
-
}
|
|
94
|
-
if (file.endsWith('package.json') && existsSync(file)) {
|
|
95
|
-
assertManifest(git('ls-tree', '--name-only', base, '--', file).trim()
|
|
96
|
-
? JSON.parse(git('show', `${base}:${file}`))
|
|
97
|
-
: {}, JSON.parse(readFileSync(file, 'utf8')));
|
|
98
|
-
}
|
|
99
|
-
if (file === 'pnpm-workspace.yaml' && existsSync(file)) {
|
|
100
|
-
assertWorkspace(git('show', `${base}:${file}`), readFileSync(file, 'utf8'));
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Execute one dependency-audit workflow phase.
|
|
105
|
-
* @param phase - Audit lifecycle phase to execute.
|
|
106
|
-
* @param env - Workflow environment and operation-specific inputs.
|
|
107
|
-
* @returns The asynchronous operation result.
|
|
108
|
-
* @throws If the input or external operation fails validation.
|
|
32
|
+
* Prepare one prompt-driven mission, or ensure its developer-facing diagnosis.
|
|
33
|
+
* @param phase - Prepare or report.
|
|
34
|
+
* @param env - Workflow environment and optional mission overrides.
|
|
109
35
|
*/
|
|
110
36
|
export async function runAuditCommand(phase, env) {
|
|
111
|
-
if (
|
|
112
|
-
|
|
113
|
-
return;
|
|
37
|
+
if (!['prepare', 'report'].includes(phase)) {
|
|
38
|
+
throw new Error(`Unsupported audit phase: ${phase}`);
|
|
114
39
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
const base = git('rev-parse', 'HEAD').trim();
|
|
118
|
-
const result = audit();
|
|
119
|
-
writeFileSync(join(directory, 'audit.json'), JSON.stringify(result.report, null, 2));
|
|
120
|
-
writeFileSync(join(directory, 'base.txt'), base);
|
|
121
|
-
output('base-sha', base);
|
|
122
|
-
output('status', result.status);
|
|
123
|
-
return;
|
|
40
|
+
if (!env.AUDIT_DIRECTORY) {
|
|
41
|
+
throw new Error('Missing AUDIT_DIRECTORY');
|
|
124
42
|
}
|
|
125
|
-
|
|
126
|
-
|
|
43
|
+
const directory = resolve(env.AUDIT_DIRECTORY);
|
|
44
|
+
mkdirSync(directory, { recursive: true });
|
|
45
|
+
if (phase === 'report') {
|
|
46
|
+
reportMission(directory, env);
|
|
127
47
|
return;
|
|
128
48
|
}
|
|
129
|
-
|
|
130
|
-
|
|
49
|
+
const pull = auditPull(env);
|
|
50
|
+
if (pull?.labels.some((label) => label.name === auditPauseLabel)) {
|
|
51
|
+
output(env, 'status', 'paused');
|
|
131
52
|
return;
|
|
132
53
|
}
|
|
133
|
-
|
|
134
|
-
collectCandidate(directory, env);
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
if (phase === 'renovate') {
|
|
138
|
-
await checkRenovate(directory, env);
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
if (phase === 'publish') {
|
|
142
|
-
const { publishAudit } = await import('./audit-github.js');
|
|
143
|
-
await publishAudit(directory, env);
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
throw new Error(`Unsupported audit phase: ${phase}`);
|
|
147
|
-
}
|
|
148
|
-
function requireValidationResults(env) {
|
|
149
|
-
const failures = [
|
|
150
|
-
'AUDIT_CHECK_RESULT',
|
|
151
|
-
'QUALITY_CHECK_RESULT',
|
|
152
|
-
'PROJECT_CHECK_RESULT',
|
|
153
|
-
]
|
|
154
|
-
.filter((key) => env[key] !== 'success')
|
|
155
|
-
.map((key) => key + '=' + (env[key] || 'missing'));
|
|
156
|
-
if (failures.length) {
|
|
157
|
-
throw new Error('Validation failed: ' + failures.join(', '));
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
function collectCandidate(directory, env) {
|
|
161
|
-
const base = readFileSync(join(directory, 'base.txt'), 'utf8').trim();
|
|
162
|
-
const mission = env['CODEX_STATUS'] || 'execution-error';
|
|
163
|
-
const candidate = { mission, audit: 'technical-error', verified: false };
|
|
54
|
+
let status;
|
|
164
55
|
try {
|
|
165
|
-
if (git('rev-parse', 'HEAD').trim() !== base) {
|
|
166
|
-
throw new Error('Codex changed the checkout commit');
|
|
167
|
-
}
|
|
168
|
-
const patch = verifyAuditPatch(base);
|
|
169
|
-
// Preserve a useful candidate even when the mission timed out or audit remains red.
|
|
170
|
-
writeFileSync(join(directory, 'fix.patch'), patch);
|
|
171
56
|
const result = audit();
|
|
172
|
-
|
|
173
|
-
writeFileSync(join(directory, '
|
|
174
|
-
candidate.verified = mission === 'success' && result.status === 'clean';
|
|
175
|
-
appendFileSync(join(directory, 'diagnosis.md'), `\nMission: ${mission}. Full audit: ${result.status}.\n`);
|
|
57
|
+
status = result.status;
|
|
58
|
+
writeFileSync(join(directory, 'audit.json'), JSON.stringify(result.report, null, 2));
|
|
176
59
|
}
|
|
177
60
|
catch (error) {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
61
|
+
status = 'technical-error';
|
|
62
|
+
writeFileSync(join(directory, 'audit.json'), JSON.stringify({ error: String(error) }));
|
|
63
|
+
}
|
|
64
|
+
output(env, 'status', status);
|
|
65
|
+
const context = `\n\nExecution context (applies also to a custom prompt):
|
|
66
|
+
Repository: ${env.GITHUB_REPOSITORY}
|
|
67
|
+
Default branch: ${env.DEFAULT_BRANCH}
|
|
68
|
+
Mission budget: ${env.CODEX_TIMEOUT_MINUTES || 20} minutes
|
|
69
|
+
Initial audit: ${status}
|
|
70
|
+
Audit report: ${join(directory, 'audit.json')}
|
|
71
|
+
Execution URL: ${auditRunUrl(env)}
|
|
72
|
+
Audit marker for PR/diagnostic bodies: ${auditMarker}
|
|
73
|
+
Pause label: ${auditPauseLabel}
|
|
74
|
+
Existing audit PR: ${pull ? '#' + pull.number + ' (' + pull.headRefName + ')' : 'none found'}
|
|
75
|
+
`;
|
|
76
|
+
writeFileSync(join(directory, 'prompt.md'), (env.AUDIT_PROMPT || auditPrompt) + context);
|
|
184
77
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
const report = JSON.parse(readFileSync(join(directory, 'audit.json'), 'utf8'));
|
|
189
|
-
const packages = auditPackages(report);
|
|
190
|
-
const prs = await github.pulls();
|
|
191
|
-
const existing = prs.find((pr) => pr.head.ref === 'automation/pnpm-audit' ||
|
|
192
|
-
pr.head.ref.startsWith('automation/pnpm-audit-'));
|
|
193
|
-
if (existing) {
|
|
194
|
-
writeFileSync(join(directory, 'existing.json'), JSON.stringify({ number: existing.number, url: existing.html_url }));
|
|
195
|
-
output('renovate', String(existing.number));
|
|
196
|
-
return;
|
|
78
|
+
function output(env, key, value) {
|
|
79
|
+
if (env.GITHUB_OUTPUT) {
|
|
80
|
+
appendFileSync(env.GITHUB_OUTPUT, `${key}=${value}\n`);
|
|
197
81
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
if (packages.some((name) => pr.title.includes(name)) ||
|
|
219
|
-
/security|vulnerab/i.test(pr.title)) {
|
|
220
|
-
writeFileSync(join(directory, 'overlap.json'), JSON.stringify({ number: pr.number, url: pr.html_url }));
|
|
221
|
-
output('renovate', String(pr.number));
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
finally {
|
|
226
|
-
try {
|
|
227
|
-
git('worktree', 'remove', '--force', temp);
|
|
228
|
-
}
|
|
229
|
-
finally {
|
|
230
|
-
rmSync(temp, { recursive: true, force: true });
|
|
231
|
-
}
|
|
82
|
+
}
|
|
83
|
+
function reportMission(directory, env) {
|
|
84
|
+
const response = env.CODEX_RESPONSE_FILE;
|
|
85
|
+
const text = response && existsSync(response)
|
|
86
|
+
? readFileSync(response, 'utf8').trim()
|
|
87
|
+
: '';
|
|
88
|
+
const diagnosis = text ||
|
|
89
|
+
`Codex status: ${env.CODEX_STATUS || 'execution-error'}. Inspect this run's logs and artifacts. No final response was produced.`;
|
|
90
|
+
writeFileSync(join(directory, 'diagnosis.md'), diagnosis);
|
|
91
|
+
if (env.GITHUB_STEP_SUMMARY) {
|
|
92
|
+
appendFileSync(env.GITHUB_STEP_SUMMARY, `${diagnosis}\n`);
|
|
93
|
+
}
|
|
94
|
+
// Preserve unpublished edits after a timeout without adding another publisher.
|
|
95
|
+
try {
|
|
96
|
+
execFileSync(executable('git'), ['add', '--intent-to-add', '.'], {
|
|
97
|
+
stdio: 'pipe',
|
|
98
|
+
});
|
|
99
|
+
const patch = execFileSync(executable('git'), ['diff', '--binary', 'HEAD'], { encoding: 'utf8', maxBuffer: 32 * 1024 * 1024 });
|
|
100
|
+
if (patch) {
|
|
101
|
+
writeFileSync(join(directory, 'unpublished.patch'), patch);
|
|
232
102
|
}
|
|
233
103
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
existsSync(response) &&
|
|
239
|
-
readFileSync(response, 'utf8').trim()) ||
|
|
240
|
-
`Codex status: ${env['CODEX_STATUS'] || 'execution-error'}. No final response; inspect the execution logs and preserved candidate.`;
|
|
241
|
-
writeFileSync(join(directory, 'diagnosis.md'), diagnosis.slice(0, 12000));
|
|
104
|
+
catch {
|
|
105
|
+
// A failed checkout/setup still needs its GitHub diagnosis.
|
|
106
|
+
}
|
|
107
|
+
ensureAuditDiagnostic(env, diagnosis.slice(0, 12000));
|
|
242
108
|
}
|
|
243
109
|
//# sourceMappingURL=audit.js.map
|
package/src/audit.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audit.js","sourceRoot":"","sources":["../../../../apps/workflow-cli/src/audit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"audit.js","sourceRoot":"","sources":["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C;IACnI,aAAa,CAAC,IAAI,CAAC,SAAS,EAAE,cAAc,CAAC,EAAE,SAAS,CAAC,CAAC;IAC1D,IAAI,GAAG,CAAC,mBAAmB,EAAE,CAAC;QAC5B,cAAc,CAAC,GAAG,CAAC,mBAAmB,EAAE,GAAG,SAAS,IAAI,CAAC,CAAC;IAC5D,CAAC;IACD,+EAA+E;IAC/E,IAAI,CAAC;QACH,YAAY,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,iBAAiB,EAAE,GAAG,CAAC,EAAE;YAC/D,KAAK,EAAE,MAAM;SACd,CAAC,CAAC;QACH,MAAM,KAAK,GAAG,YAAY,CACxB,UAAU,CAAC,KAAK,CAAC,EACjB,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,CAAC,EAC5B,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,GAAG,IAAI,GAAG,IAAI,EAAE,CAClD,CAAC;QACF,IAAI,KAAK,EAAE,CAAC;YACV,aAAa,CAAC,IAAI,CAAC,SAAS,EAAE,mBAAmB,CAAC,EAAE,KAAK,CAAC,CAAC;QAC7D,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,4DAA4D;IAC9D,CAAC;IACD,qBAAqB,CAAC,GAAG,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;AACxD,CAAC"}
|
package/src/automation.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { executeCodex } from './codex.js';
|
|
2
2
|
import { runAuditCommand } from './audit.js';
|
|
3
|
-
import { finishAudit } from './audit-github.js';
|
|
4
3
|
/**
|
|
5
4
|
* Execute automation operations which do not require Nx release selection.
|
|
6
5
|
* @param argv - CLI operation and positional arguments.
|
|
@@ -31,13 +30,8 @@ export async function runAutomation(argv, env) {
|
|
|
31
30
|
}
|
|
32
31
|
async function auditOperation(argv, env) {
|
|
33
32
|
if (argv.length !== 2) {
|
|
34
|
-
throw new Error('Expected audit
|
|
35
|
-
}
|
|
36
|
-
if (argv[1] === 'finish') {
|
|
37
|
-
await finishAudit(env);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
await runAuditCommand(argv[1], env);
|
|
33
|
+
throw new Error('Expected audit prepare or report');
|
|
41
34
|
}
|
|
35
|
+
await runAuditCommand(argv[1], env);
|
|
42
36
|
}
|
|
43
37
|
//# sourceMappingURL=automation.js.map
|