@archinsight/cli 3.0.0-snapshot.0 → 3.0.0-snapshot.2

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 (3) hide show
  1. package/README.md +54 -0
  2. package/build/index.js +940 -9
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -13,6 +13,7 @@ archinsight link [project-dir] [--format text|json] [--out file]
13
13
  archinsight structure [project-dir] [--format text|json] [--out file]
14
14
  archinsight query [project-dir] -c <context> [-s <source>] [-v c1|c2|c3|c4|no-filter] [-q query.aiq] [-f text|json] [-o file]
15
15
  archinsight render [project-dir] -c <context> [-s <source>] [-v c1|c2|c3|c4|no-filter] [-q query.aiq] [-f dot|svg|json] [-o file]
16
+ archinsight skill init [project-dir] [--target generic|codex|claude] [--out dir] [--force]
16
17
  ```
17
18
 
18
19
  `project-dir` defaults to the current directory.
@@ -27,6 +28,8 @@ archinsight render [project-dir] -c <context> [-s <source>] [-v c1|c2|c3|c4|no-f
27
28
  - `-f, --format <format>` - command output format.
28
29
  - `-o, --out <file>` - write payload output to a file instead of stdout.
29
30
  - `-t, --theme <theme>` - render theme; defaults to `light`.
31
+ - `--target <target>` - skill target for `skill init`: `generic`, `codex`, or `claude`.
32
+ - `--force` - replace existing generated skill files.
30
33
  - `-V, --version` - print version.
31
34
  - `-h, --help` - print help.
32
35
 
@@ -45,6 +48,57 @@ Render DOT for a context using the C2 built-in query:
45
48
  node archinsight-cli/build/index.js render examples -c demo -s main.ai -v c2 -f dot
46
49
  ```
47
50
 
51
+ Generate a portable AI-agent guide for an Insight project:
52
+
53
+ ```shell
54
+ archinsight skill init --target generic
55
+ ```
56
+
57
+ The generic target writes a runtime-neutral guide:
58
+
59
+ ```text
60
+ .archinsight/agent/
61
+ archinsight.md
62
+ references/
63
+ syntax.md
64
+ layered-architecture.md
65
+ queries.md
66
+ validation.md
67
+ examples/
68
+ layered-architecture.ai
69
+ c2-containers.aiq
70
+ ```
71
+
72
+ Codex and Claude targets package the same Insight reference directly into the
73
+ native skill folders:
74
+
75
+ ```shell
76
+ archinsight skill init --target codex
77
+ archinsight skill init --target claude
78
+ ```
79
+
80
+ ```text
81
+ .codex/skills/archinsight/
82
+ SKILL.md
83
+ agents/openai.yaml
84
+ references/
85
+ examples/
86
+
87
+ .claude/skills/archinsight/
88
+ SKILL.md
89
+ references/
90
+ examples/
91
+ ```
92
+
93
+ After generating a Codex or Claude skill into the default location, restart the
94
+ agent session so the skill is discovered. Pass `--out <dir>` to write the same
95
+ package somewhere else.
96
+
97
+ The guide tells agents to treat `archinsight` as the validation source of truth,
98
+ avoid guessing Insight syntax from other architecture DSLs, describe systems
99
+ layer by layer from context to containers, components, and deployment details,
100
+ and write custom `.aiq` diagram queries with the supported Cypher-style subset.
101
+
48
102
  ## Output Contract
49
103
 
50
104
  Payload output goes to stdout unless `--out` is supplied.
package/build/index.js CHANGED
@@ -37460,7 +37460,7 @@ var QueryParser = class {
37460
37460
  };
37461
37461
 
37462
37462
  // src/version.ts
37463
- var version = "3.0.0-snapshot.0";
37463
+ var version = "3.0.0-snapshot.2";
37464
37464
 
37465
37465
  // src/index.ts
37466
37466
  var hiddenStructureTypes = /* @__PURE__ */ new Set(["List", "Nothing", "Text", "text"]);
@@ -37547,6 +37547,9 @@ async function main() {
37547
37547
  case "structure":
37548
37548
  await runStructure(args);
37549
37549
  return;
37550
+ case "skill":
37551
+ await runSkill(args);
37552
+ return;
37550
37553
  }
37551
37554
  }
37552
37555
  async function runLink(args) {
@@ -37629,6 +37632,32 @@ async function runStructure(args) {
37629
37632
  }
37630
37633
  await writeOutput(args.output, formatStructure(structure));
37631
37634
  }
37635
+ async function runSkill(args) {
37636
+ if (args.skillAction !== "init") {
37637
+ throw new CliError("Usage: archinsight skill init [project-dir] [--target generic|codex|claude] [--out dir] [--force]");
37638
+ }
37639
+ const target = skillTarget(args.target);
37640
+ switch (target) {
37641
+ case "generic":
37642
+ await runSkillInit(args, genericSkillPackage());
37643
+ return;
37644
+ case "codex":
37645
+ await runSkillInit(args, codexSkillPackage());
37646
+ return;
37647
+ case "claude":
37648
+ await runSkillInit(args, claudeSkillPackage());
37649
+ return;
37650
+ }
37651
+ }
37652
+ async function runSkillInit(args, skillPackage) {
37653
+ const projectRoot = path.resolve(projectPath(args));
37654
+ const usesDefaultOutput = args.output === void 0;
37655
+ const outputRoot = path.resolve(projectRoot, args.output ?? skillPackage.defaultOutput);
37656
+ for (const file of skillPackage.files) {
37657
+ await writeGeneratedFile(path.join(outputRoot, file.path), file.content, args.force);
37658
+ }
37659
+ process.stdout.write(skillPackageSuccess(projectRoot, outputRoot, skillPackage, usesDefaultOutput));
37660
+ }
37632
37661
  async function loadProject(input) {
37633
37662
  const root = path.resolve(input);
37634
37663
  const sources = await readSources(root);
@@ -37703,11 +37732,11 @@ async function sourceFiles(directory) {
37703
37732
  const entries = await readdir(directory, { withFileTypes: true });
37704
37733
  const result = [];
37705
37734
  for (const entry of entries) {
37706
- if (entry.name === "node_modules" || entry.name === ".git" || entry.name === "build") {
37707
- continue;
37708
- }
37709
37735
  const entryPath = path.join(directory, entry.name);
37710
37736
  if (entry.isDirectory()) {
37737
+ if (isIgnoredSourceDirectory(entry.name)) {
37738
+ continue;
37739
+ }
37711
37740
  result.push(...await sourceFiles(entryPath));
37712
37741
  } else if (entry.isFile() && entry.name.endsWith(".ai")) {
37713
37742
  result.push(entryPath);
@@ -37715,6 +37744,9 @@ async function sourceFiles(directory) {
37715
37744
  }
37716
37745
  return result.sort((left, right) => left.localeCompare(right));
37717
37746
  }
37747
+ function isIgnoredSourceDirectory(name) {
37748
+ return name.startsWith(".") || name === "node_modules" || name === "build" || name === "dist";
37749
+ }
37718
37750
  async function renderSvg(dot) {
37719
37751
  const viz = await instance();
37720
37752
  const result = viz.render(dot, { format: "svg", engine: "dot" });
@@ -37896,6 +37928,24 @@ async function writeOutput(file, content) {
37896
37928
  await mkdir(path.dirname(path.resolve(file)), { recursive: true });
37897
37929
  await writeFile(file, content);
37898
37930
  }
37931
+ async function writeGeneratedFile(file, content, force) {
37932
+ if (!force && await exists(file)) {
37933
+ throw new CliError(`Refusing to overwrite '${file}'. Pass --force to replace generated agent files.`);
37934
+ }
37935
+ await mkdir(path.dirname(file), { recursive: true });
37936
+ await writeFile(file, content);
37937
+ }
37938
+ async function exists(file) {
37939
+ try {
37940
+ await stat(file);
37941
+ return true;
37942
+ } catch (error) {
37943
+ if (typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT") {
37944
+ return false;
37945
+ }
37946
+ throw error;
37947
+ }
37948
+ }
37899
37949
  function parseArgs(argv) {
37900
37950
  const options = {};
37901
37951
  const positional = [];
@@ -37909,6 +37959,10 @@ function parseArgs(argv) {
37909
37959
  options.version = true;
37910
37960
  continue;
37911
37961
  }
37962
+ if (arg === "--force") {
37963
+ options.force = true;
37964
+ continue;
37965
+ }
37912
37966
  const key = optionKey(arg);
37913
37967
  if (key !== void 0) {
37914
37968
  const value = argv[index + 1];
@@ -37926,7 +37980,8 @@ function parseArgs(argv) {
37926
37980
  }
37927
37981
  return {
37928
37982
  command: command(positional[0]),
37929
- input: positional[1],
37983
+ skillAction: skillAction(positional[0], positional[1]),
37984
+ input: inputPath(positional),
37930
37985
  context: stringOption(options.context),
37931
37986
  tab: stringOption(options.tab),
37932
37987
  view: viewOption(options.view),
@@ -37934,8 +37989,10 @@ function parseArgs(argv) {
37934
37989
  output: stringOption(options.output),
37935
37990
  format: stringOption(options.format),
37936
37991
  theme: stringOption(options.theme),
37992
+ target: stringOption(options.target),
37937
37993
  help: options.help === true,
37938
- version: options.version === true
37994
+ version: options.version === true,
37995
+ force: options.force === true
37939
37996
  };
37940
37997
  }
37941
37998
  function optionKey(arg) {
@@ -37954,11 +38011,12 @@ function optionKey(arg) {
37954
38011
  "--format": "format",
37955
38012
  "-f": "format",
37956
38013
  "--theme": "theme",
37957
- "-t": "theme"
38014
+ "-t": "theme",
38015
+ "--target": "target"
37958
38016
  }[arg];
37959
38017
  }
37960
38018
  function command(value) {
37961
- if (value === "link" || value === "render" || value === "query" || value === "structure") {
38019
+ if (value === "link" || value === "render" || value === "query" || value === "structure" || value === "skill") {
37962
38020
  return value;
37963
38021
  }
37964
38022
  if (value === void 0) {
@@ -37966,6 +38024,30 @@ function command(value) {
37966
38024
  }
37967
38025
  throw new CliError(`Unknown command '${value}'`);
37968
38026
  }
38027
+ function skillAction(commandValue, value) {
38028
+ if (commandValue !== "skill") {
38029
+ return void 0;
38030
+ }
38031
+ if (value === "init") {
38032
+ return value;
38033
+ }
38034
+ if (value === void 0) {
38035
+ return void 0;
38036
+ }
38037
+ throw new CliError(`Unknown skill command '${value}'`);
38038
+ }
38039
+ function inputPath(positional) {
38040
+ return positional[0] === "skill" ? positional[2] : positional[1];
38041
+ }
38042
+ function skillTarget(value) {
38043
+ if (value === void 0 || value === "generic") {
38044
+ return "generic";
38045
+ }
38046
+ if (value === "codex" || value === "claude") {
38047
+ return value;
38048
+ }
38049
+ throw new CliError(`Unknown skill target '${value}'`);
38050
+ }
37969
38051
  function viewOption(value) {
37970
38052
  if (value === void 0) {
37971
38053
  return void 0;
@@ -37996,6 +38078,13 @@ function renderFormat(value, fallback) {
37996
38078
  function stringOption(value) {
37997
38079
  return typeof value === "string" ? value : void 0;
37998
38080
  }
38081
+ function displayPath(from, target) {
38082
+ const relative = path.relative(from, target);
38083
+ if (relative === "") {
38084
+ return ".";
38085
+ }
38086
+ return relative.startsWith("..") || path.isAbsolute(relative) ? target : relative;
38087
+ }
37999
38088
  function helpText() {
38000
38089
  return `Archinsight CLI ${version}
38001
38090
 
@@ -38004,6 +38093,7 @@ Usage:
38004
38093
  archinsight render [project-dir] -c <context> [-s <source>] [-v c1|c2|c3|c4|no-filter] [-q query.aiq] [-f dot|svg|json] [-o file]
38005
38094
  archinsight query [project-dir] -c <context> [-s <source>] [-v c1|c2|c3|c4|no-filter] [-q query.aiq] [-f text|json] [-o file]
38006
38095
  archinsight structure [project-dir] [--format text|json] [--out file]
38096
+ archinsight skill init [project-dir] [--target generic|codex|claude] [--out dir] [--force]
38007
38097
 
38008
38098
  Options:
38009
38099
  project-dir Project directory to scan recursively, default: current directory.
@@ -38013,8 +38103,10 @@ Options:
38013
38103
  -v, --view <name> Built-in view: c1, c2, c3, c4, no-filter.
38014
38104
  -q, --query <file> Query file; overrides --view.
38015
38105
  -f, --format <format> Output format.
38016
- -o, --out <file> Write output to file instead of stdout.
38106
+ -o, --out <file> Write output to file instead of stdout; for skill init, write the guide directory.
38017
38107
  -t, --theme <theme> Render theme, default: light.
38108
+ --target <target> Skill target: generic, codex, or claude.
38109
+ --force Replace existing generated skill files.
38018
38110
  -V, --version Print version.
38019
38111
  -h, --help Show help.
38020
38112
 
@@ -38022,6 +38114,845 @@ Diagnostics text format is TSV:
38022
38114
  level<TAB>code<TAB>source<TAB>line<TAB>column<TAB>message
38023
38115
  `;
38024
38116
  }
38117
+ function genericSkillPackage() {
38118
+ return {
38119
+ target: "generic",
38120
+ defaultOutput: ".archinsight/agent",
38121
+ entrypoint: "archinsight.md",
38122
+ installedByDefault: false,
38123
+ files: [
38124
+ {
38125
+ path: "archinsight.md",
38126
+ content: genericSkillGuide()
38127
+ },
38128
+ ...sharedSkillFiles()
38129
+ ]
38130
+ };
38131
+ }
38132
+ function codexSkillPackage() {
38133
+ return {
38134
+ target: "codex",
38135
+ defaultOutput: ".codex/skills/archinsight",
38136
+ entrypoint: "SKILL.md",
38137
+ installedByDefault: true,
38138
+ files: [
38139
+ {
38140
+ path: "SKILL.md",
38141
+ content: codexSkillGuide()
38142
+ },
38143
+ {
38144
+ path: "agents/openai.yaml",
38145
+ content: codexOpenAiYaml()
38146
+ },
38147
+ ...sharedSkillFiles()
38148
+ ]
38149
+ };
38150
+ }
38151
+ function claudeSkillPackage() {
38152
+ return {
38153
+ target: "claude",
38154
+ defaultOutput: ".claude/skills/archinsight",
38155
+ entrypoint: "SKILL.md",
38156
+ installedByDefault: true,
38157
+ files: [
38158
+ {
38159
+ path: "SKILL.md",
38160
+ content: claudeSkillGuide()
38161
+ },
38162
+ ...sharedSkillFiles()
38163
+ ]
38164
+ };
38165
+ }
38166
+ function sharedSkillFiles() {
38167
+ return [
38168
+ {
38169
+ path: "references/syntax.md",
38170
+ content: genericSyntaxReference()
38171
+ },
38172
+ {
38173
+ path: "references/layered-architecture.md",
38174
+ content: genericLayeredArchitectureReference()
38175
+ },
38176
+ {
38177
+ path: "references/validation.md",
38178
+ content: genericValidationReference()
38179
+ },
38180
+ {
38181
+ path: "references/queries.md",
38182
+ content: genericQueriesReference()
38183
+ },
38184
+ {
38185
+ path: "examples/layered-architecture.ai",
38186
+ content: genericLayeredArchitectureExample()
38187
+ },
38188
+ {
38189
+ path: "examples/c2-containers.aiq",
38190
+ content: genericC2QueryExample()
38191
+ }
38192
+ ];
38193
+ }
38194
+ function skillPackageSuccess(projectRoot, outputRoot, skillPackage, usesDefaultOutput) {
38195
+ const lines = [
38196
+ `Generated ${skillPackage.target} Archinsight agent guide: ${displayPath(process.cwd(), outputRoot)}`,
38197
+ ""
38198
+ ];
38199
+ if (skillPackage.target === "generic") {
38200
+ lines.push("Next steps:");
38201
+ lines.push(` 1. Share ${displayPath(projectRoot, path.join(outputRoot, skillPackage.entrypoint))} with your AI agent.`);
38202
+ lines.push(" 2. Ask the agent to validate Insight edits with: archinsight link . --format text");
38203
+ lines.push(" 3. Keep project-specific conventions near the generated guide or pass them in the prompt.");
38204
+ } else if (skillPackage.installedByDefault && usesDefaultOutput) {
38205
+ lines.push(`Notice: restart the ${skillPackage.target} session so the Archinsight skill is discovered.`);
38206
+ } else if (skillPackage.target === "codex") {
38207
+ lines.push("Next steps:");
38208
+ lines.push(` 1. Install or copy ${displayPath(projectRoot, outputRoot)} as the archinsight skill in your Codex skills directory.`);
38209
+ lines.push(" 2. Invoke it explicitly as $archinsight when editing Insight .ai models.");
38210
+ lines.push(" 3. Ask Codex to validate Insight edits with: archinsight link . --format text");
38211
+ } else {
38212
+ lines.push("Next steps:");
38213
+ lines.push(` 1. Import or copy ${displayPath(projectRoot, outputRoot)} into your Claude skill runtime.`);
38214
+ lines.push(" 2. Ask Claude to use the Archinsight skill before editing Insight .ai models.");
38215
+ lines.push(" 3. Validate Insight edits with: archinsight link . --format text");
38216
+ }
38217
+ lines.push("");
38218
+ return lines.join("\n");
38219
+ }
38220
+ function genericSkillGuide() {
38221
+ return `# Archinsight Agent Guide
38222
+
38223
+ Use this guide when creating or editing Insight \`.ai\` architecture models.
38224
+
38225
+ Insight is its own typed architecture-as-code language. Do not infer its syntax
38226
+ from YAML, Mermaid, PlantUML, Structurizr, or C4 DSL.
38227
+
38228
+ ## Required Tool
38229
+
38230
+ Use the Archinsight CLI as the validation source of truth:
38231
+
38232
+ \`\`\`shell
38233
+ archinsight --help
38234
+ archinsight link . --format text
38235
+ \`\`\`
38236
+
38237
+ If \`archinsight\` is not available, ask the user to install or expose
38238
+ \`@archinsight/cli\` before changing \`.ai\` files.
38239
+
38240
+ ## Workflow
38241
+
38242
+ 1. Read the existing \`.ai\` files before editing.
38243
+ 2. Preserve indentation and the project's existing naming style.
38244
+ 3. Model architecture from the outside inward: context, external actors/systems,
38245
+ systems, containers/services, components, and deployment details.
38246
+ 4. Prefer small, focused files connected by \`context\`, \`import\`, and \`extend\`.
38247
+ 5. Validate every Insight change with \`archinsight link . --format text\`.
38248
+
38249
+ ## References
38250
+
38251
+ - Read \`references/syntax.md\` before writing unfamiliar Insight syntax.
38252
+ - Read \`references/layered-architecture.md\` when decomposing a system across
38253
+ C1/C2/C3/C4-style layers.
38254
+ - Read \`references/queries.md\` when writing custom diagram queries or \`.aiq\`
38255
+ files.
38256
+ - Read \`references/validation.md\` before running checks, structure inspection,
38257
+ or rendering.
38258
+ - Use \`examples/layered-architecture.ai\` as a compact valid model.
38259
+ `;
38260
+ }
38261
+ function codexSkillGuide() {
38262
+ return `---
38263
+ name: archinsight
38264
+ description: Create, edit, validate, inspect, and render Archinsight Insight architecture-as-code models. Use when working with .ai Insight files, C4-style architecture models, system/container/component diagrams, deployment projections, or when the user asks to model software architecture with Archinsight.
38265
+ ---
38266
+
38267
+ # Archinsight
38268
+
38269
+ Use this skill when creating or editing Insight \`.ai\` architecture models.
38270
+
38271
+ Insight is its own typed architecture-as-code language. Do not infer its syntax
38272
+ from YAML, Mermaid, PlantUML, Structurizr, or C4 DSL.
38273
+
38274
+ ## Codex Usage Notes
38275
+
38276
+ Treat this \`SKILL.md\` as the entrypoint. Load reference files only when needed:
38277
+
38278
+ - Read \`references/syntax.md\` before writing unfamiliar Insight syntax.
38279
+ - Read \`references/layered-architecture.md\` before decomposing a system across
38280
+ C1/C2/C3/C4-style layers.
38281
+ - Read \`references/queries.md\` before writing custom diagram queries or \`.aiq\`
38282
+ files.
38283
+ - Read \`references/validation.md\` before running checks, structure inspection,
38284
+ or rendering commands.
38285
+
38286
+ Use Codex shell access to validate changes when available. Do not silently
38287
+ install global npm packages or change machine configuration. If \`archinsight\`
38288
+ is missing, ask the user whether they want to install or expose
38289
+ \`@archinsight/cli\`.
38290
+
38291
+ ## Required Tool
38292
+
38293
+ Use the Archinsight CLI as the validation source of truth:
38294
+
38295
+ \`\`\`shell
38296
+ archinsight --help
38297
+ archinsight link . --format text
38298
+ \`\`\`
38299
+
38300
+ If \`archinsight\` is not available, ask the user to install or expose
38301
+ \`@archinsight/cli\` before changing \`.ai\` files.
38302
+
38303
+ ## Workflow
38304
+
38305
+ 1. Read the existing \`.ai\` files before editing.
38306
+ 2. Preserve indentation and the project's existing naming style.
38307
+ 3. Model architecture from the outside inward: context, external actors/systems,
38308
+ systems, containers/services, components, and deployment details.
38309
+ 4. Prefer small, focused files connected by \`context\`, \`import\`, and \`extend\`.
38310
+ 5. Use \`archinsight structure . --format text\` before broad edits when the
38311
+ project shape is unclear.
38312
+ 6. Validate every Insight change with \`archinsight link . --format text\`.
38313
+ 7. If validation fails, fix the first real syntax/type/linking error before
38314
+ adding more model content.
38315
+
38316
+ ## References
38317
+
38318
+ - Read \`references/syntax.md\` before writing unfamiliar Insight syntax.
38319
+ - Read \`references/layered-architecture.md\` when decomposing a system across
38320
+ C1/C2/C3/C4-style layers.
38321
+ - Read \`references/queries.md\` when writing custom diagram queries or \`.aiq\`
38322
+ files.
38323
+ - Read \`references/validation.md\` before running checks, structure inspection,
38324
+ or rendering.
38325
+ - Use \`examples/layered-architecture.ai\` as a compact valid model.
38326
+ `;
38327
+ }
38328
+ function claudeSkillGuide() {
38329
+ return `---
38330
+ name: archinsight
38331
+ description: Create, edit, validate, inspect, and render Archinsight Insight architecture-as-code models. Use when working with .ai Insight files, C4-style architecture models, system/container/component diagrams, deployment projections, or when the user asks to model software architecture with Archinsight.
38332
+ ---
38333
+
38334
+ # Archinsight
38335
+
38336
+ Use this skill when creating or editing Insight \`.ai\` architecture models.
38337
+
38338
+ Insight is its own typed architecture-as-code language. Do not infer its syntax
38339
+ from YAML, Mermaid, PlantUML, Structurizr, or C4 DSL.
38340
+
38341
+ ## Claude Usage Notes
38342
+
38343
+ Treat this \`SKILL.md\` as the entrypoint. Load the reference files only when
38344
+ they are needed:
38345
+
38346
+ - Read \`references/syntax.md\` before writing unfamiliar Insight syntax.
38347
+ - Read \`references/layered-architecture.md\` before decomposing a system across
38348
+ C1/C2/C3/C4-style layers.
38349
+ - Read \`references/queries.md\` before writing custom diagram queries or \`.aiq\`
38350
+ files.
38351
+ - Read \`references/validation.md\` before asking the user to run validation,
38352
+ structure inspection, or rendering commands.
38353
+
38354
+ When Claude has direct shell access, run validation yourself. When Claude is
38355
+ embedded in an editor without shell access, ask the user to run the exact command
38356
+ and paste the output. Do not silently install npm packages or change machine
38357
+ configuration.
38358
+
38359
+ ## Required Tool
38360
+
38361
+ Use the Archinsight CLI as the validation source of truth:
38362
+
38363
+ \`\`\`shell
38364
+ archinsight --help
38365
+ archinsight link . --format text
38366
+ \`\`\`
38367
+
38368
+ If \`archinsight\` is not available in Claude's environment, ask the user to
38369
+ install or expose \`@archinsight/cli\` before changing \`.ai\` files.
38370
+
38371
+ ## Workflow
38372
+
38373
+ 1. Read the existing \`.ai\` files before editing.
38374
+ 2. Preserve indentation and the project's existing naming style.
38375
+ 3. Model architecture from the outside inward: context, external actors/systems,
38376
+ systems, containers/services, components, and deployment details.
38377
+ 4. Prefer small, focused files connected by \`context\`, \`import\`, and \`extend\`.
38378
+ 5. Use \`archinsight structure . --format text\` to inspect the current model
38379
+ before broad edits when the CLI is available.
38380
+ 6. Validate every Insight change with \`archinsight link . --format text\` when
38381
+ shell access is available; otherwise ask the user to run validation.
38382
+ 7. If validation fails, fix the first real syntax/type/linking error before
38383
+ adding more model content.
38384
+
38385
+ ## Communication
38386
+
38387
+ When shell access is unavailable, give the user short copy-pasteable commands:
38388
+
38389
+ \`\`\`shell
38390
+ archinsight link . --format text
38391
+ archinsight structure . --format text
38392
+ \`\`\`
38393
+
38394
+ If rendering is needed, ask for the context id and source file when they are not
38395
+ obvious:
38396
+
38397
+ \`\`\`shell
38398
+ archinsight render . -c <context-id> -s <source.ai> -v c2 -f svg -o diagram.svg
38399
+ \`\`\`
38400
+
38401
+ Report diagnostics by source, line, column, and message. Avoid rewriting large
38402
+ sections of Insight unless the existing layering is already understood.
38403
+
38404
+ ## References
38405
+
38406
+ - Read \`references/syntax.md\` before writing unfamiliar Insight syntax.
38407
+ - Read \`references/layered-architecture.md\` when decomposing a system across
38408
+ C1/C2/C3/C4-style layers.
38409
+ - Read \`references/queries.md\` when writing custom diagram queries or \`.aiq\`
38410
+ files.
38411
+ - Read \`references/validation.md\` before running checks, structure inspection,
38412
+ or rendering.
38413
+ - Use \`examples/layered-architecture.ai\` as a compact valid model.
38414
+ `;
38415
+ }
38416
+ function codexOpenAiYaml() {
38417
+ return `interface:
38418
+ display_name: "Archinsight"
38419
+ short_description: "Work with Insight architecture models"
38420
+ default_prompt: "Use $archinsight to model or validate Insight architecture-as-code files."
38421
+
38422
+ policy:
38423
+ allow_implicit_invocation: true
38424
+ `;
38425
+ }
38426
+ function genericSyntaxReference() {
38427
+ return `# Insight Syntax Reference
38428
+
38429
+ ## Files and Contexts
38430
+
38431
+ Every model starts with a context:
38432
+
38433
+ \`\`\`insight
38434
+ context ecommerce
38435
+ name = E-commerce Platform
38436
+ \`\`\`
38437
+
38438
+ Use indentation to define ownership. Children belong to the nearest less-indented
38439
+ parent.
38440
+
38441
+ ## Common Elements
38442
+
38443
+ Use built-in constructors for C4-style architecture:
38444
+
38445
+ \`\`\`insight
38446
+ external actor customer
38447
+ name = Customer
38448
+ technology = Web browser
38449
+
38450
+ system storefront
38451
+ name = Storefront
38452
+ technology = SvelteKit, TypeScript
38453
+
38454
+ container web_app
38455
+ name = Web app
38456
+ technology = SvelteKit
38457
+
38458
+ service catalog_api
38459
+ name = Catalog API
38460
+ technology = Node.js, PostgreSQL
38461
+ \`\`\`
38462
+
38463
+ Useful built-ins include:
38464
+
38465
+ - \`context\` for a bounded architecture model.
38466
+ - \`external actor\` and \`external system\` for dependencies outside the owned system.
38467
+ - \`system\` for major systems in a context.
38468
+ - \`container\` for deployable or executable units.
38469
+ - \`service\` for backend/container services.
38470
+ - \`component\` for internals of a selected container or service.
38471
+
38472
+ ## Attributes
38473
+
38474
+ Attributes are named and typed:
38475
+
38476
+ \`\`\`insight
38477
+ name = Checkout API
38478
+ technology = Kotlin, PostgreSQL
38479
+ description = Handles cart pricing, order placement, and payment orchestration
38480
+ \`\`\`
38481
+
38482
+ Long text can continue on indented following lines:
38483
+
38484
+ \`\`\`insight
38485
+ description = Handles checkout orchestration and keeps payment provider details
38486
+ outside the storefront.
38487
+ \`\`\`
38488
+
38489
+ ## Relationships
38490
+
38491
+ Put relationships under \`links:\`.
38492
+
38493
+ \`\`\`insight
38494
+ links:
38495
+ -> checkout_api
38496
+ technology = HTTPS, JSON
38497
+ description = Places an order
38498
+ ~> analytics
38499
+ technology = Kafka
38500
+ description = Publishes order events
38501
+ \`\`\`
38502
+
38503
+ Use \`from <context-id>\` when linking to an imported element from another
38504
+ context:
38505
+
38506
+ \`\`\`insight
38507
+ import payments from context external_systems
38508
+
38509
+ links:
38510
+ -> payments from external_systems
38511
+ \`\`\`
38512
+
38513
+ ## Imports and Extensions
38514
+
38515
+ Split larger models across files by repeating the context id and extending
38516
+ existing elements:
38517
+
38518
+ \`\`\`insight
38519
+ context ecommerce
38520
+
38521
+ extend service checkout_api
38522
+ component payment_adapter
38523
+ name = Payment adapter
38524
+ technology = HTTP client
38525
+ \`\`\`
38526
+
38527
+ Use imports for elements from another context:
38528
+
38529
+ \`\`\`insight
38530
+ import stripe from context external_systems
38531
+ \`\`\`
38532
+
38533
+ ## Annotations
38534
+
38535
+ Annotations decorate the next declaration or link:
38536
+
38537
+ \`\`\`insight
38538
+ @planned
38539
+ external system warehouse
38540
+ name = Warehouse
38541
+
38542
+ links:
38543
+ @deprecated
38544
+ ~> legacy_erp
38545
+ \`\`\`
38546
+
38547
+ Use presentation definitions for durable visual styling. Avoid adding new
38548
+ Graphviz attributes directly unless the project already uses that convention.
38549
+
38550
+ ## Custom Types
38551
+
38552
+ Projects can extend the language with typed vocabulary:
38553
+
38554
+ \`\`\`insight
38555
+ define type Broker of InfrastructureComponent
38556
+ constructor broker
38557
+ \`\`\`
38558
+
38559
+ When adding custom types, follow the existing framework files and validate
38560
+ immediately. Do not invent constructors without checking whether the project
38561
+ already defines the needed type.
38562
+ `;
38563
+ }
38564
+ function genericLayeredArchitectureReference() {
38565
+ return `# Modeling Architecture by Layers
38566
+
38567
+ Describe architecture from broad intent to implementation detail. Keep every
38568
+ layer useful on its own.
38569
+
38570
+ ## C1: System Context
38571
+
38572
+ Start with the context, people, owned systems, and external dependencies.
38573
+
38574
+ \`\`\`insight
38575
+ context ecommerce
38576
+ name = E-commerce Platform
38577
+
38578
+ external actor customer
38579
+ name = Customer
38580
+ technology = Web browser
38581
+ links:
38582
+ -> storefront
38583
+
38584
+ external system payment_provider
38585
+ name = Payment Provider
38586
+ technology = HTTPS API
38587
+
38588
+ system storefront
38589
+ name = Storefront
38590
+ technology = Web app
38591
+ \`\`\`
38592
+
38593
+ At this layer, avoid implementation details. Explain who uses the system and
38594
+ which external systems matter.
38595
+
38596
+ ## C2: Containers and Services
38597
+
38598
+ Nest deployable units under the owned system:
38599
+
38600
+ \`\`\`insight
38601
+ system storefront
38602
+ name = Storefront
38603
+
38604
+ container web_app
38605
+ name = Web app
38606
+ technology = SvelteKit, TypeScript
38607
+ links:
38608
+ -> checkout_api
38609
+
38610
+ service checkout_api
38611
+ name = Checkout API
38612
+ technology = Node.js, PostgreSQL
38613
+ links:
38614
+ -> payment_provider from ecommerce
38615
+ \`\`\`
38616
+
38617
+ Use \`container\` for applications or deployable units. Use \`service\` for
38618
+ backend services. Add links that explain runtime collaboration.
38619
+
38620
+ ## C3: Components
38621
+
38622
+ Put component details in a separate file with \`extend\` when the service becomes
38623
+ interesting enough to decompose:
38624
+
38625
+ \`\`\`insight
38626
+ context ecommerce
38627
+
38628
+ extend service checkout_api
38629
+ component order_controller
38630
+ name = Order controller
38631
+ technology = REST
38632
+ responsibility = Accepts checkout requests and returns order status
38633
+ links:
38634
+ -> payment_client
38635
+
38636
+ component payment_client
38637
+ name = Payment client
38638
+ technology = HTTP client
38639
+ responsibility = Calls the external payment provider
38640
+ \`\`\`
38641
+
38642
+ Components should describe responsibilities, not every class or function.
38643
+
38644
+ ## C4 and Deployment
38645
+
38646
+ Use deployment profiles and infrastructure types when physical realization is
38647
+ important:
38648
+
38649
+ \`\`\`insight
38650
+ deploymentProfile production
38651
+ environments:
38652
+ eu
38653
+
38654
+ environment eu
38655
+ name = Europe
38656
+ \`\`\`
38657
+
38658
+ Attach deployment details to systems, containers, services, or links only when
38659
+ they clarify real runtime paths.
38660
+
38661
+ ## Layering Rules
38662
+
38663
+ - Model stable concepts first; avoid coding transient implementation details.
38664
+ - Keep identifiers short, lowercase, and stable.
38665
+ - Prefer \`name\` for display names and ids for references.
38666
+ - Use \`description\` for why a thing exists.
38667
+ - Use \`technology\` for concrete technical choices.
38668
+ - Use \`responsibility\` for components.
38669
+ - Split files by layer or subsystem once a file becomes hard to scan.
38670
+ - Validate after each layer before adding the next.
38671
+ `;
38672
+ }
38673
+ function genericValidationReference() {
38674
+ return `# Validation and Inspection
38675
+
38676
+ Run validation after every Insight edit:
38677
+
38678
+ \`\`\`shell
38679
+ archinsight link . --format text
38680
+ \`\`\`
38681
+
38682
+ The text output is TSV:
38683
+
38684
+ \`\`\`text
38685
+ level<TAB>code<TAB>source<TAB>line<TAB>column<TAB>message
38686
+ \`\`\`
38687
+
38688
+ Treat \`ERROR\` as blocking. \`WARNING\` and \`NOTE\` can still be useful design
38689
+ feedback.
38690
+
38691
+ Inspect project structure:
38692
+
38693
+ \`\`\`shell
38694
+ archinsight structure . --format text
38695
+ \`\`\`
38696
+
38697
+ Render a diagram when a context id is known:
38698
+
38699
+ \`\`\`shell
38700
+ archinsight render . -c <context-id> -v c1 -f svg -o diagram.svg
38701
+ archinsight render . -c <context-id> -v c2 -f svg -o diagram.svg
38702
+ \`\`\`
38703
+
38704
+ Run a custom query from a file:
38705
+
38706
+ \`\`\`shell
38707
+ archinsight query . -c <context-id> -s <source.ai> -q query.aiq -f text
38708
+ archinsight render . -c <context-id> -s <source.ai> -q query.aiq -f svg -o diagram.svg
38709
+ \`\`\`
38710
+
38711
+ Useful built-in views:
38712
+
38713
+ - \`c1\` for system context.
38714
+ - \`c2\` for containers/services in the selected source.
38715
+ - \`c3\` for components in the selected source.
38716
+ - \`c4\` for deployment-oriented views.
38717
+ - \`no-filter\` for the full context.
38718
+
38719
+ When a render command depends on the active file, pass \`--source <file>\`.
38720
+
38721
+ If the CLI is missing, do not silently install it. Ask the user to install or
38722
+ expose \`@archinsight/cli\`.
38723
+ `;
38724
+ }
38725
+ function genericQueriesReference() {
38726
+ return `# Insight Query Reference
38727
+
38728
+ Insight diagram queries use a small Cypher-style subset evaluated in memory.
38729
+ Use queries to select which linked model elements and relationships appear in a
38730
+ diagram.
38731
+
38732
+ ## CLI Shape
38733
+
38734
+ \`\`\`shell
38735
+ archinsight query . -c <context-id> -s <source.ai> -q query.aiq -f text
38736
+ archinsight render . -c <context-id> -s <source.ai> -q query.aiq -f svg -o diagram.svg
38737
+ \`\`\`
38738
+
38739
+ The scope variables are:
38740
+
38741
+ - \`$context\` - selected context id from \`--context\`.
38742
+ - \`$tab\` - selected source identity from \`--source\` / \`--tab\`.
38743
+
38744
+ Pass \`--source\` when a query uses \`$tab\`.
38745
+
38746
+ ## Query Shape
38747
+
38748
+ Supported clauses:
38749
+
38750
+ \`\`\`cypher
38751
+ MATCH ...
38752
+ OPTIONAL MATCH ...
38753
+ WHERE ...
38754
+ GROUP BY ...
38755
+ RETURN ...
38756
+ \`\`\`
38757
+
38758
+ \`MATCH\` clauses come first. \`GROUP BY\` is optional and appears before
38759
+ \`RETURN\`. \`RETURN\` must list the aliases that should be rendered.
38760
+
38761
+ ## Node Patterns
38762
+
38763
+ Select all nodes:
38764
+
38765
+ \`\`\`cypher
38766
+ MATCH (element)
38767
+ WHERE element.context = $context
38768
+ RETURN element
38769
+ \`\`\`
38770
+
38771
+ Select by type label:
38772
+
38773
+ \`\`\`cypher
38774
+ MATCH (service:Service)
38775
+ WHERE service.context = $context
38776
+ RETURN service
38777
+ \`\`\`
38778
+
38779
+ Labels are case-sensitive and match Insight types such as \`System\`,
38780
+ \`Container\`, \`Service\`, \`Component\`, \`ExternalSystem\`, and
38781
+ \`DeploymentElement\`.
38782
+
38783
+ Use properties in patterns for exact matches:
38784
+
38785
+ \`\`\`cypher
38786
+ MATCH (service:Service {id: 'checkout_api', context: $context})
38787
+ RETURN service
38788
+ \`\`\`
38789
+
38790
+ ## Relationships
38791
+
38792
+ Select real relationships:
38793
+
38794
+ \`\`\`cypher
38795
+ MATCH (source)-[link]->(target)
38796
+ WHERE source.context = $context
38797
+ RETURN source, link, target
38798
+ \`\`\`
38799
+
38800
+ Use \`OPTIONAL MATCH\` when nodes should still appear even if a relationship is
38801
+ missing:
38802
+
38803
+ \`\`\`cypher
38804
+ MATCH (container:ContainerElement)
38805
+ WHERE container.sourceIdentity = $tab
38806
+ OPTIONAL MATCH (container)-[link]->(target)
38807
+ RETURN container, link, target
38808
+ \`\`\`
38809
+
38810
+ Relationship aliases must be returned for edges to render.
38811
+
38812
+ ## Filtering
38813
+
38814
+ Supported filters include:
38815
+
38816
+ \`\`\`cypher
38817
+ WHERE node.context = $context
38818
+ WHERE node.sourceIdentity = $tab
38819
+ WHERE node IS External
38820
+ WHERE NOT node IS DeploymentElement
38821
+ WHERE edge.projected = 'true'
38822
+ WHERE node.id IN ['api', 'web_app']
38823
+ WHERE node.technology CONTAINS 'PostgreSQL'
38824
+ WHERE node.type <> 'Context'
38825
+ WHERE node.context = $context AND NOT node IS External
38826
+ \`\`\`
38827
+
38828
+ Use single quotes for string literals.
38829
+
38830
+ ## Relationship Selectors
38831
+
38832
+ Relationship selectors are boolean flags inside relationship braces:
38833
+
38834
+ \`\`\`cypher
38835
+ OPTIONAL MATCH (node)-[derivedLink {derived}]->(target)
38836
+ OPTIONAL MATCH (node)-[projectedLink {projected}]->(target)
38837
+ OPTIONAL MATCH ROLLUP (node)-[rollupLink {derived}]->(target)
38838
+ \`\`\`
38839
+
38840
+ Use \`{derived}\` for rolled-up edges from child relationships. Use
38841
+ \`{projected}\` for deployment/projected edges.
38842
+
38843
+ ## Grouping
38844
+
38845
+ \`GROUP BY\` controls diagram clusters. Group by parent for C2/C3 style views:
38846
+
38847
+ \`\`\`cypher
38848
+ MATCH (container:ContainerElement)
38849
+ WHERE container.sourceIdentity = $tab
38850
+ OPTIONAL MATCH (container)-[link]->(target)
38851
+ GROUP BY container.parent
38852
+ RETURN container, link, target
38853
+ \`\`\`
38854
+
38855
+ For deployment views, grouping by a typed reference attribute is valid:
38856
+
38857
+ \`\`\`cypher
38858
+ MATCH (node:Element)
38859
+ WHERE node.sourceIdentity = $tab
38860
+ OPTIONAL MATCH ROLLUP (node)-[projectedLink {projected, sourceIdentity: $tab}]->(target)
38861
+ GROUP BY node.runsOn
38862
+ RETURN node, projectedLink, target
38863
+ \`\`\`
38864
+
38865
+ Do not rely on implicit Graphviz clustering. Put grouping in the query when the
38866
+ diagram needs stable layout.
38867
+
38868
+ ## Built-In View Patterns
38869
+
38870
+ C1 usually selects systems in the selected context and rolls lower-level links
38871
+ up to system-level relationships.
38872
+
38873
+ C2 usually selects \`ContainerElement\` nodes in \`$tab\`, returns direct internal
38874
+ relationships, and includes external systems through optional/rollup matches.
38875
+
38876
+ C3 usually starts from \`(container:ContainerElement)-[:CONTAINS]->(component)\`
38877
+ and returns component relationships.
38878
+
38879
+ C4 usually selects deployment and container nodes from \`$tab\`, uses
38880
+ \`OPTIONAL MATCH ROLLUP\`, and returns projected relationships.
38881
+
38882
+ ## Authoring Rules
38883
+
38884
+ - Start from the view question: context, containers, components, or deployment.
38885
+ - Use domain variable names: \`system\`, \`container\`, \`component\`, \`externalSystem\`.
38886
+ - Return every node and relationship alias needed for rendering.
38887
+ - Add \`GROUP BY\` deliberately for diagrams with clusters.
38888
+ - Validate query files with \`archinsight query\` before rendering.
38889
+ - Keep custom queries in \`.aiq\` files when they are reused.
38890
+ `;
38891
+ }
38892
+ function genericLayeredArchitectureExample() {
38893
+ return `context shop
38894
+ name = Shop Platform
38895
+
38896
+ external actor shopper
38897
+ name = Shopper
38898
+ technology = Browser
38899
+ description = Browses products and places orders
38900
+ links:
38901
+ -> storefront
38902
+
38903
+ external system payment_provider
38904
+ name = Payment Provider
38905
+ technology = HTTPS API
38906
+ description = Authorizes card payments
38907
+
38908
+ system storefront
38909
+ name = Storefront
38910
+ technology = Web application
38911
+ description = Customer-facing commerce experience
38912
+
38913
+ container web_app
38914
+ name = Web app
38915
+ technology = SvelteKit, TypeScript
38916
+ description = Renders product pages and checkout screens
38917
+ links:
38918
+ -> checkout_api
38919
+ technology = HTTPS, JSON
38920
+ description = Starts checkout and shows order status
38921
+
38922
+ service checkout_api
38923
+ name = Checkout API
38924
+ technology = Node.js, PostgreSQL
38925
+ description = Prices carts, creates orders, and coordinates payment
38926
+ links:
38927
+ -> payment_provider
38928
+ technology = HTTPS, JSON
38929
+ description = Requests payment authorization
38930
+
38931
+ component order_controller
38932
+ name = Order controller
38933
+ technology = REST
38934
+ responsibility = Accepts checkout requests and returns order status
38935
+ links:
38936
+ -> payment_client
38937
+
38938
+ component payment_client
38939
+ name = Payment client
38940
+ technology = HTTP client
38941
+ responsibility = Calls the payment provider and normalizes errors
38942
+ `;
38943
+ }
38944
+ function genericC2QueryExample() {
38945
+ return `MATCH (container:ContainerElement)
38946
+ WHERE container.sourceIdentity = $tab
38947
+ OPTIONAL MATCH (container)-[internalLink]->(targetContainer:ContainerElement)
38948
+ OPTIONAL MATCH (container)-[outboundLink]->(externalSystem:SystemElement)
38949
+ WHERE externalSystem IS External
38950
+ OPTIONAL MATCH (sourceSystem:SystemElement)-[inboundLink]->(container)
38951
+ WHERE sourceSystem IS External
38952
+ GROUP BY container.parent
38953
+ RETURN container, internalLink, targetContainer, outboundLink, externalSystem, inboundLink, sourceSystem
38954
+ `;
38955
+ }
38025
38956
  var CliError = class extends Error {
38026
38957
  };
38027
38958
  main().catch((error) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@archinsight/cli",
3
- "version": "3.0.0-snapshot.0",
3
+ "version": "3.0.0-snapshot.2",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "repository": {