@crafter/cli-tree 0.1.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.
Files changed (104) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +328 -0
  3. package/dist/archaeology/cache.d.ts +11 -0
  4. package/dist/archaeology/delegate.d.ts +43 -0
  5. package/dist/archaeology/index.d.ts +12 -0
  6. package/dist/archaeology/index.js +61 -0
  7. package/dist/archaeology/index.js.map +9 -0
  8. package/dist/archaeology/llm.d.ts +1 -0
  9. package/dist/archaeology/merge.d.ts +3 -0
  10. package/dist/archaeology/orchestrator.d.ts +25 -0
  11. package/dist/archaeology/prompts.d.ts +13 -0
  12. package/dist/archaeology/types.d.ts +101 -0
  13. package/dist/archaeology/validate.d.ts +18 -0
  14. package/dist/chunk-57gtsvhb.js +434 -0
  15. package/dist/chunk-57gtsvhb.js.map +16 -0
  16. package/dist/chunk-5aahbfr2.js +293 -0
  17. package/dist/chunk-5aahbfr2.js.map +10 -0
  18. package/dist/chunk-pkfpaae1.js +678 -0
  19. package/dist/chunk-pkfpaae1.js.map +15 -0
  20. package/dist/chunk-q4se2rwe.js +181 -0
  21. package/dist/chunk-q4se2rwe.js.map +14 -0
  22. package/dist/chunk-v5w3w6bd.js +168 -0
  23. package/dist/chunk-v5w3w6bd.js.map +11 -0
  24. package/dist/chunk-ykze151b.js +770 -0
  25. package/dist/chunk-ykze151b.js.map +16 -0
  26. package/dist/cli.d.ts +2 -0
  27. package/dist/cli.js +433 -0
  28. package/dist/cli.js.map +10 -0
  29. package/dist/encoders/ansi.d.ts +2 -0
  30. package/dist/encoders/html.d.ts +10 -0
  31. package/dist/encoders/string.d.ts +2 -0
  32. package/dist/flow/encode.d.ts +5 -0
  33. package/dist/flow/index.d.ts +8 -0
  34. package/dist/flow/index.js +25 -0
  35. package/dist/flow/index.js.map +9 -0
  36. package/dist/flow/layout.d.ts +30 -0
  37. package/dist/flow/parse.d.ts +2 -0
  38. package/dist/flow/render.d.ts +3 -0
  39. package/dist/flow/types.d.ts +42 -0
  40. package/dist/flow/validate.d.ts +3 -0
  41. package/dist/flow/yaml.d.ts +4 -0
  42. package/dist/grid.d.ts +14 -0
  43. package/dist/index.d.ts +7 -0
  44. package/dist/index.js +21 -0
  45. package/dist/index.js.map +9 -0
  46. package/dist/miner/history.d.ts +6 -0
  47. package/dist/miner/index.d.ts +18 -0
  48. package/dist/miner/index.js +38 -0
  49. package/dist/miner/index.js.map +9 -0
  50. package/dist/miner/sessions.d.ts +3 -0
  51. package/dist/miner/stats.d.ts +2 -0
  52. package/dist/miner/suggest.d.ts +11 -0
  53. package/dist/miner/transitions.d.ts +6 -0
  54. package/dist/miner/types.d.ts +46 -0
  55. package/dist/miner/workflows.d.ts +11 -0
  56. package/dist/parse.d.ts +3 -0
  57. package/dist/render.d.ts +3 -0
  58. package/dist/types.d.ts +39 -0
  59. package/package.json +85 -0
  60. package/skill/SKILL.md +263 -0
  61. package/skill/evals/evals.json +26 -0
  62. package/skill/install.sh +38 -0
  63. package/skill/references/archaeology-guide.md +157 -0
  64. package/skill/references/skill-template.md +120 -0
  65. package/src/archaeology/cache.ts +107 -0
  66. package/src/archaeology/delegate.ts +113 -0
  67. package/src/archaeology/index.ts +48 -0
  68. package/src/archaeology/llm.ts +10 -0
  69. package/src/archaeology/merge.ts +155 -0
  70. package/src/archaeology/orchestrator.ts +185 -0
  71. package/src/archaeology/prompts.ts +178 -0
  72. package/src/archaeology/types.ts +139 -0
  73. package/src/archaeology/validate.ts +157 -0
  74. package/src/cli.ts +451 -0
  75. package/src/encoders/ansi.ts +32 -0
  76. package/src/encoders/html.ts +78 -0
  77. package/src/encoders/string.ts +20 -0
  78. package/src/flow/encode.ts +21 -0
  79. package/src/flow/index.ts +15 -0
  80. package/src/flow/layout.ts +150 -0
  81. package/src/flow/parse.ts +100 -0
  82. package/src/flow/render.ts +186 -0
  83. package/src/flow/types.ts +45 -0
  84. package/src/flow/validate.ts +111 -0
  85. package/src/flow/yaml.ts +235 -0
  86. package/src/grid.ts +59 -0
  87. package/src/index.ts +24 -0
  88. package/src/miner/history.ts +156 -0
  89. package/src/miner/index.ts +76 -0
  90. package/src/miner/sessions.ts +39 -0
  91. package/src/miner/stats.ts +43 -0
  92. package/src/miner/suggest.ts +101 -0
  93. package/src/miner/transitions.ts +62 -0
  94. package/src/miner/types.ts +45 -0
  95. package/src/miner/workflows.ts +96 -0
  96. package/src/parse.ts +321 -0
  97. package/src/render.ts +182 -0
  98. package/src/types.ts +62 -0
  99. package/workflows/docker-deploy.yml +42 -0
  100. package/workflows/docker-parallel.yml +36 -0
  101. package/workflows/gh-issue-to-pr.yml +48 -0
  102. package/workflows/git-pr-flow.yml +36 -0
  103. package/workflows/kubectl-rollout.yml +37 -0
  104. package/workflows/npm-publish.yml +42 -0
package/src/render.ts ADDED
@@ -0,0 +1,182 @@
1
+ import { createGrid, writeText } from "./grid";
2
+ import type { Grid } from "./grid";
3
+ import type { CLINode, Flag, Arg, TreeOptions } from "./types";
4
+
5
+ const BOX = {
6
+ pipe: "│",
7
+ tee: "├",
8
+ corner: "└",
9
+ dash: "──",
10
+ space: " ",
11
+ } as const;
12
+
13
+ interface RenderState {
14
+ grid: Grid;
15
+ row: number;
16
+ opts: Required<TreeOptions>;
17
+ }
18
+
19
+ function defaults(opts?: TreeOptions): Required<TreeOptions> {
20
+ return {
21
+ color: opts?.color ?? true,
22
+ indent: opts?.indent ?? 3,
23
+ showFlags: opts?.showFlags ?? true,
24
+ showArgs: opts?.showArgs ?? true,
25
+ showDescriptions: opts?.showDescriptions ?? true,
26
+ showTypes: opts?.showTypes ?? true,
27
+ showDefaults: opts?.showDefaults ?? true,
28
+ maxDepth: opts?.maxDepth ?? Infinity,
29
+ compact: opts?.compact ?? false,
30
+ };
31
+ }
32
+
33
+ function formatFlag(flag: Flag, opts: Required<TreeOptions>): string {
34
+ let text = `--${flag.name}`;
35
+ if (flag.short) text = `-${flag.short}, ${text}`;
36
+
37
+ if (opts.showTypes && flag.type !== "boolean") {
38
+ if (flag.type === "enum" && flag.enum) {
39
+ text += ` <${flag.enum.join("|")}>`;
40
+ } else {
41
+ text += ` <${flag.type}>`;
42
+ }
43
+ }
44
+
45
+ if (flag.type === "boolean") {
46
+ text += " [boolean]";
47
+ }
48
+
49
+ if (opts.showDefaults && flag.default !== undefined) {
50
+ text += ` (default: ${JSON.stringify(flag.default)})`;
51
+ }
52
+
53
+ if (flag.required) {
54
+ text += " *";
55
+ }
56
+
57
+ return text;
58
+ }
59
+
60
+ function formatArg(arg: Arg): string {
61
+ const name = arg.variadic ? `${arg.name}...` : arg.name;
62
+ return arg.required ? `<${name}>` : `[${name}]`;
63
+ }
64
+
65
+ function drawPrefix(state: RenderState, col: number, pipes: boolean[], isLast: boolean) {
66
+ const indent = state.opts.indent;
67
+ for (let i = 0; i < pipes.length; i++) {
68
+ const x = i * indent;
69
+ if (pipes[i]) {
70
+ writeText(state.grid, x, state.row, BOX.pipe, state.opts.color ? "gray" : null);
71
+ }
72
+ }
73
+
74
+ const x = pipes.length * indent;
75
+ const connector = isLast ? BOX.corner : BOX.tee;
76
+ writeText(state.grid, x, state.row, connector + BOX.dash + " ", state.opts.color ? "gray" : null);
77
+ }
78
+
79
+ function renderNode(
80
+ state: RenderState,
81
+ node: CLINode,
82
+ depth: number,
83
+ pipes: boolean[],
84
+ isLast: boolean,
85
+ isRoot: boolean,
86
+ ) {
87
+ const indent = state.opts.indent;
88
+
89
+ if (isRoot) {
90
+ writeText(state.grid, 0, state.row, node.name, state.opts.color ? "cyan" : null);
91
+ if (node.description && state.opts.showDescriptions) {
92
+ const descCol = node.name.length + 1;
93
+ writeText(state.grid, descCol, state.row, `— ${node.description}`, state.opts.color ? "gray" : null);
94
+ }
95
+ state.row++;
96
+ } else {
97
+ drawPrefix(state, pipes.length * indent, pipes, isLast);
98
+ const textStart = pipes.length * indent + 4;
99
+ writeText(state.grid, textStart, state.row, node.name, state.opts.color ? "green" : null);
100
+
101
+ if (node.aliases && node.aliases.length > 0) {
102
+ const aliasStart = textStart + node.name.length;
103
+ const aliasText = ` (${node.aliases.join(", ")})`;
104
+ writeText(state.grid, aliasStart, state.row, aliasText, state.opts.color ? "gray" : null);
105
+ }
106
+
107
+ if (node.description && state.opts.showDescriptions && !state.opts.compact) {
108
+ const nameLen = node.name.length + (node.aliases ? ` (${node.aliases.join(", ")})`.length : 0);
109
+ const descCol = textStart + nameLen + 1;
110
+ writeText(state.grid, descCol, state.row, `— ${node.description}`, state.opts.color ? "gray" : null);
111
+ }
112
+ state.row++;
113
+ }
114
+
115
+ if (depth >= state.opts.maxDepth) return;
116
+
117
+ const children: { type: "flag" | "arg" | "cmd"; item: Flag | Arg | CLINode }[] = [];
118
+
119
+ if (state.opts.showArgs && node.args) {
120
+ for (const arg of node.args) {
121
+ children.push({ type: "arg", item: arg });
122
+ }
123
+ }
124
+
125
+ if (state.opts.showFlags && node.flags) {
126
+ for (const flag of node.flags) {
127
+ children.push({ type: "flag", item: flag });
128
+ }
129
+ }
130
+
131
+ if (node.subcommands) {
132
+ for (const cmd of node.subcommands) {
133
+ children.push({ type: "cmd", item: cmd });
134
+ }
135
+ }
136
+
137
+ for (let i = 0; i < children.length; i++) {
138
+ const child = children[i]!;
139
+ const childIsLast = i === children.length - 1;
140
+ const nextPipes = isRoot ? [] : [...pipes, !isLast];
141
+
142
+ if (child.type === "flag") {
143
+ const flag = child.item as Flag;
144
+ drawPrefix(state, (nextPipes.length) * indent, nextPipes, childIsLast);
145
+ const textStart = nextPipes.length * indent + 4;
146
+ const flagText = formatFlag(flag, state.opts);
147
+ writeText(state.grid, textStart, state.row, flagText, state.opts.color ? "yellow" : null);
148
+
149
+ if (flag.description && state.opts.showDescriptions && !state.opts.compact) {
150
+ const descCol = textStart + flagText.length + 1;
151
+ writeText(state.grid, descCol, state.row, `— ${flag.description}`, state.opts.color ? "gray" : null);
152
+ }
153
+ state.row++;
154
+ } else if (child.type === "arg") {
155
+ const arg = child.item as Arg;
156
+ drawPrefix(state, (nextPipes.length) * indent, nextPipes, childIsLast);
157
+ const textStart = nextPipes.length * indent + 4;
158
+ const argText = formatArg(arg);
159
+ writeText(state.grid, textStart, state.row, argText, state.opts.color ? "magenta" : null);
160
+
161
+ if (arg.description && state.opts.showDescriptions && !state.opts.compact) {
162
+ const descCol = textStart + argText.length + 1;
163
+ writeText(state.grid, descCol, state.row, `— ${arg.description}`, state.opts.color ? "gray" : null);
164
+ }
165
+ state.row++;
166
+ } else {
167
+ const cmd = child.item as CLINode;
168
+ renderNode(state, cmd, depth + 1, nextPipes, childIsLast, false);
169
+ }
170
+ }
171
+ }
172
+
173
+ export function renderTree(root: CLINode, opts?: TreeOptions): Grid {
174
+ const resolved = defaults(opts);
175
+ const width = 120;
176
+ const grid = createGrid(width);
177
+ const state: RenderState = { grid, row: 0, opts: resolved };
178
+
179
+ renderNode(state, root, 0, [], true, true);
180
+
181
+ return grid;
182
+ }
package/src/types.ts ADDED
@@ -0,0 +1,62 @@
1
+ export type AnsiColor =
2
+ | "red"
3
+ | "green"
4
+ | "yellow"
5
+ | "blue"
6
+ | "magenta"
7
+ | "cyan"
8
+ | "white"
9
+ | "gray";
10
+
11
+ export const ANSI_COLORS: Record<AnsiColor, string> = {
12
+ red: "\x1b[31m",
13
+ green: "\x1b[32m",
14
+ yellow: "\x1b[33m",
15
+ blue: "\x1b[34m",
16
+ magenta: "\x1b[35m",
17
+ cyan: "\x1b[36m",
18
+ white: "\x1b[37m",
19
+ gray: "\x1b[90m",
20
+ };
21
+
22
+ export const ANSI_RESET = "\x1b[0m";
23
+ export const ANSI_BOLD = "\x1b[1m";
24
+ export const ANSI_DIM = "\x1b[2m";
25
+
26
+ export interface CLINode {
27
+ name: string;
28
+ description?: string;
29
+ aliases?: string[];
30
+ subcommands?: CLINode[];
31
+ flags?: Flag[];
32
+ args?: Arg[];
33
+ }
34
+
35
+ export interface Flag {
36
+ name: string;
37
+ short?: string;
38
+ type: "boolean" | "string" | "number" | "enum";
39
+ enum?: string[];
40
+ required?: boolean;
41
+ default?: unknown;
42
+ description?: string;
43
+ }
44
+
45
+ export interface Arg {
46
+ name: string;
47
+ required?: boolean;
48
+ variadic?: boolean;
49
+ description?: string;
50
+ }
51
+
52
+ export interface TreeOptions {
53
+ color?: boolean;
54
+ indent?: number;
55
+ showFlags?: boolean;
56
+ showArgs?: boolean;
57
+ showDescriptions?: boolean;
58
+ showTypes?: boolean;
59
+ showDefaults?: boolean;
60
+ maxDepth?: number;
61
+ compact?: boolean;
62
+ }
@@ -0,0 +1,42 @@
1
+ name: deploy
2
+ cli: docker
3
+ description: Build, tag, push, and run a containerized app
4
+
5
+ nodes:
6
+ - id: build
7
+ command: docker build -t myapp .
8
+ label: Build
9
+ description: Build the image from Dockerfile
10
+
11
+ - id: tag
12
+ command: docker tag myapp registry.example.com/myapp:latest
13
+ label: Tag
14
+ description: Tag the image for registry push
15
+
16
+ - id: push
17
+ command: docker push registry.example.com/myapp:latest
18
+ label: Push
19
+ description: Upload to registry
20
+
21
+ - id: pull
22
+ command: docker pull registry.example.com/myapp:latest
23
+ label: Pull (remote)
24
+ description: Pull from registry on target host
25
+
26
+ - id: run
27
+ command: docker run -d -p 80:3000 myapp
28
+ label: Run
29
+ description: Start the container
30
+
31
+ - id: logs
32
+ command: docker logs -f myapp
33
+ label: Logs
34
+ description: Follow container logs
35
+ optional: true
36
+
37
+ edges:
38
+ - build -> tag
39
+ - tag -> push
40
+ - push -> pull
41
+ - pull -> run
42
+ - run -> logs
@@ -0,0 +1,36 @@
1
+ name: parallel-deploy
2
+ cli: docker
3
+ description: Build once, push to multiple registries in parallel
4
+
5
+ nodes:
6
+ - id: build
7
+ command: docker build -t app .
8
+ label: Build
9
+
10
+ - id: tag-prod
11
+ command: docker tag app prod.registry/app
12
+ label: Tag prod
13
+
14
+ - id: tag-staging
15
+ command: docker tag app staging.registry/app
16
+ label: Tag staging
17
+
18
+ - id: push-prod
19
+ command: docker push prod.registry/app
20
+ label: Push prod
21
+
22
+ - id: push-staging
23
+ command: docker push staging.registry/app
24
+ label: Push staging
25
+
26
+ - id: notify
27
+ command: docker system info
28
+ label: Notify
29
+
30
+ edges:
31
+ - build -> tag-prod
32
+ - build -> tag-staging
33
+ - tag-prod -> push-prod
34
+ - tag-staging -> push-staging
35
+ - push-prod -> notify
36
+ - push-staging -> notify
@@ -0,0 +1,48 @@
1
+ name: issue-to-pr
2
+ cli: gh
3
+ description: Full flow from issue triage to merged PR
4
+
5
+ nodes:
6
+ - id: view-issue
7
+ command: gh issue view 123
8
+ label: View issue
9
+ description: Read the issue details
10
+
11
+ - id: assign
12
+ command: gh issue edit 123 --add-assignee @me
13
+ label: Assign
14
+ description: Assign the issue to yourself
15
+
16
+ - id: checkout
17
+ command: gh issue develop 123 --checkout
18
+ label: Branch
19
+ description: Create and checkout a development branch
20
+
21
+ - id: pr-create
22
+ command: gh pr create --fill
23
+ label: Open PR
24
+ description: Create a pull request
25
+
26
+ - id: review
27
+ command: gh pr review --approve
28
+ label: Review
29
+ description: Request review from teammates
30
+ optional: true
31
+
32
+ - id: pr-merge
33
+ command: gh pr merge --squash
34
+ label: Merge
35
+ description: Merge when approved
36
+
37
+ - id: close
38
+ command: gh issue close 123
39
+ label: Close issue
40
+ description: Close the linked issue
41
+
42
+ edges:
43
+ - view-issue -> assign
44
+ - assign -> checkout
45
+ - checkout -> pr-create
46
+ - pr-create -> review
47
+ - review -> pr-merge
48
+ - pr-merge -> close
@@ -0,0 +1,36 @@
1
+ name: pr-flow
2
+ cli: git
3
+ description: Typical flow for creating a pull request from a feature branch
4
+
5
+ nodes:
6
+ - id: checkout
7
+ command: git checkout -b feature/my-feature
8
+ label: Create branch
9
+ description: Create and switch to a new feature branch
10
+
11
+ - id: add
12
+ command: git add .
13
+ label: Stage changes
14
+ description: Stage all modified files
15
+
16
+ - id: commit
17
+ command: git commit -m "message"
18
+ label: Commit
19
+ description: Record changes with a meaningful message
20
+
21
+ - id: push
22
+ command: git push -u origin feature/my-feature
23
+ label: Push
24
+ description: Push branch to remote and set upstream
25
+
26
+ - id: pr
27
+ command: gh pr create
28
+ label: Open PR
29
+ description: Open a pull request via gh CLI
30
+ optional: true
31
+
32
+ edges:
33
+ - checkout -> add
34
+ - add -> commit
35
+ - commit -> push
36
+ - push -> pr
@@ -0,0 +1,37 @@
1
+ name: rollout
2
+ cli: kubectl
3
+ description: Apply a new deployment and monitor the rollout
4
+
5
+ nodes:
6
+ - id: apply
7
+ command: kubectl apply -f deployment.yaml
8
+ label: Apply
9
+ description: Apply the new deployment manifest
10
+
11
+ - id: status
12
+ command: kubectl rollout status deployment/myapp
13
+ label: Status
14
+ description: Watch the rollout until complete
15
+
16
+ - id: logs
17
+ command: kubectl logs -l app=myapp --tail=100
18
+ label: Logs
19
+ description: Check recent logs from the new pods
20
+
21
+ - id: verify
22
+ command: kubectl get pods -l app=myapp
23
+ label: Verify
24
+ description: Confirm pods are running
25
+
26
+ - id: undo
27
+ command: kubectl rollout undo deployment/myapp
28
+ label: Undo
29
+ description: Roll back if something went wrong
30
+ optional: true
31
+
32
+ edges:
33
+ - apply -> status
34
+ - status -> logs
35
+ - status -> verify
36
+ - logs -> undo
37
+ - verify -> undo
@@ -0,0 +1,42 @@
1
+ name: publish
2
+ cli: npm
3
+ description: Test, build, version, and publish a package
4
+
5
+ nodes:
6
+ - id: install
7
+ command: npm install
8
+ label: Install
9
+ description: Install dependencies
10
+
11
+ - id: test
12
+ command: npm test
13
+ label: Test
14
+ description: Run the test suite
15
+
16
+ - id: build
17
+ command: npm run build
18
+ label: Build
19
+ description: Build for distribution
20
+
21
+ - id: version
22
+ command: npm version patch
23
+ label: Version bump
24
+ description: Increment version
25
+
26
+ - id: publish
27
+ command: npm publish
28
+ label: Publish
29
+ description: Publish to the npm registry
30
+
31
+ - id: tag
32
+ command: npm dist-tag add mypkg@1.0.0 latest
33
+ label: Dist-tag
34
+ description: Update dist-tag
35
+ optional: true
36
+
37
+ edges:
38
+ - install -> test
39
+ - test -> build
40
+ - build -> version
41
+ - version -> publish
42
+ - publish -> tag