dev-loops 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.pi/dev-loop/defaults.yaml +477 -0
- package/AGENTS.md +25 -0
- package/CHANGELOG.md +18 -0
- package/LICENSE +21 -0
- package/README.md +178 -0
- package/agents/dev-loop.agent.md +82 -0
- package/agents/developer.agent.md +37 -0
- package/agents/docs.agent.md +33 -0
- package/agents/fixer.agent.md +53 -0
- package/agents/quality.agent.md +28 -0
- package/agents/refiner.agent.md +87 -0
- package/agents/review.agent.md +64 -0
- package/cli/index.mjs +424 -0
- package/extension/README.md +233 -0
- package/extension/checks.ts +94 -0
- package/extension/index.ts +131 -0
- package/extension/post-merge-update.ts +512 -0
- package/extension/presentation.ts +107 -0
- package/lib/dev-loops-core.mjs +284 -0
- package/package.json +103 -0
- package/scripts/README.md +1007 -0
- package/scripts/_cli-primitives.mjs +10 -0
- package/scripts/_core-helpers.mjs +30 -0
- package/scripts/docs/validate-links.mjs +567 -0
- package/scripts/docs/validate-no-duplicate-rules.mjs +250 -0
- package/scripts/github/_review-thread-mutations.mjs +214 -0
- package/scripts/github/capture-review-threads.mjs +180 -0
- package/scripts/github/create-draft-pr.mjs +108 -0
- package/scripts/github/detect-checkpoint-evidence.mjs +393 -0
- package/scripts/github/detect-linked-issue-pr.mjs +331 -0
- package/scripts/github/manage-sub-issues.mjs +394 -0
- package/scripts/github/probe-copilot-review.mjs +323 -0
- package/scripts/github/ready-for-review.mjs +93 -0
- package/scripts/github/reconcile-draft-gate.mjs +328 -0
- package/scripts/github/reply-resolve-review-thread.mjs +42 -0
- package/scripts/github/reply-resolve-review-threads.mjs +329 -0
- package/scripts/github/request-copilot-review.mjs +551 -0
- package/scripts/github/resolve-tracker-local-spec.mjs +205 -0
- package/scripts/github/stage-reviewer-draft.mjs +191 -0
- package/scripts/github/upsert-checkpoint-verdict.mjs +694 -0
- package/scripts/github/verify-fresh-review-context.mjs +125 -0
- package/scripts/github/write-gate-findings-log.mjs +212 -0
- package/scripts/loop/_checkpoint-io.mjs +55 -0
- package/scripts/loop/_checkpoint-paths.mjs +28 -0
- package/scripts/loop/_handoff-contract.mjs +230 -0
- package/scripts/loop/_inspect-run-viewer-adapter.mjs +345 -0
- package/scripts/loop/_loop-evidence.mjs +32 -0
- package/scripts/loop/_pr-runner-coordination.mjs +611 -0
- package/scripts/loop/_stale-runner-detection.mjs +145 -0
- package/scripts/loop/_steering-state-file.mjs +134 -0
- package/scripts/loop/build-handoff-envelope.mjs +181 -0
- package/scripts/loop/checkpoint-contract.mjs +49 -0
- package/scripts/loop/conductor-monitor.mjs +1850 -0
- package/scripts/loop/conductor.mjs +214 -0
- package/scripts/loop/copilot-pr-handoff.mjs +493 -0
- package/scripts/loop/debt-remediate.mjs +304 -0
- package/scripts/loop/detect-change-scope.mjs +102 -0
- package/scripts/loop/detect-copilot-loop-state.mjs +454 -0
- package/scripts/loop/detect-copilot-session-activity.mjs +186 -0
- package/scripts/loop/detect-initial-copilot-pr-state.mjs +318 -0
- package/scripts/loop/detect-internal-only-pr.mjs +270 -0
- package/scripts/loop/detect-issue-refinement-artifact.mjs +163 -0
- package/scripts/loop/detect-pr-gate-coordination-state.mjs +509 -0
- package/scripts/loop/detect-reviewer-loop-state.mjs +231 -0
- package/scripts/loop/detect-stale-runner.mjs +250 -0
- package/scripts/loop/detect-tracker-first-loop-state.mjs +76 -0
- package/scripts/loop/detect-tracker-pr-state.mjs +102 -0
- package/scripts/loop/info.mjs +267 -0
- package/scripts/loop/inspect-run-viewer/cli.mjs +117 -0
- package/scripts/loop/inspect-run-viewer/constants.mjs +80 -0
- package/scripts/loop/inspect-run-viewer/graph.mjs +757 -0
- package/scripts/loop/inspect-run-viewer/handoff-envelope-renderer.mjs +398 -0
- package/scripts/loop/inspect-run-viewer/inbox.mjs +308 -0
- package/scripts/loop/inspect-run-viewer/managed-instance.mjs +750 -0
- package/scripts/loop/inspect-run-viewer/rendering.mjs +411 -0
- package/scripts/loop/inspect-run-viewer/server.mjs +638 -0
- package/scripts/loop/inspect-run-viewer/shared.mjs +103 -0
- package/scripts/loop/inspect-run-viewer/status.mjs +715 -0
- package/scripts/loop/inspect-run-viewer-ci-changes.mjs +77 -0
- package/scripts/loop/inspect-run-viewer.mjs +82 -0
- package/scripts/loop/inspect-run.mjs +382 -0
- package/scripts/loop/outer-loop.mjs +419 -0
- package/scripts/loop/pr-runner-coordination.mjs +143 -0
- package/scripts/loop/pre-commit-branch-guard.mjs +68 -0
- package/scripts/loop/pre-flight-gate.mjs +236 -0
- package/scripts/loop/pre-pr-ready-gate.mjs +183 -0
- package/scripts/loop/pre-push-main-guard.mjs +103 -0
- package/scripts/loop/pre-write-remote-freshness-guard.mjs +32 -0
- package/scripts/loop/print-gates.mjs +42 -0
- package/scripts/loop/resolve-dev-loop-startup.mjs +533 -0
- package/scripts/loop/run-conductor-cycle.mjs +322 -0
- package/scripts/loop/run-queue.mjs +124 -0
- package/scripts/loop/run-refinement-audit.mjs +513 -0
- package/scripts/loop/run-watch-cycle.mjs +358 -0
- package/scripts/loop/steer-loop.mjs +841 -0
- package/scripts/loop/ui-designer-review-contract.mjs +76 -0
- package/scripts/loop/watch-initial-copilot-pr.mjs +253 -0
- package/scripts/projects/add-queue-item.mjs +528 -0
- package/scripts/projects/ensure-queue-board.mjs +837 -0
- package/scripts/projects/list-queue-items.mjs +489 -0
- package/scripts/projects/move-queue-item.mjs +549 -0
- package/scripts/projects/reorder-queue-item.mjs +518 -0
- package/scripts/refine/_refine-helpers.mjs +258 -0
- package/scripts/refine/prose-linkage-detector.mjs +92 -0
- package/scripts/refine/refinement-completeness-checker.mjs +88 -0
- package/scripts/refine/scope-boundary-cross-checker.mjs +163 -0
- package/scripts/refine/tree-integrity-validator.mjs +211 -0
- package/scripts/refine/verify.mjs +178 -0
- package/scripts/repo-wiki-local.mjs +156 -0
- package/scripts/repo-wiki.mjs +119 -0
- package/skills/copilot-pr-followup/SKILL.md +380 -0
- package/skills/dev-loop/SKILL.md +141 -0
- package/skills/dev-loop/scripts/dev-mode-context.mjs +152 -0
- package/skills/dev-loop/scripts/dev-mode-context.test.mjs +80 -0
- package/skills/dev-loop/scripts/init-phase.mjs +71 -0
- package/skills/dev-loop/scripts/log-bash-exit-1.mjs +25 -0
- package/skills/dev-loop/scripts/phase-files.mjs +29 -0
- package/skills/dev-loop/scripts/post-gate-verdict-fallback.mjs +480 -0
- package/skills/dev-loop/scripts/post-gate-verdict-fallback.test.mjs +732 -0
- package/skills/dev-loop/scripts/render-template.mjs +82 -0
- package/skills/dev-loop/scripts/render-template.test.mjs +63 -0
- package/skills/dev-loop/templates/bootstrap-agents.md +26 -0
- package/skills/dev-loop/templates/bootstrap-implementation-state.md +31 -0
- package/skills/dev-loop/templates/bootstrap-implementation-workflow.md +17 -0
- package/skills/dev-loop/templates/dev-mode-retrospective.md +15 -0
- package/skills/dev-loop/templates/dev-mode-review.md +17 -0
- package/skills/dev-loop/templates/dev-mode-skill-changes.md +11 -0
- package/skills/dev-loop/templates/merged-phase-plan.md +19 -0
- package/skills/dev-loop/templates/phase-doc.md +27 -0
- package/skills/dev-loop/templates/phase-summary.md +13 -0
- package/skills/dev-loop/templates/phase-variant.md +15 -0
- package/skills/dev-loop/templates/retrospective.md +11 -0
- package/skills/dev-loop/templates/review.md +32 -0
- package/skills/dev-loop/templates/ui-vision-review.md +55 -0
- package/skills/docs/acceptance-criteria-verification.md +21 -0
- package/skills/docs/anti-patterns.md +21 -0
- package/skills/docs/artifact-authority-contract.md +119 -0
- package/skills/docs/confirmation-rules.md +28 -0
- package/skills/docs/copilot-ci-status-contract.md +52 -0
- package/skills/docs/copilot-loop-operations.md +233 -0
- package/skills/docs/debt-remediation-contract.md +107 -0
- package/skills/docs/entrypoint-strategies.md +115 -0
- package/skills/docs/epic-tree-refinement-procedure.md +234 -0
- package/skills/docs/issue-intake-procedure.md +235 -0
- package/skills/docs/main-agent-contract.md +72 -0
- package/skills/docs/merge-preconditions.md +29 -0
- package/skills/docs/pr-lifecycle-contract.md +209 -0
- package/skills/docs/public-dev-loop-contract.md +497 -0
- package/skills/docs/retrospective-checkpoint-contract.md +159 -0
- package/skills/docs/stop-conditions.md +29 -0
- package/skills/docs/structural-quality.md +42 -0
- package/skills/docs/tracker-first-loop-state.md +281 -0
- package/skills/docs/validation-policy.md +27 -0
- package/skills/docs/workflow-handoff-contract.md +135 -0
- package/skills/final-approval/SKILL.md +19 -0
- package/skills/local-implementation/SKILL.md +640 -0
|
@@ -0,0 +1,549 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { formatCliError, isDirectCliRun, parseJsonText } from "../_core-helpers.mjs";
|
|
3
|
+
import { runChild as _runChild } from "../_cli-primitives.mjs";
|
|
4
|
+
|
|
5
|
+
const USAGE = `Usage: dev-loops project move --repo <owner/name> --project <number|id> --item <number|node-id> --to-column <name>
|
|
6
|
+
|
|
7
|
+
Move a GitHub Projects V2 item between Status columns.
|
|
8
|
+
|
|
9
|
+
Options:
|
|
10
|
+
--repo <owner/name> Required. Repository to scope the project search.
|
|
11
|
+
--project <number|id> Required. Project number (integer) or node ID.
|
|
12
|
+
--item <number|node-id> Required. Item to move: issue/PR number, or project item node ID.
|
|
13
|
+
--to-column <name> Required. Target Status column (e.g. "Next Up", "In Progress").
|
|
14
|
+
--help, -h Show this help.
|
|
15
|
+
|
|
16
|
+
Output (stdout):
|
|
17
|
+
JSON: { ok: true, item: { itemId, issueNumber, prNumber, previousColumn, newColumn } }
|
|
18
|
+
|
|
19
|
+
Exit codes:
|
|
20
|
+
0 — success
|
|
21
|
+
1 — usage or argument error
|
|
22
|
+
2 — GitHub API error
|
|
23
|
+
3 — project, field, column, or item not found
|
|
24
|
+
`.trim();
|
|
25
|
+
|
|
26
|
+
const VALID_ARGS = new Set(["--repo", "--project", "--item", "--to-column", "--help", "-h"]);
|
|
27
|
+
|
|
28
|
+
function parseArgs(argv) {
|
|
29
|
+
const args = {};
|
|
30
|
+
for (let i = 0; i < argv.length; i++) {
|
|
31
|
+
const arg = argv[i];
|
|
32
|
+
if (!VALID_ARGS.has(arg) && arg.startsWith("-")) {
|
|
33
|
+
throw Object.assign(
|
|
34
|
+
new Error(`Unknown flag: ${arg}`),
|
|
35
|
+
{ code: "INVALID_ARGS", usage: USAGE },
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
if (arg === "--repo") {
|
|
39
|
+
if (i + 1 >= argv.length || argv[i + 1].startsWith("-")) {
|
|
40
|
+
throw Object.assign(new Error("--repo requires a value (owner/name)"), { code: "INVALID_REPO" });
|
|
41
|
+
}
|
|
42
|
+
args.repo = argv[++i];
|
|
43
|
+
} else if (arg === "--project") {
|
|
44
|
+
if (i + 1 >= argv.length || argv[i + 1].startsWith("-")) {
|
|
45
|
+
throw Object.assign(new Error("--project requires a value (number or node ID)"), { code: "INVALID_PROJECT" });
|
|
46
|
+
}
|
|
47
|
+
args.project = argv[++i];
|
|
48
|
+
} else if (arg === "--item") {
|
|
49
|
+
if (i + 1 >= argv.length || argv[i + 1].startsWith("-")) {
|
|
50
|
+
throw Object.assign(new Error("--item requires a value (number or node ID)"), { code: "INVALID_ITEM" });
|
|
51
|
+
}
|
|
52
|
+
args.item = argv[++i];
|
|
53
|
+
} else if (arg === "--to-column") {
|
|
54
|
+
if (i + 1 >= argv.length || argv[i + 1].startsWith("-")) {
|
|
55
|
+
throw Object.assign(new Error("--to-column requires a value"), { code: "INVALID_COLUMN" });
|
|
56
|
+
}
|
|
57
|
+
args.toColumn = argv[++i];
|
|
58
|
+
} else if (arg === "--help" || arg === "-h") {
|
|
59
|
+
args.help = true;
|
|
60
|
+
} else {
|
|
61
|
+
throw Object.assign(new Error(`Unexpected argument: ${arg}`), { code: "INVALID_ARGS", usage: USAGE });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return args;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// ── Validation ───────────────────────────────────────────────────────────
|
|
68
|
+
|
|
69
|
+
const OWNER_RE = /^[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$/;
|
|
70
|
+
const REPO_NAME_RE = /^[a-zA-Z0-9](?:[a-zA-Z0-9_.-]*[a-zA-Z0-9])?$/;
|
|
71
|
+
const GLOBAL_NODE_ID_RE = /^[A-Za-z0-9_]+$/;
|
|
72
|
+
|
|
73
|
+
function validateRepo(repo) {
|
|
74
|
+
if (!repo || typeof repo !== "string") {
|
|
75
|
+
throw Object.assign(new Error("--repo is required"), { code: "INVALID_REPO" });
|
|
76
|
+
}
|
|
77
|
+
const trimmed = repo.trim();
|
|
78
|
+
if (trimmed !== repo) {
|
|
79
|
+
throw Object.assign(new Error(`--repo must not have leading/trailing whitespace, got "${repo}"`), { code: "INVALID_REPO" });
|
|
80
|
+
}
|
|
81
|
+
const slashIdx = repo.indexOf("/");
|
|
82
|
+
if (slashIdx === -1) {
|
|
83
|
+
throw Object.assign(new Error(`--repo must be exactly owner/name, got "${repo}"`), { code: "INVALID_REPO" });
|
|
84
|
+
}
|
|
85
|
+
const owner = repo.slice(0, slashIdx);
|
|
86
|
+
const name = repo.slice(slashIdx + 1);
|
|
87
|
+
if (!owner || !name || !OWNER_RE.test(owner) || !REPO_NAME_RE.test(name)) {
|
|
88
|
+
throw Object.assign(new Error(`--repo must be exactly owner/name, got "${repo}"`), { code: "INVALID_REPO" });
|
|
89
|
+
}
|
|
90
|
+
return repo;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function parseProjectRef(raw) {
|
|
94
|
+
if (!raw || typeof raw !== "string" || raw.trim().length === 0) {
|
|
95
|
+
throw Object.assign(new Error("--project is required"), { code: "INVALID_PROJECT" });
|
|
96
|
+
}
|
|
97
|
+
const trimmed = raw.trim();
|
|
98
|
+
const asNum = Number(trimmed);
|
|
99
|
+
if (Number.isInteger(asNum) && asNum > 0 && String(asNum) === trimmed) {
|
|
100
|
+
return { kind: "number", value: asNum };
|
|
101
|
+
}
|
|
102
|
+
if (trimmed === "0") {
|
|
103
|
+
throw Object.assign(new Error(`--project must be a positive integer or a node ID, got "${raw}"`), { code: "INVALID_PROJECT" });
|
|
104
|
+
}
|
|
105
|
+
if (GLOBAL_NODE_ID_RE.test(trimmed)) {
|
|
106
|
+
return { kind: "id", value: trimmed };
|
|
107
|
+
}
|
|
108
|
+
throw Object.assign(new Error(`--project must be a positive integer or a node ID, got "${raw}"`), { code: "INVALID_PROJECT" });
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function parseItemRef(raw) {
|
|
112
|
+
if (!raw || typeof raw !== "string" || raw.trim().length === 0) {
|
|
113
|
+
throw Object.assign(new Error("--item is required"), { code: "INVALID_ITEM" });
|
|
114
|
+
}
|
|
115
|
+
const trimmed = raw.trim();
|
|
116
|
+
const asNum = Number(trimmed);
|
|
117
|
+
if (Number.isInteger(asNum) && asNum > 0 && String(asNum) === trimmed) {
|
|
118
|
+
return { kind: "number", value: asNum };
|
|
119
|
+
}
|
|
120
|
+
if (trimmed === "0") {
|
|
121
|
+
throw Object.assign(new Error(`--item must be a positive integer or an item node ID, got "${raw}"`), { code: "INVALID_ITEM" });
|
|
122
|
+
}
|
|
123
|
+
if (GLOBAL_NODE_ID_RE.test(trimmed)) {
|
|
124
|
+
return { kind: "id", value: trimmed };
|
|
125
|
+
}
|
|
126
|
+
throw Object.assign(new Error(`--item must be a positive integer or an item node ID, got "${raw}"`), { code: "INVALID_ITEM" });
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// ── API helpers ──────────────────────────────────────────────────────────
|
|
130
|
+
|
|
131
|
+
async function ghGraphql(query, vars, env, runChild = _runChild) {
|
|
132
|
+
const fieldArgs = [];
|
|
133
|
+
for (const [key, value] of Object.entries(vars)) {
|
|
134
|
+
fieldArgs.push("--field", `${key}=${value}`);
|
|
135
|
+
}
|
|
136
|
+
const result = await runChild(
|
|
137
|
+
"gh",
|
|
138
|
+
["api", "graphql", "--field", `query=${query}`, ...fieldArgs],
|
|
139
|
+
env,
|
|
140
|
+
);
|
|
141
|
+
if (result.code !== 0) {
|
|
142
|
+
const detail = result.stderr.trim() || `exit code ${result.code}`;
|
|
143
|
+
throw Object.assign(new Error(`gh api graphql failed: ${detail}`), { code: "GH_API_ERROR" });
|
|
144
|
+
}
|
|
145
|
+
const payload = parseJsonText(result.stdout);
|
|
146
|
+
if (payload.errors && payload.errors.length > 0) {
|
|
147
|
+
throw Object.assign(
|
|
148
|
+
new Error(`GraphQL errors: ${payload.errors.map((e) => e.message).join("; ")}`),
|
|
149
|
+
{ code: "GRAPHQL_ERROR" },
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
return payload;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// ── GraphQL fragments ────────────────────────────────────────────────────
|
|
156
|
+
|
|
157
|
+
const GET_USER_ID = [
|
|
158
|
+
"query($login:String!) {",
|
|
159
|
+
" user(login:$login) { id }",
|
|
160
|
+
"}"
|
|
161
|
+
].join("\n");
|
|
162
|
+
|
|
163
|
+
const GET_ORG_ID = [
|
|
164
|
+
"query($login:String!) {",
|
|
165
|
+
" organization(login:$login) { id }",
|
|
166
|
+
"}"
|
|
167
|
+
].join("\n");
|
|
168
|
+
|
|
169
|
+
const LIST_USER_PROJECTS = [
|
|
170
|
+
"query($login:String!, $after:String) {",
|
|
171
|
+
" user(login:$login) {",
|
|
172
|
+
" projectsV2(first:50, after:$after) {",
|
|
173
|
+
" pageInfo { hasNextPage endCursor }",
|
|
174
|
+
" nodes { id number title url }",
|
|
175
|
+
" }",
|
|
176
|
+
" }",
|
|
177
|
+
"}"
|
|
178
|
+
].join("\n");
|
|
179
|
+
|
|
180
|
+
const LIST_ORG_PROJECTS = [
|
|
181
|
+
"query($login:String!, $after:String) {",
|
|
182
|
+
" organization(login:$login) {",
|
|
183
|
+
" projectsV2(first:50, after:$after) {",
|
|
184
|
+
" pageInfo { hasNextPage endCursor }",
|
|
185
|
+
" nodes { id number title url }",
|
|
186
|
+
" }",
|
|
187
|
+
" }",
|
|
188
|
+
"}"
|
|
189
|
+
].join("\n");
|
|
190
|
+
|
|
191
|
+
const GET_PROJECT_FIELDS = [
|
|
192
|
+
"query($projectId:ID!, $after:String) {",
|
|
193
|
+
" node(id:$projectId) {",
|
|
194
|
+
" ... on ProjectV2 {",
|
|
195
|
+
" fields(first:50, after:$after) {",
|
|
196
|
+
" pageInfo { hasNextPage endCursor }",
|
|
197
|
+
" nodes {",
|
|
198
|
+
" ... on ProjectV2SingleSelectField {",
|
|
199
|
+
" id name",
|
|
200
|
+
" options { id name }",
|
|
201
|
+
" }",
|
|
202
|
+
" }",
|
|
203
|
+
" }",
|
|
204
|
+
" }",
|
|
205
|
+
" }",
|
|
206
|
+
"}"
|
|
207
|
+
].join("\n");
|
|
208
|
+
|
|
209
|
+
const GET_PROJECT_ITEMS_BY_CONTENT = [
|
|
210
|
+
"query($projectId:ID!, $after:String) {",
|
|
211
|
+
" node(id:$projectId) {",
|
|
212
|
+
" ... on ProjectV2 {",
|
|
213
|
+
" items(first:10, after:$after, orderBy:{field:POSITION, direction:ASC}) {",
|
|
214
|
+
" pageInfo { hasNextPage endCursor }",
|
|
215
|
+
" nodes {",
|
|
216
|
+
" id",
|
|
217
|
+
" fieldValues(first:20) {",
|
|
218
|
+
" nodes {",
|
|
219
|
+
" ... on ProjectV2ItemFieldSingleSelectValue {",
|
|
220
|
+
" field { ... on ProjectV2SingleSelectField { id name } }",
|
|
221
|
+
" name",
|
|
222
|
+
" }",
|
|
223
|
+
" }",
|
|
224
|
+
" }",
|
|
225
|
+
" content {",
|
|
226
|
+
" ... on Issue { number repository { nameWithOwner } }",
|
|
227
|
+
" ... on PullRequest { number repository { nameWithOwner } }",
|
|
228
|
+
" }",
|
|
229
|
+
" }",
|
|
230
|
+
" }",
|
|
231
|
+
" }",
|
|
232
|
+
" }",
|
|
233
|
+
"}"
|
|
234
|
+
].join("\n");
|
|
235
|
+
|
|
236
|
+
const GET_PROJECT_ITEM = [
|
|
237
|
+
"query($projectId:ID!, $itemId:ID!) {",
|
|
238
|
+
" node(id:$projectId) {",
|
|
239
|
+
" ... on ProjectV2 {",
|
|
240
|
+
" item: item(id:$itemId) {",
|
|
241
|
+
" id",
|
|
242
|
+
" fieldValues(first:20) {",
|
|
243
|
+
" nodes {",
|
|
244
|
+
" ... on ProjectV2ItemFieldSingleSelectValue {",
|
|
245
|
+
" field { ... on ProjectV2SingleSelectField { id name } }",
|
|
246
|
+
" name",
|
|
247
|
+
" }",
|
|
248
|
+
" }",
|
|
249
|
+
" }",
|
|
250
|
+
" content {",
|
|
251
|
+
" ... on Issue { number title url }",
|
|
252
|
+
" ... on PullRequest { number title url }",
|
|
253
|
+
" }",
|
|
254
|
+
" }",
|
|
255
|
+
" }",
|
|
256
|
+
" }",
|
|
257
|
+
"}"
|
|
258
|
+
].join("\n");
|
|
259
|
+
|
|
260
|
+
const UPDATE_ITEM_FIELD = [
|
|
261
|
+
"mutation($projectId:ID!, $itemId:ID!, $fieldId:ID!, $optionId:String!) {",
|
|
262
|
+
" updateProjectV2ItemFieldValue(input:{projectId:$projectId, itemId:$itemId, fieldId:$fieldId, value:{singleSelectOptionId:$optionId}}) {",
|
|
263
|
+
" projectV2Item {",
|
|
264
|
+
" id",
|
|
265
|
+
" }",
|
|
266
|
+
" }",
|
|
267
|
+
"}"
|
|
268
|
+
].join("\n");
|
|
269
|
+
|
|
270
|
+
// ── Owner resolution ────────────────────────────────────────────────────
|
|
271
|
+
|
|
272
|
+
async function resolveOwner(login, env, runChild) {
|
|
273
|
+
const userPayload = await ghGraphql(GET_USER_ID, { login }, env, runChild);
|
|
274
|
+
if (userPayload?.data?.user?.id) {
|
|
275
|
+
return { id: userPayload.data.user.id, kind: "user" };
|
|
276
|
+
}
|
|
277
|
+
const orgPayload = await ghGraphql(GET_ORG_ID, { login }, env, runChild);
|
|
278
|
+
if (orgPayload?.data?.organization?.id) {
|
|
279
|
+
return { id: orgPayload.data.organization.id, kind: "org" };
|
|
280
|
+
}
|
|
281
|
+
throw Object.assign(
|
|
282
|
+
new Error(`Could not resolve owner ID for "${login}"`),
|
|
283
|
+
{ code: "NO_USER_ID" },
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// ── Paginated project listing ────────────────────────────────────────────
|
|
288
|
+
|
|
289
|
+
async function listAllProjects(login, kind, env, runChild) {
|
|
290
|
+
const query = kind === "org" ? LIST_ORG_PROJECTS : LIST_USER_PROJECTS;
|
|
291
|
+
const projects = [];
|
|
292
|
+
let after = null;
|
|
293
|
+
while (true) {
|
|
294
|
+
const vars = { login };
|
|
295
|
+
if (after) vars.after = after;
|
|
296
|
+
const payload = await ghGraphql(query, vars, env, runChild);
|
|
297
|
+
const connection = kind === "org"
|
|
298
|
+
? payload?.data?.organization?.projectsV2
|
|
299
|
+
: payload?.data?.user?.projectsV2;
|
|
300
|
+
const nodes = connection?.nodes ?? [];
|
|
301
|
+
projects.push(...nodes);
|
|
302
|
+
const pageInfo = connection?.pageInfo ?? {};
|
|
303
|
+
if (!pageInfo.hasNextPage) break;
|
|
304
|
+
if (!pageInfo.endCursor) {
|
|
305
|
+
throw Object.assign(
|
|
306
|
+
new Error("Invalid projects list payload: hasNextPage is true but endCursor is missing"),
|
|
307
|
+
{ code: "GH_API_ERROR" },
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
after = pageInfo.endCursor;
|
|
311
|
+
}
|
|
312
|
+
return projects;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// ── Paginated field listing ──────────────────────────────────────────────
|
|
316
|
+
|
|
317
|
+
async function listAllFields(projectId, env, runChild) {
|
|
318
|
+
const fields = [];
|
|
319
|
+
let after = null;
|
|
320
|
+
while (true) {
|
|
321
|
+
const vars = { projectId };
|
|
322
|
+
if (after) vars.after = after;
|
|
323
|
+
const payload = await ghGraphql(GET_PROJECT_FIELDS, vars, env, runChild);
|
|
324
|
+
const connection = payload?.data?.node?.fields;
|
|
325
|
+
const nodes = connection?.nodes ?? [];
|
|
326
|
+
fields.push(...nodes);
|
|
327
|
+
const pageInfo = connection?.pageInfo ?? {};
|
|
328
|
+
if (!pageInfo.hasNextPage) break;
|
|
329
|
+
if (!pageInfo.endCursor) {
|
|
330
|
+
throw Object.assign(
|
|
331
|
+
new Error("Invalid fields payload: hasNextPage is true but endCursor is missing"),
|
|
332
|
+
{ code: "GH_API_ERROR" },
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
after = pageInfo.endCursor;
|
|
336
|
+
}
|
|
337
|
+
return fields;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// ── Exit code classification ────────────────────────────────────────────
|
|
341
|
+
|
|
342
|
+
function classifyExitCode(err) {
|
|
343
|
+
if (err.code === "INVALID_REPO" || err.code === "INVALID_PROJECT" || err.code === "INVALID_ITEM" ||
|
|
344
|
+
err.code === "INVALID_COLUMN" || err.code === "INVALID_ARGS") return 1;
|
|
345
|
+
if (err.code === "PROJECT_NOT_FOUND" || err.code === "FIELD_NOT_FOUND" || err.code === "COLUMN_NOT_FOUND" ||
|
|
346
|
+
err.code === "ITEM_NOT_FOUND") return 3;
|
|
347
|
+
return 2;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// ── Main logic ──────────────────────────────────────────────────────────
|
|
351
|
+
|
|
352
|
+
async function main(args, { env = process.env, runChild } = {}) {
|
|
353
|
+
const child = runChild ?? _runChild;
|
|
354
|
+
const repo = validateRepo(args.repo);
|
|
355
|
+
const [owner, repoName] = repo.split("/");
|
|
356
|
+
const projectRef = parseProjectRef(args.project);
|
|
357
|
+
const itemRef = parseItemRef(args.item);
|
|
358
|
+
const toColumn = (args.toColumn ?? "").trim();
|
|
359
|
+
if (!toColumn) {
|
|
360
|
+
throw Object.assign(new Error("--to-column is required"), { code: "INVALID_COLUMN" });
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// 1. Resolve owner
|
|
364
|
+
const { id: ownerId, kind: ownerKind } = await resolveOwner(owner, env, child);
|
|
365
|
+
|
|
366
|
+
// 2. Resolve project
|
|
367
|
+
const projects = await listAllProjects(owner, ownerKind, env, child);
|
|
368
|
+
let project;
|
|
369
|
+
if (projectRef.kind === "id") {
|
|
370
|
+
project = projects.find((p) => p.id === projectRef.value);
|
|
371
|
+
} else {
|
|
372
|
+
project = projects.find((p) => p.number === projectRef.value);
|
|
373
|
+
}
|
|
374
|
+
if (!project) {
|
|
375
|
+
throw Object.assign(
|
|
376
|
+
new Error(`Project ${projectRef.kind === "id" ? `"${projectRef.value}"` : `number ${projectRef.value}`} not found under owner "${owner}"`),
|
|
377
|
+
{ code: "PROJECT_NOT_FOUND" },
|
|
378
|
+
);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// 3. Resolve Status field and target column
|
|
382
|
+
const fieldNodes = await listAllFields(project.id, env, child);
|
|
383
|
+
const statusField = fieldNodes.find((f) => f.name === "Status" && f.options);
|
|
384
|
+
if (!statusField) {
|
|
385
|
+
throw Object.assign(
|
|
386
|
+
new Error(`Status field not found in project "${project.title}" (number ${project.number})`),
|
|
387
|
+
{ code: "FIELD_NOT_FOUND" },
|
|
388
|
+
);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
const targetOption = statusField.options.find((o) => o.name === toColumn);
|
|
392
|
+
if (!targetOption) {
|
|
393
|
+
const available = statusField.options.map((o) => o.name).join(", ");
|
|
394
|
+
throw Object.assign(
|
|
395
|
+
new Error(`Column "${toColumn}" not found in Status field. Available: ${available}`),
|
|
396
|
+
{ code: "COLUMN_NOT_FOUND" },
|
|
397
|
+
);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
// 4. Find the item
|
|
401
|
+
let itemId;
|
|
402
|
+
let previousColumn = null;
|
|
403
|
+
let issueNumber = null;
|
|
404
|
+
let prNumber = null;
|
|
405
|
+
|
|
406
|
+
if (itemRef.kind === "id") {
|
|
407
|
+
// Direct item node ID lookup
|
|
408
|
+
const itemPayload = await ghGraphql(GET_PROJECT_ITEM, {
|
|
409
|
+
projectId: project.id,
|
|
410
|
+
itemId: itemRef.value,
|
|
411
|
+
}, env, child);
|
|
412
|
+
const item = itemPayload?.data?.node?.item;
|
|
413
|
+
if (!item) {
|
|
414
|
+
throw Object.assign(
|
|
415
|
+
new Error(`Item "${itemRef.value}" not found in project "${project.title}"`),
|
|
416
|
+
{ code: "ITEM_NOT_FOUND" },
|
|
417
|
+
);
|
|
418
|
+
}
|
|
419
|
+
itemId = item.id;
|
|
420
|
+
const fvs = item.fieldValues?.nodes ?? [];
|
|
421
|
+
for (const fv of fvs) {
|
|
422
|
+
if (fv && fv.field && fv.field.name === "Status") {
|
|
423
|
+
previousColumn = fv.name;
|
|
424
|
+
break;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
if (item.content) {
|
|
428
|
+
if (item.content.__typename === "Issue") {
|
|
429
|
+
issueNumber = item.content.number;
|
|
430
|
+
} else {
|
|
431
|
+
prNumber = item.content.number;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
} else {
|
|
435
|
+
// Look up by issue/PR number in the project
|
|
436
|
+
const itemsPayload = await ghGraphql(GET_PROJECT_ITEMS_BY_CONTENT, {
|
|
437
|
+
projectId: project.id,
|
|
438
|
+
}, env, child);
|
|
439
|
+
const items = itemsPayload?.data?.node?.items?.nodes ?? [];
|
|
440
|
+
|
|
441
|
+
// Filter by matching repo exactly and item number (when known)
|
|
442
|
+
const matchingItems = items.filter((it) => {
|
|
443
|
+
if (!it.content) return false;
|
|
444
|
+
const repoMatch = it.content.repository?.nameWithOwner === repo;
|
|
445
|
+
if (itemRef.kind === "number") {
|
|
446
|
+
return repoMatch && it.content.number === itemRef.value;
|
|
447
|
+
}
|
|
448
|
+
return repoMatch;
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
if (matchingItems.length === 0) {
|
|
452
|
+
throw Object.assign(
|
|
453
|
+
new Error(`Item #${itemRef.value} not found in project "${project.title}" for repo "${repo}"`),
|
|
454
|
+
{ code: "ITEM_NOT_FOUND" },
|
|
455
|
+
);
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
// Use the first match (by position order)
|
|
459
|
+
const match = matchingItems[0];
|
|
460
|
+
itemId = match.id;
|
|
461
|
+
const fvs = match.fieldValues?.nodes ?? [];
|
|
462
|
+
for (const fv of fvs) {
|
|
463
|
+
if (fv && fv.field && fv.field.name === "Status") {
|
|
464
|
+
previousColumn = fv.name;
|
|
465
|
+
break;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
if (match.content) {
|
|
469
|
+
if (match.content.__typename === "Issue") {
|
|
470
|
+
issueNumber = match.content.number;
|
|
471
|
+
} else {
|
|
472
|
+
prNumber = match.content.number;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
// 5. No-op if already at target column
|
|
478
|
+
if (previousColumn === toColumn) {
|
|
479
|
+
return {
|
|
480
|
+
ok: true,
|
|
481
|
+
item: {
|
|
482
|
+
itemId,
|
|
483
|
+
issueNumber,
|
|
484
|
+
prNumber,
|
|
485
|
+
previousColumn,
|
|
486
|
+
newColumn: toColumn,
|
|
487
|
+
unchanged: true,
|
|
488
|
+
},
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
// 6. Update Status via mutation
|
|
493
|
+
const updatePayload = await ghGraphql(UPDATE_ITEM_FIELD, {
|
|
494
|
+
projectId: project.id,
|
|
495
|
+
itemId,
|
|
496
|
+
fieldId: statusField.id,
|
|
497
|
+
optionId: targetOption.id,
|
|
498
|
+
}, env, child);
|
|
499
|
+
|
|
500
|
+
const updated = updatePayload?.data?.updateProjectV2ItemFieldValue?.projectV2Item;
|
|
501
|
+
if (!updated) {
|
|
502
|
+
throw Object.assign(new Error("Failed to update item field value"), { code: "MUTATION_FAILED" });
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
return {
|
|
506
|
+
ok: true,
|
|
507
|
+
item: {
|
|
508
|
+
itemId,
|
|
509
|
+
issueNumber,
|
|
510
|
+
prNumber,
|
|
511
|
+
previousColumn,
|
|
512
|
+
newColumn: toColumn,
|
|
513
|
+
unchanged: false,
|
|
514
|
+
},
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
// ── CLI entrypoint ──────────────────────────────────────────────────────
|
|
519
|
+
|
|
520
|
+
async function runCli(argv, { stdout = process.stdout, stderr = process.stderr, env = process.env } = {}) {
|
|
521
|
+
let args;
|
|
522
|
+
try {
|
|
523
|
+
args = parseArgs(argv);
|
|
524
|
+
} catch (err) {
|
|
525
|
+
stderr.write(`${formatCliError(err)}\n`);
|
|
526
|
+
process.exitCode = 1;
|
|
527
|
+
return;
|
|
528
|
+
}
|
|
529
|
+
if (args.help) {
|
|
530
|
+
stdout.write(USAGE);
|
|
531
|
+
return;
|
|
532
|
+
}
|
|
533
|
+
try {
|
|
534
|
+
const result = await main(args, { env });
|
|
535
|
+
stdout.write(JSON.stringify(result) + "\n");
|
|
536
|
+
} catch (err) {
|
|
537
|
+
stderr.write(JSON.stringify({ ok: false, error: err.message, code: err.code ?? "UNKNOWN" }) + "\n");
|
|
538
|
+
process.exitCode = classifyExitCode(err);
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
if (isDirectCliRun(import.meta.url)) {
|
|
543
|
+
runCli(process.argv.slice(2)).catch((error) => {
|
|
544
|
+
process.stderr.write(JSON.stringify({ ok: false, error: error.message, code: error.code ?? "UNKNOWN" }) + "\n");
|
|
545
|
+
process.exitCode = 2;
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
export { main };
|