agentplane 0.3.13 → 0.3.14
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/assets/RUNNER.md +1 -1
- package/assets/agents/ORCHESTRATOR.json +1 -1
- package/assets/agents/SKILL_EXTRACTOR.json +31 -0
- package/assets/framework.manifest.json +7 -0
- package/assets/policy/incidents.md +5 -3
- package/assets/policy/workflow.branch_pr.md +10 -5
- package/dist/.build-manifest.json +278 -178
- package/dist/cli/output.d.ts +29 -0
- package/dist/cli/output.d.ts.map +1 -1
- package/dist/cli/output.js +33 -0
- package/dist/cli/run-cli/command-catalog/core.d.ts.map +1 -1
- package/dist/cli/run-cli/command-catalog/core.js +29 -87
- package/dist/cli/run-cli/command-catalog/lifecycle.d.ts.map +1 -1
- package/dist/cli/run-cli/command-catalog/lifecycle.js +4 -12
- package/dist/cli/run-cli/command-catalog/project.d.ts +1 -1
- package/dist/cli/run-cli/command-catalog/project.d.ts.map +1 -1
- package/dist/cli/run-cli/command-catalog/project.js +16 -38
- package/dist/cli/run-cli/command-catalog/shared.d.ts +9 -6
- package/dist/cli/run-cli/command-catalog/shared.d.ts.map +1 -1
- package/dist/cli/run-cli/command-catalog/shared.js +23 -6
- package/dist/cli/run-cli/command-catalog/task.d.ts.map +1 -1
- package/dist/cli/run-cli/command-catalog/task.js +6 -18
- package/dist/cli/run-cli/command-catalog.d.ts +1 -1
- package/dist/cli/run-cli/command-catalog.d.ts.map +1 -1
- package/dist/cli/run-cli/commands/init/recipes.d.ts.map +1 -1
- package/dist/cli/run-cli/commands/init/recipes.js +1 -0
- package/dist/cli/run-cli.js +1 -1
- package/dist/cli/run-cli.test-helpers.d.ts +1 -74
- package/dist/cli/run-cli.test-helpers.d.ts.map +1 -1
- package/dist/cli/run-cli.test-helpers.js +1 -769
- package/dist/commands/branch/cleanup-merged.d.ts.map +1 -1
- package/dist/commands/branch/cleanup-merged.js +5 -9
- package/dist/commands/branch/work-start.command.d.ts.map +1 -1
- package/dist/commands/branch/work-start.command.js +1 -0
- package/dist/commands/commit.spec.d.ts.map +1 -1
- package/dist/commands/commit.spec.js +2 -0
- package/dist/commands/doctor/branch-pr.d.ts +1 -1
- package/dist/commands/doctor/branch-pr.d.ts.map +1 -1
- package/dist/commands/doctor/branch-pr.js +5 -2
- package/dist/commands/guard/impl/commands.d.ts.map +1 -1
- package/dist/commands/guard/impl/commands.js +4 -1
- package/dist/commands/guard/impl/comment-commit.d.ts.map +1 -1
- package/dist/commands/guard/impl/comment-commit.js +2 -1
- package/dist/commands/guard/impl/env.d.ts +6 -0
- package/dist/commands/guard/impl/env.d.ts.map +1 -1
- package/dist/commands/guard/impl/env.js +41 -0
- package/dist/commands/pr/internal/auto-commit.d.ts.map +1 -1
- package/dist/commands/pr/internal/auto-commit.js +2 -1
- package/dist/commands/pr/internal/sync-branch.d.ts +36 -0
- package/dist/commands/pr/internal/sync-branch.d.ts.map +1 -0
- package/dist/commands/pr/internal/sync-branch.js +113 -0
- package/dist/commands/pr/internal/sync-github.d.ts +28 -0
- package/dist/commands/pr/internal/sync-github.d.ts.map +1 -0
- package/dist/commands/pr/internal/sync-github.js +178 -0
- package/dist/commands/pr/internal/sync-model.d.ts +36 -0
- package/dist/commands/pr/internal/sync-model.d.ts.map +1 -0
- package/dist/commands/pr/internal/sync-model.js +1 -0
- package/dist/commands/pr/internal/sync-open-step.d.ts +10 -0
- package/dist/commands/pr/internal/sync-open-step.d.ts.map +1 -0
- package/dist/commands/pr/internal/sync-open-step.js +128 -0
- package/dist/commands/pr/internal/sync-support.d.ts +7 -0
- package/dist/commands/pr/internal/sync-support.d.ts.map +1 -0
- package/dist/commands/pr/internal/sync-support.js +29 -0
- package/dist/commands/pr/internal/sync-update-step.d.ts +6 -0
- package/dist/commands/pr/internal/sync-update-step.d.ts.map +1 -0
- package/dist/commands/pr/internal/sync-update-step.js +68 -0
- package/dist/commands/pr/internal/sync.d.ts +2 -6
- package/dist/commands/pr/internal/sync.d.ts.map +1 -1
- package/dist/commands/pr/internal/sync.js +83 -529
- package/dist/commands/pr/open.d.ts.map +1 -1
- package/dist/commands/pr/open.js +25 -8
- package/dist/commands/pr/pr.command.d.ts.map +1 -1
- package/dist/commands/pr/pr.command.js +7 -2
- package/dist/commands/recipes/impl/apply.d.ts +1 -1
- package/dist/commands/recipes/impl/apply.d.ts.map +1 -1
- package/dist/commands/recipes/impl/apply.js +1 -2
- package/dist/commands/recipes/impl/commands/active.d.ts.map +1 -1
- package/dist/commands/recipes/impl/commands/active.js +6 -5
- package/dist/commands/recipes/impl/commands/add.d.ts +1 -0
- package/dist/commands/recipes/impl/commands/add.d.ts.map +1 -1
- package/dist/commands/recipes/impl/commands/add.js +32 -27
- package/dist/commands/recipes/impl/commands/detach.d.ts.map +1 -1
- package/dist/commands/recipes/impl/commands/detach.js +35 -21
- package/dist/commands/recipes/impl/commands/disable.d.ts.map +1 -1
- package/dist/commands/recipes/impl/commands/disable.js +5 -3
- package/dist/commands/recipes/impl/commands/enable.d.ts.map +1 -1
- package/dist/commands/recipes/impl/commands/enable.js +5 -3
- package/dist/commands/recipes/impl/commands/explain.d.ts.map +1 -1
- package/dist/commands/recipes/impl/commands/explain.js +57 -47
- package/dist/commands/recipes/impl/commands/info.d.ts.map +1 -1
- package/dist/commands/recipes/impl/commands/info.js +25 -21
- package/dist/commands/recipes/impl/commands/install.d.ts +1 -1
- package/dist/commands/recipes/impl/commands/install.d.ts.map +1 -1
- package/dist/commands/recipes/impl/commands/install.js +3 -13
- package/dist/commands/recipes/impl/commands/list-remote.d.ts.map +1 -1
- package/dist/commands/recipes/impl/commands/list-remote.js +2 -3
- package/dist/commands/recipes/impl/commands/list.d.ts.map +1 -1
- package/dist/commands/recipes/impl/commands/list.js +7 -6
- package/dist/commands/recipes/impl/commands/remove.d.ts.map +1 -1
- package/dist/commands/recipes/impl/commands/remove.js +12 -7
- package/dist/commands/recipes/impl/commands/update.d.ts.map +1 -1
- package/dist/commands/recipes/impl/commands/update.js +38 -24
- package/dist/commands/recipes/impl/index.d.ts +1 -1
- package/dist/commands/recipes/impl/index.d.ts.map +1 -1
- package/dist/commands/recipes/impl/installed-recipes.d.ts +1 -1
- package/dist/commands/recipes/impl/installed-recipes.d.ts.map +1 -1
- package/dist/commands/recipes/impl/installed-recipes.js +1 -2
- package/dist/commands/recipes/impl/mutation-transaction.d.ts +7 -0
- package/dist/commands/recipes/impl/mutation-transaction.d.ts.map +1 -0
- package/dist/commands/recipes/impl/mutation-transaction.js +47 -0
- package/dist/commands/recipes/impl/overlay-project.d.ts +19 -3
- package/dist/commands/recipes/impl/overlay-project.d.ts.map +1 -1
- package/dist/commands/recipes/impl/overlay-project.js +76 -38
- package/dist/commands/recipes/impl/paths.d.ts +0 -3
- package/dist/commands/recipes/impl/paths.d.ts.map +1 -1
- package/dist/commands/recipes/impl/paths.js +0 -3
- package/dist/commands/recipes/impl/project-installed-recipes.d.ts +4 -1
- package/dist/commands/recipes/impl/project-installed-recipes.d.ts.map +1 -1
- package/dist/commands/recipes/impl/project-installed-recipes.js +6 -4
- package/dist/commands/recipes/impl/project-recipe-state.d.ts +1 -1
- package/dist/commands/recipes/impl/project-recipe-state.d.ts.map +1 -1
- package/dist/commands/recipes/impl/project-registry.d.ts +5 -1
- package/dist/commands/recipes/impl/project-registry.d.ts.map +1 -1
- package/dist/commands/recipes/impl/project-registry.js +34 -14
- package/dist/commands/recipes/impl/resolver.d.ts +1 -1
- package/dist/commands/recipes/impl/resolver.d.ts.map +1 -1
- package/dist/commands/recipes/impl/resolver.js +1 -1
- package/dist/commands/recipes/impl/types.d.ts +1 -1
- package/dist/commands/recipes/impl/types.d.ts.map +1 -1
- package/dist/commands/recipes/impl/version.d.ts +5 -0
- package/dist/commands/recipes/impl/version.d.ts.map +1 -0
- package/dist/commands/recipes/impl/version.js +9 -0
- package/dist/commands/recipes.d.ts +5 -4
- package/dist/commands/recipes.d.ts.map +1 -1
- package/dist/commands/recipes.js +3 -3
- package/dist/commands/release/apply.command.d.ts +1 -1
- package/dist/commands/release/apply.command.d.ts.map +1 -1
- package/dist/commands/release/apply.command.js +15 -379
- package/dist/commands/release/apply.mutation.d.ts +1 -0
- package/dist/commands/release/apply.mutation.d.ts.map +1 -1
- package/dist/commands/release/apply.mutation.js +24 -1
- package/dist/commands/release/apply.pipeline.d.ts +22 -0
- package/dist/commands/release/apply.pipeline.d.ts.map +1 -0
- package/dist/commands/release/apply.pipeline.js +371 -0
- package/dist/commands/release/apply.preflight.d.ts +2 -0
- package/dist/commands/release/apply.preflight.d.ts.map +1 -1
- package/dist/commands/release/apply.preflight.js +13 -4
- package/dist/commands/release/apply.types.d.ts +27 -0
- package/dist/commands/release/apply.types.d.ts.map +1 -1
- package/dist/commands/release.test-helpers.d.ts +4 -0
- package/dist/commands/release.test-helpers.d.ts.map +1 -1
- package/dist/commands/release.test-helpers.js +7 -0
- package/dist/commands/shared/reconcile-check.d.ts.map +1 -1
- package/dist/commands/shared/reconcile-check.js +2 -2
- package/dist/commands/shared/task-backend.d.ts +6 -1
- package/dist/commands/shared/task-backend.d.ts.map +1 -1
- package/dist/commands/shared/task-backend.js +34 -2
- package/dist/commands/shared/task-mutation.d.ts.map +1 -1
- package/dist/commands/shared/task-mutation.js +4 -4
- package/dist/commands/shared/task-store/intents.d.ts +34 -0
- package/dist/commands/shared/task-store/intents.d.ts.map +1 -0
- package/dist/commands/shared/task-store/intents.js +265 -0
- package/dist/commands/shared/task-store/readme.d.ts +28 -0
- package/dist/commands/shared/task-store/readme.d.ts.map +1 -0
- package/dist/commands/shared/task-store/readme.js +125 -0
- package/dist/commands/shared/task-store/store.d.ts +26 -0
- package/dist/commands/shared/task-store/store.d.ts.map +1 -0
- package/dist/commands/shared/task-store/store.js +105 -0
- package/dist/commands/shared/task-store/types.d.ts +94 -0
- package/dist/commands/shared/task-store/types.d.ts.map +1 -0
- package/dist/commands/shared/task-store/types.js +1 -0
- package/dist/commands/shared/task-store.d.ts +3 -109
- package/dist/commands/shared/task-store.d.ts.map +1 -1
- package/dist/commands/shared/task-store.js +2 -493
- package/dist/commands/task/block.d.ts.map +1 -1
- package/dist/commands/task/block.js +7 -2
- package/dist/commands/task/comment.d.ts.map +1 -1
- package/dist/commands/task/comment.js +7 -2
- package/dist/commands/task/finish-shared.d.ts.map +1 -1
- package/dist/commands/task/finish-shared.js +3 -3
- package/dist/commands/task/finish.d.ts.map +1 -1
- package/dist/commands/task/finish.js +102 -15
- package/dist/commands/task/hosted-merge-sync.d.ts.map +1 -1
- package/dist/commands/task/hosted-merge-sync.js +9 -4
- package/dist/commands/task/list.run.d.ts.map +1 -1
- package/dist/commands/task/list.run.js +14 -4
- package/dist/commands/task/new.command.d.ts.map +1 -1
- package/dist/commands/task/new.command.js +16 -2
- package/dist/commands/task/new.js +2 -2
- package/dist/commands/task/show.d.ts.map +1 -1
- package/dist/commands/task/show.js +3 -3
- package/dist/commands/task/update.d.ts.map +1 -1
- package/dist/commands/task/update.js +11 -3
- package/dist/runner/adapters/codex.d.ts.map +1 -1
- package/dist/runner/adapters/codex.js +3 -33
- package/dist/runner/adapters/custom.d.ts.map +1 -1
- package/dist/runner/adapters/custom.js +3 -30
- package/dist/runner/adapters/runtime-shared.d.ts +14 -0
- package/dist/runner/adapters/runtime-shared.d.ts.map +1 -0
- package/dist/runner/adapters/runtime-shared.js +36 -0
- package/dist/runner/context/base-prompt-sources.d.ts +30 -0
- package/dist/runner/context/base-prompt-sources.d.ts.map +1 -0
- package/dist/runner/context/base-prompt-sources.js +144 -0
- package/dist/runner/context/base-prompts.d.ts +3 -22
- package/dist/runner/context/base-prompts.d.ts.map +1 -1
- package/dist/runner/context/base-prompts.js +6 -450
- package/dist/runner/context/overlay-prompt-blocks.d.ts +7 -0
- package/dist/runner/context/overlay-prompt-blocks.d.ts.map +1 -0
- package/dist/runner/context/overlay-prompt-blocks.js +72 -0
- package/dist/runner/context/prompt-block-shared.d.ts +54 -0
- package/dist/runner/context/prompt-block-shared.d.ts.map +1 -0
- package/dist/runner/context/prompt-block-shared.js +106 -0
- package/dist/runner/context/recipe-context.d.ts +2 -1
- package/dist/runner/context/recipe-context.d.ts.map +1 -1
- package/dist/runner/context/recipe-context.js +2 -1
- package/dist/runner/context/recipe-prompt-blocks.d.ts +6 -0
- package/dist/runner/context/recipe-prompt-blocks.d.ts.map +1 -0
- package/dist/runner/context/recipe-prompt-blocks.js +143 -0
- package/dist/runner/usecases/scenario-materialize-task.js +2 -2
- package/dist/runner/usecases/task-run-inspect.js +2 -2
- package/dist/runner/usecases/task-run-lifecycle-shared.js +2 -2
- package/dist/runner/usecases/task-run.d.ts.map +1 -1
- package/dist/runner/usecases/task-run.js +4 -2
- package/dist/runtime/capabilities/recipe.d.ts +1 -1
- package/dist/runtime/capabilities/recipe.d.ts.map +1 -1
- package/dist/runtime/execution-context.d.ts +63 -0
- package/dist/runtime/execution-context.d.ts.map +1 -0
- package/dist/{usecases/context/resolve-context.js → runtime/execution-context.js} +23 -26
- package/dist/runtime/incidents/advice-strategy.d.ts +15 -0
- package/dist/runtime/incidents/advice-strategy.d.ts.map +1 -0
- package/dist/runtime/incidents/advice-strategy.js +54 -0
- package/dist/runtime/incidents/plan-strategy.d.ts +9 -0
- package/dist/runtime/incidents/plan-strategy.d.ts.map +1 -0
- package/dist/runtime/incidents/plan-strategy.js +205 -0
- package/dist/runtime/incidents/registry-strategy.d.ts +6 -0
- package/dist/runtime/incidents/registry-strategy.d.ts.map +1 -0
- package/dist/runtime/incidents/registry-strategy.js +280 -0
- package/dist/runtime/incidents/resolve.d.ts +3 -25
- package/dist/runtime/incidents/resolve.d.ts.map +1 -1
- package/dist/runtime/incidents/resolve.js +3 -683
- package/dist/runtime/incidents/shared.d.ts +34 -0
- package/dist/runtime/incidents/shared.d.ts.map +1 -0
- package/dist/runtime/incidents/shared.js +171 -0
- package/dist/testing/cli-harness/recipe-archives.d.ts +28 -0
- package/dist/testing/cli-harness/recipe-archives.d.ts.map +1 -0
- package/dist/testing/cli-harness/recipe-archives.js +374 -0
- package/dist/testing/cli-harness/stdio.d.ts +26 -0
- package/dist/testing/cli-harness/stdio.d.ts.map +1 -0
- package/dist/testing/cli-harness/stdio.js +84 -0
- package/dist/testing/cli-harness.d.ts +25 -0
- package/dist/testing/cli-harness.d.ts.map +1 -0
- package/dist/testing/cli-harness.js +313 -0
- package/dist/testing/index.d.ts +2 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +1 -0
- package/package.json +7 -4
- package/dist/commands/recipes/impl/manifest.d.ts +0 -4
- package/dist/commands/recipes/impl/manifest.d.ts.map +0 -1
- package/dist/commands/recipes/impl/manifest.js +0 -7
- package/dist/commands/recipes/impl/normalize.d.ts +0 -8
- package/dist/commands/recipes/impl/normalize.d.ts.map +0 -1
- package/dist/commands/recipes/impl/normalize.js +0 -54
- package/dist/commands/recipes/impl/scenario.d.ts +0 -16
- package/dist/commands/recipes/impl/scenario.d.ts.map +0 -1
- package/dist/commands/recipes/impl/scenario.js +0 -262
- package/dist/recipes/bundled-recipes.d.ts +0 -17
- package/dist/recipes/bundled-recipes.d.ts.map +0 -1
- package/dist/recipes/bundled-recipes.js +0 -15
- package/dist/usecases/context/resolve-context.d.ts +0 -68
- package/dist/usecases/context/resolve-context.d.ts.map +0 -1
- package/dist/usecases/task/task-list-usecase.d.ts +0 -9
- package/dist/usecases/task/task-list-usecase.d.ts.map +0 -1
- package/dist/usecases/task/task-list-usecase.js +0 -17
- package/dist/usecases/task/task-new-usecase.d.ts +0 -9
- package/dist/usecases/task/task-new-usecase.d.ts.map +0 -1
- package/dist/usecases/task/task-new-usecase.js +0 -17
|
@@ -1,337 +1,78 @@
|
|
|
1
|
-
import { mkdir, readFile
|
|
1
|
+
import { mkdir, readFile } from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import {
|
|
3
|
+
import { resolveBaseBranch } from "@agentplaneorg/core";
|
|
4
4
|
import { mapBackendError } from "../../../cli/error-map.js";
|
|
5
5
|
import { exitCodeForError } from "../../../cli/exit-codes.js";
|
|
6
6
|
import { fileExists } from "../../../cli/fs-utils.js";
|
|
7
7
|
import { workflowModeMessage } from "../../../cli/output.js";
|
|
8
8
|
import { CliError } from "../../../shared/errors.js";
|
|
9
|
-
import { writeJsonStableIfChanged, writeTextIfChanged } from "../../../shared/write-if-changed.js";
|
|
10
|
-
import { execFileAsync, gitEnv } from "../../shared/git.js";
|
|
11
|
-
import { gitDiffStat } from "../../shared/git-diff.js";
|
|
12
|
-
import { gitBranchUpstream, gitCurrentBranch } from "../../shared/git-ops.js";
|
|
13
|
-
import { parseTaskIdFromBranch } from "../../shared/git-worktree.js";
|
|
14
|
-
import { isTransientGhTransportError, normalizeGhTransportError, withGhTransportRetry, } from "../../shared/gh-transport.js";
|
|
15
9
|
import { INCIDENTS_POLICY_PATH } from "../../incidents/shared.js";
|
|
16
|
-
import {
|
|
10
|
+
import { resolvePrArtifactHeadSha, parsePrMeta } from "../../shared/pr-meta.js";
|
|
17
11
|
import { isTaskLocalOnlyAdvance } from "../../shared/task-local-freshness.js";
|
|
18
12
|
import { loadBackendTask, loadCommandContext, } from "../../shared/task-backend.js";
|
|
19
13
|
import { resolvePrPaths } from "./pr-paths.js";
|
|
20
14
|
import { readPrHandoffNotes } from "./note-store.js";
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (code === "ENOENT")
|
|
33
|
-
return null;
|
|
34
|
-
throw err;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
async function restoreIncidentRegistryIfNeeded(opts) {
|
|
38
|
-
const incidentsPath = path.join(opts.gitRoot, INCIDENTS_POLICY_PATH);
|
|
39
|
-
const nextText = await readTextIfExists(incidentsPath);
|
|
40
|
-
if (nextText === opts.previousText)
|
|
41
|
-
return;
|
|
42
|
-
if (opts.previousText === null) {
|
|
43
|
-
await rm(incidentsPath, { force: true });
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
await writeTextIfChanged(incidentsPath, opts.previousText);
|
|
47
|
-
}
|
|
48
|
-
function isUnknownRevisionError(err) {
|
|
49
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
50
|
-
return (/unknown revision or path not in the working tree/i.test(message) ||
|
|
51
|
-
/bad revision/i.test(message) ||
|
|
52
|
-
/ambiguous argument/i.test(message));
|
|
53
|
-
}
|
|
54
|
-
function parseGithubRepoFromRemoteUrl(remoteUrl) {
|
|
55
|
-
const trimmed = remoteUrl.trim();
|
|
56
|
-
if (!trimmed)
|
|
57
|
-
return null;
|
|
58
|
-
const httpsMatch = /^https?:\/\/github\.com\/([^/]+)\/([^/]+?)(?:\.git)?\/?$/.exec(trimmed);
|
|
59
|
-
if (httpsMatch)
|
|
60
|
-
return `${httpsMatch[1]}/${httpsMatch[2]}`;
|
|
61
|
-
const sshMatch = /^git@github\.com:([^/]+)\/([^/]+?)(?:\.git)?$/.exec(trimmed);
|
|
62
|
-
if (sshMatch)
|
|
63
|
-
return `${sshMatch[1]}/${sshMatch[2]}`;
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
async function resolveGithubRepoFromOrigin(gitRoot) {
|
|
67
|
-
try {
|
|
68
|
-
const { stdout } = await execFileAsync("git", ["remote", "get-url", "origin"], {
|
|
69
|
-
cwd: gitRoot,
|
|
70
|
-
env: gitEnv(),
|
|
71
|
-
});
|
|
72
|
-
return parseGithubRepoFromRemoteUrl(stdout);
|
|
73
|
-
}
|
|
74
|
-
catch {
|
|
75
|
-
return null;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
function normalizeObservedGithubPr(record) {
|
|
79
|
-
const number = Number(record.number);
|
|
80
|
-
if (!Number.isInteger(number) || number <= 0)
|
|
81
|
-
return null;
|
|
82
|
-
const state = record.state?.trim().toLowerCase() ?? "";
|
|
83
|
-
const mergedAt = record.merged_at?.trim() ?? null;
|
|
84
|
-
const status = mergedAt && mergedAt.length > 0
|
|
85
|
-
? "MERGED"
|
|
86
|
-
: state === "open"
|
|
87
|
-
? "OPEN"
|
|
88
|
-
: state === "closed"
|
|
89
|
-
? "CLOSED"
|
|
90
|
-
: null;
|
|
91
|
-
if (!status)
|
|
92
|
-
return null;
|
|
93
|
-
const prUrl = record.html_url?.trim() ?? null;
|
|
94
|
-
const mergeCommit = record.merge_commit_sha?.trim() ?? null;
|
|
95
|
-
const base = record.base?.ref?.trim() ?? null;
|
|
96
|
-
const headSha = record.head?.sha?.trim() ?? null;
|
|
97
|
-
return {
|
|
98
|
-
prNumber: number,
|
|
99
|
-
prUrl,
|
|
100
|
-
status,
|
|
101
|
-
mergedAt,
|
|
102
|
-
mergeCommit,
|
|
103
|
-
base,
|
|
104
|
-
headSha,
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
async function tryLookupExistingGithubPrByBranch(opts) {
|
|
108
|
-
const repo = await resolveGithubRepoFromOrigin(opts.gitRoot);
|
|
109
|
-
if (!repo)
|
|
110
|
-
return null;
|
|
111
|
-
const owner = repo.split("/")[0]?.trim() ?? "";
|
|
112
|
-
if (!owner)
|
|
113
|
-
return null;
|
|
114
|
-
const query = new URLSearchParams({ state: "all", head: `${owner}:${opts.branch}` });
|
|
115
|
-
const baseBranch = opts.baseBranch?.trim() ?? "";
|
|
116
|
-
if (baseBranch)
|
|
117
|
-
query.set("base", baseBranch);
|
|
118
|
-
const endpoint = `repos/${repo}/pulls?${query.toString()}`;
|
|
119
|
-
try {
|
|
120
|
-
const { stdout } = await withGhTransportRetry(() => execFileAsync("gh", ["api", endpoint], {
|
|
121
|
-
cwd: opts.gitRoot,
|
|
122
|
-
env: ghEnv(),
|
|
123
|
-
maxBuffer: 10 * 1024 * 1024,
|
|
124
|
-
}), { label: `running gh api ${endpoint}` });
|
|
125
|
-
const parsed = JSON.parse(stdout);
|
|
126
|
-
if (!Array.isArray(parsed) || parsed.length === 0)
|
|
127
|
-
return null;
|
|
128
|
-
for (const record of parsed) {
|
|
129
|
-
const observed = normalizeObservedGithubPr(record);
|
|
130
|
-
if (observed)
|
|
131
|
-
return observed;
|
|
132
|
-
}
|
|
133
|
-
return null;
|
|
134
|
-
}
|
|
135
|
-
catch (err) {
|
|
136
|
-
const code = err?.code;
|
|
137
|
-
if (code === "ENOENT")
|
|
138
|
-
return null;
|
|
139
|
-
const message = normalizeGhTransportError(err);
|
|
140
|
-
if (message.trim().length > 0)
|
|
141
|
-
return null;
|
|
142
|
-
return null;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
function formatGithubPrLink(prNumber, prUrl, verb) {
|
|
146
|
-
return prUrl?.trim()
|
|
147
|
-
? `${verb} GitHub PR #${prNumber}: ${prUrl.trim()}`
|
|
148
|
-
: `${verb} GitHub PR #${prNumber}`;
|
|
149
|
-
}
|
|
150
|
-
function shouldPersistObservedGithubPrMeta(observed) {
|
|
151
|
-
if (!observed)
|
|
152
|
-
return false;
|
|
153
|
-
return observed.status === "MERGED";
|
|
154
|
-
}
|
|
155
|
-
function taskPrArtifactRefreshMessage(taskId) {
|
|
156
|
-
return `📝 ${extractTaskSuffix(taskId)} task: refresh PR artifacts`;
|
|
157
|
-
}
|
|
158
|
-
async function resolveRenderableBranchHead(opts) {
|
|
159
|
-
const branchHeadSha = await resolveBranchHeadSha({
|
|
160
|
-
gitRoot: opts.gitRoot,
|
|
15
|
+
import { currentBranchMatchesTask, resolvePrSyncBranch, resolveRenderableBranchHead, } from "./sync-branch.js";
|
|
16
|
+
import { runPrOpenSync } from "./sync-open-step.js";
|
|
17
|
+
import { nowIso, readTextIfExists, restoreIncidentRegistryIfNeeded } from "./sync-support.js";
|
|
18
|
+
import { runPrUpdateSync } from "./sync-update-step.js";
|
|
19
|
+
async function buildPrSyncCommonState(opts) {
|
|
20
|
+
const handoffNotes = await readPrHandoffNotes(opts.notesPath);
|
|
21
|
+
const now = nowIso();
|
|
22
|
+
const createdAt = opts.existingMeta?.created_at ?? now;
|
|
23
|
+
const { headSha, artifactRefresh } = await resolveRenderableBranchHead({
|
|
24
|
+
gitRoot: opts.resolved.gitRoot,
|
|
25
|
+
taskId: opts.task.id,
|
|
161
26
|
branch: opts.branch,
|
|
162
27
|
});
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
function formatUnpublishedRemoteHeadReason(branch) {
|
|
181
|
-
return (`task branch ${branch} is not yet published on origin; push it with ` +
|
|
182
|
-
`\`git push -u origin ${branch}\` and rerun \`agentplane pr open\``);
|
|
183
|
-
}
|
|
184
|
-
function isMissingRemoteHeadCreateError(err) {
|
|
185
|
-
const text = normalizeGhTransportError(err);
|
|
186
|
-
if (!/\b422\b/i.test(text))
|
|
187
|
-
return false;
|
|
188
|
-
return (/head sha/i.test(text) ||
|
|
189
|
-
/head ref/i.test(text) ||
|
|
190
|
-
/head.*must be a branch/i.test(text) ||
|
|
191
|
-
/head.*not found/i.test(text) ||
|
|
192
|
-
/field["']?\s*:\s*["']head["']/i.test(text) ||
|
|
193
|
-
/field\s+head\b/i.test(text) ||
|
|
194
|
-
/no commits between/i.test(text));
|
|
195
|
-
}
|
|
196
|
-
function summarizeGithubPrCreateFailure(err) {
|
|
197
|
-
const text = normalizeGhTransportError(err);
|
|
198
|
-
if (err?.code === "ENOENT") {
|
|
199
|
-
return "gh CLI is unavailable";
|
|
200
|
-
}
|
|
201
|
-
if (/authentication required/i.test(text) ||
|
|
202
|
-
/not logged into github/i.test(text) ||
|
|
203
|
-
/bad credentials/i.test(text) ||
|
|
204
|
-
/permission denied/i.test(text) ||
|
|
205
|
-
/\b401\b/i.test(text) ||
|
|
206
|
-
/\b403\b/i.test(text)) {
|
|
207
|
-
return "GitHub auth or permissions unavailable";
|
|
208
|
-
}
|
|
209
|
-
if (isTransientGhTransportError(err)) {
|
|
210
|
-
return "GitHub transport failed; retry `agentplane pr open`";
|
|
211
|
-
}
|
|
212
|
-
return "GitHub PR creation failed";
|
|
213
|
-
}
|
|
214
|
-
async function tryCreateGithubPr(opts) {
|
|
215
|
-
const repo = await resolveGithubRepoFromOrigin(opts.gitRoot);
|
|
216
|
-
if (!repo) {
|
|
217
|
-
return {
|
|
218
|
-
observed: null,
|
|
219
|
-
stagedReason: "GitHub origin repo unavailable",
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
const baseBranch = opts.baseBranch?.trim() ?? "";
|
|
223
|
-
if (!baseBranch) {
|
|
224
|
-
return {
|
|
225
|
-
observed: null,
|
|
226
|
-
stagedReason: "base branch unresolved",
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
try {
|
|
230
|
-
const { stdout } = await withGhTransportRetry(() => execFileAsync("gh", [
|
|
231
|
-
"api",
|
|
232
|
-
`repos/${repo}/pulls`,
|
|
233
|
-
"-X",
|
|
234
|
-
"POST",
|
|
235
|
-
"-f",
|
|
236
|
-
`title=${opts.title}`,
|
|
237
|
-
"-f",
|
|
238
|
-
`body=${opts.body}`,
|
|
239
|
-
"-f",
|
|
240
|
-
`head=${opts.branch}`,
|
|
241
|
-
"-f",
|
|
242
|
-
`base=${baseBranch}`,
|
|
243
|
-
], {
|
|
244
|
-
cwd: opts.gitRoot,
|
|
245
|
-
env: ghEnv(),
|
|
246
|
-
maxBuffer: 10 * 1024 * 1024,
|
|
247
|
-
}), { label: `running gh api repos/${repo}/pulls` });
|
|
248
|
-
return {
|
|
249
|
-
observed: normalizeObservedGithubPr(JSON.parse(stdout)),
|
|
250
|
-
stagedReason: null,
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
catch (err) {
|
|
254
|
-
if (isMissingRemoteHeadCreateError(err)) {
|
|
255
|
-
return {
|
|
256
|
-
observed: null,
|
|
257
|
-
stagedReason: formatUnpublishedRemoteHeadReason(opts.branch),
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
return {
|
|
261
|
-
observed: null,
|
|
262
|
-
stagedReason: summarizeGithubPrCreateFailure(err),
|
|
263
|
-
};
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
async function resolveBranchHeadSha(opts) {
|
|
267
|
-
try {
|
|
268
|
-
const { stdout } = await execFileAsync("git", ["rev-parse", opts.branch], {
|
|
269
|
-
cwd: opts.gitRoot,
|
|
270
|
-
env: gitEnv(),
|
|
28
|
+
const preservePreviousHead = Boolean(opts.existingMeta?.head_sha) &&
|
|
29
|
+
Boolean(headSha) &&
|
|
30
|
+
(await isTaskLocalOnlyAdvance({
|
|
31
|
+
gitRoot: opts.resolved.gitRoot,
|
|
32
|
+
workflowDir: opts.workflowDir,
|
|
33
|
+
tasksPath: opts.tasksPath,
|
|
34
|
+
taskId: opts.task.id,
|
|
35
|
+
fromRef: opts.existingMeta?.head_sha ?? null,
|
|
36
|
+
toRef: headSha,
|
|
37
|
+
}));
|
|
38
|
+
const renderedHeadSha = artifactRefresh
|
|
39
|
+
? (opts.existingMeta?.head_sha ?? undefined)
|
|
40
|
+
: resolvePrArtifactHeadSha({
|
|
41
|
+
previousHeadSha: opts.existingMeta?.head_sha ?? null,
|
|
42
|
+
currentHeadSha: headSha,
|
|
43
|
+
preservePrevious: preservePreviousHead,
|
|
271
44
|
});
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
45
|
+
const preservedRenderUpdatedAt = opts.existingMeta &&
|
|
46
|
+
(opts.existingMeta.branch ?? null) === opts.branch &&
|
|
47
|
+
(opts.existingMeta.base ?? null) === (opts.baseBranch ?? null) &&
|
|
48
|
+
(opts.existingMeta.head_sha ?? null) === (renderedHeadSha ?? null)
|
|
49
|
+
? opts.existingMeta.updated_at
|
|
50
|
+
: null;
|
|
51
|
+
const renderUpdatedAt = preservedRenderUpdatedAt ?? now;
|
|
52
|
+
return {
|
|
53
|
+
task: opts.task,
|
|
54
|
+
resolved: opts.resolved,
|
|
55
|
+
workflowDir: opts.workflowDir,
|
|
56
|
+
tasksPath: opts.tasksPath,
|
|
57
|
+
prDir: opts.prDir,
|
|
58
|
+
metaPath: opts.metaPath,
|
|
59
|
+
diffstatPath: opts.diffstatPath,
|
|
60
|
+
notesPath: opts.notesPath,
|
|
61
|
+
verifyLogPath: opts.verifyLogPath,
|
|
62
|
+
reviewPath: opts.reviewPath,
|
|
63
|
+
githubTitlePath: opts.githubTitlePath,
|
|
64
|
+
githubBodyPath: opts.githubBodyPath,
|
|
65
|
+
existingMeta: opts.existingMeta,
|
|
66
|
+
handoffNotes,
|
|
67
|
+
now,
|
|
68
|
+
createdAt,
|
|
69
|
+
branch: opts.branch,
|
|
283
70
|
baseBranch: opts.baseBranch,
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
path.relative(opts.gitRoot, opts.prDir),
|
|
290
|
-
path.relative(opts.gitRoot, path.join(taskDir, "README.md")),
|
|
291
|
-
],
|
|
292
|
-
});
|
|
293
|
-
}
|
|
294
|
-
catch (err) {
|
|
295
|
-
if (!isUnknownRevisionError(err))
|
|
296
|
-
throw err;
|
|
297
|
-
return "";
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
async function resolvePrDiffBaseRef(opts) {
|
|
301
|
-
const upstreamRef = await gitBranchUpstream(opts.gitRoot, opts.baseBranch);
|
|
302
|
-
const candidate = upstreamRef?.trim() ?? "";
|
|
303
|
-
if (!candidate)
|
|
304
|
-
return opts.baseBranch;
|
|
305
|
-
try {
|
|
306
|
-
const { stdout } = await execFileAsync("git", ["rev-parse", "--verify", candidate], {
|
|
307
|
-
cwd: opts.gitRoot,
|
|
308
|
-
env: gitEnv(),
|
|
309
|
-
});
|
|
310
|
-
return stdout.trim() ? candidate : opts.baseBranch;
|
|
311
|
-
}
|
|
312
|
-
catch (err) {
|
|
313
|
-
if (!isUnknownRevisionError(err))
|
|
314
|
-
throw err;
|
|
315
|
-
return opts.baseBranch;
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
async function resolvePrSyncBranch(opts) {
|
|
319
|
-
const explicitBranch = opts.branch?.trim() ?? "";
|
|
320
|
-
if (explicitBranch) {
|
|
321
|
-
return { branch: explicitBranch, source: "explicit" };
|
|
322
|
-
}
|
|
323
|
-
if (await fileExists(opts.metaPath)) {
|
|
324
|
-
const metaBranch = parsePrMeta(await readFile(opts.metaPath, "utf8"), opts.taskId).branch?.trim() ?? "";
|
|
325
|
-
if (metaBranch) {
|
|
326
|
-
return { branch: metaBranch, source: "meta" };
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
const currentBranchValue = await gitCurrentBranch(opts.resolved.gitRoot);
|
|
330
|
-
const currentBranch = currentBranchValue.trim();
|
|
331
|
-
if (currentBranch) {
|
|
332
|
-
return { branch: currentBranch, source: "current" };
|
|
333
|
-
}
|
|
334
|
-
return { branch: null, source: "none" };
|
|
71
|
+
headSha,
|
|
72
|
+
artifactRefresh,
|
|
73
|
+
renderedHeadSha,
|
|
74
|
+
renderUpdatedAt,
|
|
75
|
+
};
|
|
335
76
|
}
|
|
336
77
|
export async function ensurePrArtifactsSynced(opts) {
|
|
337
78
|
const ctx = opts.ctx ??
|
|
@@ -340,7 +81,7 @@ export async function ensurePrArtifactsSynced(opts) {
|
|
|
340
81
|
if (config.workflow_mode !== "branch_pr")
|
|
341
82
|
return null;
|
|
342
83
|
const resolvedBranch = await resolvePrSyncBranch({
|
|
343
|
-
resolved,
|
|
84
|
+
gitRoot: resolved.gitRoot,
|
|
344
85
|
metaPath,
|
|
345
86
|
taskId: opts.taskId,
|
|
346
87
|
branch: opts.branch,
|
|
@@ -349,7 +90,7 @@ export async function ensurePrArtifactsSynced(opts) {
|
|
|
349
90
|
if (!branch)
|
|
350
91
|
return null;
|
|
351
92
|
if (resolvedBranch.source === "current" &&
|
|
352
|
-
|
|
93
|
+
!currentBranchMatchesTask(config.branch.task_prefix, branch, opts.taskId)) {
|
|
353
94
|
return null;
|
|
354
95
|
}
|
|
355
96
|
const baseBranch = await resolveBaseBranch({
|
|
@@ -402,7 +143,7 @@ export async function syncPrArtifacts(opts) {
|
|
|
402
143
|
});
|
|
403
144
|
}
|
|
404
145
|
const resolvedBranch = await resolvePrSyncBranch({
|
|
405
|
-
resolved,
|
|
146
|
+
gitRoot: resolved.gitRoot,
|
|
406
147
|
metaPath,
|
|
407
148
|
taskId: task.id,
|
|
408
149
|
branch: opts.branch,
|
|
@@ -433,226 +174,39 @@ export async function syncPrArtifacts(opts) {
|
|
|
433
174
|
const existingMeta = metaExists && (await fileExists(metaPath))
|
|
434
175
|
? parsePrMeta(await readFile(metaPath, "utf8"), task.id)
|
|
435
176
|
: null;
|
|
436
|
-
const handoffNotes = await readPrHandoffNotes(notesPath);
|
|
437
|
-
const now = nowIso();
|
|
438
|
-
const createdAt = existingMeta?.created_at ?? now;
|
|
439
177
|
const baseBranch = await resolveBaseBranch({
|
|
440
178
|
cwd: opts.cwd,
|
|
441
179
|
rootOverride: opts.rootOverride ?? null,
|
|
442
180
|
cliBaseOpt: null,
|
|
443
181
|
mode: config.workflow_mode,
|
|
444
182
|
});
|
|
445
|
-
const
|
|
446
|
-
|
|
447
|
-
|
|
183
|
+
const common = await buildPrSyncCommonState({
|
|
184
|
+
task,
|
|
185
|
+
resolved,
|
|
186
|
+
workflowDir: config.paths.workflow_dir,
|
|
187
|
+
tasksPath: config.paths.tasks_path,
|
|
188
|
+
prDir,
|
|
189
|
+
metaPath,
|
|
190
|
+
diffstatPath,
|
|
191
|
+
notesPath,
|
|
192
|
+
verifyLogPath,
|
|
193
|
+
reviewPath,
|
|
194
|
+
githubTitlePath,
|
|
195
|
+
githubBodyPath,
|
|
196
|
+
existingMeta,
|
|
448
197
|
branch,
|
|
198
|
+
baseBranch,
|
|
449
199
|
});
|
|
450
|
-
const preservePreviousHead = Boolean(existingMeta?.head_sha) &&
|
|
451
|
-
Boolean(headSha) &&
|
|
452
|
-
(await isTaskLocalOnlyAdvance({
|
|
453
|
-
gitRoot: resolved.gitRoot,
|
|
454
|
-
workflowDir: config.paths.workflow_dir,
|
|
455
|
-
tasksPath: config.paths.tasks_path,
|
|
456
|
-
taskId: task.id,
|
|
457
|
-
fromRef: existingMeta?.head_sha ?? null,
|
|
458
|
-
toRef: headSha,
|
|
459
|
-
}));
|
|
460
|
-
const renderedHeadSha = artifactRefresh
|
|
461
|
-
? (existingMeta?.head_sha ?? undefined)
|
|
462
|
-
: resolvePrArtifactHeadSha({
|
|
463
|
-
previousHeadSha: existingMeta?.head_sha ?? null,
|
|
464
|
-
currentHeadSha: headSha,
|
|
465
|
-
preservePrevious: preservePreviousHead,
|
|
466
|
-
});
|
|
467
|
-
const preservedRenderUpdatedAt = existingMeta &&
|
|
468
|
-
(existingMeta.branch ?? null) === branch &&
|
|
469
|
-
(existingMeta.base ?? null) === (baseBranch ?? null) &&
|
|
470
|
-
(existingMeta.head_sha ?? null) === (renderedHeadSha ?? null)
|
|
471
|
-
? existingMeta.updated_at
|
|
472
|
-
: null;
|
|
473
|
-
const renderUpdatedAt = preservedRenderUpdatedAt ?? now;
|
|
474
200
|
if (opts.mode === "open") {
|
|
475
201
|
const remoteMode = opts.remoteMode ?? "auto";
|
|
476
|
-
const
|
|
477
|
-
? await computePrDiffstat({
|
|
478
|
-
gitRoot: resolved.gitRoot,
|
|
479
|
-
baseBranch,
|
|
480
|
-
branch,
|
|
481
|
-
prDir,
|
|
482
|
-
})
|
|
483
|
-
: "";
|
|
484
|
-
const renderedSummaryHeadSha = artifactRefresh
|
|
485
|
-
? renderedHeadSha
|
|
486
|
-
: (renderedHeadSha ?? headSha);
|
|
487
|
-
let nextMeta = buildOpenedPrMeta({
|
|
488
|
-
taskId: task.id,
|
|
489
|
-
branch,
|
|
490
|
-
at: now,
|
|
491
|
-
previousMeta: existingMeta,
|
|
492
|
-
base: baseBranch,
|
|
493
|
-
headSha: renderedHeadSha,
|
|
494
|
-
});
|
|
495
|
-
const linkedExistingOutcome = typeof nextMeta.pr_number === "number" && nextMeta.pr_number > 0
|
|
496
|
-
? {
|
|
497
|
-
action: "linked-existing",
|
|
498
|
-
message: formatGithubPrLink(nextMeta.pr_number, nextMeta.pr_url ?? null, "linked to"),
|
|
499
|
-
}
|
|
500
|
-
: null;
|
|
501
|
-
let openOutcome;
|
|
502
|
-
const githubTitle = buildGithubPrTitle(task);
|
|
503
|
-
const githubBody = renderGithubPrBody({
|
|
504
|
-
task,
|
|
505
|
-
handoffNotes,
|
|
506
|
-
autoSummary: renderPrAutoSummary({
|
|
507
|
-
updatedAt: renderUpdatedAt,
|
|
508
|
-
branch,
|
|
509
|
-
headSha: renderedSummaryHeadSha ?? null,
|
|
510
|
-
diffstat,
|
|
511
|
-
}),
|
|
512
|
-
});
|
|
513
|
-
const observedGithubPr = await tryLookupExistingGithubPrByBranch({
|
|
514
|
-
gitRoot: resolved.gitRoot,
|
|
515
|
-
branch,
|
|
516
|
-
baseBranch,
|
|
517
|
-
});
|
|
518
|
-
if (observedGithubPr) {
|
|
519
|
-
if (shouldPersistObservedGithubPrMeta(observedGithubPr)) {
|
|
520
|
-
nextMeta = buildObservedGithubPrMeta({
|
|
521
|
-
meta: nextMeta,
|
|
522
|
-
observed: observedGithubPr,
|
|
523
|
-
at: now,
|
|
524
|
-
});
|
|
525
|
-
}
|
|
526
|
-
openOutcome = {
|
|
527
|
-
action: "linked-existing",
|
|
528
|
-
message: formatGithubPrLink(observedGithubPr.prNumber, observedGithubPr.prUrl, "linked to"),
|
|
529
|
-
};
|
|
530
|
-
}
|
|
531
|
-
else if (remoteMode === "sync-only") {
|
|
532
|
-
openOutcome = linkedExistingOutcome ?? {
|
|
533
|
-
action: "sync-only",
|
|
534
|
-
message: "local PR artifacts synced; remote PR creation skipped (--sync-only)",
|
|
535
|
-
};
|
|
536
|
-
}
|
|
537
|
-
else {
|
|
538
|
-
const createdGithubPr = await tryCreateGithubPr({
|
|
539
|
-
gitRoot: resolved.gitRoot,
|
|
540
|
-
branch,
|
|
541
|
-
baseBranch,
|
|
542
|
-
title: githubTitle,
|
|
543
|
-
body: githubBody,
|
|
544
|
-
});
|
|
545
|
-
if (createdGithubPr.observed) {
|
|
546
|
-
if (shouldPersistObservedGithubPrMeta(createdGithubPr.observed)) {
|
|
547
|
-
nextMeta = buildObservedGithubPrMeta({
|
|
548
|
-
meta: nextMeta,
|
|
549
|
-
observed: createdGithubPr.observed,
|
|
550
|
-
at: now,
|
|
551
|
-
});
|
|
552
|
-
}
|
|
553
|
-
openOutcome = {
|
|
554
|
-
action: "created",
|
|
555
|
-
message: formatGithubPrLink(createdGithubPr.observed.prNumber, createdGithubPr.observed.prUrl, "created"),
|
|
556
|
-
};
|
|
557
|
-
}
|
|
558
|
-
else {
|
|
559
|
-
openOutcome = linkedExistingOutcome ?? {
|
|
560
|
-
action: "staged",
|
|
561
|
-
message: `local PR artifacts synced; remote PR creation staged (${createdGithubPr.stagedReason ?? "remote creation unavailable"})`,
|
|
562
|
-
};
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
const nextAutoSummary = renderPrAutoSummary({
|
|
566
|
-
updatedAt: renderUpdatedAt,
|
|
567
|
-
branch,
|
|
568
|
-
headSha: renderedSummaryHeadSha ?? null,
|
|
569
|
-
diffstat,
|
|
570
|
-
});
|
|
571
|
-
const nextReview = renderPrReviewDocument({
|
|
572
|
-
task,
|
|
202
|
+
const { meta, openOutcome } = await runPrOpenSync(common, {
|
|
573
203
|
author: opts.author,
|
|
574
|
-
|
|
575
|
-
branch,
|
|
576
|
-
handoffNotes,
|
|
577
|
-
autoSummary: nextAutoSummary,
|
|
578
|
-
});
|
|
579
|
-
const nextGithubBody = renderGithubPrBody({
|
|
580
|
-
task,
|
|
581
|
-
handoffNotes,
|
|
582
|
-
autoSummary: nextAutoSummary,
|
|
583
|
-
});
|
|
584
|
-
await writeJsonStableIfChanged(metaPath, nextMeta);
|
|
585
|
-
await writeTextIfChanged(diffstatPath, diffstat ? `${diffstat}\n` : "");
|
|
586
|
-
if (!(await fileExists(notesPath))) {
|
|
587
|
-
await writeTextIfChanged(notesPath, "");
|
|
588
|
-
}
|
|
589
|
-
if (!(await fileExists(verifyLogPath))) {
|
|
590
|
-
await writeTextIfChanged(verifyLogPath, "");
|
|
591
|
-
}
|
|
592
|
-
await writeTextIfChanged(reviewPath, nextReview);
|
|
593
|
-
await writeTextIfChanged(githubTitlePath, `${githubTitle}\n`);
|
|
594
|
-
await writeTextIfChanged(githubBodyPath, nextGithubBody);
|
|
595
|
-
return { meta: nextMeta, prDir, resolved, openOutcome };
|
|
596
|
-
}
|
|
597
|
-
if (!baseBranch) {
|
|
598
|
-
throw new CliError({
|
|
599
|
-
exitCode: exitCodeForError("E_USAGE"),
|
|
600
|
-
code: "E_USAGE",
|
|
601
|
-
message: "Base branch could not be resolved (use `agentplane branch base set`).",
|
|
204
|
+
remoteMode,
|
|
602
205
|
});
|
|
206
|
+
return { meta, prDir, resolved, openOutcome };
|
|
603
207
|
}
|
|
604
|
-
const
|
|
605
|
-
|
|
606
|
-
baseBranch,
|
|
607
|
-
branch,
|
|
608
|
-
prDir,
|
|
609
|
-
});
|
|
610
|
-
let nextMeta = buildUpdatedPrMeta({
|
|
611
|
-
meta: existingMeta,
|
|
612
|
-
branch,
|
|
613
|
-
at: now,
|
|
614
|
-
base: baseBranch,
|
|
615
|
-
headSha: renderedHeadSha,
|
|
616
|
-
});
|
|
617
|
-
const observedGithubPr = await tryLookupExistingGithubPrByBranch({
|
|
618
|
-
gitRoot: resolved.gitRoot,
|
|
619
|
-
branch,
|
|
620
|
-
baseBranch,
|
|
621
|
-
});
|
|
622
|
-
if (shouldPersistObservedGithubPrMeta(observedGithubPr)) {
|
|
623
|
-
nextMeta = buildObservedGithubPrMeta({
|
|
624
|
-
meta: nextMeta,
|
|
625
|
-
observed: observedGithubPr,
|
|
626
|
-
at: now,
|
|
627
|
-
});
|
|
628
|
-
}
|
|
629
|
-
const nextAutoSummary = renderPrAutoSummary({
|
|
630
|
-
updatedAt: nextMeta.updated_at,
|
|
631
|
-
branch,
|
|
632
|
-
headSha: artifactRefresh
|
|
633
|
-
? (nextMeta.head_sha ?? renderedHeadSha ?? null)
|
|
634
|
-
: (nextMeta.head_sha ?? renderedHeadSha ?? headSha ?? null),
|
|
635
|
-
diffstat,
|
|
636
|
-
});
|
|
637
|
-
const nextReview = renderPrReviewDocument({
|
|
638
|
-
task,
|
|
639
|
-
createdAt,
|
|
640
|
-
branch,
|
|
641
|
-
handoffNotes,
|
|
642
|
-
autoSummary: nextAutoSummary,
|
|
643
|
-
});
|
|
644
|
-
const githubTitle = buildGithubPrTitle(task);
|
|
645
|
-
const githubBody = renderGithubPrBody({
|
|
646
|
-
task,
|
|
647
|
-
handoffNotes,
|
|
648
|
-
autoSummary: nextAutoSummary,
|
|
649
|
-
});
|
|
650
|
-
await writeTextIfChanged(diffstatPath, diffstat ? `${diffstat}\n` : "");
|
|
651
|
-
await writeTextIfChanged(reviewPath, nextReview);
|
|
652
|
-
await writeTextIfChanged(githubTitlePath, `${githubTitle}\n`);
|
|
653
|
-
await writeTextIfChanged(githubBodyPath, githubBody);
|
|
654
|
-
await writeJsonStableIfChanged(metaPath, nextMeta);
|
|
655
|
-
return { meta: nextMeta, prDir, resolved };
|
|
208
|
+
const { meta } = await runPrUpdateSync(common);
|
|
209
|
+
return { meta, prDir, resolved };
|
|
656
210
|
}
|
|
657
211
|
finally {
|
|
658
212
|
await restoreIncidentRegistryIfNeeded({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"open.d.ts","sourceRoot":"","sources":["../../../src/commands/pr/open.ts"],"names":[],"mappings":"AAQA,OAAO,EAAsB,KAAK,cAAc,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"open.d.ts","sourceRoot":"","sources":["../../../src/commands/pr/open.ts"],"names":[],"mappings":"AAQA,OAAO,EAAsB,KAAK,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAuDpF,wBAAsB,SAAS,CAAC,IAAI,EAAE;IACpC,GAAG,CAAC,EAAE,cAAc,CAAC;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,GAAG,OAAO,CAAC,MAAM,CAAC,CAgElB"}
|