pi-matt-pocock 0.1.0 → 0.2.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/ARCHITECTURE.zh-CN.md +216 -0
- package/README.md +180 -25
- package/TODO.md +1 -5
- package/UPSTREAM.md +63 -0
- package/package.json +10 -5
- package/procedures/HTML-REPORT.md +2 -2
- package/procedures/bdd.md +3 -3
- package/procedures/code-review.md +42 -20
- package/procedures/deslop.md +56 -0
- package/procedures/domain.md +1 -1
- package/procedures/grill-with-docs.md +3 -3
- package/procedures/grilling.md +2 -2
- package/procedures/implement.md +7 -6
- package/procedures/improve-codebase-architecture.md +4 -4
- package/procedures/tdd.md +10 -10
- package/procedures/to-spec.md +2 -2
- package/procedures/to-tickets.md +1 -1
- package/procedures/triage.md +2 -2
- package/procedures/wayfinder.md +5 -5
- package/procedures/writing-for-agents.md +14 -0
- package/scripts/check-upstream-sync.mjs +212 -0
- package/src/catalog.json +895 -0
- package/src/catalog.ts +176 -0
- package/src/index.ts +550 -298
- package/src/native-dialog.ts +403 -0
- package/src/resolver.ts +127 -0
- package/src/workflow.ts +113 -130
- package/upstream-selection.json +49 -0
- package/src/procedures.ts +0 -33
package/src/catalog.ts
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
|
|
4
|
+
export type ProcedureKind = "workflow" | "utility" | "reference" | "asset";
|
|
5
|
+
export type InvocationMode = "model" | "user" | "internal";
|
|
6
|
+
|
|
7
|
+
export interface WorkflowPlacement {
|
|
8
|
+
route: string;
|
|
9
|
+
phase: string;
|
|
10
|
+
entry?: boolean;
|
|
11
|
+
allowedNext: string[];
|
|
12
|
+
title?: string;
|
|
13
|
+
label?: string;
|
|
14
|
+
description?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface ProcedureDefinition {
|
|
18
|
+
id: string;
|
|
19
|
+
file: string;
|
|
20
|
+
kind: ProcedureKind;
|
|
21
|
+
invocation: InvocationMode;
|
|
22
|
+
label: string;
|
|
23
|
+
description?: string;
|
|
24
|
+
aliases?: string[];
|
|
25
|
+
standalone?: boolean;
|
|
26
|
+
requires?: string[];
|
|
27
|
+
discloses?: string[];
|
|
28
|
+
workflows?: WorkflowPlacement[];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const procedureDirectory = fileURLToPath(new URL("../procedures/", import.meta.url));
|
|
32
|
+
const catalogPath = fileURLToPath(new URL("./catalog.json", import.meta.url));
|
|
33
|
+
|
|
34
|
+
export const procedureCatalog = JSON.parse(readFileSync(catalogPath, "utf8")) as ProcedureDefinition[];
|
|
35
|
+
const definitionsById = new Map(procedureCatalog.map((definition) => [definition.id, definition]));
|
|
36
|
+
|
|
37
|
+
export function catalogFiles(): string[] {
|
|
38
|
+
return procedureCatalog.map((definition) => definition.file);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function findProcedure(id: string): ProcedureDefinition | undefined {
|
|
42
|
+
return definitionsById.get(normalizeProcedureId(id));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function findProcedureByFile(file: string): ProcedureDefinition | undefined {
|
|
46
|
+
const normalized = file.replace(/^\.\//, "");
|
|
47
|
+
return procedureCatalog.find((definition) => definition.file === normalized);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function normalizeProcedureId(id: string): string {
|
|
51
|
+
const normalized = id.trim().replace(/\.md$/i, "");
|
|
52
|
+
for (const definition of procedureCatalog) {
|
|
53
|
+
if (definition.id === normalized || definition.aliases?.includes(normalized)) return definition.id;
|
|
54
|
+
}
|
|
55
|
+
return normalized;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function workflowDefinitions(route?: string): ProcedureDefinition[] {
|
|
59
|
+
return procedureCatalog.filter((definition) => definition.workflows?.some((workflow) => !route || workflow.route === route));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function workflowPlacement(route: string, procedure: string): WorkflowPlacement | undefined {
|
|
63
|
+
return findProcedure(procedure)?.workflows?.find((workflow) => workflow.route === route);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function workflowEntry(route: string): ProcedureDefinition | undefined {
|
|
67
|
+
return workflowDefinitions(route).find((definition) => workflowPlacement(route, definition.id)?.entry);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface WorkflowRouteDefinition {
|
|
71
|
+
route: string;
|
|
72
|
+
title: string;
|
|
73
|
+
label: string;
|
|
74
|
+
description: string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function workflowRoutes(): WorkflowRouteDefinition[] {
|
|
78
|
+
return procedureCatalog.flatMap((definition) => (definition.workflows ?? [])
|
|
79
|
+
.filter((workflow) => workflow.entry)
|
|
80
|
+
.map((workflow) => ({
|
|
81
|
+
route: workflow.route,
|
|
82
|
+
title: workflow.title ?? workflow.route,
|
|
83
|
+
label: workflow.label ?? definition.label,
|
|
84
|
+
description: workflow.description ?? definition.description ?? definition.id,
|
|
85
|
+
})));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function allowedTransitions(route: string, procedure: string): string[] {
|
|
89
|
+
return workflowPlacement(route, procedure)?.allowedNext ?? [];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function standaloneCapabilities(): ProcedureDefinition[] {
|
|
93
|
+
return procedureCatalog.filter((definition) => definition.standalone);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function modelStandaloneCapabilities(): ProcedureDefinition[] {
|
|
97
|
+
return standaloneCapabilities().filter((definition) => definition.invocation === "model");
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function validateProcedureCatalog(): string[] {
|
|
101
|
+
const errors: string[] = [];
|
|
102
|
+
const ids = new Set<string>();
|
|
103
|
+
const files = new Set<string>();
|
|
104
|
+
|
|
105
|
+
for (const definition of procedureCatalog) {
|
|
106
|
+
if (ids.has(definition.id)) errors.push(`${definition.id}: duplicate catalog id`);
|
|
107
|
+
if (files.has(definition.file)) errors.push(`${definition.file}: classified more than once`);
|
|
108
|
+
ids.add(definition.id);
|
|
109
|
+
files.add(definition.file);
|
|
110
|
+
|
|
111
|
+
if (!existsSync(`${procedureDirectory}${definition.file}`)) {
|
|
112
|
+
errors.push(`${definition.id}: file not found: ${definition.file}`);
|
|
113
|
+
}
|
|
114
|
+
for (const dependency of [...(definition.requires ?? []), ...(definition.discloses ?? [])]) {
|
|
115
|
+
if (!findProcedure(dependency)) errors.push(`${definition.id}: unknown catalog target: ${dependency}`);
|
|
116
|
+
}
|
|
117
|
+
for (const workflow of definition.workflows ?? []) {
|
|
118
|
+
for (const next of workflow.allowedNext) {
|
|
119
|
+
if (!workflowPlacement(workflow.route, next)) errors.push(`${definition.id}: invalid ${workflow.route} transition: ${next}`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
for (const alias of definition.aliases ?? []) {
|
|
123
|
+
if (findProcedure(alias)?.id !== definition.id) errors.push(`${definition.id}: alias does not resolve: ${alias}`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const routes = new Map<string, WorkflowPlacement[]>();
|
|
128
|
+
for (const definition of procedureCatalog) {
|
|
129
|
+
for (const workflow of definition.workflows ?? []) {
|
|
130
|
+
const placements = routes.get(workflow.route) ?? [];
|
|
131
|
+
placements.push(workflow);
|
|
132
|
+
routes.set(workflow.route, placements);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
for (const [route, placements] of routes) {
|
|
136
|
+
const entries = placements.filter((workflow) => workflow.entry);
|
|
137
|
+
if (entries.length !== 1) errors.push(`${route}: expected exactly one workflow entry, found ${entries.length}`);
|
|
138
|
+
const entry = entries[0];
|
|
139
|
+
if (entry && (!entry.title || !entry.label || !entry.description)) {
|
|
140
|
+
errors.push(`${route}: workflow entry requires title, label, and description`);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const entryDefinition = workflowEntry(route);
|
|
144
|
+
if (entryDefinition) {
|
|
145
|
+
const reachable = new Set<string>([entryDefinition.id]);
|
|
146
|
+
const queue = [entryDefinition.id];
|
|
147
|
+
while (queue.length > 0) {
|
|
148
|
+
const current = queue.shift()!;
|
|
149
|
+
const currentPlacement = workflowPlacement(route, current);
|
|
150
|
+
for (const next of currentPlacement?.allowedNext ?? []) {
|
|
151
|
+
if (!reachable.has(next)) {
|
|
152
|
+
reachable.add(next);
|
|
153
|
+
queue.push(next);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
for (const definition of workflowDefinitions(route)) {
|
|
158
|
+
if (!reachable.has(definition.id)) {
|
|
159
|
+
errors.push(`${route}: unreachable workflow procedure: ${definition.id}`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const inbound = new Set(procedureCatalog.flatMap((definition) => [
|
|
166
|
+
...(definition.requires ?? []),
|
|
167
|
+
...(definition.discloses ?? []),
|
|
168
|
+
]));
|
|
169
|
+
for (const definition of procedureCatalog) {
|
|
170
|
+
if (definition.kind === "reference" && !inbound.has(definition.id)) {
|
|
171
|
+
errors.push(`${definition.id}: internal reference has no inbound catalog edge`);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return errors;
|
|
176
|
+
}
|