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,489 @@
|
|
|
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 list --repo <owner/name> --project <number|id> [--column <name>] [--limit <n>]
|
|
6
|
+
|
|
7
|
+
List GitHub Projects V2 items filtered by Status column, ordered by position
|
|
8
|
+
ascending. Returns machine-readable JSON.
|
|
9
|
+
|
|
10
|
+
Options:
|
|
11
|
+
--repo <owner/name> Required. Repository to scope the project search.
|
|
12
|
+
--project <number|id> Required. Project number (integer) or node ID.
|
|
13
|
+
--column <name> Filter items by Status column value (e.g. "Next Up").
|
|
14
|
+
--limit <n> Return at most <n> items.
|
|
15
|
+
--help, -h Show this help.
|
|
16
|
+
|
|
17
|
+
Output (stdout):
|
|
18
|
+
JSON: { ok: true, items: [{ issueNumber, prNumber, title, url, itemId, contentId, status }, ...] }
|
|
19
|
+
|
|
20
|
+
Exit codes:
|
|
21
|
+
0 — success
|
|
22
|
+
1 — usage or argument error
|
|
23
|
+
2 — GitHub API error
|
|
24
|
+
3 — project, field, or column not found
|
|
25
|
+
`.trim();
|
|
26
|
+
|
|
27
|
+
const VALID_ARGS = new Set(["--repo", "--project", "--column", "--limit", "--help", "-h"]);
|
|
28
|
+
|
|
29
|
+
function parseArgs(argv) {
|
|
30
|
+
const args = {};
|
|
31
|
+
for (let i = 0; i < argv.length; i++) {
|
|
32
|
+
const arg = argv[i];
|
|
33
|
+
if (!VALID_ARGS.has(arg) && arg.startsWith("-")) {
|
|
34
|
+
throw Object.assign(
|
|
35
|
+
new Error(`Unknown flag: ${arg}`),
|
|
36
|
+
{ code: "INVALID_ARGS", usage: USAGE },
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
if (arg === "--repo") {
|
|
40
|
+
if (i + 1 >= argv.length || argv[i + 1].startsWith("-")) {
|
|
41
|
+
throw Object.assign(
|
|
42
|
+
new Error("--repo requires a value (owner/name)"),
|
|
43
|
+
{ code: "INVALID_ARGS", usage: USAGE },
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
args.repo = argv[++i];
|
|
47
|
+
} else if (arg === "--project") {
|
|
48
|
+
if (i + 1 >= argv.length || argv[i + 1].startsWith("-")) {
|
|
49
|
+
throw Object.assign(
|
|
50
|
+
new Error("--project requires a value (number or node ID)"),
|
|
51
|
+
{ code: "INVALID_ARGS", usage: USAGE },
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
args.project = argv[++i];
|
|
55
|
+
} else if (arg === "--column") {
|
|
56
|
+
if (i + 1 >= argv.length || argv[i + 1].startsWith("-")) {
|
|
57
|
+
throw Object.assign(
|
|
58
|
+
new Error("--column requires a value"),
|
|
59
|
+
{ code: "INVALID_ARGS", usage: USAGE },
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
args.column = argv[++i];
|
|
63
|
+
} else if (arg === "--limit") {
|
|
64
|
+
if (i + 1 >= argv.length || argv[i + 1].startsWith("-")) {
|
|
65
|
+
throw Object.assign(
|
|
66
|
+
new Error("--limit requires a positive integer"),
|
|
67
|
+
{ code: "INVALID_ARGS", usage: USAGE },
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
const val = Number(argv[++i]);
|
|
71
|
+
if (!Number.isInteger(val) || val < 1) {
|
|
72
|
+
throw Object.assign(
|
|
73
|
+
new Error(`--limit must be a positive integer, got "${argv[i]}"`),
|
|
74
|
+
{ code: "INVALID_ARGS", usage: USAGE },
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
args.limit = val;
|
|
78
|
+
} else if (arg === "--help" || arg === "-h") {
|
|
79
|
+
args.help = true;
|
|
80
|
+
} else {
|
|
81
|
+
throw Object.assign(
|
|
82
|
+
new Error(`Unexpected argument: ${arg}`),
|
|
83
|
+
{ code: "INVALID_ARGS", usage: USAGE },
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return args;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// ── Validation ───────────────────────────────────────────────────────────
|
|
91
|
+
|
|
92
|
+
const OWNER_RE = /^[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$/;
|
|
93
|
+
const REPO_NAME_RE = /^[a-zA-Z0-9](?:[a-zA-Z0-9_.-]*[a-zA-Z0-9])?$/;
|
|
94
|
+
const GLOBAL_NODE_ID_RE = /^[A-Za-z0-9_]+$/;
|
|
95
|
+
|
|
96
|
+
function validateRepo(repo) {
|
|
97
|
+
if (!repo || typeof repo !== "string") {
|
|
98
|
+
throw Object.assign(new Error("--repo is required"), { code: "INVALID_REPO" });
|
|
99
|
+
}
|
|
100
|
+
const trimmed = repo.trim();
|
|
101
|
+
if (trimmed !== repo) {
|
|
102
|
+
throw Object.assign(
|
|
103
|
+
new Error(`--repo must not have leading/trailing whitespace, got "${repo}"`),
|
|
104
|
+
{ code: "INVALID_REPO" },
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
const slashIdx = repo.indexOf("/");
|
|
108
|
+
if (slashIdx === -1) {
|
|
109
|
+
throw Object.assign(new Error(`--repo must be exactly owner/name, got "${repo}"`), { code: "INVALID_REPO" });
|
|
110
|
+
}
|
|
111
|
+
const owner = repo.slice(0, slashIdx);
|
|
112
|
+
const name = repo.slice(slashIdx + 1);
|
|
113
|
+
if (!owner || !name || !OWNER_RE.test(owner) || !REPO_NAME_RE.test(name)) {
|
|
114
|
+
throw Object.assign(new Error(`--repo must be exactly owner/name, got "${repo}"`), { code: "INVALID_REPO" });
|
|
115
|
+
}
|
|
116
|
+
return repo;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function parseProjectRef(raw) {
|
|
120
|
+
if (!raw || typeof raw !== "string" || raw.trim().length === 0) {
|
|
121
|
+
throw Object.assign(new Error("--project is required"), { code: "INVALID_PROJECT" });
|
|
122
|
+
}
|
|
123
|
+
const trimmed = raw.trim();
|
|
124
|
+
const asNum = Number(trimmed);
|
|
125
|
+
if (Number.isInteger(asNum) && asNum > 0 && String(asNum) === trimmed) {
|
|
126
|
+
return { kind: "number", value: asNum };
|
|
127
|
+
}
|
|
128
|
+
// Reject bare "0" — valid node ID character but not a meaningful project reference
|
|
129
|
+
if (trimmed === "0") {
|
|
130
|
+
throw Object.assign(
|
|
131
|
+
new Error(`--project must be a positive integer or a node ID, got "${raw}"`),
|
|
132
|
+
{ code: "INVALID_PROJECT" },
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
if (GLOBAL_NODE_ID_RE.test(trimmed)) {
|
|
136
|
+
return { kind: "id", value: trimmed };
|
|
137
|
+
}
|
|
138
|
+
throw Object.assign(
|
|
139
|
+
new Error(`--project must be a positive integer or a node ID, got "${raw}"`),
|
|
140
|
+
{ code: "INVALID_PROJECT" },
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// ── API helpers ──────────────────────────────────────────────────────────
|
|
145
|
+
|
|
146
|
+
async function ghGraphql(query, vars, env, runChild = _runChild) {
|
|
147
|
+
const fieldArgs = [];
|
|
148
|
+
for (const [key, value] of Object.entries(vars)) {
|
|
149
|
+
fieldArgs.push("--field", `${key}=${value}`);
|
|
150
|
+
}
|
|
151
|
+
const result = await runChild(
|
|
152
|
+
"gh",
|
|
153
|
+
["api", "graphql", "--field", `query=${query}`, ...fieldArgs],
|
|
154
|
+
env,
|
|
155
|
+
);
|
|
156
|
+
if (result.code !== 0) {
|
|
157
|
+
const detail = result.stderr.trim() || `exit code ${result.code}`;
|
|
158
|
+
throw Object.assign(new Error(`gh api graphql failed: ${detail}`), { code: "GH_API_ERROR" });
|
|
159
|
+
}
|
|
160
|
+
const payload = parseJsonText(result.stdout);
|
|
161
|
+
if (payload.errors && payload.errors.length > 0) {
|
|
162
|
+
throw Object.assign(
|
|
163
|
+
new Error(`GraphQL errors: ${payload.errors.map((e) => e.message).join("; ")}`),
|
|
164
|
+
{ code: "GRAPHQL_ERROR" },
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
return payload;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// ── GraphQL fragments ────────────────────────────────────────────────────
|
|
171
|
+
|
|
172
|
+
const GET_USER_ID = [
|
|
173
|
+
"query($login:String!) {",
|
|
174
|
+
" user(login:$login) { id }",
|
|
175
|
+
"}"
|
|
176
|
+
].join("\n");
|
|
177
|
+
|
|
178
|
+
const GET_ORG_ID = [
|
|
179
|
+
"query($login:String!) {",
|
|
180
|
+
" organization(login:$login) { id }",
|
|
181
|
+
"}"
|
|
182
|
+
].join("\n");
|
|
183
|
+
|
|
184
|
+
const LIST_USER_PROJECTS = [
|
|
185
|
+
"query($login:String!, $after:String) {",
|
|
186
|
+
" user(login:$login) {",
|
|
187
|
+
" projectsV2(first:50, after:$after) {",
|
|
188
|
+
" pageInfo { hasNextPage endCursor }",
|
|
189
|
+
" nodes { id number title url }",
|
|
190
|
+
" }",
|
|
191
|
+
" }",
|
|
192
|
+
"}"
|
|
193
|
+
].join("\n");
|
|
194
|
+
|
|
195
|
+
const LIST_ORG_PROJECTS = [
|
|
196
|
+
"query($login:String!, $after:String) {",
|
|
197
|
+
" organization(login:$login) {",
|
|
198
|
+
" projectsV2(first:50, after:$after) {",
|
|
199
|
+
" pageInfo { hasNextPage endCursor }",
|
|
200
|
+
" nodes { id number title url }",
|
|
201
|
+
" }",
|
|
202
|
+
" }",
|
|
203
|
+
"}"
|
|
204
|
+
].join("\n");
|
|
205
|
+
|
|
206
|
+
const GET_PROJECT_FIELDS = [
|
|
207
|
+
"query($projectId:ID!, $after:String) {",
|
|
208
|
+
" node(id:$projectId) {",
|
|
209
|
+
" ... on ProjectV2 {",
|
|
210
|
+
" fields(first:50, after:$after) {",
|
|
211
|
+
" pageInfo { hasNextPage endCursor }",
|
|
212
|
+
" nodes {",
|
|
213
|
+
" ... on ProjectV2SingleSelectField {",
|
|
214
|
+
" id name",
|
|
215
|
+
" options { id name }",
|
|
216
|
+
" }",
|
|
217
|
+
" }",
|
|
218
|
+
" }",
|
|
219
|
+
" }",
|
|
220
|
+
" }",
|
|
221
|
+
"}"
|
|
222
|
+
].join("\n");
|
|
223
|
+
|
|
224
|
+
const GET_PROJECT_ITEMS = [
|
|
225
|
+
"query($projectId:ID!, $after:String) {",
|
|
226
|
+
" node(id:$projectId) {",
|
|
227
|
+
" ... on ProjectV2 {",
|
|
228
|
+
" items(first:100, after:$after) {",
|
|
229
|
+
" pageInfo { hasNextPage endCursor }",
|
|
230
|
+
" nodes {",
|
|
231
|
+
" id",
|
|
232
|
+
" fieldValues(first:20) {",
|
|
233
|
+
" nodes {",
|
|
234
|
+
" ... on ProjectV2ItemFieldSingleSelectValue {",
|
|
235
|
+
" field { ... on ProjectV2SingleSelectField { id name } }",
|
|
236
|
+
" name",
|
|
237
|
+
" }",
|
|
238
|
+
" }",
|
|
239
|
+
" }",
|
|
240
|
+
" content {",
|
|
241
|
+
" ... on Issue { number title url id }",
|
|
242
|
+
" ... on PullRequest { number title url id }",
|
|
243
|
+
" }",
|
|
244
|
+
" }",
|
|
245
|
+
" }",
|
|
246
|
+
" }",
|
|
247
|
+
" }",
|
|
248
|
+
"}"
|
|
249
|
+
].join("\n");
|
|
250
|
+
|
|
251
|
+
// ── Owner resolution ────────────────────────────────────────────────────
|
|
252
|
+
|
|
253
|
+
async function resolveOwner(login, env, runChild) {
|
|
254
|
+
const userPayload = await ghGraphql(GET_USER_ID, { login }, env, runChild);
|
|
255
|
+
if (userPayload?.data?.user?.id) {
|
|
256
|
+
return { id: userPayload.data.user.id, kind: "user" };
|
|
257
|
+
}
|
|
258
|
+
const orgPayload = await ghGraphql(GET_ORG_ID, { login }, env, runChild);
|
|
259
|
+
if (orgPayload?.data?.organization?.id) {
|
|
260
|
+
return { id: orgPayload.data.organization.id, kind: "org" };
|
|
261
|
+
}
|
|
262
|
+
throw Object.assign(
|
|
263
|
+
new Error(`Could not resolve owner ID for "${login}"`),
|
|
264
|
+
{ code: "NO_USER_ID" },
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// ── Paginated project listing ────────────────────────────────────────────
|
|
269
|
+
|
|
270
|
+
async function listAllProjects(login, kind, env, runChild) {
|
|
271
|
+
const query = kind === "org" ? LIST_ORG_PROJECTS : LIST_USER_PROJECTS;
|
|
272
|
+
const projects = [];
|
|
273
|
+
let after = null;
|
|
274
|
+
while (true) {
|
|
275
|
+
const vars = { login };
|
|
276
|
+
if (after) vars.after = after;
|
|
277
|
+
const payload = await ghGraphql(query, vars, env, runChild);
|
|
278
|
+
const connection = kind === "org"
|
|
279
|
+
? payload?.data?.organization?.projectsV2
|
|
280
|
+
: payload?.data?.user?.projectsV2;
|
|
281
|
+
const nodes = connection?.nodes ?? [];
|
|
282
|
+
projects.push(...nodes);
|
|
283
|
+
const pageInfo = connection?.pageInfo ?? {};
|
|
284
|
+
if (!pageInfo.hasNextPage) break;
|
|
285
|
+
if (!pageInfo.endCursor) {
|
|
286
|
+
throw Object.assign(
|
|
287
|
+
new Error("Invalid projects list payload: hasNextPage is true but endCursor is missing"),
|
|
288
|
+
{ code: "GH_API_ERROR" },
|
|
289
|
+
);
|
|
290
|
+
}
|
|
291
|
+
after = pageInfo.endCursor;
|
|
292
|
+
}
|
|
293
|
+
return projects;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// ── Paginated field listing ──────────────────────────────────────────────
|
|
297
|
+
|
|
298
|
+
async function listAllFields(projectId, env, runChild) {
|
|
299
|
+
const fields = [];
|
|
300
|
+
let after = null;
|
|
301
|
+
while (true) {
|
|
302
|
+
const vars = { projectId };
|
|
303
|
+
if (after) vars.after = after;
|
|
304
|
+
const payload = await ghGraphql(GET_PROJECT_FIELDS, vars, env, runChild);
|
|
305
|
+
const connection = payload?.data?.node?.fields;
|
|
306
|
+
const nodes = connection?.nodes ?? [];
|
|
307
|
+
fields.push(...nodes);
|
|
308
|
+
const pageInfo = connection?.pageInfo ?? {};
|
|
309
|
+
if (!pageInfo.hasNextPage) break;
|
|
310
|
+
if (!pageInfo.endCursor) {
|
|
311
|
+
throw Object.assign(
|
|
312
|
+
new Error("Invalid fields payload: hasNextPage is true but endCursor is missing"),
|
|
313
|
+
{ code: "GH_API_ERROR" },
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
after = pageInfo.endCursor;
|
|
317
|
+
}
|
|
318
|
+
return fields;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// ── Paginated item listing ───────────────────────────────────────────────
|
|
322
|
+
|
|
323
|
+
async function listAllItems(projectId, env, runChild) {
|
|
324
|
+
const items = [];
|
|
325
|
+
let after = null;
|
|
326
|
+
while (true) {
|
|
327
|
+
const vars = { projectId };
|
|
328
|
+
if (after) vars.after = after;
|
|
329
|
+
const payload = await ghGraphql(GET_PROJECT_ITEMS, vars, env, runChild);
|
|
330
|
+
const connection = payload?.data?.node?.items;
|
|
331
|
+
const nodes = connection?.nodes ?? [];
|
|
332
|
+
items.push(...nodes);
|
|
333
|
+
const pageInfo = connection?.pageInfo ?? {};
|
|
334
|
+
if (!pageInfo.hasNextPage) break;
|
|
335
|
+
if (!pageInfo.endCursor) {
|
|
336
|
+
throw Object.assign(
|
|
337
|
+
new Error("Invalid items payload: hasNextPage is true but endCursor is missing"),
|
|
338
|
+
{ code: "GH_API_ERROR" },
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
after = pageInfo.endCursor;
|
|
342
|
+
}
|
|
343
|
+
return items;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// ── Exit code classification ────────────────────────────────────────────
|
|
347
|
+
|
|
348
|
+
function classifyExitCode(err) {
|
|
349
|
+
if (err.code === "INVALID_REPO" || err.code === "INVALID_PROJECT" || err.code === "INVALID_ARGS") return 1;
|
|
350
|
+
if (err.code === "PROJECT_NOT_FOUND" || err.code === "FIELD_NOT_FOUND" || err.code === "COLUMN_NOT_FOUND") return 3;
|
|
351
|
+
return 2;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// ── Main logic ──────────────────────────────────────────────────────────
|
|
355
|
+
|
|
356
|
+
async function main(args, { env = process.env, runChild } = {}) {
|
|
357
|
+
const child = runChild ?? _runChild;
|
|
358
|
+
const repo = validateRepo(args.repo);
|
|
359
|
+
const [owner] = repo.split("/");
|
|
360
|
+
const projectRef = parseProjectRef(args.project);
|
|
361
|
+
|
|
362
|
+
// 1. Resolve owner (user or org)
|
|
363
|
+
const { id: ownerId, kind: ownerKind } = await resolveOwner(owner, env, child);
|
|
364
|
+
|
|
365
|
+
// 2. Resolve project
|
|
366
|
+
let project;
|
|
367
|
+
if (projectRef.kind === "id") {
|
|
368
|
+
// Direct ID: use it directly (verify it belongs to owner via projects list)
|
|
369
|
+
const projects = await listAllProjects(owner, ownerKind, env, child);
|
|
370
|
+
project = projects.find((p) => p.id === projectRef.value);
|
|
371
|
+
if (!project) {
|
|
372
|
+
throw Object.assign(
|
|
373
|
+
new Error(`Project with ID "${projectRef.value}" not found under owner "${owner}"`),
|
|
374
|
+
{ code: "PROJECT_NOT_FOUND" },
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
} else {
|
|
378
|
+
// By number
|
|
379
|
+
const projects = await listAllProjects(owner, ownerKind, env, child);
|
|
380
|
+
project = projects.find((p) => p.number === projectRef.value);
|
|
381
|
+
if (!project) {
|
|
382
|
+
throw Object.assign(
|
|
383
|
+
new Error(`Project number ${projectRef.value} not found under owner "${owner}"`),
|
|
384
|
+
{ code: "PROJECT_NOT_FOUND" },
|
|
385
|
+
);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// 3. Resolve Status field and target column
|
|
390
|
+
const fieldNodes = await listAllFields(project.id, env, child);
|
|
391
|
+
const statusField = fieldNodes.find((f) => f.name === "Status" && f.options);
|
|
392
|
+
if (!statusField) {
|
|
393
|
+
throw Object.assign(
|
|
394
|
+
new Error(`Status field not found in project "${project.title}" (number ${project.number})`),
|
|
395
|
+
{ code: "FIELD_NOT_FOUND" },
|
|
396
|
+
);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
let targetOption = null;
|
|
400
|
+
if (args.column) {
|
|
401
|
+
targetOption = statusField.options.find(
|
|
402
|
+
(o) => o.name === args.column,
|
|
403
|
+
);
|
|
404
|
+
if (!targetOption) {
|
|
405
|
+
const available = statusField.options.map((o) => o.name).join(", ");
|
|
406
|
+
throw Object.assign(
|
|
407
|
+
new Error(
|
|
408
|
+
`Column "${args.column}" not found in Status field. Available: ${available}`,
|
|
409
|
+
),
|
|
410
|
+
{ code: "COLUMN_NOT_FOUND" },
|
|
411
|
+
);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// 4. List and filter items (ordered by position ascending, GraphQL default)
|
|
416
|
+
const rawItems = await listAllItems(project.id, env, child);
|
|
417
|
+
|
|
418
|
+
const results = [];
|
|
419
|
+
for (const item of rawItems) {
|
|
420
|
+
const content = item.content;
|
|
421
|
+
if (!content) continue;
|
|
422
|
+
|
|
423
|
+
// Determine status from field values
|
|
424
|
+
let status = null;
|
|
425
|
+
const fieldValues = item.fieldValues?.nodes ?? [];
|
|
426
|
+
for (const fv of fieldValues) {
|
|
427
|
+
if (fv && fv.field && fv.field.name === "Status") {
|
|
428
|
+
status = fv.name;
|
|
429
|
+
break;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// Filter by column
|
|
434
|
+
if (args.column && status !== args.column) continue;
|
|
435
|
+
|
|
436
|
+
const isPr = content.__typename === "PullRequest";
|
|
437
|
+
|
|
438
|
+
results.push({
|
|
439
|
+
issueNumber: isPr ? null : content.number,
|
|
440
|
+
prNumber: isPr ? content.number : null,
|
|
441
|
+
title: content.title ?? null,
|
|
442
|
+
url: content.url ?? null,
|
|
443
|
+
itemId: item.id,
|
|
444
|
+
contentId: content.id ?? null,
|
|
445
|
+
status: status ?? null,
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
// 5. Items are returned in position order from GraphQL. Apply limit.
|
|
450
|
+
const limited = args.limit ? results.slice(0, args.limit) : results;
|
|
451
|
+
|
|
452
|
+
return {
|
|
453
|
+
ok: true,
|
|
454
|
+
items: limited,
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
// ── CLI entrypoint ──────────────────────────────────────────────────────
|
|
459
|
+
|
|
460
|
+
async function runCli(argv, { stdout = process.stdout, stderr = process.stderr, env = process.env } = {}) {
|
|
461
|
+
let args;
|
|
462
|
+
try {
|
|
463
|
+
args = parseArgs(argv);
|
|
464
|
+
} catch (err) {
|
|
465
|
+
stderr.write(`${formatCliError(err)}\n`);
|
|
466
|
+
process.exitCode = 1;
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
if (args.help) {
|
|
470
|
+
stdout.write(USAGE);
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
try {
|
|
474
|
+
const result = await main(args, { env });
|
|
475
|
+
stdout.write(JSON.stringify(result) + "\n");
|
|
476
|
+
} catch (err) {
|
|
477
|
+
stderr.write(JSON.stringify({ ok: false, error: err.message, code: err.code ?? "UNKNOWN" }) + "\n");
|
|
478
|
+
process.exitCode = classifyExitCode(err);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
if (isDirectCliRun(import.meta.url)) {
|
|
483
|
+
runCli(process.argv.slice(2)).catch((error) => {
|
|
484
|
+
process.stderr.write(JSON.stringify({ ok: false, error: error.message, code: error.code ?? "UNKNOWN" }) + "\n");
|
|
485
|
+
process.exitCode = 2;
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
export { main };
|