@on-par/factory-cli 0.9.29-next.2 → 0.9.29-next.3

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.
@@ -0,0 +1,114 @@
1
+ // packages/cli/src/cli/run-result.ts — turn one run's outcome, merge result, events and costs into the `--json` run result (#3907)
2
+ const CI_PARKS = new Set(['ci-failed', 'ci-infra', 'ci-never-started']);
3
+ function errorMessage(error) {
4
+ if (error === undefined || error === null)
5
+ return undefined;
6
+ return error instanceof Error ? error.message : String(error);
7
+ }
8
+ function classifyMerge(merge) {
9
+ switch (merge.kind) {
10
+ case 'merged':
11
+ return { outcome: 'merged', exitReason: 'merged' };
12
+ case 'held':
13
+ return { outcome: 'held', exitReason: `held by ${merge.gate ?? 'gate'}: ${merge.detail}` };
14
+ case 'ci-failed':
15
+ return { outcome: 'ci-failed', exitReason: merge.detail || 'CI failed' };
16
+ case 'timed-out':
17
+ return { outcome: 'pr-open', exitReason: `merge timed out: ${merge.detail}` };
18
+ case 'land-failed':
19
+ return { outcome: 'failed', exitReason: `land failed: ${merge.detail}` };
20
+ case 'failed-before-pr':
21
+ return undefined;
22
+ }
23
+ }
24
+ /** Maps a run's outcome (and `--merge` result, which wins when present) to one of the six result outcomes plus a reason. */
25
+ export function classifyRunOutcome(outcome, merge, error) {
26
+ const merged = merge ? classifyMerge(merge) : undefined;
27
+ if (merged)
28
+ return merged;
29
+ const message = errorMessage(error);
30
+ if (!outcome)
31
+ return { outcome: 'failed', exitReason: message ?? 'the run produced no outcome' };
32
+ const withError = (reason) => (message ? `${reason}: ${message}` : reason);
33
+ switch (outcome.state) {
34
+ case 'shipped':
35
+ return { outcome: 'pr-open', exitReason: `PR #${outcome.prNumber} opened` };
36
+ case 'ready':
37
+ if (outcome.prNumber === undefined) {
38
+ return { outcome: 'held', exitReason: 'stopped before SHIP: no PR opened' };
39
+ }
40
+ return { outcome: 'pr-open', exitReason: `PR #${outcome.prNumber} opened${outcome.draft ? ' (draft)' : ''}` };
41
+ case 'parked':
42
+ if (CI_PARKS.has(outcome.reason))
43
+ return { outcome: 'ci-failed', exitReason: withError(`parked: ${outcome.reason}`) };
44
+ if (outcome.reason === 'held')
45
+ return { outcome: 'held', exitReason: withError('parked: held') };
46
+ return { outcome: 'parked', exitReason: withError(`parked: ${outcome.reason}`) };
47
+ case 'escalated':
48
+ return { outcome: 'parked', exitReason: withError(`parked: ${outcome.reason}`) };
49
+ case 'released':
50
+ return { outcome: 'failed', exitReason: `released: ${outcome.reason}` };
51
+ }
52
+ }
53
+ function buildPhases(events, costs, finishedAt) {
54
+ const byName = new Map();
55
+ for (const e of events) {
56
+ if (e.type !== 'phase_started' && e.type !== 'phase_completed')
57
+ continue;
58
+ const name = e.phase ?? e.msg.trim().split(/\s+/)[0] ?? '';
59
+ if (name === '')
60
+ continue;
61
+ let p = byName.get(name);
62
+ if (e.type === 'phase_started') {
63
+ if (!p) {
64
+ p = { startedAt: e.ts, finishedAt: null, attempts: 0 };
65
+ byName.set(name, p);
66
+ }
67
+ p.attempts += 1;
68
+ }
69
+ else if (p) {
70
+ p.finishedAt = e.ts;
71
+ }
72
+ }
73
+ return [...byName].map(([name, p]) => {
74
+ const end = p.finishedAt ?? finishedAt;
75
+ const inWindow = costs.filter((c) => c.ts >= p.startedAt && c.ts <= end);
76
+ return { name, ...p, model: inWindow.at(-1)?.model ?? null };
77
+ });
78
+ }
79
+ const round6 = (n) => Math.round(n * 1e6) / 1e6;
80
+ /** Builds the schema-valid run result from what the run recorded; pure, no I/O. */
81
+ export function buildRunResult(input) {
82
+ const { outcome, merge, repo, startedAt } = input;
83
+ const issueKey = String(input.issue);
84
+ const events = input.events.filter((e) => e.issue === issueKey && e.ts >= startedAt);
85
+ const costs = input.costs.filter((c) => c.issue === issueKey && c.ts >= startedAt);
86
+ const prNumber = merge?.prNumber ?? (outcome && 'prNumber' in outcome ? outcome.prNumber : undefined);
87
+ const prState = merge?.kind === 'merged' ? 'merged' : outcome?.state === 'ready' && outcome.draft ? 'draft' : 'open';
88
+ const byModel = {};
89
+ let total = 0;
90
+ for (const c of costs) {
91
+ total += c.cost ?? 0;
92
+ byModel[c.model] = (byModel[c.model] ?? 0) + (c.cost ?? 0);
93
+ }
94
+ for (const model of Object.keys(byModel))
95
+ byModel[model] = round6(byModel[model]);
96
+ return {
97
+ schemaVersion: 1,
98
+ issue: input.issue,
99
+ repo,
100
+ ...classifyRunOutcome(outcome, merge, input.error),
101
+ pr: prNumber === undefined
102
+ ? null
103
+ : { number: prNumber, url: repo ? `https://github.com/${repo}/pull/${prNumber}` : null, state: prState },
104
+ branch: outcome?.branch ?? input.branch ?? null,
105
+ baseSha: input.baseSha,
106
+ headSha: input.headSha,
107
+ startedAt,
108
+ finishedAt: input.finishedAt,
109
+ phases: buildPhases(events, costs, input.finishedAt),
110
+ cost: { usd: round6(total), byModel },
111
+ reworkRounds: outcome?.reworkRounds ?? 0,
112
+ };
113
+ }
114
+ //# sourceMappingURL=run-result.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-result.js","sourceRoot":"","sources":["../../src/cli/run-result.ts"],"names":[],"mappings":"AAAA,mIAAmI;AAOnI,MAAM,QAAQ,GAAwB,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,UAAU,EAAE,kBAAkB,CAAC,CAAC,CAAC;AAiB7F,SAAS,YAAY,CAAC,KAAc;IAClC,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,SAAS,CAAC;IAC5D,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAChE,CAAC;AAED,SAAS,aAAa,CAAC,KAAkB;IACvC,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;QACnB,KAAK,QAAQ;YACX,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC;QACrD,KAAK,M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/factory-cli",
3
- "version": "0.9.29-next.2",
3
+ "version": "0.9.29-next.3",
4
4
  "description": "On PAR Dev's Software Factory CLI: takes a GitHub issue through plan, build and check with AI agents, then opens a ready-for-review PR.",
5
5
  "keywords": [
6
6
  "ai-agents",
@@ -48,9 +48,9 @@
48
48
  "@octokit/plugin-retry": "^8.1.1",
49
49
  "@octokit/plugin-throttling": "^11.0.5",
50
50
  "@octokit/rest": "^22.0.0",
51
- "@on-par/factory-config": "0.9.29-next.2",
52
- "@on-par/factory-core": "0.9.29-next.2",
53
- "@on-par/factory-tui": "0.9.29-next.2",
51
+ "@on-par/factory-config": "0.9.29-next.3",
52
+ "@on-par/factory-core": "0.9.29-next.3",
53
+ "@on-par/factory-tui": "0.9.29-next.3",
54
54
  "commander": "^15.0.0",
55
55
  "zod": "^4.6.5"
56
56
  },
@@ -0,0 +1,135 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "type": "object",
4
+ "properties": {
5
+ "schemaVersion": {
6
+ "type": "number",
7
+ "const": 1
8
+ },
9
+ "issue": {
10
+ "type": "integer",
11
+ "minimum": -9007199254740991,
12
+ "maximum": 9007199254740991
13
+ },
14
+ "repo": {
15
+ "type": ["string", "null"]
16
+ },
17
+ "outcome": {
18
+ "type": "string",
19
+ "enum": ["merged", "pr-open", "held", "ci-failed", "parked", "failed"]
20
+ },
21
+ "exitReason": {
22
+ "type": "string",
23
+ "minLength": 1
24
+ },
25
+ "pr": {
26
+ "anyOf": [
27
+ {
28
+ "type": "object",
29
+ "properties": {
30
+ "number": {
31
+ "type": "integer",
32
+ "minimum": -9007199254740991,
33
+ "maximum": 9007199254740991
34
+ },
35
+ "url": {
36
+ "type": ["string", "null"]
37
+ },
38
+ "state": {
39
+ "type": "string",
40
+ "enum": ["open", "draft", "merged"]
41
+ }
42
+ },
43
+ "required": ["number", "url", "state"],
44
+ "additionalProperties": false
45
+ },
46
+ {
47
+ "type": "null"
48
+ }
49
+ ]
50
+ },
51
+ "branch": {
52
+ "type": ["string", "null"]
53
+ },
54
+ "baseSha": {
55
+ "type": ["string", "null"]
56
+ },
57
+ "headSha": {
58
+ "type": ["string", "null"]
59
+ },
60
+ "startedAt": {
61
+ "type": "string"
62
+ },
63
+ "finishedAt": {
64
+ "type": "string"
65
+ },
66
+ "phases": {
67
+ "type": "array",
68
+ "items": {
69
+ "type": "object",
70
+ "properties": {
71
+ "name": {
72
+ "type": "string"
73
+ },
74
+ "startedAt": {
75
+ "type": "string"
76
+ },
77
+ "finishedAt": {
78
+ "type": ["string", "null"]
79
+ },
80
+ "model": {
81
+ "type": ["string", "null"]
82
+ },
83
+ "attempts": {
84
+ "type": "integer",
85
+ "minimum": -9007199254740991,
86
+ "maximum": 9007199254740991
87
+ }
88
+ },
89
+ "required": ["name", "startedAt", "finishedAt", "model", "attempts"],
90
+ "additionalProperties": false
91
+ }
92
+ },
93
+ "cost": {
94
+ "type": "object",
95
+ "properties": {
96
+ "usd": {
97
+ "type": "number"
98
+ },
99
+ "byModel": {
100
+ "type": "object",
101
+ "propertyNames": {
102
+ "type": "string"
103
+ },
104
+ "additionalProperties": {
105
+ "type": "number"
106
+ }
107
+ }
108
+ },
109
+ "required": ["usd", "byModel"],
110
+ "additionalProperties": false
111
+ },
112
+ "reworkRounds": {
113
+ "type": "integer",
114
+ "minimum": -9007199254740991,
115
+ "maximum": 9007199254740991
116
+ }
117
+ },
118
+ "required": [
119
+ "schemaVersion",
120
+ "issue",
121
+ "repo",
122
+ "outcome",
123
+ "exitReason",
124
+ "pr",
125
+ "branch",
126
+ "baseSha",
127
+ "headSha",
128
+ "startedAt",
129
+ "finishedAt",
130
+ "phases",
131
+ "cost",
132
+ "reworkRounds"
133
+ ],
134
+ "additionalProperties": false
135
+ }