erdos-problems 0.2.1 → 0.2.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.
Files changed (38) hide show
  1. package/README.md +218 -356
  2. package/docs/LAUNCH_KIT.md +84 -0
  3. package/package.json +13 -5
  4. package/packs/graph-theory/README.md +17 -0
  5. package/packs/graph-theory/problems/1008/CHECKPOINT_TEMPLATE.md +9 -0
  6. package/packs/graph-theory/problems/1008/CONTEXT.md +9 -0
  7. package/packs/graph-theory/problems/1008/FRONTIER_NOTE.md +8 -0
  8. package/packs/graph-theory/problems/1008/OPS_DETAILS.yaml +25 -0
  9. package/packs/graph-theory/problems/1008/REPORT_TEMPLATE.md +9 -0
  10. package/packs/graph-theory/problems/1008/ROUTE_HISTORY.md +5 -0
  11. package/packs/graph-theory/problems/1008/ROUTE_PACKET.yaml +13 -0
  12. package/packs/graph-theory/problems/1008/context.yaml +27 -0
  13. package/packs/graph-theory/problems/19/CHECKPOINT_TEMPLATE.md +9 -0
  14. package/packs/graph-theory/problems/19/CONTEXT.md +9 -0
  15. package/packs/graph-theory/problems/19/FRONTIER_NOTE.md +8 -0
  16. package/packs/graph-theory/problems/19/OPS_DETAILS.yaml +25 -0
  17. package/packs/graph-theory/problems/19/REPORT_TEMPLATE.md +9 -0
  18. package/packs/graph-theory/problems/19/ROUTE_HISTORY.md +5 -0
  19. package/packs/graph-theory/problems/19/ROUTE_PACKET.yaml +13 -0
  20. package/packs/graph-theory/problems/19/context.yaml +25 -0
  21. package/packs/graph-theory/problems/22/CHECKPOINT_TEMPLATE.md +9 -0
  22. package/packs/graph-theory/problems/22/CONTEXT.md +9 -0
  23. package/packs/graph-theory/problems/22/FRONTIER_NOTE.md +8 -0
  24. package/packs/graph-theory/problems/22/OPS_DETAILS.yaml +25 -0
  25. package/packs/graph-theory/problems/22/REPORT_TEMPLATE.md +9 -0
  26. package/packs/graph-theory/problems/22/ROUTE_HISTORY.md +5 -0
  27. package/packs/graph-theory/problems/22/ROUTE_PACKET.yaml +13 -0
  28. package/packs/graph-theory/problems/22/context.yaml +26 -0
  29. package/packs/number-theory/README.md +3 -0
  30. package/src/cli/index.js +15 -5
  31. package/src/commands/archive.js +10 -1
  32. package/src/commands/cluster.js +15 -1
  33. package/src/commands/graph-theory.js +180 -0
  34. package/src/commands/number-theory.js +107 -2
  35. package/src/commands/workspace.js +39 -1
  36. package/src/runtime/graph-theory.js +167 -0
  37. package/src/runtime/number-theory.js +60 -0
  38. package/src/runtime/state.js +31 -0
@@ -0,0 +1,180 @@
1
+ import { getProblem } from '../atlas/catalog.js';
2
+ import { buildGraphTheoryStatusSnapshot } from '../runtime/graph-theory.js';
3
+ import { readCurrentProblem } from '../runtime/workspace.js';
4
+
5
+ function resolveGraphTheoryProblem(problemId) {
6
+ const resolvedId = problemId ?? readCurrentProblem();
7
+ if (!resolvedId) {
8
+ return { error: 'Missing problem id and no active problem is selected.' };
9
+ }
10
+
11
+ const problem = getProblem(resolvedId);
12
+ if (!problem) {
13
+ return { error: `Unknown problem: ${resolvedId}` };
14
+ }
15
+ if (problem.cluster !== 'graph-theory') {
16
+ return { error: `Problem ${resolvedId} is not in the graph-theory pack.` };
17
+ }
18
+ return { problem };
19
+ }
20
+
21
+ function parseArgs(args) {
22
+ const parsed = { problemId: null, asJson: false };
23
+ for (const token of args) {
24
+ if (token === '--json') {
25
+ parsed.asJson = true;
26
+ continue;
27
+ }
28
+ if (!parsed.problemId) {
29
+ parsed.problemId = token;
30
+ continue;
31
+ }
32
+ return { error: `Unknown graph-theory option: ${token}` };
33
+ }
34
+ return parsed;
35
+ }
36
+
37
+ function printStatus(snapshot) {
38
+ console.log(`${snapshot.displayName} graph-theory harness`);
39
+ console.log(`Family role: ${snapshot.familyRole}`);
40
+ console.log(`Harness profile: ${snapshot.harnessProfile}`);
41
+ console.log(`Site status: ${snapshot.siteStatus}`);
42
+ console.log(`Archive mode: ${snapshot.archiveMode ?? '(none)'}`);
43
+ console.log(`Active route: ${snapshot.activeRoute ?? '(none)'}`);
44
+ console.log(`Route breakthrough: ${snapshot.routeBreakthrough ? 'yes' : 'no'}`);
45
+ console.log(`Open problem: ${snapshot.openProblem ? 'yes' : 'no'}`);
46
+ console.log(`Problem solved: ${snapshot.problemSolved ? 'yes' : 'no'}`);
47
+ console.log(`Frontier label: ${snapshot.frontierLabel}`);
48
+ console.log(`Frontier detail: ${snapshot.frontierDetail}`);
49
+ console.log(`Checkpoint focus: ${snapshot.checkpointFocus ?? '(none)'}`);
50
+ console.log(`Next honest move: ${snapshot.nextHonestMove}`);
51
+ console.log(`Route packet present: ${snapshot.routePacketPresent ? 'yes' : 'no'}`);
52
+ if (snapshot.routePacket?.route_packet_id) {
53
+ console.log(`Route packet id: ${snapshot.routePacket.route_packet_id}`);
54
+ }
55
+ console.log(`Frontier note: ${snapshot.frontierNotePresent ? snapshot.frontierNotePath : '(missing)'}`);
56
+ console.log(`Route history: ${snapshot.routeHistoryPresent ? snapshot.routeHistoryPath : '(missing)'}`);
57
+ console.log(`Checkpoint template: ${snapshot.checkpointTemplatePresent ? snapshot.checkpointTemplatePath : '(missing)'}`);
58
+ console.log(`Report template: ${snapshot.reportTemplatePresent ? snapshot.reportTemplatePath : '(missing)'}`);
59
+ console.log(`Active ticket: ${snapshot.activeTicketDetail?.ticket_id ?? '(none)'}`);
60
+ console.log(`Ready atoms: ${snapshot.readyAtomCount}`);
61
+ if (snapshot.firstReadyAtom) {
62
+ console.log(`First ready atom: ${snapshot.firstReadyAtom.atom_id} — ${snapshot.firstReadyAtom.title}`);
63
+ }
64
+ }
65
+
66
+ function printFrontier(snapshot) {
67
+ console.log(`${snapshot.displayName} graph-theory frontier`);
68
+ console.log(`Active route: ${snapshot.activeRoute ?? '(none)'}`);
69
+ console.log(`Frontier label: ${snapshot.frontierLabel}`);
70
+ console.log(`Frontier detail: ${snapshot.frontierDetail}`);
71
+ console.log(`Archive mode: ${snapshot.archiveMode ?? '(none)'}`);
72
+ console.log(`Next honest move: ${snapshot.nextHonestMove}`);
73
+ }
74
+
75
+ function printRoutes(snapshot) {
76
+ console.log(`${snapshot.displayName} graph-theory routes`);
77
+ console.log(`Active route: ${snapshot.activeRoute ?? '(none)'}`);
78
+ if (!snapshot.opsDetails?.routes?.length) {
79
+ console.log('Routes: none recorded.');
80
+ return;
81
+ }
82
+ for (const route of snapshot.opsDetails.routes) {
83
+ const flags = [];
84
+ if (route.route_id === snapshot.activeRoute) {
85
+ flags.push('active');
86
+ }
87
+ if (route.status && !flags.includes(route.status)) {
88
+ flags.push(route.status);
89
+ }
90
+ console.log(`- ${route.route_id}${flags.length ? ` [${flags.join(', ')}]` : ''}`);
91
+ if (route.title) {
92
+ console.log(` title: ${route.title}`);
93
+ }
94
+ if (route.summary) {
95
+ console.log(` summary: ${route.summary}`);
96
+ }
97
+ if (route.why_now) {
98
+ console.log(` why now: ${route.why_now}`);
99
+ }
100
+ if (route.next_move) {
101
+ console.log(` next move: ${route.next_move}`);
102
+ }
103
+ }
104
+ }
105
+
106
+ function printTickets(snapshot) {
107
+ console.log(`${snapshot.displayName} graph-theory tickets`);
108
+ console.log(`Active ticket: ${snapshot.activeTicketDetail?.ticket_id ?? '(none)'}`);
109
+ if (!snapshot.opsDetails?.tickets?.length) {
110
+ console.log('Tickets: none recorded.');
111
+ return;
112
+ }
113
+ for (const ticket of snapshot.opsDetails.tickets) {
114
+ const flags = [];
115
+ if (ticket.ticket_id === snapshot.activeTicketDetail?.ticket_id) {
116
+ flags.push('active');
117
+ }
118
+ if (ticket.status && !flags.includes(ticket.status)) {
119
+ flags.push(ticket.status);
120
+ }
121
+ console.log(`- ${ticket.ticket_id}${flags.length ? ` [${flags.join(', ')}]` : ''}`);
122
+ if (ticket.title) {
123
+ console.log(` title: ${ticket.title}`);
124
+ }
125
+ if (ticket.summary) {
126
+ console.log(` summary: ${ticket.summary}`);
127
+ }
128
+ if (ticket.current_blocker) {
129
+ console.log(` blocker: ${ticket.current_blocker}`);
130
+ }
131
+ if (ticket.next_move) {
132
+ console.log(` next move: ${ticket.next_move}`);
133
+ }
134
+ }
135
+ }
136
+
137
+ export function runGraphTheoryCommand(args) {
138
+ const [subcommand, ...rest] = args;
139
+ if (!subcommand || subcommand === 'help' || subcommand === '--help') {
140
+ console.log('Usage:');
141
+ console.log(' erdos graph-theory status [<id>] [--json]');
142
+ console.log(' erdos graph-theory frontier [<id>] [--json]');
143
+ console.log(' erdos graph-theory routes [<id>] [--json]');
144
+ console.log(' erdos graph-theory tickets [<id>] [--json]');
145
+ return 0;
146
+ }
147
+ if (!['status', 'frontier', 'routes', 'tickets'].includes(subcommand)) {
148
+ console.error(`Unknown graph-theory subcommand: ${subcommand}`);
149
+ return 1;
150
+ }
151
+ const parsed = parseArgs(rest);
152
+ if (parsed.error) {
153
+ console.error(parsed.error);
154
+ return 1;
155
+ }
156
+ const { problem, error } = resolveGraphTheoryProblem(parsed.problemId);
157
+ if (error) {
158
+ console.error(error);
159
+ return 1;
160
+ }
161
+ const snapshot = buildGraphTheoryStatusSnapshot(problem);
162
+ if (parsed.asJson) {
163
+ console.log(JSON.stringify(snapshot, null, 2));
164
+ return 0;
165
+ }
166
+ if (subcommand === 'frontier') {
167
+ printFrontier(snapshot);
168
+ return 0;
169
+ }
170
+ if (subcommand === 'routes') {
171
+ printRoutes(snapshot);
172
+ return 0;
173
+ }
174
+ if (subcommand === 'tickets') {
175
+ printTickets(snapshot);
176
+ return 0;
177
+ }
178
+ printStatus(snapshot);
179
+ return 0;
180
+ }
@@ -1,5 +1,10 @@
1
1
  import { getProblem } from '../atlas/catalog.js';
2
- import { buildNumberTheoryStatusSnapshot } from '../runtime/number-theory.js';
2
+ import {
3
+ buildNumberTheoryStatusSnapshot,
4
+ getNumberTheoryAtomSnapshot,
5
+ getNumberTheoryRouteSnapshot,
6
+ getNumberTheoryTicketSnapshot,
7
+ } from '../runtime/number-theory.js';
3
8
  import { readCurrentProblem } from '../runtime/workspace.js';
4
9
 
5
10
  function resolveNumberTheoryProblem(problemId) {
@@ -24,6 +29,7 @@ function parseArgs(args) {
24
29
  const parsed = {
25
30
  problemId: null,
26
31
  asJson: false,
32
+ entityId: null,
27
33
  };
28
34
 
29
35
  for (const token of args) {
@@ -35,6 +41,10 @@ function parseArgs(args) {
35
41
  parsed.problemId = token;
36
42
  continue;
37
43
  }
44
+ if (!parsed.entityId) {
45
+ parsed.entityId = token;
46
+ continue;
47
+ }
38
48
  return { error: `Unknown number-theory option: ${token}` };
39
49
  }
40
50
 
@@ -146,6 +156,44 @@ function printTickets(snapshot) {
146
156
  }
147
157
  }
148
158
 
159
+ function printRouteDetail(snapshot) {
160
+ const route = snapshot.routeDetail;
161
+ console.log(`${snapshot.displayName} number-theory route ${snapshot.routeId}`);
162
+ console.log(`Title: ${route.title ?? snapshot.routeId}`);
163
+ console.log(`Status: ${route.status ?? '(unknown)'}`);
164
+ console.log(`Active route: ${route.route_id === snapshot.activeRoute ? 'yes' : 'no'}`);
165
+ console.log(`Summary: ${route.summary ?? '(none)'}`);
166
+ console.log(`Why now: ${route.why_now ?? '(none)'}`);
167
+ console.log(`Next move: ${route.next_move ?? '(none)'}`);
168
+ if (Array.isArray(route.ticket_ids) && route.ticket_ids.length > 0) {
169
+ console.log(`Tickets: ${route.ticket_ids.join(', ')}`);
170
+ }
171
+ }
172
+
173
+ function printTicketDetail(snapshot) {
174
+ const ticket = snapshot.ticketDetail;
175
+ console.log(`${snapshot.displayName} number-theory ticket ${snapshot.ticketId}`);
176
+ console.log(`Title: ${ticket.title ?? snapshot.ticketId}`);
177
+ console.log(`Status: ${ticket.status ?? '(unknown)'}`);
178
+ console.log(`Active ticket: ${ticket.ticket_id === snapshot.activeTicketDetail?.ticket_id ? 'yes' : 'no'}`);
179
+ console.log(`Summary: ${ticket.summary ?? '(none)'}`);
180
+ console.log(`Current blocker: ${ticket.current_blocker ?? '(none)'}`);
181
+ console.log(`Next move: ${ticket.next_move ?? '(none)'}`);
182
+ if (Array.isArray(ticket.atom_ids) && ticket.atom_ids.length > 0) {
183
+ console.log(`Atoms: ${ticket.atom_ids.join(', ')}`);
184
+ }
185
+ }
186
+
187
+ function printAtomDetail(snapshot) {
188
+ const atom = snapshot.atomDetail;
189
+ console.log(`${snapshot.displayName} number-theory atom ${snapshot.atomId}`);
190
+ console.log(`Title: ${atom.title ?? snapshot.atomId}`);
191
+ console.log(`Status: ${atom.status ?? '(unknown)'}`);
192
+ console.log(`Current frontier atom: ${atom.atom_id === snapshot.firstReadyAtom?.atom_id ? 'yes' : 'no'}`);
193
+ console.log(`Summary: ${atom.summary ?? '(none)'}`);
194
+ console.log(`Next move: ${atom.next_move ?? '(none)'}`);
195
+ }
196
+
149
197
  export function runNumberTheoryCommand(args) {
150
198
  const [subcommand, ...rest] = args;
151
199
 
@@ -155,10 +203,13 @@ export function runNumberTheoryCommand(args) {
155
203
  console.log(' erdos number-theory frontier [<id>] [--json]');
156
204
  console.log(' erdos number-theory routes [<id>] [--json]');
157
205
  console.log(' erdos number-theory tickets [<id>] [--json]');
206
+ console.log(' erdos number-theory route <problem-id> <route-id> [--json]');
207
+ console.log(' erdos number-theory ticket <problem-id> <ticket-id> [--json]');
208
+ console.log(' erdos number-theory atom <problem-id> <atom-id> [--json]');
158
209
  return 0;
159
210
  }
160
211
 
161
- if (!['status', 'frontier', 'routes', 'tickets'].includes(subcommand)) {
212
+ if (!['status', 'frontier', 'routes', 'tickets', 'route', 'ticket', 'atom'].includes(subcommand)) {
162
213
  console.error(`Unknown number-theory subcommand: ${subcommand}`);
163
214
  return 1;
164
215
  }
@@ -175,6 +226,60 @@ export function runNumberTheoryCommand(args) {
175
226
  return 1;
176
227
  }
177
228
 
229
+ if (subcommand === 'route') {
230
+ if (!parsed.entityId) {
231
+ console.error('Missing route id.');
232
+ return 1;
233
+ }
234
+ const snapshot = getNumberTheoryRouteSnapshot(problem, parsed.entityId);
235
+ if (!snapshot) {
236
+ console.error(`Unknown number-theory route: ${parsed.entityId}`);
237
+ return 1;
238
+ }
239
+ if (parsed.asJson) {
240
+ console.log(JSON.stringify(snapshot, null, 2));
241
+ return 0;
242
+ }
243
+ printRouteDetail(snapshot);
244
+ return 0;
245
+ }
246
+
247
+ if (subcommand === 'ticket') {
248
+ if (!parsed.entityId) {
249
+ console.error('Missing ticket id.');
250
+ return 1;
251
+ }
252
+ const snapshot = getNumberTheoryTicketSnapshot(problem, parsed.entityId);
253
+ if (!snapshot) {
254
+ console.error(`Unknown number-theory ticket: ${parsed.entityId}`);
255
+ return 1;
256
+ }
257
+ if (parsed.asJson) {
258
+ console.log(JSON.stringify(snapshot, null, 2));
259
+ return 0;
260
+ }
261
+ printTicketDetail(snapshot);
262
+ return 0;
263
+ }
264
+
265
+ if (subcommand === 'atom') {
266
+ if (!parsed.entityId) {
267
+ console.error('Missing atom id.');
268
+ return 1;
269
+ }
270
+ const snapshot = getNumberTheoryAtomSnapshot(problem, parsed.entityId);
271
+ if (!snapshot) {
272
+ console.error(`Unknown number-theory atom: ${parsed.entityId}`);
273
+ return 1;
274
+ }
275
+ if (parsed.asJson) {
276
+ console.log(JSON.stringify(snapshot, null, 2));
277
+ return 0;
278
+ }
279
+ printAtomDetail(snapshot);
280
+ return 0;
281
+ }
282
+
178
283
  const snapshot = buildNumberTheoryStatusSnapshot(problem);
179
284
  if (parsed.asJson) {
180
285
  console.log(JSON.stringify(snapshot, null, 2));
@@ -1,11 +1,12 @@
1
1
  import { getProblem } from '../atlas/catalog.js';
2
2
  import { loadConfig } from '../runtime/config.js';
3
+ import { buildGraphTheoryStatusSnapshot } from '../runtime/graph-theory.js';
3
4
  import { buildNumberTheoryStatusSnapshot } from '../runtime/number-theory.js';
4
5
  import { buildSunflowerStatusSnapshot } from '../runtime/sunflower.js';
5
6
  import { getWorkspaceSummary } from '../runtime/workspace.js';
6
7
 
7
8
  export function runWorkspaceCommand(args) {
8
- const [subcommand] = args;
9
+ const [subcommand, ...rest] = args;
9
10
 
10
11
  if (!subcommand || subcommand === 'help' || subcommand === '--help') {
11
12
  console.log('Usage:');
@@ -18,8 +19,30 @@ export function runWorkspaceCommand(args) {
18
19
  return 1;
19
20
  }
20
21
 
22
+ const asJson = rest.includes('--json');
23
+
21
24
  const summary = getWorkspaceSummary();
22
25
  const config = loadConfig();
26
+ if (asJson) {
27
+ const payload = {
28
+ ...summary,
29
+ preferredAgent: config.preferredAgent,
30
+ };
31
+ if (summary.activeProblem) {
32
+ const problem = getProblem(summary.activeProblem);
33
+ if (problem?.cluster === 'sunflower') {
34
+ payload.sunflower = buildSunflowerStatusSnapshot(problem);
35
+ }
36
+ if (problem?.cluster === 'number-theory') {
37
+ payload.numberTheory = buildNumberTheoryStatusSnapshot(problem);
38
+ }
39
+ if (problem?.cluster === 'graph-theory') {
40
+ payload.graphTheory = buildGraphTheoryStatusSnapshot(problem);
41
+ }
42
+ }
43
+ console.log(JSON.stringify(payload, null, 2));
44
+ return 0;
45
+ }
23
46
  console.log(`Workspace root: ${summary.workspaceRoot}`);
24
47
  console.log(`State dir: ${summary.stateDir}`);
25
48
  console.log(`Initialized: ${summary.hasState ? 'yes' : 'no'}`);
@@ -92,6 +115,21 @@ export function runWorkspaceCommand(args) {
92
115
  console.log(`Number-theory first ready atom: ${numberTheory.firstReadyAtom.atom_id} — ${numberTheory.firstReadyAtom.title}`);
93
116
  }
94
117
  }
118
+ if (problem?.cluster === 'graph-theory') {
119
+ const graphTheory = buildGraphTheoryStatusSnapshot(problem);
120
+ console.log(`Graph-theory family role: ${graphTheory.familyRole ?? '(none)'}`);
121
+ console.log(`Graph-theory harness profile: ${graphTheory.harnessProfile ?? '(none)'}`);
122
+ console.log(`Graph-theory route: ${graphTheory.activeRoute ?? '(none)'}`);
123
+ console.log(`Graph-theory frontier: ${graphTheory.frontierDetail ?? '(none)'}`);
124
+ console.log(`Graph-theory frontier note: ${graphTheory.frontierNotePath ?? '(none)'}`);
125
+ console.log(`Graph-theory route history: ${graphTheory.routeHistoryPath ?? '(none)'}`);
126
+ console.log(`Graph-theory archive mode: ${graphTheory.archiveMode ?? '(none)'}`);
127
+ console.log(`Graph-theory active ticket: ${graphTheory.activeTicketDetail?.ticket_id ?? '(none)'}`);
128
+ console.log(`Graph-theory ready atoms: ${graphTheory.readyAtomCount}`);
129
+ if (graphTheory.firstReadyAtom) {
130
+ console.log(`Graph-theory first ready atom: ${graphTheory.firstReadyAtom.atom_id} — ${graphTheory.firstReadyAtom.title}`);
131
+ }
132
+ }
95
133
  }
96
134
  return 0;
97
135
  }
@@ -0,0 +1,167 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { parse } from 'yaml';
4
+ import { getPackProblemDir } from './paths.js';
5
+
6
+ function readYamlIfPresent(filePath) {
7
+ if (!fs.existsSync(filePath)) {
8
+ return null;
9
+ }
10
+ return parse(fs.readFileSync(filePath, 'utf8'));
11
+ }
12
+
13
+ function getPackFile(problemId, fileName) {
14
+ return path.join(getPackProblemDir('graph-theory', problemId), fileName);
15
+ }
16
+
17
+ function normalizeQuestionLedger(rawLedger) {
18
+ return {
19
+ openQuestions: rawLedger?.open_questions ?? [],
20
+ activeRouteNotes: rawLedger?.active_route_notes ?? [],
21
+ routeBreakthroughs: rawLedger?.route_breakthroughs ?? [],
22
+ problemSolved: rawLedger?.problem_solved ?? [],
23
+ };
24
+ }
25
+
26
+ function parseOpsDetails(problemId) {
27
+ const opsDetailsPath = getPackFile(problemId, 'OPS_DETAILS.yaml');
28
+ const payload = readYamlIfPresent(opsDetailsPath);
29
+ if (!payload) {
30
+ return null;
31
+ }
32
+ return {
33
+ packetId: payload.packet_id ?? null,
34
+ summary: payload.summary ?? null,
35
+ path: opsDetailsPath,
36
+ routes: payload.routes ?? [],
37
+ tickets: payload.tickets ?? [],
38
+ atoms: payload.atoms ?? [],
39
+ };
40
+ }
41
+
42
+ function findRouteDetail(opsDetails, routeId) {
43
+ if (!opsDetails || !Array.isArray(opsDetails.routes)) {
44
+ return null;
45
+ }
46
+ return opsDetails.routes.find((route) => route.route_id === routeId) ?? null;
47
+ }
48
+
49
+ function firstMatching(items, predicate) {
50
+ if (!Array.isArray(items)) {
51
+ return null;
52
+ }
53
+ return items.find(predicate) ?? items[0] ?? null;
54
+ }
55
+
56
+ function resolveArchiveMode(problem) {
57
+ const siteStatus = String(problem.siteStatus ?? '').toLowerCase();
58
+ if (siteStatus === 'solved') {
59
+ return 'method_exemplar';
60
+ }
61
+ if (siteStatus === 'proved' || siteStatus === 'proved (lean)') {
62
+ return 'proof_archive';
63
+ }
64
+ if (siteStatus === 'decidable') {
65
+ return 'decision_archive';
66
+ }
67
+ return null;
68
+ }
69
+
70
+ function solvedLikeSiteStatus(problem) {
71
+ const siteStatus = String(problem.siteStatus ?? '').toLowerCase();
72
+ return siteStatus === 'solved' || siteStatus === 'proved' || siteStatus === 'proved (lean)';
73
+ }
74
+
75
+ export function buildGraphTheoryStatusSnapshot(problem) {
76
+ const contextPath = getPackFile(problem.problemId, 'context.yaml');
77
+ const contextMarkdownPath = getPackFile(problem.problemId, 'CONTEXT.md');
78
+ const routePacketPath = getPackFile(problem.problemId, 'ROUTE_PACKET.yaml');
79
+ const frontierNotePath = getPackFile(problem.problemId, 'FRONTIER_NOTE.md');
80
+ const routeHistoryPath = getPackFile(problem.problemId, 'ROUTE_HISTORY.md');
81
+ const checkpointTemplatePath = getPackFile(problem.problemId, 'CHECKPOINT_TEMPLATE.md');
82
+ const reportTemplatePath = getPackFile(problem.problemId, 'REPORT_TEMPLATE.md');
83
+
84
+ const context = readYamlIfPresent(contextPath) ?? {};
85
+ const routePacket = readYamlIfPresent(routePacketPath);
86
+ const opsDetails = parseOpsDetails(problem.problemId);
87
+
88
+ const activeRoute =
89
+ problem.researchState?.active_route
90
+ ?? context.default_active_route
91
+ ?? routePacket?.route_id
92
+ ?? null;
93
+ const archiveMode = resolveArchiveMode(problem);
94
+ const problemSolved = typeof problem.researchState?.problem_solved === 'boolean'
95
+ ? problem.researchState.problem_solved
96
+ : solvedLikeSiteStatus(problem);
97
+ const openProblem = typeof problem.researchState?.open_problem === 'boolean'
98
+ ? problem.researchState.open_problem
99
+ : String(problem.siteStatus ?? '').toLowerCase() === 'open';
100
+ const routeBreakthrough = typeof problem.researchState?.route_breakthrough === 'boolean'
101
+ ? problem.researchState.route_breakthrough
102
+ : problemSolved;
103
+
104
+ const activeRouteDetail = findRouteDetail(opsDetails, activeRoute) ?? firstMatching(opsDetails?.routes, () => true);
105
+ const activeTicketDetail = firstMatching(
106
+ opsDetails?.tickets,
107
+ (ticket) => ticket.status === 'active' && (!activeRoute || ticket.route_id === activeRoute),
108
+ );
109
+ const firstReadyAtom = firstMatching(
110
+ opsDetails?.atoms,
111
+ (atom) => atom.status === 'ready' && (!activeRoute || atom.route_id === activeRoute),
112
+ );
113
+ const readyAtoms = Array.isArray(opsDetails?.atoms)
114
+ ? opsDetails.atoms.filter((atom) => atom.status === 'ready')
115
+ : [];
116
+
117
+ return {
118
+ generatedAt: new Date().toISOString(),
119
+ problemId: problem.problemId,
120
+ displayName: problem.displayName,
121
+ title: problem.title,
122
+ cluster: problem.cluster,
123
+ familyRole: context.family_role ?? 'graph_theory_pack',
124
+ harnessProfile: context.harness_profile ?? 'starter_cockpit',
125
+ activeRoute,
126
+ routeBreakthrough,
127
+ problemSolved,
128
+ openProblem,
129
+ siteStatus: problem.siteStatus,
130
+ archiveMode,
131
+ bootstrapFocus: context.bootstrap_focus ?? null,
132
+ routeStory: context.route_story ?? routePacket?.frontier_claim ?? problem.shortStatement,
133
+ frontierLabel: context.frontier_label ?? activeRoute ?? 'graph_theory_frontier',
134
+ frontierDetail: firstReadyAtom?.summary ?? context.frontier_detail ?? activeRouteDetail?.summary ?? problem.shortStatement,
135
+ checkpointFocus: context.checkpoint_focus ?? activeRouteDetail?.why_now ?? null,
136
+ nextHonestMove:
137
+ firstReadyAtom?.next_move
138
+ ?? activeTicketDetail?.next_move
139
+ ?? context.next_honest_move
140
+ ?? 'Freeze the current graph-theory packet without widening status claims.',
141
+ relatedCoreProblems: context.related_core_problems ?? [],
142
+ literatureFocus: context.literature_focus ?? [],
143
+ artifactFocus: context.artifact_focus ?? [],
144
+ questionLedger: normalizeQuestionLedger(context.question_ledger),
145
+ contextPresent: fs.existsSync(contextPath),
146
+ contextPath,
147
+ contextMarkdownPath,
148
+ routePacketPresent: Boolean(routePacket),
149
+ routePacket,
150
+ routePacketPath,
151
+ frontierNotePresent: fs.existsSync(frontierNotePath),
152
+ frontierNotePath,
153
+ routeHistoryPresent: fs.existsSync(routeHistoryPath),
154
+ routeHistoryPath,
155
+ checkpointTemplatePresent: fs.existsSync(checkpointTemplatePath),
156
+ checkpointTemplatePath,
157
+ reportTemplatePresent: fs.existsSync(reportTemplatePath),
158
+ reportTemplatePath,
159
+ opsDetailsPresent: Boolean(opsDetails),
160
+ opsDetailsPath: opsDetails?.path ?? getPackFile(problem.problemId, 'OPS_DETAILS.yaml'),
161
+ opsDetails,
162
+ activeRouteDetail,
163
+ activeTicketDetail,
164
+ firstReadyAtom,
165
+ readyAtomCount: readyAtoms.length,
166
+ };
167
+ }
@@ -39,6 +39,27 @@ function parseOpsDetails(problemId) {
39
39
  };
40
40
  }
41
41
 
42
+ function findRouteDetail(opsDetails, routeId) {
43
+ if (!opsDetails || !Array.isArray(opsDetails.routes)) {
44
+ return null;
45
+ }
46
+ return opsDetails.routes.find((route) => route.route_id === routeId) ?? null;
47
+ }
48
+
49
+ function findTicketDetail(opsDetails, ticketId) {
50
+ if (!opsDetails || !Array.isArray(opsDetails.tickets)) {
51
+ return null;
52
+ }
53
+ return opsDetails.tickets.find((ticket) => ticket.ticket_id === ticketId) ?? null;
54
+ }
55
+
56
+ function findAtomDetail(opsDetails, atomId) {
57
+ if (!opsDetails || !Array.isArray(opsDetails.atoms)) {
58
+ return null;
59
+ }
60
+ return opsDetails.atoms.find((atom) => atom.atom_id === atomId) ?? null;
61
+ }
62
+
42
63
  function findActiveRouteDetail(opsDetails, activeRoute) {
43
64
  if (!opsDetails || !Array.isArray(opsDetails.routes)) {
44
65
  return null;
@@ -167,3 +188,42 @@ export function buildNumberTheoryStatusSnapshot(problem) {
167
188
  readyAtomCount: readyAtoms.length,
168
189
  };
169
190
  }
191
+
192
+ export function getNumberTheoryRouteSnapshot(problem, routeId) {
193
+ const snapshot = buildNumberTheoryStatusSnapshot(problem);
194
+ const routeDetail = findRouteDetail(snapshot.opsDetails, routeId);
195
+ if (!routeDetail) {
196
+ return null;
197
+ }
198
+ return {
199
+ ...snapshot,
200
+ routeId,
201
+ routeDetail,
202
+ };
203
+ }
204
+
205
+ export function getNumberTheoryTicketSnapshot(problem, ticketId) {
206
+ const snapshot = buildNumberTheoryStatusSnapshot(problem);
207
+ const ticketDetail = findTicketDetail(snapshot.opsDetails, ticketId);
208
+ if (!ticketDetail) {
209
+ return null;
210
+ }
211
+ return {
212
+ ...snapshot,
213
+ ticketId,
214
+ ticketDetail,
215
+ };
216
+ }
217
+
218
+ export function getNumberTheoryAtomSnapshot(problem, atomId) {
219
+ const snapshot = buildNumberTheoryStatusSnapshot(problem);
220
+ const atomDetail = findAtomDetail(snapshot.opsDetails, atomId);
221
+ if (!atomDetail) {
222
+ return null;
223
+ }
224
+ return {
225
+ ...snapshot,
226
+ atomId,
227
+ atomDetail,
228
+ };
229
+ }
@@ -1,6 +1,7 @@
1
1
  import { getProblem } from '../atlas/catalog.js';
2
2
  import { ensureConfig, loadConfig } from './config.js';
3
3
  import { fileExists, readJson, writeJson, writeText } from './files.js';
4
+ import { buildGraphTheoryStatusSnapshot } from './graph-theory.js';
4
5
  import {
5
6
  getWorkspaceQuestionLedgerPath,
6
7
  getWorkspaceRoot,
@@ -249,6 +250,36 @@ function deriveProblemSummary(problem) {
249
250
  };
250
251
  }
251
252
 
253
+ if (problem.cluster === 'graph-theory') {
254
+ const snapshot = buildGraphTheoryStatusSnapshot(problem);
255
+ return {
256
+ familyRole: snapshot.familyRole,
257
+ harnessProfile: snapshot.harnessProfile,
258
+ activeRoute: snapshot.activeRoute,
259
+ routeBreakthrough: snapshot.routeBreakthrough,
260
+ problemSolved: snapshot.problemSolved,
261
+ openProblem: snapshot.openProblem,
262
+ currentFrontier: {
263
+ kind: snapshot.firstReadyAtom ? 'ready_atom' : 'route_frontier',
264
+ detail: snapshot.firstReadyAtom
265
+ ? `${snapshot.firstReadyAtom.atom_id} — ${snapshot.firstReadyAtom.title}`
266
+ : snapshot.frontierDetail,
267
+ },
268
+ routeStory: snapshot.activeRouteDetail?.summary || snapshot.routeStory,
269
+ checkpointFocus: snapshot.checkpointFocus,
270
+ nextHonestMove: snapshot.nextHonestMove,
271
+ packArtifacts: {
272
+ frontierNotePath: snapshot.frontierNotePath,
273
+ routeHistoryPath: snapshot.routeHistoryPath,
274
+ checkpointTemplatePath: snapshot.checkpointTemplatePath,
275
+ reportTemplatePath: snapshot.reportTemplatePath,
276
+ },
277
+ activeTicketId: snapshot.activeTicketDetail?.ticket_id ?? null,
278
+ activeAtomId: snapshot.firstReadyAtom?.atom_id ?? null,
279
+ questionLedger: snapshot.questionLedger,
280
+ };
281
+ }
282
+
252
283
  return deriveGenericProblemSummary(problem);
253
284
  }
254
285