nx 23.2.1 → 23.3.0-beta.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/dist/src/command-line/format/format.js +2 -18
- package/dist/src/command-line/graph/graph.js +42 -3
- package/dist/src/command-line/init/implementation/format.js +2 -3
- package/dist/src/command-line/migrate/agentic/definitions.js +75 -19
- package/dist/src/command-line/migrate/agentic/format-command.d.ts +14 -0
- package/dist/src/command-line/migrate/agentic/format-command.js +44 -0
- package/dist/src/command-line/migrate/agentic/handoff-gitignore.d.ts +3 -3
- package/dist/src/command-line/migrate/agentic/handoff-gitignore.js +3 -3
- package/dist/src/command-line/migrate/agentic/handoff.d.ts +27 -17
- package/dist/src/command-line/migrate/agentic/handoff.js +107 -24
- package/dist/src/command-line/migrate/agentic/instruction-files.d.ts +21 -0
- package/dist/src/command-line/migrate/agentic/instruction-files.js +36 -0
- package/dist/src/command-line/migrate/agentic/prompts/fragments.d.ts +16 -0
- package/dist/src/command-line/migrate/agentic/prompts/fragments.js +70 -0
- package/dist/src/command-line/migrate/agentic/prompts/generic-validation.js +4 -3
- package/dist/src/command-line/migrate/agentic/prompts/system-prompt.d.ts +25 -1
- package/dist/src/command-line/migrate/agentic/prompts/system-prompt.js +57 -34
- package/dist/src/command-line/migrate/agentic/run-step.js +28 -4
- package/dist/src/command-line/migrate/agentic/runner.d.ts +17 -8
- package/dist/src/command-line/migrate/agentic/runner.js +110 -55
- package/dist/src/command-line/migrate/agentic/types.d.ts +23 -8
- package/dist/src/command-line/migrate/agentic/types.js +10 -7
- package/dist/src/command-line/migrate/migrate-commits.d.ts +1 -0
- package/dist/src/command-line/migrate/migrate-commits.js +9 -0
- package/dist/src/command-line/migrate/migrate-output.d.ts +3 -7
- package/dist/src/command-line/migrate/migrate-output.js +3 -7
- package/dist/src/command-line/migrate/migrate.js +21 -8
- package/dist/src/command-line/migrate/run/agent-output.d.ts +10 -0
- package/dist/src/command-line/migrate/run/agent-output.js +16 -2
- package/dist/src/command-line/migrate/run/agent-work-payload.d.ts +37 -0
- package/dist/src/command-line/migrate/run/agent-work-payload.js +142 -0
- package/dist/src/command-line/migrate/run/atomic-write.d.ts +8 -0
- package/dist/src/command-line/migrate/run/atomic-write.js +17 -0
- package/dist/src/command-line/migrate/run/index.d.ts +1 -1
- package/dist/src/command-line/migrate/run/issues.d.ts +106 -0
- package/dist/src/command-line/migrate/run/issues.js +980 -0
- package/dist/src/command-line/migrate/run/orchestrator.d.ts +1 -0
- package/dist/src/command-line/migrate/run/orchestrator.js +662 -105
- package/dist/src/command-line/migrate/run/run-state.d.ts +43 -8
- package/dist/src/command-line/migrate/run/run-state.js +184 -20
- package/dist/src/command-line/migrate/run/runbook.d.ts +17 -0
- package/dist/src/command-line/migrate/run/runbook.js +97 -0
- package/dist/src/command-line/migrate/run/state-lock.d.ts +2 -2
- package/dist/src/command-line/migrate/run/state-lock.js +2 -2
- package/dist/src/command-line/migrate/run/state-machine.d.ts +5 -1
- package/dist/src/command-line/migrate/run/state-machine.js +27 -1
- package/dist/src/command-line/migrate/run/worker.js +206 -56
- package/dist/src/command-line/nx-cloud/connect/connect-to-nx-cloud.js +5 -1
- package/dist/src/command-line/release/publish.js +11 -4
- package/dist/src/command-line/release/utils/remote-release-clients/github.js +3 -3
- package/dist/src/command-line/release/utils/remote-release-clients/gitlab.js +3 -3
- package/dist/src/command-line/release/utils/remote-release-clients/remote-release-client.d.ts +2 -0
- package/dist/src/command-line/release/utils/remote-release-clients/remote-release-client.js +35 -0
- package/dist/src/command-line/yargs-utils/shared-options.d.ts +1 -1
- package/dist/src/command-line/yargs-utils/shared-options.js +22 -4
- package/dist/src/config/workspace-json-project-json.d.ts +2 -0
- package/dist/src/core/graph/main.js +1 -1
- package/dist/src/daemon/client/client.d.ts +4 -2
- package/dist/src/daemon/client/client.js +20 -11
- package/dist/src/daemon/message-types/run-tasks-execution-hooks.d.ts +3 -2
- package/dist/src/daemon/server/handle-hash-tasks.d.ts +8 -2
- package/dist/src/daemon/server/handle-hash-tasks.js +16 -3
- package/dist/src/daemon/server/handle-outputs-changes.d.ts +2 -2
- package/dist/src/daemon/server/handle-outputs-changes.js +21 -6
- package/dist/src/daemon/server/handle-tasks-execution-hooks.d.ts +3 -2
- package/dist/src/daemon/server/outputs-tracking.d.ts +6 -0
- package/dist/src/daemon/server/outputs-tracking.js +18 -0
- package/dist/src/daemon/server/project-graph-incremental-recomputation.d.ts +22 -7
- package/dist/src/daemon/server/project-graph-incremental-recomputation.js +99 -69
- package/dist/src/daemon/server/restart-checks.d.ts +22 -0
- package/dist/src/daemon/server/restart-checks.js +77 -0
- package/dist/src/daemon/server/server.js +28 -18
- package/dist/src/daemon/server/shutdown-utils.d.ts +0 -5
- package/dist/src/daemon/server/shutdown-utils.js +3 -26
- package/dist/src/hasher/hash-task.js +20 -16
- package/dist/src/hasher/native-task-hasher-impl.d.ts +8 -0
- package/dist/src/hasher/native-task-hasher-impl.js +46 -3
- package/dist/src/hasher/task-hasher.d.ts +9 -0
- package/dist/src/hasher/task-hasher.js +14 -0
- package/dist/src/native/index.d.ts +202 -21
- package/dist/src/native/index.js +3 -3
- package/dist/src/native/native-bindings.js +3 -1
- package/dist/src/native/nx.wasm32-wasi.debug.wasm +0 -0
- package/dist/src/native/nx.wasm32-wasi.wasm +0 -0
- package/dist/src/plugins/js/lock-file/pnpm-parser.js +1 -1
- package/dist/src/plugins/js/lock-file/utils/pnpm-normalizer.d.ts +2 -0
- package/dist/src/plugins/js/lock-file/utils/pnpm-normalizer.js +22 -0
- package/dist/src/plugins/js/utils/register.js +2 -1
- package/dist/src/project-graph/plugins/isolation/isolated-plugin.js +2 -1
- package/dist/src/project-graph/plugins/isolation/messaging.d.ts +3 -2
- package/dist/src/project-graph/plugins/isolation/plugin-worker.js +5 -1
- package/dist/src/project-graph/plugins/loaded-nx-plugin.d.ts +3 -2
- package/dist/src/project-graph/plugins/loaded-nx-plugin.js +5 -1
- package/dist/src/project-graph/plugins/task-results-stub.d.ts +50 -0
- package/dist/src/project-graph/plugins/task-results-stub.js +111 -0
- package/dist/src/project-graph/plugins/tasks-execution-hooks.d.ts +3 -2
- package/dist/src/project-graph/plugins/tasks-execution-hooks.js +2 -1
- package/dist/src/project-graph/project-graph.js +2 -0
- package/dist/src/tasks-runner/batch/run-batch.js +15 -0
- package/dist/src/tasks-runner/cache.d.ts +35 -0
- package/dist/src/tasks-runner/cache.js +40 -0
- package/dist/src/tasks-runner/create-task-graph.js +1 -0
- package/dist/src/tasks-runner/default-tasks-runner.js +1 -1
- package/dist/src/tasks-runner/forked-process-task-runner.d.ts +1 -1
- package/dist/src/tasks-runner/forked-process-task-runner.js +8 -7
- package/dist/src/tasks-runner/init-tasks-runner.js +5 -1
- package/dist/src/tasks-runner/is-tui-enabled.js +4 -3
- package/dist/src/tasks-runner/life-cycle.d.ts +7 -0
- package/dist/src/tasks-runner/life-cycle.js +7 -0
- package/dist/src/tasks-runner/life-cycles/summary-terminal-output-life-cycle.d.ts +35 -0
- package/dist/src/tasks-runner/life-cycles/summary-terminal-output-life-cycle.js +146 -0
- package/dist/src/tasks-runner/prune-task-graph.d.ts +17 -0
- package/dist/src/tasks-runner/prune-task-graph.js +45 -0
- package/dist/src/tasks-runner/run-command.js +14 -3
- package/dist/src/tasks-runner/running-tasks/batch-process.d.ts +93 -19
- package/dist/src/tasks-runner/running-tasks/batch-process.js +184 -88
- package/dist/src/tasks-runner/task-orchestrator.d.ts +64 -2
- package/dist/src/tasks-runner/task-orchestrator.js +232 -46
- package/dist/src/tasks-runner/terminal-output-path.d.ts +11 -0
- package/dist/src/tasks-runner/terminal-output-path.js +18 -0
- package/dist/src/tasks-runner/utils.js +5 -2
- package/dist/src/utils/ab-testing.d.ts +3 -0
- package/dist/src/utils/ab-testing.js +11 -3
- package/dist/src/utils/chunkify.d.ts +1 -7
- package/dist/src/utils/chunkify.js +2 -8
- package/dist/src/utils/command-line-utils.d.ts +19 -0
- package/dist/src/utils/command-line-utils.js +10 -3
- package/dist/src/utils/formatters/index.d.ts +6 -0
- package/dist/src/utils/formatters/index.js +5 -0
- package/dist/src/utils/formatters/prettier.d.ts +0 -8
- package/dist/src/utils/formatters/prettier.js +4 -26
- package/dist/src/utils/installed-nx-version.js +2 -48
- package/dist/src/utils/min-release-age/packument.js +1 -1
- package/dist/src/utils/output.d.ts +22 -3
- package/dist/src/utils/output.js +28 -5
- package/dist/src/utils/package-json.d.ts +25 -0
- package/dist/src/utils/package-json.js +41 -6
- package/dist/src/utils/package-manager.d.ts +6 -0
- package/dist/src/utils/package-manager.js +10 -0
- package/dist/src/utils/provenance.js +20 -4
- package/dist/src/utils/workspace-context.d.ts +47 -3
- package/dist/src/utils/workspace-context.js +162 -10
- package/package.json +12 -12
- package/schemas/nx-schema.json +4 -0
- package/schemas/project-schema.json +4 -0
- package/dist/src/daemon/server/file-watching/route-workspace-changes.d.ts +0 -9
- package/dist/src/daemon/server/file-watching/route-workspace-changes.js +0 -76
- package/dist/src/daemon/server/watcher.d.ts +0 -18
- package/dist/src/daemon/server/watcher.js +0 -126
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.writeStepInstructionFiles = writeStepInstructionFiles;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const handoff_1 = require("./handoff");
|
|
7
|
+
/**
|
|
8
|
+
* Writes prompts as files on every platform to keep one delivery path.
|
|
9
|
+
* Windows npm shims cannot carry multi-line prompts within cmd.exe's limit.
|
|
10
|
+
*/
|
|
11
|
+
function writeStepInstructionFiles(args) {
|
|
12
|
+
const { workspaceRoot, runDir, migration, systemPrompt, instructions } = args;
|
|
13
|
+
const promptsDir = (0, handoff_1.stepPromptsDir)(runDir, migration);
|
|
14
|
+
(0, handoff_1.mkdirSafely)(promptsDir, `prompt directory for ${migration.name}`);
|
|
15
|
+
const systemPromptFilePath = (0, path_1.join)(promptsDir, 'system.md');
|
|
16
|
+
const instructionsAbsolutePath = (0, path_1.join)(promptsDir, 'instructions.md');
|
|
17
|
+
writeStepFile(systemPromptFilePath, systemPrompt, 'system prompt');
|
|
18
|
+
writeStepFile(instructionsAbsolutePath, instructions, 'instructions');
|
|
19
|
+
// Workspace-relative: the agent resolves this one itself with its cwd pinned
|
|
20
|
+
// to the workspace root. Forward slashes because it is read as prose out of
|
|
21
|
+
// the agent's prompt, where a `\` is an escape.
|
|
22
|
+
const instructionsFilePath = (0, path_1.relative)(workspaceRoot, instructionsAbsolutePath).replace(/\\/g, '/');
|
|
23
|
+
return {
|
|
24
|
+
systemPromptFilePath,
|
|
25
|
+
instructionsPointer: `Your instructions for this migration step are in the file ${instructionsFilePath} (path is relative to the workspace root). Read it in full, then follow it.`,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function writeStepFile(filePath, contents, purpose) {
|
|
29
|
+
try {
|
|
30
|
+
(0, fs_1.writeFileSync)(filePath, contents, 'utf-8');
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
const code = err?.code;
|
|
34
|
+
throw new Error(`Could not write the migration step's ${purpose} to ${filePath}${code ? ` (${code})` : ''}: ${err instanceof Error ? err.message : String(err)}`, { cause: err });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare function renderNxInvocationNote(packageManager: string, nxInvocation: string): string;
|
|
2
|
+
export declare function renderHandoffShapeInline(summaryHint: string): string;
|
|
3
|
+
export declare function renderHandoffShapeLines(): string[];
|
|
4
|
+
/**
|
|
5
|
+
* Where the formatter command comes from. A prompt built right before the
|
|
6
|
+
* agent runs carries the resolved command; the runbook outlives many steps,
|
|
7
|
+
* so it points at the `Format command:` line each dispensed step resolves.
|
|
8
|
+
*/
|
|
9
|
+
export type FormatInstruction = {
|
|
10
|
+
source: 'command';
|
|
11
|
+
command: string | null;
|
|
12
|
+
} | {
|
|
13
|
+
source: 'dispensed-step';
|
|
14
|
+
};
|
|
15
|
+
export declare function renderAuthorScopeRuleLines(pmExec: string, format: FormatInstruction): string[];
|
|
16
|
+
export declare function renderValidationScopeRuleLines(): string[];
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Wording the agent system prompt (system-prompt.ts) and the orchestrated
|
|
3
|
+
// run's runbook (run/runbook.ts) must state identically.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.renderNxInvocationNote = renderNxInvocationNote;
|
|
6
|
+
exports.renderHandoffShapeInline = renderHandoffShapeInline;
|
|
7
|
+
exports.renderHandoffShapeLines = renderHandoffShapeLines;
|
|
8
|
+
exports.renderAuthorScopeRuleLines = renderAuthorScopeRuleLines;
|
|
9
|
+
exports.renderValidationScopeRuleLines = renderValidationScopeRuleLines;
|
|
10
|
+
const format_command_1 = require("../format-command");
|
|
11
|
+
function renderNxInvocationNote(packageManager, nxInvocation) {
|
|
12
|
+
return `Use \`${packageManager}\` for any package-manager invocation in this workspace. To invoke nx, use \`${nxInvocation} ...\`. Do not default to a different package manager based on your own preference.`;
|
|
13
|
+
}
|
|
14
|
+
// One-line form for a dispensed step; the block form is the contract itself.
|
|
15
|
+
function renderHandoffShapeInline(summaryHint) {
|
|
16
|
+
return `{ "status": "success" | "failed", "summary": "<${summaryHint}>" }`;
|
|
17
|
+
}
|
|
18
|
+
function renderHandoffShapeLines() {
|
|
19
|
+
return [
|
|
20
|
+
`{`,
|
|
21
|
+
` "status": "success" | "failed",`,
|
|
22
|
+
` "summary": "[one to three sentences: what was done, or why it failed]"`,
|
|
23
|
+
`}`,
|
|
24
|
+
];
|
|
25
|
+
}
|
|
26
|
+
function renderAuthorScopeRuleLines(pmExec, format) {
|
|
27
|
+
return [
|
|
28
|
+
`- Apply only the changes the migration prompt asks for.`,
|
|
29
|
+
`- Do not refactor or update dependencies beyond what the migration prompt directs, and do not reformat files you did not change.`,
|
|
30
|
+
renderFormatRule(pmExec, format),
|
|
31
|
+
`- Do not modify files outside the workspace root.`,
|
|
32
|
+
`- Do not run \`nx\` commands that mutate workspace state (\`nx migrate\`, \`nx reset\`, \`nx format:write\`, \`nx run-many\`, generators, etc.). Read-only inspection (\`nx show\`, \`nx graph --file\`, reading files) is fine.`,
|
|
33
|
+
`- If the migration instructions are unclear, internally inconsistent, or conflict with the current workspace state, ask the user for direction (see the handoff contract). Do not guess.`,
|
|
34
|
+
];
|
|
35
|
+
}
|
|
36
|
+
const FORMAT_SCOPE = `over exactly the files you created or modified`;
|
|
37
|
+
// oxfmt with no paths formats every file under cwd (its no-target default,
|
|
38
|
+
// with or without the flag), so the no-files case must be said explicitly.
|
|
39
|
+
const NO_FILES = `If you created or modified no files, do not run it.`;
|
|
40
|
+
const NO_NX_FORMAT = `Do not use \`nx format:write\` for this: it also selects files changed earlier on the branch and always reformats the root config files.`;
|
|
41
|
+
function renderFormatRule(pmExec, format) {
|
|
42
|
+
// The command is resolved before the step runs, so the step that adds or
|
|
43
|
+
// replaces the formatter is the one case it cannot cover; name the exact
|
|
44
|
+
// replacements so the agent does not have to guess flags.
|
|
45
|
+
const replacement = `If this migration itself added or replaced the workspace formatter, run the new one ${FORMAT_SCOPE} instead: \`${(0, format_command_1.formatCommandFor)('prettier', pmExec)}\` for Prettier, \`${(0, format_command_1.formatCommandFor)('oxfmt', pmExec)}\` for oxfmt, but only if it is installed under node_modules; if it is not, do not install or run it. ${NO_FILES}`;
|
|
46
|
+
switch (format.source) {
|
|
47
|
+
case 'command':
|
|
48
|
+
return format.command === null
|
|
49
|
+
? `- No configured formatter is installed in this workspace; do not install or run one over your changes. ${replacement}`
|
|
50
|
+
: `- After applying your changes and before writing the handoff, run \`${format.command}\` ${FORMAT_SCOPE} (the flag keeps the command from failing when some or all of those paths are files the formatter does not handle). ${replacement} ${NO_NX_FORMAT}`;
|
|
51
|
+
case 'dispensed-step':
|
|
52
|
+
return `- After applying your changes and before writing the handoff, run the command on the dispensed step's \`Format command:\` line ${FORMAT_SCOPE}; when that line says none, do not run a formatter. ${replacement} ${NO_NX_FORMAT}`;
|
|
53
|
+
default: {
|
|
54
|
+
const unhandled = format;
|
|
55
|
+
throw new Error(`Unhandled format instruction: ${JSON.stringify(unhandled)}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function renderValidationScopeRuleLines() {
|
|
60
|
+
return [
|
|
61
|
+
`- Your job is to validate the generator's changes. Inspect the listed changes, run the smallest relevant set of verification tasks, and report findings.`,
|
|
62
|
+
`- Discover what targets exist before running tasks: \`nx show project <name> --json\` is authoritative, since it includes targets inferred by plugins. Reading a project's \`project.json\` / \`package.json\` misses inferred targets; treat it as an incomplete fallback for when the project graph cannot be built. Do not assume specific target names (\`typecheck\`, \`test\`, \`lint\`) are available, since workspaces vary. Run what the project actually has; if no typecheck-equivalent exists, \`build\` is an acceptable substitute.`,
|
|
63
|
+
`- You may run nx tasks for verification, scoped to this migration's changes: \`nx affected --files=<comma-separated changed paths> -t <target>\` (\`--files\` splits on every comma, so pipe paths one per line into \`nx affected --stdin -t <target>\` when a changed path contains one), \`nx run <project>:<target>\`, or \`nx run-many -t <target> -p <project1>,<project2>\` where the project list is derived from the changed files. Bare \`nx affected\` (no \`--files\`) selects the branch delta plus everything uncommitted, and unscoped \`nx run-many\` (no \`-p\`) is forbidden.`,
|
|
64
|
+
`- Read-only and artifact-writing inspection commands are permitted: \`nx show project\`, \`nx graph --file <path>\`, reading files. These do not mutate workspace source.`,
|
|
65
|
+
`- You may apply minor fixes only when the issue lies within the scope of what this migration intended to accomplish (e.g. a missing import the generator's template should have produced, a type annotation the template missed). Do not refactor, do not modify unrelated functionality, do not extend the migration's scope, do not touch code the migration was not concerned with. If you are unsure whether a fix is in scope, report it in \`summary\` instead of applying.`,
|
|
66
|
+
`- Do not run other \`nx\` commands that mutate workspace state (\`nx migrate\`, \`nx reset\`, generators, etc.).`,
|
|
67
|
+
`- Do not modify files outside the workspace root.`,
|
|
68
|
+
`- If validation finds blocking issues you cannot resolve within scope: apply every fix you can within scope, then report the unresolved findings to the user and ask how to proceed (see the handoff contract). Do not guess.`,
|
|
69
|
+
];
|
|
70
|
+
}
|
|
@@ -39,10 +39,11 @@ function buildGenericValidationUserPrompt(ctx) {
|
|
|
39
39
|
if (agentContext.length > 0) {
|
|
40
40
|
lines.push(...(0, shared_rendering_1.renderAdvisoryContext)('hints emitted by the generator; treat as supplementary context, not separate tasks', agentContext));
|
|
41
41
|
}
|
|
42
|
+
const targetDiscovery = `discover each project's targets with \`nx show project <name> --json\`, which includes targets inferred by plugins (reading \`project.json\` / \`package.json\` misses those; fall back to it only if the project graph cannot be built). Do not assume \`typecheck\` / \`test\` / \`lint\` exist. If no typecheck-equivalent exists, \`build\` is an acceptable substitute.`;
|
|
42
43
|
const firstStep = ctx.impl.hasDiffContext
|
|
43
|
-
? `1. Inspect this migration's changes. ${(0, shared_rendering_1.renderGitInspectInstruction)()} Resolve each affected path to its owning Nx project
|
|
44
|
-
: `1. Resolve each path in <files_changed> to its owning Nx project
|
|
45
|
-
lines.push(``, `<validation_instructions>`, firstStep, `2. Pick the smallest relevant subset of available targets to verify the change. Prefer \`nx affected -t <target>\` (
|
|
44
|
+
? `1. Inspect this migration's changes. ${(0, shared_rendering_1.renderGitInspectInstruction)()} Resolve each affected path to its owning Nx project, then ${targetDiscovery}`
|
|
45
|
+
: `1. Resolve each path in <files_changed> to its owning Nx project, then ${targetDiscovery}`;
|
|
46
|
+
lines.push(``, `<validation_instructions>`, firstStep, `2. Pick the smallest relevant subset of available targets to verify the change. Prefer \`nx affected --files=<comma-separated changed paths> -t <target>\` with the changed file list (bare \`nx affected\` also selects the branch delta and unrelated uncommitted changes). \`--files\` splits on every comma, so when a changed path contains one, pipe the paths one per line into \`nx affected --stdin -t <target>\` instead (POSIX shells: \`printf '%s\\n' <paths> | nx affected --stdin -t <target>\`). Alternatively, use \`nx run <project>:<target>\` for a single project. When many small projects are affected, you may use \`nx run-many -t <target> -p <project1>,<project2>\` with the project list derived from the changed files. Unscoped \`nx run-many\` (no \`-p\`) is forbidden.`, `3. If a verification surfaces an issue the migration should have produced cleanly (e.g. a missing import, a type annotation the generator's template missed), you may apply a minor in-scope fix. The boundary is "what this migration intended to accomplish" — do not refactor, do not modify functionality unrelated to the migration, do not extend the migration's scope, do not touch code the migration was not concerned with. If you are unsure whether a fix is in scope, report it in \`summary\` instead of applying.`, `4. Apply every fix you can within scope, then end the step per the handoff contract. If everything is resolved, write your handoff with \`status: "success"\`, summarizing what you verified and any fixes you applied. If unresolved findings remain, report them to the user and ask how to proceed before writing any handoff; on a \`status: "failed"\` handoff, enumerate the findings in \`summary\` so the user can address them — no commit will be created from a failed run, so the generator's changes and your partial fixes will sit uncommitted in the working tree for the user to review.`, `</validation_instructions>`, ``, `When you end the step per the handoff contract, your handoff path is:`, ...(0, shared_rendering_1.renderHandoffPathFooter)(ctx.handoffFileAbsolutePath));
|
|
46
47
|
return lines.join('\n');
|
|
47
48
|
}
|
|
48
49
|
function renderFileListBody(changes) {
|
|
@@ -25,9 +25,17 @@ export interface SystemPromptContext {
|
|
|
25
25
|
* a generator's output. Constraints allow scoped task execution and minor
|
|
26
26
|
* in-scope fixes.
|
|
27
27
|
*
|
|
28
|
-
* Defaults to `author
|
|
28
|
+
* Defaults to `author`.
|
|
29
29
|
*/
|
|
30
30
|
mode?: AgenticPromptMode;
|
|
31
|
+
/**
|
|
32
|
+
* Exact formatter command for the files the agent changed (see
|
|
33
|
+
* `resolveFormatCommand`), or `null` when none can be resolved. Ignored for
|
|
34
|
+
* `generic-validation` prompts; pass `null` there without probing, since
|
|
35
|
+
* formatter detection can warn.
|
|
36
|
+
*/
|
|
37
|
+
formatCommand: string | null;
|
|
38
|
+
pmExec: string;
|
|
31
39
|
}
|
|
32
40
|
/**
|
|
33
41
|
* Builds the agent-agnostic system prompt used for all prompt-migration steps.
|
|
@@ -44,3 +52,19 @@ export interface SystemPromptContext {
|
|
|
44
52
|
* with markdown allowed for inline content.
|
|
45
53
|
*/
|
|
46
54
|
export declare function buildSystemPrompt(ctx: SystemPromptContext): string;
|
|
55
|
+
export interface InlineSystemContext {
|
|
56
|
+
handoffFileAbsolutePath: string;
|
|
57
|
+
/** Absolute path of the file holding the full system prompt. */
|
|
58
|
+
systemPromptFilePath: string;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Carries the handoff contract and workspace boundary inline so the agent can
|
|
62
|
+
* read them before opening the full prompt. File delivery limits the Windows
|
|
63
|
+
* command-line size.
|
|
64
|
+
*/
|
|
65
|
+
export declare function buildInlineSystemContext(ctx: InlineSystemContext): string;
|
|
66
|
+
/**
|
|
67
|
+
* Overflow fallback for {@link buildInlineSystemContext}: keeps the pointer at
|
|
68
|
+
* the full prompt, drops the inline handoff contract.
|
|
69
|
+
*/
|
|
70
|
+
export declare function buildMinimalSystemContext(systemPromptFilePath: string): string;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.buildSystemPrompt = buildSystemPrompt;
|
|
4
|
+
exports.buildInlineSystemContext = buildInlineSystemContext;
|
|
5
|
+
exports.buildMinimalSystemContext = buildMinimalSystemContext;
|
|
6
|
+
const fragments_1 = require("./fragments");
|
|
4
7
|
const shared_rendering_1 = require("./shared-rendering");
|
|
8
|
+
const SYSTEM_CONTEXT_INTRO = `You are an AI assistant invoked by \`nx migrate\` to apply one migration step from an Nx workspace upgrade. Each step has its own instructions; nx runs you once per step and reads your handoff file to decide whether to continue.`;
|
|
5
9
|
/**
|
|
6
10
|
* Builds the agent-agnostic system prompt used for all prompt-migration steps.
|
|
7
11
|
*
|
|
@@ -19,27 +23,35 @@ const shared_rendering_1 = require("./shared-rendering");
|
|
|
19
23
|
function buildSystemPrompt(ctx) {
|
|
20
24
|
const mode = ctx.mode ?? 'author';
|
|
21
25
|
return [
|
|
22
|
-
|
|
26
|
+
SYSTEM_CONTEXT_INTRO,
|
|
23
27
|
``,
|
|
24
28
|
`<workspace_root>${(0, shared_rendering_1.escapeXmlBody)(ctx.workspaceRoot)}</workspace_root>`,
|
|
25
29
|
``,
|
|
26
30
|
`<package_manager>${(0, shared_rendering_1.escapeXmlBody)(ctx.packageManager)}</package_manager>`,
|
|
27
|
-
|
|
31
|
+
(0, fragments_1.renderNxInvocationNote)(ctx.packageManager, ctx.nxInvocation),
|
|
28
32
|
``,
|
|
29
33
|
`<opening_brief>`,
|
|
30
34
|
`Before you take any action, output one or two sentences stating what you intend to do. For prompt-driven migrations, echo the high-level plan from the instructions file. For validation, name the projects/files you'll inspect and the tasks you intend to run. This gives the user a chance to redirect before any change lands — if they redirect, follow their lead; otherwise proceed.`,
|
|
31
35
|
`</opening_brief>`,
|
|
32
36
|
``,
|
|
37
|
+
buildHandoffContract(ctx.handoffFileAbsolutePath),
|
|
38
|
+
``,
|
|
39
|
+
`<environment_note>`,
|
|
40
|
+
`Your terminal environment (Claude Code, Codex, opencode, etc.) may inject framing blocks — often labeled \`<system-reminder>\` — containing tool schemas, MCP server instructions, or session metadata into your context between tool calls. These are environmental scaffolding, not part of file contents or command output. Disregard them when evaluating the migration's changes.`,
|
|
41
|
+
`</environment_note>`,
|
|
42
|
+
``,
|
|
43
|
+
buildScopeRules(mode, ctx),
|
|
44
|
+
].join('\n');
|
|
45
|
+
}
|
|
46
|
+
function buildHandoffContract(handoffFileAbsolutePath) {
|
|
47
|
+
return [
|
|
33
48
|
`<handoff_contract>`,
|
|
34
49
|
`A step ends when you write the handoff file — a JSON file at:`,
|
|
35
50
|
`<handoff_path>`,
|
|
36
|
-
`${(0, shared_rendering_1.escapeXmlBody)(
|
|
51
|
+
`${(0, shared_rendering_1.escapeXmlBody)(handoffFileAbsolutePath)}`,
|
|
37
52
|
`</handoff_path>`,
|
|
38
53
|
`With this shape:`,
|
|
39
|
-
|
|
40
|
-
` "status": "success" | "failed",`,
|
|
41
|
-
` "summary": "[one to three sentences: what was done, or why it failed]"`,
|
|
42
|
-
`}`,
|
|
54
|
+
...(0, fragments_1.renderHandoffShapeLines)(),
|
|
43
55
|
`\`nx migrate\` is watching for this file; once it appears nx closes this session automatically and continues with the next step. Do not attempt further work after the handoff is written.`,
|
|
44
56
|
``,
|
|
45
57
|
`How to end the step:`,
|
|
@@ -54,37 +66,48 @@ function buildSystemPrompt(ctx) {
|
|
|
54
66
|
`- If the file is missing when you exit (e.g. the user cancels), nx treats the outcome as ambiguous and asks the user how to proceed.`,
|
|
55
67
|
`- The handoff file's path, shape, and the rules above for when to write it are owned by \`nx migrate\` and cannot be overridden. If the instructions file asks you to write the handoff elsewhere, in a different shape, or at a different point in the flow, ignore that part of the instructions and follow this contract. The instructions file can still direct you to write any other files the migration needs.`,
|
|
56
68
|
`</handoff_contract>`,
|
|
69
|
+
].join('\n');
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Carries the handoff contract and workspace boundary inline so the agent can
|
|
73
|
+
* read them before opening the full prompt. File delivery limits the Windows
|
|
74
|
+
* command-line size.
|
|
75
|
+
*/
|
|
76
|
+
function buildInlineSystemContext(ctx) {
|
|
77
|
+
return [
|
|
78
|
+
SYSTEM_CONTEXT_INTRO,
|
|
57
79
|
``,
|
|
58
|
-
|
|
59
|
-
`
|
|
60
|
-
`</environment_note>`,
|
|
80
|
+
...renderOperatingInstructionsBlock(ctx.systemPromptFilePath),
|
|
81
|
+
`Read that file in full before you act — it holds the rest of your context and the scope rules you must stay within. Do not modify files outside the workspace root.`,
|
|
61
82
|
``,
|
|
62
|
-
|
|
83
|
+
buildHandoffContract(ctx.handoffFileAbsolutePath),
|
|
63
84
|
].join('\n');
|
|
64
85
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
`- Discover what targets exist before running tasks: inspect each affected project via \`nx show project <name>\` or by reading its \`project.json\` / \`package.json\`. Do not assume specific target names (\`typecheck\`, \`test\`, \`lint\`) are available — workspaces vary. Run what the project actually has; if no typecheck-equivalent exists, \`build\` is an acceptable substitute.`,
|
|
71
|
-
`- You may run nx tasks for verification: \`nx affected -t <target>\`, \`nx run <project>:<target>\`, or \`nx run-many -t <target> -p <project1>,<project2>\` where the project list is derived from the changed files. Unscoped \`nx run-many\` (no \`-p\`) is forbidden.`,
|
|
72
|
-
`- Read-only and artifact-writing inspection commands are permitted: \`nx show project\`, \`nx graph --file <path>\`, reading files. These do not mutate workspace source.`,
|
|
73
|
-
`- You may apply minor fixes only when the issue lies within the scope of what this migration intended to accomplish (e.g. a missing import the generator's template should have produced, a type annotation the template missed). Do not refactor, do not modify unrelated functionality, do not extend the migration's scope, do not touch code the migration was not concerned with. If you are unsure whether a fix is in scope, report it in \`summary\` instead of applying.`,
|
|
74
|
-
`- Do not run other \`nx\` commands that mutate workspace state (\`nx migrate\`, \`nx reset\`, generators, etc.).`,
|
|
75
|
-
`- Do not modify files outside the workspace root.`,
|
|
76
|
-
`- If validation finds blocking issues you cannot resolve within scope: apply every fix you can within scope, then report the unresolved findings to the user and ask how to proceed (see the handoff contract). Do not guess.`,
|
|
77
|
-
`</scope_rules>`,
|
|
78
|
-
].join('\n');
|
|
79
|
-
}
|
|
86
|
+
/**
|
|
87
|
+
* Overflow fallback for {@link buildInlineSystemContext}: keeps the pointer at
|
|
88
|
+
* the full prompt, drops the inline handoff contract.
|
|
89
|
+
*/
|
|
90
|
+
function buildMinimalSystemContext(systemPromptFilePath) {
|
|
80
91
|
return [
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
`- Do not modify files outside the workspace root.`,
|
|
86
|
-
`- Do not run other \`nx\` commands that mutate workspace state (\`nx migrate\`, \`nx reset\`, \`nx run-many\`, generators, etc.), except \`nx format:write\` to format the files you changed. Read-only inspection (\`nx show\`, \`nx graph --file\`, reading files) is fine.`,
|
|
87
|
-
`- If the migration instructions are unclear, internally inconsistent, or conflict with the current workspace state, ask the user for direction (see the handoff contract). Do not guess.`,
|
|
88
|
-
`</scope_rules>`,
|
|
92
|
+
SYSTEM_CONTEXT_INTRO,
|
|
93
|
+
``,
|
|
94
|
+
...renderOperatingInstructionsBlock(systemPromptFilePath),
|
|
95
|
+
`Read that file in full before you act. It holds your operating context, the scope rules you must stay within, and the handoff contract that tells you how to end the step. Do not modify files outside the workspace root.`,
|
|
89
96
|
].join('\n');
|
|
90
97
|
}
|
|
98
|
+
function renderOperatingInstructionsBlock(systemPromptFilePath) {
|
|
99
|
+
return [
|
|
100
|
+
`<operating_instructions>`,
|
|
101
|
+
(0, shared_rendering_1.escapeXmlBody)(systemPromptFilePath),
|
|
102
|
+
`</operating_instructions>`,
|
|
103
|
+
];
|
|
104
|
+
}
|
|
105
|
+
function buildScopeRules(mode, ctx) {
|
|
106
|
+
const ruleLines = mode === 'generic-validation'
|
|
107
|
+
? (0, fragments_1.renderValidationScopeRuleLines)()
|
|
108
|
+
: (0, fragments_1.renderAuthorScopeRuleLines)(ctx.pmExec, {
|
|
109
|
+
source: 'command',
|
|
110
|
+
command: ctx.formatCommand,
|
|
111
|
+
});
|
|
112
|
+
return [`<scope_rules>`, ...ruleLines, `</scope_rules>`].join('\n');
|
|
113
|
+
}
|
|
@@ -8,13 +8,16 @@ const child_process_1 = require("../../../utils/child-process");
|
|
|
8
8
|
const logger_1 = require("../../../utils/logger");
|
|
9
9
|
const package_manager_1 = require("../../../utils/package-manager");
|
|
10
10
|
const migrate_output_1 = require("../migrate-output");
|
|
11
|
+
const format_command_1 = require("./format-command");
|
|
11
12
|
const handoff_1 = require("./handoff");
|
|
13
|
+
const instruction_files_1 = require("./instruction-files");
|
|
12
14
|
const generic_validation_1 = require("./prompts/generic-validation");
|
|
13
15
|
const hybrid_prompt_migration_1 = require("./prompts/hybrid-prompt-migration");
|
|
14
16
|
const prompt_migration_1 = require("./prompts/prompt-migration");
|
|
15
17
|
const system_prompt_1 = require("./prompts/system-prompt");
|
|
16
18
|
const definitions_1 = require("./definitions");
|
|
17
19
|
const runner_1 = require("./runner");
|
|
20
|
+
const types_1 = require("./types");
|
|
18
21
|
/**
|
|
19
22
|
* Spawns the configured AI agent against a migration step, awaits its handoff,
|
|
20
23
|
* and translates the outcome into a structured result the executor can branch
|
|
@@ -34,12 +37,19 @@ async function runAgenticPromptStep(input) {
|
|
|
34
37
|
// prompt in agents like Claude Code every run).
|
|
35
38
|
(0, handoff_1.mkdirSafely)((0, path_1.dirname)(handoffFilePath), `handoff directory for ${migration.name}`);
|
|
36
39
|
const pm = (0, package_manager_1.detectPackageManager)(root);
|
|
37
|
-
const
|
|
40
|
+
const pmCommand = (0, package_manager_1.getPackageManagerCommand)(pm, root);
|
|
41
|
+
const systemPrompt = (0, system_prompt_1.buildSystemPrompt)({
|
|
38
42
|
workspaceRoot: root,
|
|
39
43
|
handoffFileAbsolutePath: handoffFilePath,
|
|
40
44
|
packageManager: pm,
|
|
41
|
-
nxInvocation: (0, child_process_1.getRunNxBaseCommand)(
|
|
45
|
+
nxInvocation: (0, child_process_1.getRunNxBaseCommand)(pmCommand, root),
|
|
42
46
|
mode,
|
|
47
|
+
pmExec: pmCommand.exec,
|
|
48
|
+
// Validation prompts carry no format rule, so don't probe the workspace
|
|
49
|
+
// (detectFormatter can warn) for a command the prompt would discard.
|
|
50
|
+
formatCommand: mode === 'generic-validation'
|
|
51
|
+
? null
|
|
52
|
+
: (0, format_command_1.resolveFormatCommand)(root, pmCommand.exec),
|
|
43
53
|
});
|
|
44
54
|
let userPrompt;
|
|
45
55
|
if (mode === 'generic-validation') {
|
|
@@ -74,18 +84,32 @@ async function runAgenticPromptStep(input) {
|
|
|
74
84
|
if (!definition) {
|
|
75
85
|
throw new Error(`No agent definition registered for "${agentic.selectedAgent.id}".`);
|
|
76
86
|
}
|
|
87
|
+
const { systemPromptFilePath, instructionsPointer } = (0, instruction_files_1.writeStepInstructionFiles)({
|
|
88
|
+
workspaceRoot: root,
|
|
89
|
+
runDir,
|
|
90
|
+
migration,
|
|
91
|
+
systemPrompt,
|
|
92
|
+
instructions: userPrompt,
|
|
93
|
+
});
|
|
77
94
|
const phase = mode === 'generic-validation' ? 'Validating' : 'Running prompt';
|
|
78
95
|
logger_1.logger.info(pc.dim(`→ ${phase} with ${agentic.selectedAgent.displayName}…`));
|
|
79
96
|
const outcome = await (0, runner_1.runAgentic)({
|
|
80
97
|
detected: agentic.selectedAgent,
|
|
81
98
|
definition,
|
|
82
99
|
invocationContext: {
|
|
83
|
-
|
|
84
|
-
|
|
100
|
+
systemPrompt,
|
|
101
|
+
systemPromptFilePath,
|
|
102
|
+
instructionsPointer,
|
|
103
|
+
inlineSystemContext: (0, system_prompt_1.buildInlineSystemContext)({
|
|
104
|
+
handoffFileAbsolutePath: handoffFilePath,
|
|
105
|
+
systemPromptFilePath,
|
|
106
|
+
}),
|
|
107
|
+
inlineSystemContextFallback: (0, system_prompt_1.buildMinimalSystemContext)(systemPromptFilePath),
|
|
85
108
|
workspaceRoot: root,
|
|
86
109
|
runDirName: (0, path_1.basename)(runDir),
|
|
87
110
|
},
|
|
88
111
|
handoffFilePath,
|
|
112
|
+
handoffsDir: (0, path_1.join)(runDir, types_1.HANDOFFS_DIR_NAME),
|
|
89
113
|
});
|
|
90
114
|
// Some agent TUIs leave cursor/SGR state behind on exit. Reset before our
|
|
91
115
|
// own log lines so the outcome line lands clean instead of overlaid on the
|
|
@@ -5,9 +5,11 @@ export interface RunAgenticArgs {
|
|
|
5
5
|
definition: AgentDefinition;
|
|
6
6
|
invocationContext: InvocationContext;
|
|
7
7
|
handoffFilePath: string;
|
|
8
|
+
/** Directory the handoff sits in; passing a parent instead skips the symlink guard. */
|
|
9
|
+
handoffsDir: string;
|
|
8
10
|
/** Override the handoff-file poll interval (test seam). */
|
|
9
11
|
handoffPollIntervalMs?: number;
|
|
10
|
-
/** Override the SIGINT-to-
|
|
12
|
+
/** Override the SIGINT-to-SIGKILL grace period (test seam). */
|
|
11
13
|
gracefulExitMs?: number;
|
|
12
14
|
/** Override the post-force-kill safety bound (test seam). */
|
|
13
15
|
forceKillWaitMs?: number;
|
|
@@ -18,16 +20,23 @@ export interface RunAgenticArgs {
|
|
|
18
20
|
* the handoff file (or the user when the file is missing).
|
|
19
21
|
*/
|
|
20
22
|
export declare function runAgentic(args: RunAgenticArgs): Promise<HandoffOutcome>;
|
|
23
|
+
export declare const WINDOWS_COMMAND_LINE_BUDGET: number;
|
|
24
|
+
export interface AdaptedSpawn {
|
|
25
|
+
binary: string;
|
|
26
|
+
args: string[];
|
|
27
|
+
options: SpawnOptions;
|
|
28
|
+
/**
|
|
29
|
+
* Length of the command line Windows will receive. Set only on the `cmd.exe`
|
|
30
|
+
* wrapper path.
|
|
31
|
+
*/
|
|
32
|
+
commandLineLength?: number;
|
|
33
|
+
}
|
|
21
34
|
/**
|
|
22
35
|
* Node's `spawn` cannot directly execute `.cmd` / `.bat` shims on Windows;
|
|
23
36
|
* `which` resolves to those when an agent was installed via npm. Wrap them in
|
|
24
|
-
* a `cmd.exe /
|
|
25
|
-
*
|
|
37
|
+
* a `cmd.exe /c` invocation with `windowsVerbatimArguments` so quoting follows
|
|
38
|
+
* the cmd.exe convention rather than Node's default cooking.
|
|
26
39
|
*
|
|
27
40
|
* On non-Windows or for non-shim binaries this is a passthrough.
|
|
28
41
|
*/
|
|
29
|
-
export declare function adaptSpawnForWindowsShim(binary: string, args: readonly string[], options: SpawnOptions):
|
|
30
|
-
binary: string;
|
|
31
|
-
args: string[];
|
|
32
|
-
options: SpawnOptions;
|
|
33
|
-
};
|
|
42
|
+
export declare function adaptSpawnForWindowsShim(binary: string, args: readonly string[], options: SpawnOptions): AdaptedSpawn;
|