@widnyana/design-thinking 0.0.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.
- package/LICENSE +30 -0
- package/README.md +82 -0
- package/extensions/design-thinking.ts +166 -0
- package/package.json +51 -0
- package/prompts/cg-map.md +41 -0
- package/prompts/cg-plan.md +65 -0
- package/prompts/cg-review.md +69 -0
- package/prompts/cg.md +50 -0
- package/references/design-graph.md +88 -0
- package/references/effect-ts.md +156 -0
- package/references/method.md +229 -0
- package/references/protocol.md +228 -0
- package/skills/design-graph/SKILL.md +98 -0
- package/skills/design-method/SKILL.md +239 -0
- package/skills/graph-protocol/SKILL.md +238 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 r17x — original Design Thinking concepts, methodology, and
|
|
4
|
+
the Effect-TS instantiation (https://gist.github.com/r17x/90eb2f7be93932b5693753aedb09c01a)
|
|
5
|
+
|
|
6
|
+
Copyright (c) 2026 Widnyana Putra — pi package adaptation: generalization of the
|
|
7
|
+
method to a stack-agnostic form, the Design Graph artifact spec, the Graph
|
|
8
|
+
Protocol notation, the pi extension, and the prompt templates.
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
Attribution: the underlying design methodology originates from r17x. The
|
|
21
|
+
generalized method, Graph Protocol, and pi packaging in this repository are a
|
|
22
|
+
derived work.
|
|
23
|
+
|
|
24
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
25
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
26
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
27
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
28
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
29
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
30
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# design-thinking — a pi package
|
|
2
|
+
|
|
3
|
+
AI coding agents ship code before asking what breaks. This extension flips the
|
|
4
|
+
order: with `/dt` active, [pi](https://pi.dev) draws the call graph first —
|
|
5
|
+
nodes are functions, edges are data flow, every failure path is named — then
|
|
6
|
+
writes code that *is* the graph. Plans, reviews, and refactors render in a
|
|
7
|
+
fixed, mechanically checkable notation (Graph Protocol) that looks the same in
|
|
8
|
+
Go, Rust, Python, or TypeScript.
|
|
9
|
+
|
|
10
|
+
Method by [r17x](https://github.com/r17x) ([Design Thinking
|
|
11
|
+
gist](https://gist.github.com/r17x/90eb2f7be93932b5693753aedb09c01a),
|
|
12
|
+
originally Effect-TS), generalized into this stack-agnostic pi package.
|
|
13
|
+
Licensed MIT — see [LICENSE](LICENSE).
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
# from npm
|
|
19
|
+
pi install npm:@widnyana/design-thinking
|
|
20
|
+
|
|
21
|
+
# pinned version
|
|
22
|
+
pi install npm:@widnyana/design-thinking@0.0.1
|
|
23
|
+
|
|
24
|
+
# from a local checkout of this repo
|
|
25
|
+
pi install /absolute/path/to/pi-packages/design-thinking
|
|
26
|
+
|
|
27
|
+
# try without installing
|
|
28
|
+
pi -e npm:@widnyana/design-thinking
|
|
29
|
+
pi -e ./pi-packages/design-thinking
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
> The `npm:` prefix is required — a bare name is parsed by pi as a local path.
|
|
33
|
+
|
|
34
|
+
## Usage
|
|
35
|
+
|
|
36
|
+
| Command | What it does |
|
|
37
|
+
|---|---|
|
|
38
|
+
| `/dt` | Toggle Design Thinking mode. While on, plans and reviews render as Design Graphs. Persists across restarts. |
|
|
39
|
+
| `/dt on\|off\|status` | Set or query the mode explicitly. |
|
|
40
|
+
| `/dt <prompt>` | Turn the mode **on** (never off), then run `<prompt>` under it — graph and clarifying questions first, implementation after your go-ahead. |
|
|
41
|
+
| `/cg <module \| task>` | Generate a call graph: extract the graph existing code implements, or sketch one for a task. |
|
|
42
|
+
| `/cg-plan <task>` | Design before code — full Design Graph, then implement to match it. |
|
|
43
|
+
| `/cg-review [file\|module\|diff]` | Reconstruct the implemented graph, diff it against the method's checklist, end with a VERDICT. |
|
|
44
|
+
| `/cg-map <language\|framework>` | Map the Protocol vocabulary onto a stack's idioms (Result vs exceptions, RAII vs defer). |
|
|
45
|
+
|
|
46
|
+
## A real-world walkthrough
|
|
47
|
+
|
|
48
|
+
Task: *add rate limiting to an Express API.* One design pass, end to end:
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
> /dt # mode on — graph-first rules injected
|
|
52
|
+
|
|
53
|
+
> /cg-plan add per-user rate limiting to the API
|
|
54
|
+
→ agent sketches a DesignGraph first (SHAPES, GRAPH, E, boundaries),
|
|
55
|
+
then implements code that matches it
|
|
56
|
+
|
|
57
|
+
> /cg-map nodejs # optional: before planning, when the
|
|
58
|
+
→ maps ⟳↯☠🔒 onto express idioms # stack's vocabulary is unclear
|
|
59
|
+
(middleware = boundary, AbortError = ↯escape)
|
|
60
|
+
|
|
61
|
+
> git diff → review it with:
|
|
62
|
+
> /cg-review src/middleware/ratelimit.ts
|
|
63
|
+
→ extracts the graph the code ACTUALLY implements, diffs it against
|
|
64
|
+
the planned one, findings grouped by § number, ends with VERDICT
|
|
65
|
+
|
|
66
|
+
> /dt off # done — back to normal mode
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
The cycle:
|
|
70
|
+
|
|
71
|
+
```mermaid
|
|
72
|
+
flowchart LR
|
|
73
|
+
A["/dt on"] --> B{"stack idioms<br/>clear?"}
|
|
74
|
+
B -- no --> M["/cg-map nodejs"]
|
|
75
|
+
B -- yes --> P
|
|
76
|
+
M --> P["/cg-plan <task>"]
|
|
77
|
+
P --> C[implement] --> R["/cg-review <file>"] --> O["/dt off"]
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Skills (`graph-protocol`, `design-method`, `design-graph`) are loaded by the
|
|
81
|
+
agent on demand mid-turn — you never invoke them directly; the `/cg*` prompts
|
|
82
|
+
and `/dt` mode tell the model when to reach for them.
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Design Thinking — pi extension
|
|
3
|
+
*
|
|
4
|
+
* Adopts the three pillars:
|
|
5
|
+
* - Design Thinking : the mindset (§1–§10 pipeline, problem-first)
|
|
6
|
+
* - Design Graph : the artifact (annotated call graph of a concrete problem)
|
|
7
|
+
* - Graph Protocol : the notation spec (fixed sections, fixed markers)
|
|
8
|
+
*
|
|
9
|
+
* When /dt mode is active, every turn appends a compact distilled block to the
|
|
10
|
+
* system prompt so design/plan/review answers render as Design Graphs in
|
|
11
|
+
* Graph Protocol form. Full specs live in the package's references/ directory,
|
|
12
|
+
* loaded on demand — not inlined here, to keep the injected prompt small.
|
|
13
|
+
*
|
|
14
|
+
* Commands:
|
|
15
|
+
* /dt toggle Design Thinking mode
|
|
16
|
+
* /dt on|off set explicitly
|
|
17
|
+
* /dt status show current state
|
|
18
|
+
* /dt <prompt> turn mode ON (never off), then run <prompt> as a user
|
|
19
|
+
* message — graph + clarifying questions before implementation
|
|
20
|
+
*
|
|
21
|
+
* Stack-agnostic: no language detection, no auto-enable. Adapt the vocabulary
|
|
22
|
+
* to whatever stack the project uses; never the discipline.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import path from "node:path";
|
|
26
|
+
import { fileURLToPath } from "node:url";
|
|
27
|
+
|
|
28
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
29
|
+
|
|
30
|
+
const STATE_TYPE = "design-thinking-state";
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Absolute path to the shipped references/ directory, resolved from this
|
|
34
|
+
* file's own location (§6 boundary: import.meta.url → fs path). Works from
|
|
35
|
+
* a repo checkout and from an npm install — e.g.
|
|
36
|
+
* ~/.pi/agent/npm/node_modules/@widnyana/design-thinking/references — so
|
|
37
|
+
* the model can actually read the full specs in /dt mode.
|
|
38
|
+
*/
|
|
39
|
+
const REF_DIR = path.resolve(
|
|
40
|
+
path.dirname(fileURLToPath(import.meta.url)),
|
|
41
|
+
"..",
|
|
42
|
+
"references",
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
/** Compact distilled prompt block injected while active (~33 lines). */
|
|
46
|
+
const DISTILLED = `
|
|
47
|
+
DESIGN THINKING MODE — active.
|
|
48
|
+
Read the problem. Draw the data flow as a call graph. Write code that IS the graph.
|
|
49
|
+
|
|
50
|
+
X → DesignGraph<A, E, R>
|
|
51
|
+
│ │ │ │ │
|
|
52
|
+
│ │ │ │ └─ R: what each node needs (§5)
|
|
53
|
+
│ │ │ └──── E: where the graph breaks (§4)
|
|
54
|
+
│ │ └─────── A: what flows through nodes (§2)
|
|
55
|
+
│ │
|
|
56
|
+
│ └─ nodes = functions, edges = data flow
|
|
57
|
+
│
|
|
58
|
+
└─ the problem
|
|
59
|
+
|
|
60
|
+
Pipeline: shapes → graph(A) → cardinality → E(⟳retry ↯escape ☠die) → R →
|
|
61
|
+
🔒 parse at boundaries → ⛈ orthogonal behavior → scope → test-R → verdict.
|
|
62
|
+
|
|
63
|
+
Rules:
|
|
64
|
+
- Design, plan, and review answers must render a Design Graph in Graph Protocol
|
|
65
|
+
form — fixed sections: PROBLEM, SHAPES, GRAPH, CARDINALITY, BOUNDARIES,
|
|
66
|
+
BEHAVIOR, SCOPE, TEST LAYERS, VERDICT.
|
|
67
|
+
- The happy path (A) stays readable; failure handling lives at defined join points.
|
|
68
|
+
- Each layer scopes its own E; inner errors never leak through.
|
|
69
|
+
- If the code doesn't match the call graph, the implementation is wrong.
|
|
70
|
+
- For build/fix/refactor tasks: present the Design Graph and any clarifying
|
|
71
|
+
questions FIRST; implement only after the user approves the design.
|
|
72
|
+
- Adapt vocabulary to the current language/stack; never the discipline.
|
|
73
|
+
|
|
74
|
+
Full specs — read these when a section needs detail:
|
|
75
|
+
- ${REF_DIR}/protocol.md (Graph Protocol: notation spec + worked example)
|
|
76
|
+
- ${REF_DIR}/method.md (the §1–§10 method, generalized)
|
|
77
|
+
- ${REF_DIR}/design-graph.md (the artifact spec + completeness checklist)
|
|
78
|
+
`.trim();
|
|
79
|
+
|
|
80
|
+
interface DtState {
|
|
81
|
+
enabled: boolean;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export default function designThinkingExtension(pi: ExtensionAPI) {
|
|
85
|
+
let enabled = false;
|
|
86
|
+
|
|
87
|
+
function applyStatus(ctx: ExtensionContext) {
|
|
88
|
+
ctx.ui.setStatus(
|
|
89
|
+
"design-thinking",
|
|
90
|
+
enabled ? "design-thinking: on" : undefined,
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function persist() {
|
|
95
|
+
pi.appendEntry<DtState>(STATE_TYPE, { enabled });
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function restore(ctx: ExtensionContext) {
|
|
99
|
+
const branch = ctx.sessionManager.getBranch();
|
|
100
|
+
let restored: boolean | undefined;
|
|
101
|
+
for (const entry of branch) {
|
|
102
|
+
if (entry.type === "custom" && entry.customType === STATE_TYPE) {
|
|
103
|
+
const data = entry.data as DtState | undefined;
|
|
104
|
+
if (data && typeof data.enabled === "boolean") {
|
|
105
|
+
restored = data.enabled;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (restored !== undefined) {
|
|
110
|
+
enabled = restored;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Restore toggle state when a session starts, loads, or reloads.
|
|
115
|
+
pi.on("session_start", async (_event, ctx) => {
|
|
116
|
+
restore(ctx);
|
|
117
|
+
applyStatus(ctx);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
pi.on("session_shutdown", async (_event, ctx) => {
|
|
121
|
+
ctx.ui.setStatus("design-thinking", undefined);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
// /dt — the Design Thinking tool. Toggles mode, or /dt on|off|status.
|
|
125
|
+
pi.registerCommand("dt", {
|
|
126
|
+
description: "Design Thinking mode: /dt toggles, on|off|status set/query, anything else runs as a prompt with mode on",
|
|
127
|
+
handler: async (args, ctx) => {
|
|
128
|
+
const arg = (args ?? "").trim();
|
|
129
|
+
const lower = arg.toLowerCase();
|
|
130
|
+
|
|
131
|
+
if (lower === "status") {
|
|
132
|
+
ctx.ui.notify(`Design Thinking mode: ${enabled ? "on" : "off"}`, "info");
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// "on"/"off" set explicitly; anything else is a prompt to run in this
|
|
137
|
+
// mode and always turns the mode ON (never toggles it off); bare /dt toggles.
|
|
138
|
+
const prompt = /^(on|off|status)$/.test(lower) ? "" : arg;
|
|
139
|
+
enabled = lower === "on" || prompt ? true : lower === "off" ? false : !enabled;
|
|
140
|
+
persist();
|
|
141
|
+
applyStatus(ctx);
|
|
142
|
+
ctx.ui.notify(
|
|
143
|
+
enabled
|
|
144
|
+
? "Design Thinking ON — plans and reviews will render as Design Graphs (Graph Protocol)"
|
|
145
|
+
: "Design Thinking OFF",
|
|
146
|
+
"info",
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
if (prompt) {
|
|
150
|
+
// deliverAs "steer": sends immediately when idle, queues mid-stream.
|
|
151
|
+
await pi.sendUserMessage(
|
|
152
|
+
`${prompt}\n\n(Design Thinking is ON: before implementing, present the Design Graph (Graph Protocol) and any clarifying questions, then wait for my go-ahead.)`,
|
|
153
|
+
{ deliverAs: "steer" },
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
// While active, append the distilled block to the system prompt every turn.
|
|
160
|
+
pi.on("before_agent_start", async (event) => {
|
|
161
|
+
if (!enabled) return undefined;
|
|
162
|
+
return {
|
|
163
|
+
systemPrompt: event.systemPrompt + "\n\n" + DISTILLED + "\n",
|
|
164
|
+
};
|
|
165
|
+
});
|
|
166
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@widnyana/design-thinking",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Design Thinking · Design Graph · Graph Protocol — a stack-agnostic design methodology for pi. Turns every plan, review, and refactor into an annotated call graph. Method originally by r17x; generalized to a pi package by widnyana.",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "Widnyana Putra",
|
|
8
|
+
"url": "https://github.com/widnyana"
|
|
9
|
+
},
|
|
10
|
+
"contributors": [
|
|
11
|
+
{
|
|
12
|
+
"name": "r17x",
|
|
13
|
+
"url": "https://github.com/r17x",
|
|
14
|
+
"note": "Original Design Thinking concepts and methodology"
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"files": [
|
|
19
|
+
"extensions",
|
|
20
|
+
"prompts",
|
|
21
|
+
"skills",
|
|
22
|
+
"references",
|
|
23
|
+
"README.md",
|
|
24
|
+
"LICENSE"
|
|
25
|
+
],
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+https://github.com/widnyana/eyay-toolkits.git",
|
|
29
|
+
"directory": "pi-packages/design-thinking"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"pi-package",
|
|
33
|
+
"design",
|
|
34
|
+
"architecture",
|
|
35
|
+
"methodology",
|
|
36
|
+
"call-graph"
|
|
37
|
+
],
|
|
38
|
+
"pi": {
|
|
39
|
+
"extensions": ["./extensions"],
|
|
40
|
+
"prompts": ["./prompts"],
|
|
41
|
+
"skills": ["./skills"]
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"@earendil-works/pi-coding-agent": "*"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@earendil-works/pi-coding-agent": "0.84.3",
|
|
48
|
+
"@types/node": "^22.10.0",
|
|
49
|
+
"typescript": "^5.7.0"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Map the Graph Protocol vocabulary onto a language/framework's concrete idioms
|
|
3
|
+
argument-hint: "<language | framework>"
|
|
4
|
+
---
|
|
5
|
+
Map the Design Graph method onto: $@
|
|
6
|
+
|
|
7
|
+
Produce a vocabulary mapping so the method's three channels (A, E, R) and its
|
|
8
|
+
markers have concrete, idiomatic counterparts in the target stack. Output a
|
|
9
|
+
mapping table followed by a small worked mini-graph in Graph Protocol format.
|
|
10
|
+
|
|
11
|
+
## Mapping table (required rows)
|
|
12
|
+
|
|
13
|
+
| Protocol concept | Question to answer for the target stack |
|
|
14
|
+
|---|---|
|
|
15
|
+
| **A** — happy path | Where does the straight-line happy path live? (main fn, do-block, generator pipeline, SQL CTE chain…) |
|
|
16
|
+
| **E** — failure carrying | How are failures values vs control flow? (Result/Either, checked exceptions, error returns, panics+recover, throw at layer joins…) |
|
|
17
|
+
| **⟳ retry** | Idiomatic retry: library, decorator, middleware, policy object? |
|
|
18
|
+
| **↯ escape** | Idiomatic fallback: default value, cache read, alternative path? |
|
|
19
|
+
| **☠ die** | What counts as a defect? (assert, panic, raise RuntimeError, process abort…) |
|
|
20
|
+
| **R** — dependencies | How are deps declared and provided? (constructor injection, traits, typeclasses, DI container, closure capture, context.Context…) |
|
|
21
|
+
| **🔒 boundary parse** | Where do unknown→trusted conversions live? (schema lib, DTO layer, parsing constructors, guards…) |
|
|
22
|
+
| **(1) (N) (T)** | One-shot vs stream vs time-bounded: iterators, channels, observables, TTL caches… |
|
|
23
|
+
| **⛈ behavior layers** | Middleware/decorator/aspect story of the stack |
|
|
24
|
+
| **Scope** | RAII, defer, context managers, try-with-resources, drop… |
|
|
25
|
+
| **A/E structural split** | How the stack separates happy path from failure join points (pipe, middleware stack, Result chain, try/catch at edges) |
|
|
26
|
+
| **E layer scoping** | How each layer translates inner errors into its own error type before handing off |
|
|
27
|
+
|
|
28
|
+
## Rules
|
|
29
|
+
|
|
30
|
+
- Be concrete: name actual libraries, patterns, and syntax idioms of the stack.
|
|
31
|
+
- If the stack lacks a native counterpart for a concept, say so and name the
|
|
32
|
+
closest convention (and its cost).
|
|
33
|
+
- After the table, render a mini Design Graph (PROBLEM → header tree → GRAPH →
|
|
34
|
+
VERDICT only) for a small example task in this stack, using the mapped
|
|
35
|
+
vocabulary — proving the mapping works end to end.
|
|
36
|
+
- This mapping is a companion artifact: once produced, refer to it in later
|
|
37
|
+
`/cg-plan` and `/cg-review` runs in the same stack.
|
|
38
|
+
|
|
39
|
+
Full specs load as skills in the `design-thinking` pi package:
|
|
40
|
+
`/skill:graph-protocol` (notation), `/skill:design-method` (the method),
|
|
41
|
+
`/skill:design-graph` (artifact).
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Design before code — produce a complete Design Graph for a task, then implement to match it
|
|
3
|
+
argument-hint: "<task description>"
|
|
4
|
+
---
|
|
5
|
+
Task: $@
|
|
6
|
+
|
|
7
|
+
Design it before writing any code. Apply the full Design Thinking pipeline and
|
|
8
|
+
produce a complete Design Graph in Graph Protocol format. Code suggestions must
|
|
9
|
+
match the graph — if a snippet contradicts the graph, fix the graph or fix the
|
|
10
|
+
code, never let them drift silently.
|
|
11
|
+
|
|
12
|
+
## Graph Protocol — quick reference
|
|
13
|
+
|
|
14
|
+
Emit ALL sections below, in this order, with these markers:
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
PROBLEM: <one line — if it doesn't fit, the problem is not understood; refine first>
|
|
18
|
+
|
|
19
|
+
X → DesignGraph<A, E, R>
|
|
20
|
+
│ │ │ │ │
|
|
21
|
+
│ │ │ │ └─ R: what each node needs (§5)
|
|
22
|
+
│ │ │ └──── E: where the graph breaks (§4)
|
|
23
|
+
│ │ └─────── A: what flows through nodes (§2)
|
|
24
|
+
│ │
|
|
25
|
+
│ └─ nodes = functions, edges = data flow
|
|
26
|
+
│
|
|
27
|
+
└─ the problem
|
|
28
|
+
|
|
29
|
+
SHAPES: records · IDs · state variants · named errors
|
|
30
|
+
GRAPH: ascii call graph, annotated inline:
|
|
31
|
+
R: deps · E: err ⟳retry[×n] → ↯escape(alt) | ☠die · 🔒 unknown→trusted
|
|
32
|
+
CARDINALITY: node (1) one-shot · (N) many over time · (T) time-bounded
|
|
33
|
+
BOUNDARIES: every untrusted→trusted crossing (parse, don't validate)
|
|
34
|
+
BEHAVIOR: orthogonal layers (retry, cache, logging) that wrap without changing the graph
|
|
35
|
+
SCOPE: resources: acquire@x → release@x (structural, not convention)
|
|
36
|
+
TEST LAYERS: the R tests provide — same GRAPH, zero code change
|
|
37
|
+
VERDICT: the target structure the implementation must satisfy
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Pipeline to follow
|
|
41
|
+
|
|
42
|
+
1. **§1 Shapes** — the domain nouns, named before any graph is drawn.
|
|
43
|
+
2. **§2 A** — happy path as a call graph, drawn first.
|
|
44
|
+
3. **§3 Cardinality** — one-shot `(1)`, many `(N)`, time-bounded `(T)` per node.
|
|
45
|
+
4. **§4 E** — every break point gets one of: `⟳retry`, `↯escape(alt)`, `☠die`.
|
|
46
|
+
5. **§5 R** — every node declares its requirements; provided at the composition root.
|
|
47
|
+
6. **§6 Boundary** — parse `unknown → trusted` at edges only; trust inside.
|
|
48
|
+
7. **§7 Behavior** — cross-cutting concerns wrap nodes orthogonally.
|
|
49
|
+
8. **§8 Scope** — acquire/release structurally bound (RAII / defer / context managers).
|
|
50
|
+
9. **§9 Test** — same graph runs with test R; if it can't, hidden deps exist.
|
|
51
|
+
10. **§10 Structure** — happy path body = A only; failure handling at defined
|
|
52
|
+
join points = E. Divergent strategies (per-fork failure semantics) are the
|
|
53
|
+
one exception — mark them.
|
|
54
|
+
|
|
55
|
+
## Output contract
|
|
56
|
+
|
|
57
|
+
- Design Graph first (all Protocol sections), then the implementation.
|
|
58
|
+
- Each layer scopes its own E before handing off; inner errors never leak.
|
|
59
|
+
- Adapt vocabulary to the project's language/stack — never the discipline.
|
|
60
|
+
- The VERDICT section states the structural invariants the code must satisfy so
|
|
61
|
+
the graph can later be re-checked in review (`/cg-review`).
|
|
62
|
+
|
|
63
|
+
Full specs load as skills in the `design-thinking` pi package:
|
|
64
|
+
`/skill:graph-protocol` (notation), `/skill:design-method` (the method),
|
|
65
|
+
`/skill:design-graph` (artifact).
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Review code against its call graph — reconstruct the implemented Design Graph and diff it
|
|
3
|
+
argument-hint: "[file | module | diff, default: current diff]"
|
|
4
|
+
---
|
|
5
|
+
Review target: ${@:-the current uncommitted diff (git diff)}
|
|
6
|
+
|
|
7
|
+
Reconstruct the Design Graph the code ACTUALLY implements — not the one the
|
|
8
|
+
author intended. Then diff it against the method's completeness checklist.
|
|
9
|
+
Every mismatch is a finding.
|
|
10
|
+
|
|
11
|
+
## Graph Protocol — quick reference
|
|
12
|
+
|
|
13
|
+
Emit ALL sections below, in this order, with these markers:
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
PROBLEM: <one line — what this code does, as implemented>
|
|
17
|
+
|
|
18
|
+
X → DesignGraph<A, E, R>
|
|
19
|
+
│ │ │ │ │
|
|
20
|
+
│ │ │ │ └─ R: what each node needs (§5)
|
|
21
|
+
│ │ │ └──── E: where the graph breaks (§4)
|
|
22
|
+
│ │ └─────── A: what flows through nodes (§2)
|
|
23
|
+
│ │
|
|
24
|
+
│ └─ nodes = functions, edges = data flow
|
|
25
|
+
│
|
|
26
|
+
└─ the problem
|
|
27
|
+
|
|
28
|
+
SHAPES: records · IDs · state variants · named errors (as actually present)
|
|
29
|
+
GRAPH: ascii call graph of the implemented code, annotated inline:
|
|
30
|
+
R: deps · E: err ⟳retry[×n] → ↯escape(alt) | ☠die · 🔒 unknown→trusted
|
|
31
|
+
CARDINALITY: node (1) one-shot · (N) many over time · (T) time-bounded
|
|
32
|
+
BOUNDARIES: every untrusted→trusted crossing (parse, don't validate)
|
|
33
|
+
BEHAVIOR: orthogonal layers that wrap without changing the graph
|
|
34
|
+
SCOPE: resources: acquire@x → release@x (structural, not convention)
|
|
35
|
+
TEST LAYERS: can this graph run with substituted R? if not — hidden deps
|
|
36
|
+
VERDICT: <matches | mismatches listed by § number>
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Findings checklist (group findings by § number)
|
|
40
|
+
|
|
41
|
+
- **§1 Shapes** — unnamed errors (stringly-typed failures), bare-string IDs,
|
|
42
|
+
missing state variants.
|
|
43
|
+
- **§2 A** — happy path unreadable; error handling woven through it (A/E tangled).
|
|
44
|
+
- **§3 Cardinality** — `(N)` implemented as `(1)`, unbounded collection treated
|
|
45
|
+
as one-shot, missing cache/dedupe for `(T)`.
|
|
46
|
+
- **§4 E** — unmarked breaks, silent swallowing, `☠die` used for domain errors,
|
|
47
|
+
retry on non-transient failures.
|
|
48
|
+
- **§5 R** — hidden dependencies, node constructs its own infrastructure,
|
|
49
|
+
world-mocking required to test one node.
|
|
50
|
+
- **§6 Boundary** — validation scattered inside the graph instead of parsing at
|
|
51
|
+
edges, trusted shapes built from untrusted data without conversion.
|
|
52
|
+
- **§7 Behavior** — retry/timeout/logging hard-coded into business logic
|
|
53
|
+
instead of wrapping orthogonally.
|
|
54
|
+
- **§8 Scope** — resources released by convention or not at all; cleanup as TODO.
|
|
55
|
+
- **§9 Test** — graph can't run with substituted R.
|
|
56
|
+
- **§10 Structure** — per-layer E scoping violated (inner errors leak through);
|
|
57
|
+
divergent strategies not marked.
|
|
58
|
+
|
|
59
|
+
## Output contract
|
|
60
|
+
|
|
61
|
+
- Implemented graph first (all Protocol sections), then findings, then VERDICT.
|
|
62
|
+
- VERDICT must be explicit: "code matches graph" or the mismatch list.
|
|
63
|
+
- If an intended graph exists (e.g. from a prior `/cg-plan`), diff against it;
|
|
64
|
+
otherwise review against the checklist alone.
|
|
65
|
+
- Severity: mark findings that will cause runtime failures vs structural debt.
|
|
66
|
+
|
|
67
|
+
Full specs load as skills in the `design-thinking` pi package:
|
|
68
|
+
`/skill:graph-protocol` (notation), `/skill:design-method` (the method),
|
|
69
|
+
`/skill:design-graph` (artifact).
|
package/prompts/cg.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Generate a call graph of a module or task in Graph Protocol format
|
|
3
|
+
argument-hint: "<module | task>"
|
|
4
|
+
---
|
|
5
|
+
Extract (if target is existing code) or sketch (if target is a task) the call graph for: $@
|
|
6
|
+
|
|
7
|
+
Apply the Design Graph method — nodes are functions, edges are data flow.
|
|
8
|
+
|
|
9
|
+
## Graph Protocol — quick reference
|
|
10
|
+
|
|
11
|
+
Emit ALL sections below, in this order, with these markers:
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
PROBLEM: <one line>
|
|
15
|
+
|
|
16
|
+
X → DesignGraph<A, E, R>
|
|
17
|
+
│ │ │ │ │
|
|
18
|
+
│ │ │ │ └─ R: what each node needs (§5)
|
|
19
|
+
│ │ │ └──── E: where the graph breaks (§4)
|
|
20
|
+
│ │ └─────── A: what flows through nodes (§2)
|
|
21
|
+
│ │
|
|
22
|
+
│ └─ nodes = functions, edges = data flow
|
|
23
|
+
│
|
|
24
|
+
└─ the problem
|
|
25
|
+
|
|
26
|
+
SHAPES: records · IDs · state variants · named errors
|
|
27
|
+
GRAPH: ascii call graph, annotated inline:
|
|
28
|
+
R: deps · E: err ⟳retry[×n] → ↯escape(alt) | ☠die · 🔒 unknown→trusted
|
|
29
|
+
CARDINALITY: node (1) one-shot · (N) many over time · (T) time-bounded
|
|
30
|
+
BOUNDARIES: every untrusted→trusted crossing (parse, don't validate)
|
|
31
|
+
BEHAVIOR: orthogonal layers (retry, cache, logging) that wrap without changing the graph
|
|
32
|
+
SCOPE: resources: acquire@x → release@x (structural, not convention)
|
|
33
|
+
TEST LAYERS: the R tests provide — same GRAPH, zero code change
|
|
34
|
+
VERDICT: code matches graph? happy path free of error handling? E fully enumerated?
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Rules
|
|
38
|
+
|
|
39
|
+
- The graph is the ground truth. For existing code, reconstruct the graph the
|
|
40
|
+
code ACTUALLY implements — not what the author intended.
|
|
41
|
+
- Every node gets cardinality + `R:`. Every failure gets `⟳`, `↯`, or `☠`.
|
|
42
|
+
Every trust crossing gets `🔒`.
|
|
43
|
+
- Adapt vocabulary to the target language/stack (exceptions vs Result types,
|
|
44
|
+
RAII vs context managers, etc.) — never the discipline.
|
|
45
|
+
- If you find nodes that violate the method (tangled happy path, unscoped
|
|
46
|
+
resources, hidden dependencies), list them under VERDICT, grouped by § number.
|
|
47
|
+
|
|
48
|
+
If the full spec is needed, load the skills shipped in the `design-thinking`
|
|
49
|
+
pi package: `/skill:graph-protocol` (notation) and `/skill:design-method`
|
|
50
|
+
(the method).
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# Design Graph — The Artifact
|
|
2
|
+
|
|
3
|
+
A **Design Graph** is the annotated call graph of a concrete problem. It is
|
|
4
|
+
what you produce when you apply [Design Thinking](method.md) to something, and
|
|
5
|
+
it is written in [Graph Protocol](protocol.md) notation.
|
|
6
|
+
|
|
7
|
+
Nodes are functions. Edges are data flow. The annotations answer, for every
|
|
8
|
+
node: what flows through it (A), how many times it runs (cardinality), where
|
|
9
|
+
and how it can fail (E), and what it needs to exist (R) — plus the global
|
|
10
|
+
concerns: trust boundaries, behavior layers, resource scope, and test layers.
|
|
11
|
+
|
|
12
|
+
A Design Graph is not documentation written after the fact. It is drawn
|
|
13
|
+
**before** implementation (planning), **reconstructed** from implementation
|
|
14
|
+
(review), and **compared** against implementation (verdict). The graph is the
|
|
15
|
+
contract; the code is one instantiation of it.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## What a complete Design Graph contains
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
PROBLEM: <one line>
|
|
23
|
+
|
|
24
|
+
X → DesignGraph<A, E, R>
|
|
25
|
+
│ │ │ │ │
|
|
26
|
+
│ │ │ │ └─ R: what each node needs (§5)
|
|
27
|
+
│ │ │ └──── E: where the graph breaks (§4)
|
|
28
|
+
│ │ └─────── A: what flows through nodes (§2)
|
|
29
|
+
│ │
|
|
30
|
+
│ └─ nodes = functions, edges = data flow
|
|
31
|
+
│
|
|
32
|
+
└─ the problem
|
|
33
|
+
|
|
34
|
+
SHAPES: … every noun the graph needs
|
|
35
|
+
GRAPH: … ascii call graph with inline R:/E:/🔒/(n) annotations
|
|
36
|
+
CARDINALITY: … every node marked (1) (N) or (T)
|
|
37
|
+
BOUNDARIES: … every unknown → trusted crossing
|
|
38
|
+
BEHAVIOR: … every orthogonal layer and what it wraps
|
|
39
|
+
SCOPE: … every resource with acquire@x → release@x
|
|
40
|
+
TEST LAYERS: … the R tests provide — same GRAPH, zero code change
|
|
41
|
+
VERDICT: … code matches graph? A and E structurally separated?
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Completeness checklist
|
|
45
|
+
|
|
46
|
+
A Design Graph is complete when all of the following hold:
|
|
47
|
+
|
|
48
|
+
- [ ] Every node has a cardinality marker — `(1)`, `(N)`, or `(T)`.
|
|
49
|
+
- [ ] Every node lists its `R:` — even if `R: none` (that is a feature: the
|
|
50
|
+
node is runnable standalone).
|
|
51
|
+
- [ ] Every edge crossing a trust boundary is marked `🔒 unknown → trusted`.
|
|
52
|
+
- [ ] Every failure mode has a strategy — `⟳retry`, `↯escape(alt)`, or
|
|
53
|
+
`☠die`. No unmarked breaks, no silent swallowing.
|
|
54
|
+
- [ ] Every layer scopes its E before handing off (inner errors translated,
|
|
55
|
+
never leaked).
|
|
56
|
+
- [ ] Every resource has an acquire point and a structural release point.
|
|
57
|
+
- [ ] BEHAVIOR lists only layers that can be removed without touching the
|
|
58
|
+
happy path.
|
|
59
|
+
- [ ] TEST LAYERS shows a full R substitution — if it can't, the graph has
|
|
60
|
+
hidden dependencies.
|
|
61
|
+
- [ ] VERDICT explicitly answers whether code and graph match, and names the
|
|
62
|
+
mismatches.
|
|
63
|
+
|
|
64
|
+
## The three uses
|
|
65
|
+
|
|
66
|
+
### 1. Plan (`/cg-plan`)
|
|
67
|
+
Draw the graph first. Code is written only after the VERDICT question — "does
|
|
68
|
+
my code match this?" — has a target to be checked against. If a code
|
|
69
|
+
suggestion contradicts the graph, fix the graph or fix the code; never let
|
|
70
|
+
them drift silently.
|
|
71
|
+
|
|
72
|
+
### 2. Extract (`/cg`)
|
|
73
|
+
Given existing code, reconstruct the graph the code *actually* implements —
|
|
74
|
+
not the one the author intended. The reconstructed graph is the ground truth
|
|
75
|
+
for review and refactoring.
|
|
76
|
+
|
|
77
|
+
### 3. Review (`/cg-review`)
|
|
78
|
+
Render the implemented graph, then diff it against the intended graph (or
|
|
79
|
+
against the method's completeness checklist when no intended graph exists).
|
|
80
|
+
Every mismatch is a finding, grouped by § number. The review ends with a
|
|
81
|
+
VERDICT line.
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## Worked example
|
|
86
|
+
|
|
87
|
+
See the end of [protocol.md](protocol.md) for a complete, non-TS worked
|
|
88
|
+
example (a resumable URL-sync CLI in Python) with all sections filled.
|