@anhlp/alp-core 0.0.0-beta.1

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 (144) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +7 -0
  3. package/README.md +7 -0
  4. package/dist/adapter.d.ts +20 -0
  5. package/dist/adapter.js +30 -0
  6. package/dist/atomic.d.ts +2 -0
  7. package/dist/atomic.js +28 -0
  8. package/dist/backup.d.ts +27 -0
  9. package/dist/backup.js +582 -0
  10. package/dist/beads.d.ts +65 -0
  11. package/dist/beads.js +213 -0
  12. package/dist/delegation.d.ts +2 -0
  13. package/dist/delegation.js +32 -0
  14. package/dist/errors.d.ts +4 -0
  15. package/dist/errors.js +11 -0
  16. package/dist/formulas.d.ts +25 -0
  17. package/dist/formulas.js +201 -0
  18. package/dist/hook-run.d.ts +44 -0
  19. package/dist/hook-run.js +60 -0
  20. package/dist/hooks.d.ts +35 -0
  21. package/dist/hooks.js +30 -0
  22. package/dist/index.d.ts +30 -0
  23. package/dist/index.js +63 -0
  24. package/dist/init.d.ts +30 -0
  25. package/dist/init.js +88 -0
  26. package/dist/library-edit.d.ts +90 -0
  27. package/dist/library-edit.js +315 -0
  28. package/dist/library.d.ts +28 -0
  29. package/dist/library.js +108 -0
  30. package/dist/log.d.ts +37 -0
  31. package/dist/log.js +156 -0
  32. package/dist/migrations.d.ts +9 -0
  33. package/dist/migrations.js +95 -0
  34. package/dist/models.d.ts +11 -0
  35. package/dist/models.js +44 -0
  36. package/dist/permissions.d.ts +14 -0
  37. package/dist/permissions.js +229 -0
  38. package/dist/profiles.d.ts +27 -0
  39. package/dist/profiles.js +122 -0
  40. package/dist/promptsafe.d.ts +1 -0
  41. package/dist/promptsafe.js +13 -0
  42. package/dist/providers.d.ts +90 -0
  43. package/dist/providers.js +101 -0
  44. package/dist/resolver.d.ts +41 -0
  45. package/dist/resolver.js +240 -0
  46. package/dist/safe-path.d.ts +2 -0
  47. package/dist/safe-path.js +24 -0
  48. package/dist/shell.d.ts +16 -0
  49. package/dist/shell.js +22 -0
  50. package/dist/state-schema.d.ts +9 -0
  51. package/dist/state-schema.js +54 -0
  52. package/dist/task-rows.d.ts +47 -0
  53. package/dist/task-rows.js +45 -0
  54. package/dist/tasks.d.ts +128 -0
  55. package/dist/tasks.js +835 -0
  56. package/dist/teams.d.ts +69 -0
  57. package/dist/teams.js +159 -0
  58. package/dist/template-path.d.ts +2 -0
  59. package/dist/template-path.js +10 -0
  60. package/dist/trust.d.ts +8 -0
  61. package/dist/trust.js +47 -0
  62. package/dist/types.d.ts +51 -0
  63. package/dist/upgrade.d.ts +10 -0
  64. package/dist/upgrade.js +200 -0
  65. package/dist/user-settings.d.ts +6 -0
  66. package/dist/user-settings.js +72 -0
  67. package/dist/validation.d.ts +17 -0
  68. package/dist/validation.js +295 -0
  69. package/dist/verify.d.ts +15 -0
  70. package/dist/verify.js +123 -0
  71. package/dist/workflow.d.ts +14 -0
  72. package/dist/workflow.js +24 -0
  73. package/package.json +309 -0
  74. package/src/adapter.d.ts +20 -0
  75. package/src/adapter.js +29 -0
  76. package/src/atomic.d.ts +2 -0
  77. package/src/atomic.js +28 -0
  78. package/src/backup.d.ts +27 -0
  79. package/src/backup.js +570 -0
  80. package/src/beads.js +236 -0
  81. package/src/delegation.js +28 -0
  82. package/src/errors.js +7 -0
  83. package/src/formulas.d.ts +25 -0
  84. package/src/formulas.js +202 -0
  85. package/src/hook-run.js +57 -0
  86. package/src/hooks.js +36 -0
  87. package/src/index.js +31 -0
  88. package/src/init.js +92 -0
  89. package/src/library-edit.js +346 -0
  90. package/src/library.js +117 -0
  91. package/src/log.d.ts +37 -0
  92. package/src/log.js +177 -0
  93. package/src/migrations.d.ts +9 -0
  94. package/src/migrations.js +111 -0
  95. package/src/models.js +45 -0
  96. package/src/permissions.d.ts +14 -0
  97. package/src/permissions.js +242 -0
  98. package/src/profiles.js +139 -0
  99. package/src/promptsafe.d.ts +1 -0
  100. package/src/promptsafe.js +19 -0
  101. package/src/providers.js +122 -0
  102. package/src/resolver.js +238 -0
  103. package/src/safe-path.js +20 -0
  104. package/src/shell.js +28 -0
  105. package/src/state-schema.d.ts +9 -0
  106. package/src/state-schema.js +60 -0
  107. package/src/task-rows.js +44 -0
  108. package/src/tasks.d.ts +128 -0
  109. package/src/tasks.js +881 -0
  110. package/src/teams.js +170 -0
  111. package/src/template-path.js +8 -0
  112. package/src/trust.js +59 -0
  113. package/src/types.d.ts +51 -0
  114. package/src/upgrade.js +195 -0
  115. package/src/user-settings.d.ts +6 -0
  116. package/src/user-settings.js +76 -0
  117. package/src/validation.d.ts +17 -0
  118. package/src/validation.js +302 -0
  119. package/src/verify.d.ts +15 -0
  120. package/src/verify.js +127 -0
  121. package/src/workflow.js +28 -0
  122. package/templates/ALP.md +52 -0
  123. package/templates/agents/lead/AGENT.md +90 -0
  124. package/templates/agents/main/AGENT.md +150 -0
  125. package/templates/agents/oracle/AGENT.md +44 -0
  126. package/templates/agents/peer/AGENT.md +55 -0
  127. package/templates/agents/reviewer/AGENT.md +80 -0
  128. package/templates/agents/supervisor/AGENT.md +72 -0
  129. package/templates/providers/antigravity.json +6 -0
  130. package/templates/providers/opencode.json +7 -0
  131. package/templates/role-skills.json +8 -0
  132. package/templates/skills/bug-loop/SKILL.md +44 -0
  133. package/templates/skills/bug-loop/references/test-proof.md +25 -0
  134. package/templates/skills/goal-griller/SKILL.md +49 -0
  135. package/templates/skills/prompt-leverage/SKILL.md +37 -0
  136. package/templates/skills/prompt-leverage/references/brief-template.md +27 -0
  137. package/templates/skills/sequence-execution-plan/SKILL.md +42 -0
  138. package/templates/skills/sequence-execution-plan/references/plan-template.md +22 -0
  139. package/templates/skills/smart-commits/SKILL.md +40 -0
  140. package/templates/skills/xia/SKILL.md +42 -0
  141. package/templates/teams/cafe/HOUSE_RULES.md +1 -0
  142. package/templates/teams/cafe/team.json +15 -0
  143. package/templates/teams/pho/HOUSE_RULES.md +1 -0
  144. package/templates/teams/pho/team.json +14 -0
@@ -0,0 +1,44 @@
1
+ import { gatesOf, loadTasks, readyTasks, summarize } from './tasks.js';
2
+
3
+ /**
4
+ * A project's tasks as task screens show them (ALPD §22): readiness, what blocks or waits,
5
+ * approvals for the user, handoffs and progress. Used by the Paseo Tasks panel and the web app.
6
+ * @param {string} projectRoot
7
+ */
8
+ export async function taskRows(projectRoot) {
9
+ const { tasks, errors } = await loadTasks(projectRoot);
10
+ const ready = new Set(readyTasks(tasks).map(task => task.id));
11
+ // Each parent's children, closed and in all.
12
+ /** @type {Map<string, { done: number, total: number }>} */
13
+ const children = new Map();
14
+ for (const task of tasks) {
15
+ if (!task.parent) continue;
16
+ const count = children.get(task.parent) ?? { done: 0, total: 0 };
17
+ count.total += 1;
18
+ if (task.status === 'closed') count.done += 1;
19
+ children.set(task.parent, count);
20
+ }
21
+ const rows = tasks.map(task => {
22
+ const row = summarize(task, tasks);
23
+ const approvals = task.status === 'closed' ? [] : task.gates.filter(gate => gate.kind === 'human' && !gate.resolved).map(gate => ({ gate: gate.id, note: gate.note ?? '' }));
24
+ const waits = task.status === 'closed' ? [] : gatesOf(task, tasks);
25
+ return {
26
+ id: task.id, title: task.title, type: task.type, priority: task.priority, status: task.status, rev: task.rev,
27
+ ...(task.parent ? { parent: task.parent } : {}),
28
+ ...(task.assignee ? { assignee: task.assignee.agent } : {}),
29
+ ready: ready.has(task.id),
30
+ ...(row.blockedBy ? { blockedBy: row.blockedBy } : {}),
31
+ ...(waits.length ? { waits } : {}),
32
+ ...(approvals.length ? { approvals } : {}),
33
+ ...(task.handoff ? { handoff: { outcome: String(task.handoff.outcome), summary: String(task.handoff.summary ?? ''), ...(typeof task.handoff.agent === 'string' ? { agent: task.handoff.agent } : {}) } } : {}),
34
+ ...(task.closed ? { closed: { reason: task.closed.reason, ...(task.closed.summary ? { summary: task.closed.summary } : {}), at: task.closed.at } } : {}),
35
+ ...(task.description ? { description: task.description.slice(0, 4000) } : {}),
36
+ ...(task.labels.length ? { labels: task.labels } : {}),
37
+ ...(task.paths.length ? { paths: task.paths } : {}),
38
+ ...(children.has(task.id) ? { progress: children.get(task.id) } : {}),
39
+ createdAt: task.createdAt,
40
+ updatedAt: task.updatedAt,
41
+ };
42
+ });
43
+ return { tasks: rows, unreadable: errors };
44
+ }
package/src/tasks.d.ts ADDED
@@ -0,0 +1,128 @@
1
+ export type TaskType = 'task' | 'bug' | 'feature' | 'chore' | 'epic';
2
+ export type TaskStatus = 'open' | 'in_progress' | 'review' | 'closed';
3
+ export type CloseReason = 'done' | 'wontfix' | 'duplicate' | 'superseded';
4
+
5
+ export type TaskLogEntry = { at: string; by: string; event: string; [detail: string]: unknown };
6
+
7
+ export type Task = {
8
+ id: string;
9
+ rev: number;
10
+ title: string;
11
+ description: string;
12
+ type: TaskType;
13
+ priority: number;
14
+ status: TaskStatus;
15
+ labels: string[];
16
+ paths: string[];
17
+ parent: string | null;
18
+ blockedBy: string[];
19
+ discoveredFrom: string | null;
20
+ related: string[];
21
+ gates: TaskGate[];
22
+ assignee: { agent: string; session?: string; assignment?: string; pid?: number; pidStartedAt?: number; epoch?: string; since: string } | null;
23
+ handoff: Record<string, unknown> | null;
24
+ /** The last run of the project's verify commands for this task. */
25
+ verified: TaskVerification | null;
26
+ createdBy: string;
27
+ createdAt: string;
28
+ updatedAt: string;
29
+ closed: { at: string; by: string; reason: CloseReason; summary?: string; unverified?: string } | null;
30
+ log: TaskLogEntry[];
31
+ compacted?: { at: string; by: string; chars: number };
32
+ /** Where an imported task came from. */
33
+ external?: { system: string; id: string };
34
+ /** The formula step a task was poured from. */
35
+ step?: { formula: string; id: string; human?: boolean };
36
+ /** The formula an epic was poured from. */
37
+ formula?: { name: string; version?: number; vars: Record<string, string> };
38
+ };
39
+
40
+ export type GateKind = 'human' | 'timer' | 'gh:pr' | 'gh:run';
41
+ export type TaskGate = {
42
+ id: string;
43
+ kind: GateKind;
44
+ note?: string;
45
+ until?: string;
46
+ repo?: string;
47
+ ref?: string;
48
+ at: string;
49
+ by: string;
50
+ resolved?: { at: string; by: string; note?: string };
51
+ };
52
+
53
+ export type TaskInput = {
54
+ title?: string;
55
+ description?: string;
56
+ type?: TaskType;
57
+ priority?: number | string;
58
+ labels?: string[];
59
+ paths?: string[];
60
+ parent?: string | null;
61
+ blockedBy?: string[];
62
+ related?: string[];
63
+ discoveredFrom?: string | null;
64
+ };
65
+
66
+ export type TaskLinks = { blockedBy?: string[]; related?: string[]; parent?: string };
67
+ export type TaskSummary = Pick<Task, 'id' | 'title' | 'type' | 'priority' | 'status'> & { labels?: string[]; parent?: string; blockedBy?: string[]; gates?: string[]; assignee?: string; verified?: 'passed' | 'failed' | 'skipped' };
68
+ type WriteOptions = { ifRev?: number };
69
+
70
+ export const TASKS_DIR: string;
71
+ export const TASK_TYPES: TaskType[];
72
+ export const TASK_STATUSES: TaskStatus[];
73
+ export const CLOSE_REASONS: CloseReason[];
74
+ export const GATE_KINDS: GateKind[];
75
+ export const MAX_GATES: number;
76
+ export const TITLE_CHARS: number;
77
+ export const DESCRIPTION_CHARS: number;
78
+ export const NOTE_CHARS: number;
79
+ export const MAX_LABELS: number;
80
+ export const MAX_PATHS: number;
81
+ export const MAX_LINKS: number;
82
+
83
+ export function isTaskId(id: unknown): id is string;
84
+ export function tasksDir(projectRoot: string): string;
85
+ export function loadTasks(projectRoot: string): Promise<{ tasks: Task[]; errors: Array<{ file: string; error: string }> }>;
86
+ export function getTask(projectRoot: string, id: string): Promise<Task>;
87
+ export function blockersOf(task: Task, tasks: Task[]): string[];
88
+ export function readyTasks(tasks: Task[]): Task[];
89
+ export function childrenOf(id: string, tasks: Task[]): Task[];
90
+ export function summarize(task: Task, tasks: Task[]): TaskSummary;
91
+ export function listTasks(tasks: Task[], filter?: { status?: TaskStatus; label?: string; parent?: string; all?: boolean }): Task[];
92
+ export function createTask(projectRoot: string, input: TaskInput & { title: string }, by: string): Promise<Task>;
93
+ export function updateTask(projectRoot: string, id: string, input: TaskInput & { note?: string }, by: string, options?: WriteOptions): Promise<Task>;
94
+ export function linkTask(projectRoot: string, id: string, change: { add?: TaskLinks; remove?: TaskLinks }, by: string, options?: WriteOptions): Promise<Task>;
95
+ export function startTask(projectRoot: string, id: string, assignee: { agent: string; session?: string; assignment?: string; pid?: number; pidStartedAt?: number; epoch?: string }, by: string, options?: WriteOptions): Promise<Task>;
96
+ export function closeTask(projectRoot: string, id: string, close: { reason?: CloseReason; summary?: string; unverified?: string }, by: string, options?: WriteOptions): Promise<Task>;
97
+ export function verificationFailed(task: Task): boolean;
98
+ export function recordVerification(projectRoot: string, id: string, verification: { passed: boolean; where?: string; commands?: Array<{ step: string; command: string; exitCode: number; ms: number; output?: string; timedOut?: boolean }>; skipped?: string }, by: string): Promise<Task>;
99
+ export function reopenTask(projectRoot: string, id: string, reopen: { note?: string }, by: string, options?: WriteOptions): Promise<Task>;
100
+ export function submitTask(projectRoot: string, id: string, submit: { assignment: string; handoff: { outcome: string; summary: string } & Record<string, unknown>; agent: string }, by: string): Promise<Task>;
101
+ export function releaseOrphans(projectRoot: string, isOrphan: (assignee: { agent: string; assignment: string; pid?: number; pidStartedAt?: number; epoch?: string }) => boolean, describe: (assignee: { agent: string; assignment: string }) => Promise<string | undefined>, by: string): Promise<Task[]>;
102
+ export function orphanedEntry(task: Task): { at: string; by: string; event: 'orphaned'; agent: string; assignment: string; note?: string } | undefined;
103
+ export function retakeTask(projectRoot: string, id: string, assignee: { assignment: string; pid?: number; pidStartedAt?: number; epoch?: string }, by: string): Promise<Task>;
104
+ export function releaseTask(projectRoot: string, id: string, release: { assignment: string; handoff?: ({ outcome: string; summary: string } & Record<string, unknown>) | null; agent: string; reason: string }, by: string): Promise<Task>;
105
+ export function taskDigest(tasks: Task[], errors?: Array<{ file: string; error: string }>): string;
106
+ export function startRefusal(task: Task, tasks: Task[]): string | undefined;
107
+ export function gateOpen(gate: TaskGate, now?: number): boolean;
108
+ export function describeGate(gate: TaskGate): string;
109
+ export function gatesOf(task: Task, tasks: Task[]): string[];
110
+ export function addGate(projectRoot: string, id: string, gate: { kind: GateKind; note?: string; until?: string; ref?: string | number }, by: string): Promise<Task>;
111
+ export function resolveGate(projectRoot: string, id: string, gateId: string, resolve: { by: string; note?: string; remove?: boolean; ifRev?: number }): Promise<Task>;
112
+ export function checkGates(projectRoot: string, gh: (args: string[], options: { cwd: string }) => Promise<string>): Promise<{ cleared: Array<{ task: string; gate: string; detail: string }>; pending: Array<{ task: string; gate: string; detail: string }>; errors: Array<{ task: string; gate: string; error: string }> }>;
113
+ export function compactTasks(projectRoot: string, options: { days?: number; dryRun?: boolean }, by: string): Promise<Array<{ id: string; before: number; after: number }>>;
114
+ export type TaskBatch = {
115
+ tasks: Task[];
116
+ errors: Array<{ file: string; error: string }>;
117
+ add(input: TaskInput & { title: string }, by: string, options?: { id?: string; createdAt?: string; event?: string; details?: Record<string, unknown>; extra?: Partial<Task> & Record<string, unknown> }): Task;
118
+ touch(task: Task, by?: string, event?: string, details?: Record<string, unknown>): void;
119
+ link(task: Task, kind: 'blockedBy' | 'parent' | 'discoveredFrom' | 'related', other: string): string | undefined;
120
+ };
121
+ export function batch<T>(projectRoot: string, work: (batch: TaskBatch) => T | Promise<T>, options?: { dryRun?: boolean }): Promise<T>;
122
+
123
+ export type TaskVerification = { at: string; by: string; passed: boolean; where?: string; commands: Array<{ step: string; command: string; exitCode: number; ms: number; output?: string; timedOut?: boolean }>; skipped?: string };
124
+
125
+ export type EpicReport = { id: string; title: string; status: TaskStatus; tasks: number; closed: number; durationMs: number; reworked: number; verification: { passed: number; failed: number; skipped: number; none: number }; unverified: string[]; lines: string[]; text: string };
126
+ export function epicReport(id: string, tasks: Task[]): EpicReport;
127
+ export function landedParents(tasks: Task[]): Array<{ task: Task; children: number }>;
128
+ export function withTaskLock<T>(projectRoot: string, work: () => Promise<T>): Promise<T>;