refactor(packages): extract boulder-state package

This commit is contained in:
YeonGyu-Kim
2026-05-21 01:19:16 +09:00
parent 7028c1f40a
commit f7ceb03efe
24 changed files with 1228 additions and 1177 deletions
+8 -13
View File
@@ -1,13 +1,8 @@
/**
* Boulder State Constants
*/
export const BOULDER_DIR = ".omo"
export const BOULDER_FILE = "boulder.json"
export const BOULDER_STATE_PATH = `${BOULDER_DIR}/${BOULDER_FILE}`
export const NOTEPAD_DIR = "notepads"
export const NOTEPAD_BASE_PATH = `${BOULDER_DIR}/${NOTEPAD_DIR}`
/** Prometheus plan directory pattern */
export const PROMETHEUS_PLANS_DIR = ".omo/plans"
export {
BOULDER_DIR,
BOULDER_FILE,
BOULDER_STATE_PATH,
NOTEPAD_BASE_PATH,
NOTEPAD_DIR,
PROMETHEUS_PLANS_DIR,
} from "@oh-my-opencode/boulder-state"
File diff suppressed because it is too large Load Diff
+1 -78
View File
@@ -1,78 +1 @@
import { existsSync, readFileSync } from "node:fs"
import type { TopLevelTaskRef } from "./types"
const TODO_HEADING_PATTERN = /^##\s+TODOs\b/i
const FINAL_VERIFICATION_HEADING_PATTERN = /^##\s+Final Verification Wave\b/i
const SECOND_LEVEL_HEADING_PATTERN = /^##\s+/
const UNCHECKED_CHECKBOX_PATTERN = /^(\s*)[-*]\s*\[\s*\]\s*(.+)$/
const CHECKED_CHECKBOX_PATTERN = /^(\s*)[-*]\s*\[[xX]\]\s*(.+)$/
const TODO_TASK_PATTERN = /^(\d+)\.\s+(.+)$/
const FINAL_WAVE_TASK_PATTERN = /^(F\d+)\.\s+(.+)$/i
type PlanSection = "todo" | "final-wave" | "other"
function buildTaskRef(
section: "todo" | "final-wave",
taskLabel: string,
): TopLevelTaskRef | null {
const pattern = section === "todo" ? TODO_TASK_PATTERN : FINAL_WAVE_TASK_PATTERN
const match = taskLabel.match(pattern)
if (!match) {
return null
}
const rawLabel = match[1]
const title = match[2].trim()
return {
key: `${section}:${rawLabel.toLowerCase()}`,
section,
label: rawLabel,
title,
}
}
export function readCurrentTopLevelTask(planPath: string): TopLevelTaskRef | null {
if (!existsSync(planPath)) {
return null
}
try {
const content = readFileSync(planPath, "utf-8")
const lines = content.split(/\r?\n/)
let section: PlanSection = "other"
for (const line of lines) {
if (SECOND_LEVEL_HEADING_PATTERN.test(line)) {
section = TODO_HEADING_PATTERN.test(line)
? "todo"
: FINAL_VERIFICATION_HEADING_PATTERN.test(line)
? "final-wave"
: "other"
}
const uncheckedTaskMatch = line.match(UNCHECKED_CHECKBOX_PATTERN)
if (!uncheckedTaskMatch) {
continue
}
if (uncheckedTaskMatch[1].length > 0) {
continue
}
if (section !== "todo" && section !== "final-wave") {
continue
}
const taskRef = buildTaskRef(section, uncheckedTaskMatch[2].trim())
if (taskRef) {
return taskRef
}
}
return null
} catch {
return null
}
}
export { readCurrentTopLevelTask } from "@oh-my-opencode/boulder-state"
+11 -107
View File
@@ -1,107 +1,11 @@
/**
* Boulder State Types
*
* Manages the active work plan state for Sisyphus orchestrator.
* Named after Sisyphus's boulder - the eternal task that must be rolled.
*/
export interface BoulderState {
schema_version?: 2
active_work_id?: string
works?: Record<string, BoulderWorkState>
/** Absolute path to the active plan file */
active_plan: string
/** ISO timestamp when work started */
started_at: string
ended_at?: string
elapsed_ms?: number
status?: BoulderWorkStatus
updated_at?: string
/** Session IDs that have worked on this plan */
session_ids: string[]
session_origins?: Record<string, "direct" | "appended">
/** Plan name derived from filename */
plan_name: string
/** Agent type to use when resuming (e.g., 'atlas') */
agent?: string
/** Absolute path to the git worktree root where work happens */
worktree_path?: string
/** Preferred reusable subagent sessions keyed by current top-level plan task */
task_sessions?: Record<string, TaskSessionState>
}
export type BoulderSessionOrigin = "direct" | "appended"
export type BoulderWorkStatus = "active" | "completed" | "paused" | "abandoned"
export type BoulderTaskStatus = "running" | "completed" | "cancelled"
export interface BoulderWorkState {
work_id: string
active_plan: string
plan_name: string
status?: BoulderWorkStatus
started_at: string
ended_at?: string
elapsed_ms?: number
updated_at?: string
session_ids: string[]
session_origins?: Record<string, BoulderSessionOrigin>
agent?: string
worktree_path?: string
task_sessions?: Record<string, TaskSessionState>
}
export interface PlanProgress {
/** Total number of checkboxes */
total: number
/** Number of completed checkboxes */
completed: number
/** Whether all tasks are done */
isComplete: boolean
}
export interface TaskSessionState {
/** Stable identifier for the current top-level plan task (e.g. todo:1 / final-wave:F1) */
task_key: string
/** Original task label from the plan file */
task_label: string
/** Full task title from the plan file */
task_title: string
/** Preferred reusable subagent session */
session_id: string
/** Agent associated with the task session, when known */
agent?: string
/** Category associated with the task session, when known */
category?: string
started_at?: string
ended_at?: string
elapsed_ms?: number
status?: BoulderTaskStatus
/** Last update timestamp */
updated_at: string
}
export interface BoulderWorkResumeOption {
work_id: string
plan_name: string
active_plan: string
worktree_path?: string
status: BoulderWorkStatus
started_at: string
updated_at: string
ended_at?: string
elapsed_ms?: number
session_count: number
progress: PlanProgress
is_current_mirror: boolean
}
export interface TopLevelTaskRef {
/** Stable identifier for the current top-level plan task */
key: string
/** Task section in the Prometheus plan */
section: "todo" | "final-wave"
/** Original label token (e.g. 1 / F1) */
label: string
/** Full task title extracted from the checkbox line */
title: string
}
export type {
BoulderSessionOrigin,
BoulderState,
BoulderTaskStatus,
BoulderWorkResumeOption,
BoulderWorkState,
BoulderWorkStatus,
PlanProgress,
TaskSessionState,
TopLevelTaskRef,
} from "@oh-my-opencode/boulder-state"