codechart 0.1.3 → 0.3.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/README.md +33 -7
- package/dist/cli.js +2113 -1104
- package/package.json +4 -1
- package/skills/codechart/SKILL.md +7 -5
- package/skills/codechart/flow-guide.md +7 -3
- package/skills/codechart/spec-guide.md +44 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codechart",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Agent skill + CLI: maps and flowcharts of code changes for AI coding agents, in terminal, chat and HTML",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agent-skills",
|
|
@@ -72,5 +72,8 @@
|
|
|
72
72
|
"typescript": "^6.0.3",
|
|
73
73
|
"typescript-eslint": "^8.72.1",
|
|
74
74
|
"vitest": "^5.0.5"
|
|
75
|
+
},
|
|
76
|
+
"overrides": {
|
|
77
|
+
"minimatch": "^11.0.1"
|
|
75
78
|
}
|
|
76
79
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: codechart
|
|
3
|
-
description: 'Use whenever you are about to describe code changes or a plan for them, whether you made the changes or not. Triggers include "summarize the changes", "summarize the staged/uncommitted changes", "what changed", "what did you change", "recap", "walk me through the diff", "explain this diff/commit/branch", "write the PR description", "review what we did", "wrap up", and finishing a task with a summary; also "make a plan", "how would you implement", "plan this feature/migration/refactor", "design the schema change", any request for a map, diagram or overview of how files, tables, models, services or config relate; and any request to see how code behaves: "show me the flow", "how does this work", "walk me through the logic", "what are the edge cases", "what happens when…", "draw the decision flow". Not needed when the change is a single file with only text, comments, formatting, a typo or a version bump: if there is a diff, look at it first and skip this skill then.'
|
|
3
|
+
description: 'Use whenever you are about to describe code changes or a plan for them, whether you made the changes or not. Triggers include "summarize the changes", "summarize the staged/uncommitted changes", "what changed", "what did you change", "recap", "walk me through the diff", "explain this diff/commit/branch", "write the PR description", "review what we did", "wrap up", and finishing a task with a summary; also "make a plan", "how would you implement", "plan this feature/migration/refactor", "design the schema change", any request for a map, diagram or overview of how files, tables, models, services, infrastructure or config relate; and any request to see how code behaves: "show me the flow", "how does this work", "walk me through the logic", "what are the edge cases", "what happens when…", "draw the decision flow". Not needed when the change is a single file with only text, comments, formatting, a typo or a version bump: if there is a diff, look at it first and skip this skill then.'
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# codechart
|
|
@@ -9,7 +9,7 @@ Renders maps and flows from JSON specs you write, for a **plan** or **change sum
|
|
|
9
9
|
|
|
10
10
|
A flow the user asked for ("show me the flow"): skip step 1, write a flow spec without `rules` (`summary`, unchanged code `existing`), render as in step 2 with `--output both`.
|
|
11
11
|
|
|
12
|
-
Skip it for a trivial change (see description), a question not about code changes or behaviour, or if the user said no diagram. If `codechart` is "not found", say once "codechart is not installed, so no map" and go on; never install it.
|
|
12
|
+
Skip it for a trivial change (see description), a question not about code changes or behaviour, or if the user said no diagram. If `codechart` is "not found", say once "the codechart CLI is not installed (`npm i -g codechart`), so no map" and go on; never install it.
|
|
13
13
|
|
|
14
14
|
## 1. Check
|
|
15
15
|
|
|
@@ -40,7 +40,7 @@ codechart render --md - <<'EOF'
|
|
|
40
40
|
EOF
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
-
Commit or branch not checked out: add `--at '<sha or branch>'` so anchors are read from it. On errors, fix the spec and rerun. Stderr `no map drawn`/`no flow drawn`: skip it silently. Rare cases: [spec-guide.md](spec-guide.md), [flow-guide.md](flow-guide.md), `codechart schema [--flow]`.
|
|
43
|
+
For a change summary, add the same `--git`/`--since`/`--commit`/`--head` you gave `check`. Commit or branch not checked out: add `--at '<sha or branch>'` so anchors are read from it. On errors, fix the spec and rerun. A `✗` line is a claim that doesn't match the code: if your spec was wrong (status, path), fix it and rerender; if the change really differs from what you said, keep the `✗` and say so. Stderr `no map drawn`/`no flow drawn`: skip it silently. Rare cases: [spec-guide.md](spec-guide.md), [flow-guide.md](flow-guide.md), `codechart schema [--flow]`.
|
|
44
44
|
|
|
45
45
|
### Flow (one behaviour each)
|
|
46
46
|
|
|
@@ -63,7 +63,7 @@ Draw only branches you saw in the code or (plan) will build; unverified ones go
|
|
|
63
63
|
```
|
|
64
64
|
|
|
65
65
|
- 2+ outgoing links make a decision: label ends in `?`, unique, each link labelled. "if", "else", "or" or `;` in a label hides a branch: make it a decision. Labels: verb + object, ≤ 30 chars, one action (no `+` or `and`: split into steps).
|
|
66
|
-
- `status`: summary `existing`/`new`/`changed`; plan (`"kind": "plan"`) `existing` (keeps its anchor) or `
|
|
66
|
+
- `status`: summary `existing`/`new`/`changed`; plan (`"kind": "plan"`) `existing` (keeps its anchor), `planned` or `removed` (keeps its anchor). Plan: keep links that exist now; one the plan drops gets `"removed": true`.
|
|
67
67
|
- Anchor every non-planned step and non-planned link leaving a decision (a link is planned if either end is, or with `"planned": true`), each its own: the path plus `match`, a distinctive piece of one line copied from the diff (no line lookup; it must be on exactly one line of the file, else drop `match` and use source `path:line`), or `path:start-end` for a block. Paths are relative to the repo root (or cwd). Never drop a failing anchor or mark it `planned`: fix it.
|
|
68
68
|
- Over ~15 steps, split. `gaps`: unverified branches, unread code, what you didn't run. No keys beyond the skeleton's.
|
|
69
69
|
|
|
@@ -82,9 +82,11 @@ Draw only branches you saw in the code or (plan) will build; unverified ones go
|
|
|
82
82
|
```
|
|
83
83
|
|
|
84
84
|
- One node per table, model, file, service or endpoint, never merged: `new`, `changed`, `removed`, `config` (config/env), `context` (untouched neighbour the reader needs). Under 15; tests and docs go in `omitted`.
|
|
85
|
+
- Infrastructure: one node per resource, module or Kubernetes object, labelled as the code names it (`aws_s3_bucket.logs`, `module.vpc`, `Deployment api`), `kind` `other`, `path` the file that declares it; variables and values `config`; `terraform plan not run` goes in `gaps`. See [spec-guide.md](spec-guide.md#infrastructure).
|
|
85
86
|
- `layer` required, from a small set. `kind`: `table` `enum` `model` `service` `endpoint` `component` `file` (default with `path`) `config` `other`. Migration label: `migration: <what it does>`.
|
|
86
87
|
- `fields`: all you read, `change`: `added`/`removed`/`modified`; `fieldsComplete: true` only if you read the whole definition.
|
|
87
|
-
-
|
|
88
|
+
- Optional on a `new`/`changed` node with `path`: `match`, a distinctive piece of one line from the diff, as proof (shown in the HTML).
|
|
89
|
+
- Edges: dependent → dependency, labelled with the column, method or key; only ones you saw or will build. `kind`: `fk` `calls` `imports` `reads` `writes` `renders` `configures` `other`. Plan: a link moved between existing nodes gets `"change": "added"`/`"removed"`; a field whose type changes gets `was` (old type).
|
|
88
90
|
- Context `short`: only what you read in this task, unread goes in `gaps`; `full`: also read the definitions of entities on the map.
|
|
89
91
|
|
|
90
92
|
## 3. Reply
|
|
@@ -25,13 +25,16 @@ An invented branch is the worst failure: it destroys the user's trust in the too
|
|
|
25
25
|
| `existing` | untouched by the change | built on unchanged; keeps its anchor |
|
|
26
26
|
| `new` | added by the change | rejected |
|
|
27
27
|
| `changed` | altered by the change | rejected |
|
|
28
|
-
| `planned` | rejected | anything the plan adds or alters, including a change to an existing step |
|
|
28
|
+
| `planned` | rejected | anything the plan adds or alters, including a change to an existing step (keep its anchor then) |
|
|
29
|
+
| `removed` | rejected | a step the plan deletes; keeps its anchor, since the code exists now |
|
|
29
30
|
|
|
30
31
|
## Links
|
|
31
32
|
|
|
32
33
|
- Only a `decision` branches: a `step` has at most 1 outgoing link, an `end` none.
|
|
33
34
|
- `{ "from", "to" }`; a link leaving a decision also needs a `label` (`yes`, `no`, `none`, `cli`). A decision has at least 2 outgoing links. Loops back to an earlier step are allowed.
|
|
34
|
-
- A link is planned when either end is `planned`, or it sets `"planned": true` (a plan adds a new branch between existing steps).
|
|
35
|
+
- A link is planned when either end is `planned`, or it sets `"planned": true` (a plan adds a new branch between existing steps, or a new link into a step it alters).
|
|
36
|
+
- In a plan, keep every link that exists now. One the plan drops between steps that stay sets `"removed": true` (with its anchor, if it leaves a decision); links to a `removed` step are removed without it. A step's shape (step, decision, end) follows the flow after the plan.
|
|
37
|
+
- A plan that removes something or alters an existing step (a `planned` step with a `source`) is drawn in the HTML as **Now** and **After plan** side by side.
|
|
35
38
|
|
|
36
39
|
## Anchors
|
|
37
40
|
|
|
@@ -40,6 +43,7 @@ An invented branch is the worst failure: it destroys the user's trust in the too
|
|
|
40
43
|
- Anchors are read from the working tree. For a commit or branch that isn't checked out, render with `--at '<sha or branch>'` so they are read from that commit instead; otherwise lines that changed since won't resolve.
|
|
41
44
|
- Required on every non-planned step and every non-planned link leaving a decision, each with its own anchor (a branch never inherits the decision's). Planned steps and links need none.
|
|
42
45
|
- `render` checks every anchor against the files. A broken anchor fails the render: reread the file and fix the line, never drop the anchor or mark the step `planned` to get past it.
|
|
46
|
+
- Rendered with `--git`, `--since` or `--commit`, a summary's `new` or `changed` step whose file isn't in the diff gets a `✗` line (a warning; `--strict` exits 1).
|
|
43
47
|
- Read the code you draw: flows have no context mode, and every anchor must be a line you actually saw.
|
|
44
48
|
|
|
45
49
|
## Rules and gaps
|
|
@@ -113,4 +117,4 @@ A plan to reject revoked invites in that endpoint: the steps above become `exist
|
|
|
113
117
|
{ "id": "403", "label": "403 invite revoked", "status": "planned" }
|
|
114
118
|
```
|
|
115
119
|
|
|
116
|
-
Links: `expired → revoked` (`no`) replaces `expired → member
|
|
120
|
+
Links: `expired → revoked` (`no`) replaces `expired → member`, so keep `expired → member` with `"removed": true` (and its anchor); add `revoked → 403` (`yes`) and `revoked → member` (`no`). The three new ones are planned because `revoked` is. The HTML shows today's flow next to the one after the plan.
|
|
@@ -46,12 +46,54 @@ Rules:
|
|
|
46
46
|
- `kind`: table, enum, model, service, endpoint, component, file, config, other. Defaults to `file` when `path` is set, so a plain file node needs only `path`.
|
|
47
47
|
- `layer`: free text, one per area: `database`, `backend`, `frontend`, `config`, `ci`. Nodes in a layer are drawn together, so keep the set small and consistent.
|
|
48
48
|
- `summary`: one short line, what it is (not what changed).
|
|
49
|
-
- `fields`: for tables, models and enums: **every** field you read, not only the changed ones. Mark changes with `change` (added, removed, modified); leave unchanged fields unmarked. In `short` mode only fields you actually read; in a plan, the fields you are committing to build are always listed (they are the plan).
|
|
49
|
+
- `fields`: for tables, models and enums: **every** field you read, not only the changed ones. Mark changes with `change` (added, removed, modified); leave unchanged fields unmarked. On a `modified` field, `was` is the old type when the type changes (`"type": "enum", "was": "text"`). In `short` mode only fields you actually read; in a plan, the fields you are committing to build are always listed (they are the plan).
|
|
50
|
+
- `match` (optional, needs `path`): a distinctive piece of one line in that file, copied from the diff, like a flow anchor. It must be on exactly one line. The HTML shows the line in the node's panel; the terminal doesn't.
|
|
50
51
|
- `fieldsComplete`: required on every node with `fields`.
|
|
51
52
|
- `true`: you read the whole definition (model, table or enum) and listed every field.
|
|
52
53
|
- `false`: you list only what you saw, such as the changed columns in a migration. The map then says only some fields are shown.
|
|
53
54
|
- In `full` context, open the definition so you can list every field and set `true`.
|
|
54
55
|
|
|
56
|
+
## Infrastructure
|
|
57
|
+
|
|
58
|
+
Terraform, OpenTofu, Terragrunt, Helm, Kustomize and Kubernetes files match the built-in `infrastructure` rule. No special kinds:
|
|
59
|
+
|
|
60
|
+
| Thing | Node |
|
|
61
|
+
|---|---|
|
|
62
|
+
| Resource or data source | `kind: other`, label as the code names it (`aws_s3_bucket.logs`), `path` its `.tf` file, `match` its block line (`resource "aws_s3_bucket" "logs"`) |
|
|
63
|
+
| Module call | `kind: other`, label `module.vpc`, `path` the file with the `module` block, `match` its line (`module "vpc"`) |
|
|
64
|
+
| Local module's code, when the change edits it | `kind: file`, label `modules/vpc`, `path` its folder |
|
|
65
|
+
| Kubernetes object (manifest or Helm template) | `kind: other`, label `Deployment api`, `path` its file |
|
|
66
|
+
| Chart | `kind: file`, label `chart: api`, `path` its folder |
|
|
67
|
+
| Variable, output, tfvars or values key, ConfigMap or Secret | `kind: config`, status `config` |
|
|
68
|
+
|
|
69
|
+
- `layer` by role: `network`, `compute`, `storage`, `iam`, `dns`, `config`; not by file or environment.
|
|
70
|
+
- Edges: dependent → dependency, labelled with the attribute that refers (`vpc_id`, `role`, `serviceName`). `reads` for a reference or a variable, `configures` for values or inputs fed into a module or template, `other` for `depends_on`.
|
|
71
|
+
- `fields`: the attributes you changed or that matter, with `was` on a changed value (`"name": "instance_type", "type": "t3.small", "change": "modified", "was": "t3.micro"`); `fieldsComplete: false` unless you listed the whole block.
|
|
72
|
+
- `gaps`: resources and remote modules you didn't read, and `terraform plan not run` (you can't tell an in-place update from a replacement without it). A rename or a replacement you did spot is a risk for your prose.
|
|
73
|
+
|
|
74
|
+
```json
|
|
75
|
+
{ "kind": "summary", "title": "Access logs bucket for the load balancer", "rules": ["infrastructure"],
|
|
76
|
+
"nodes": [
|
|
77
|
+
{ "id": "logs", "label": "aws_s3_bucket.logs", "kind": "other", "status": "new", "layer": "storage", "path": "infra/logs.tf", "match": "resource \"aws_s3_bucket\" \"logs\"" },
|
|
78
|
+
{ "id": "alb", "label": "aws_lb.api", "kind": "other", "status": "changed", "layer": "network", "path": "infra/alb.tf", "fieldsComplete": false,
|
|
79
|
+
"fields": [{ "name": "access_logs.enabled", "type": "true", "change": "modified", "was": "false" }] },
|
|
80
|
+
{ "id": "retention", "label": "var.log_retention_days", "kind": "config", "status": "config", "layer": "config", "path": "infra/variables.tf" }
|
|
81
|
+
],
|
|
82
|
+
"edges": [
|
|
83
|
+
{ "from": "alb", "to": "logs", "label": "access_logs.bucket", "kind": "reads" },
|
|
84
|
+
{ "from": "logs", "to": "retention", "label": "expiration.days", "kind": "reads" }
|
|
85
|
+
],
|
|
86
|
+
"gaps": ["terraform plan not run"] }
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## What `render` checks
|
|
90
|
+
|
|
91
|
+
Warnings, not failures (`--strict` makes them exit 1). Each mismatch is named in a `✗` line at the top of the output.
|
|
92
|
+
|
|
93
|
+
- **File exists:** every node with a `path`, except a summary's `removed` node (a class deleted from a file that stays) and a plan's `new` node (not built yet). A folder counts.
|
|
94
|
+
- **In the diff:** in a summary rendered with `--git`, `--since` or `--commit`, every `new`, `changed` or `removed` node's file. `context` and `config` nodes are not checked against the diff.
|
|
95
|
+
- **`match`:** found on exactly one line, when the file must exist.
|
|
96
|
+
|
|
55
97
|
## Edges
|
|
56
98
|
|
|
57
99
|
```json
|
|
@@ -62,6 +104,7 @@ Rules:
|
|
|
62
104
|
- `label`: the column, method or key that makes the link (`team_id`, `list_projects()`, `reads DEFAULT_CURRENCY`). Short.
|
|
63
105
|
- `kind`: fk, calls, imports, reads, writes, renders, configures, other. Use `writes` for a migration that creates or alters a table, and `other` for a model's `maps` edge to its table.
|
|
64
106
|
- Only edges you saw in code, or (in a plan) ones you are committing to build.
|
|
107
|
+
- In a plan, `change` marks a link that moves between nodes existing before and after: `"added"` for one the plan builds, `"removed"` for one it drops. Leave it out on edges to a `new` or `removed` node; their status already says it. The HTML then shows the plan as Now and After side by side.
|
|
65
108
|
|
|
66
109
|
## gaps vs omitted vs your prose
|
|
67
110
|
|