@thinkingsage/kanon 0.8.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 (199) hide show
  1. package/CHANGELOG.md +410 -0
  2. package/LICENSE +21 -0
  3. package/README.md +168 -0
  4. package/bridge/mcp-server.cjs +14171 -0
  5. package/package.json +98 -0
  6. package/src/adapters/capabilities.ts +178 -0
  7. package/src/adapters/claude-code.ts +110 -0
  8. package/src/adapters/cline.ts +98 -0
  9. package/src/adapters/codex.ts +173 -0
  10. package/src/adapters/copilot.ts +106 -0
  11. package/src/adapters/cursor.ts +97 -0
  12. package/src/adapters/degradation.ts +95 -0
  13. package/src/adapters/index.ts +324 -0
  14. package/src/adapters/kiro-frontmatter.ts +139 -0
  15. package/src/adapters/kiro-inclusion.ts +86 -0
  16. package/src/adapters/kiro.ts +412 -0
  17. package/src/adapters/qdeveloper.ts +115 -0
  18. package/src/adapters/types.ts +81 -0
  19. package/src/adapters/windsurf.ts +96 -0
  20. package/src/admin.ts +283 -0
  21. package/src/asset-conventions.ts +118 -0
  22. package/src/attribution-backfill.ts +319 -0
  23. package/src/attribution-report.ts +95 -0
  24. package/src/attribution.ts +239 -0
  25. package/src/backends/github.ts +194 -0
  26. package/src/backends/http.ts +122 -0
  27. package/src/backends/index.ts +39 -0
  28. package/src/backends/local.ts +47 -0
  29. package/src/backends/s3.ts +157 -0
  30. package/src/backends/types.ts +59 -0
  31. package/src/base-cache.ts +270 -0
  32. package/src/browse-ui.ts +3754 -0
  33. package/src/browse.ts +1038 -0
  34. package/src/build.ts +1108 -0
  35. package/src/catalog.ts +204 -0
  36. package/src/cli-deprecated.ts +29 -0
  37. package/src/cli.ts +773 -0
  38. package/src/collection-admin.ts +287 -0
  39. package/src/collection-builder.ts +464 -0
  40. package/src/collections.ts +116 -0
  41. package/src/compatibility.ts +105 -0
  42. package/src/config.ts +743 -0
  43. package/src/eval/rubrics/kiro-progressive-steering.ts +841 -0
  44. package/src/eval.ts +1169 -0
  45. package/src/file-writer.ts +61 -0
  46. package/src/format-registry.ts +141 -0
  47. package/src/guild/auto-updater.ts +163 -0
  48. package/src/guild/backend-resolver.ts +49 -0
  49. package/src/guild/cli.ts +592 -0
  50. package/src/guild/collection-expander.ts +47 -0
  51. package/src/guild/global-cache.ts +247 -0
  52. package/src/guild/hook-generator.ts +100 -0
  53. package/src/guild/manifest.ts +154 -0
  54. package/src/guild/path-utils.ts +12 -0
  55. package/src/guild/sync.ts +622 -0
  56. package/src/guild/version-resolver.ts +42 -0
  57. package/src/help/metadata.ts +445 -0
  58. package/src/help/renderer.ts +265 -0
  59. package/src/help/typo-suggester.ts +25 -0
  60. package/src/hooks/expression.ts +493 -0
  61. package/src/hooks/pipeline.ts +141 -0
  62. package/src/import.ts +773 -0
  63. package/src/importers/claude-code.ts +134 -0
  64. package/src/importers/cline.ts +103 -0
  65. package/src/importers/codex.ts +140 -0
  66. package/src/importers/copilot.ts +103 -0
  67. package/src/importers/cursor.ts +105 -0
  68. package/src/importers/index.ts +390 -0
  69. package/src/importers/kiro.ts +110 -0
  70. package/src/importers/qdeveloper.ts +103 -0
  71. package/src/importers/types.ts +54 -0
  72. package/src/importers/windsurf.ts +104 -0
  73. package/src/install.ts +1005 -0
  74. package/src/manifest-admin.ts +306 -0
  75. package/src/mcp-bridge.ts +240 -0
  76. package/src/mutation/delta.ts +50 -0
  77. package/src/mutation/history.ts +66 -0
  78. package/src/mutation/operators.ts +524 -0
  79. package/src/mutation/runner.ts +332 -0
  80. package/src/new.ts +106 -0
  81. package/src/outcomes/collision.ts +127 -0
  82. package/src/outcomes/normalize.ts +208 -0
  83. package/src/outcomes/registry.ts +173 -0
  84. package/src/parser.ts +446 -0
  85. package/src/provenance-backfill-cli.ts +319 -0
  86. package/src/provenance-backfill.ts +520 -0
  87. package/src/publish.ts +354 -0
  88. package/src/reconcile-orchestrator.ts +502 -0
  89. package/src/reconcile-report-renderer.ts +176 -0
  90. package/src/resolve-body.ts +15 -0
  91. package/src/rosetta/builtins/compatibility-profiles.ts +297 -0
  92. package/src/rosetta/builtins/contracts.ts +1033 -0
  93. package/src/rosetta/builtins/pretty-printers/claude-code-native.ts +122 -0
  94. package/src/rosetta/builtins/pretty-printers/cline-native.ts +50 -0
  95. package/src/rosetta/builtins/pretty-printers/codex-native.ts +127 -0
  96. package/src/rosetta/builtins/pretty-printers/copilot-native.ts +50 -0
  97. package/src/rosetta/builtins/pretty-printers/cursor-native.ts +50 -0
  98. package/src/rosetta/builtins/pretty-printers/index.ts +81 -0
  99. package/src/rosetta/builtins/pretty-printers/kiro-native.ts +166 -0
  100. package/src/rosetta/builtins/pretty-printers/kiro-power.ts +108 -0
  101. package/src/rosetta/builtins/pretty-printers/kiro-skill.ts +88 -0
  102. package/src/rosetta/builtins/pretty-printers/qdeveloper-native.ts +51 -0
  103. package/src/rosetta/builtins/pretty-printers/superpowers.ts +97 -0
  104. package/src/rosetta/builtins/pretty-printers/windsurf-native.ts +50 -0
  105. package/src/rosetta/builtins/sources/claude-code-native.ts +348 -0
  106. package/src/rosetta/builtins/sources/cline-native.ts +176 -0
  107. package/src/rosetta/builtins/sources/codex-native.ts +343 -0
  108. package/src/rosetta/builtins/sources/copilot-native.ts +178 -0
  109. package/src/rosetta/builtins/sources/cursor-native.ts +176 -0
  110. package/src/rosetta/builtins/sources/index.ts +95 -0
  111. package/src/rosetta/builtins/sources/kiro-native.ts +462 -0
  112. package/src/rosetta/builtins/sources/kiro-power.ts +285 -0
  113. package/src/rosetta/builtins/sources/kiro-skill.ts +230 -0
  114. package/src/rosetta/builtins/sources/qdeveloper-native.ts +181 -0
  115. package/src/rosetta/builtins/sources/superpowers.ts +240 -0
  116. package/src/rosetta/builtins/sources/windsurf-native.ts +176 -0
  117. package/src/rosetta/builtins/targets/claude-code.ts +181 -0
  118. package/src/rosetta/builtins/targets/cline.ts +87 -0
  119. package/src/rosetta/builtins/targets/codex.ts +226 -0
  120. package/src/rosetta/builtins/targets/copilot.ts +103 -0
  121. package/src/rosetta/builtins/targets/cursor.ts +87 -0
  122. package/src/rosetta/builtins/targets/index.ts +60 -0
  123. package/src/rosetta/builtins/targets/kiro.ts +278 -0
  124. package/src/rosetta/builtins/targets/qdeveloper.ts +103 -0
  125. package/src/rosetta/builtins/targets/windsurf.ts +87 -0
  126. package/src/rosetta/canonical.ts +729 -0
  127. package/src/rosetta/compatibility.ts +432 -0
  128. package/src/rosetta/contracts.ts +329 -0
  129. package/src/rosetta/detector.ts +724 -0
  130. package/src/rosetta/diagnostics.ts +630 -0
  131. package/src/rosetta/engine-bootstrap.ts +103 -0
  132. package/src/rosetta/engine.ts +744 -0
  133. package/src/rosetta/index.ts +381 -0
  134. package/src/rosetta/inspection.ts +530 -0
  135. package/src/rosetta/plan.ts +448 -0
  136. package/src/rosetta/provenance-digest.ts +369 -0
  137. package/src/rosetta/reconcile.ts +812 -0
  138. package/src/rosetta/redaction.ts +467 -0
  139. package/src/rosetta/registry.ts +712 -0
  140. package/src/rosetta/renderers.ts +571 -0
  141. package/src/rosetta/request-guard.ts +335 -0
  142. package/src/rosetta/resolution.ts +419 -0
  143. package/src/rosetta/source-accounting.ts +233 -0
  144. package/src/rosetta/templates.ts +129 -0
  145. package/src/rosetta-cli.ts +717 -0
  146. package/src/rosetta-docs-generator.ts +793 -0
  147. package/src/rosetta-profiles-cli.ts +367 -0
  148. package/src/schemas.ts +1712 -0
  149. package/src/spec-coordination.ts +1141 -0
  150. package/src/temper.ts +747 -0
  151. package/src/template-bundle-loader.ts +312 -0
  152. package/src/template-engine.ts +53 -0
  153. package/src/translation-application-policy.ts +496 -0
  154. package/src/translation-orchestrator.ts +1013 -0
  155. package/src/translation-plan-applier.ts +473 -0
  156. package/src/tutorial.ts +305 -0
  157. package/src/validate.ts +1093 -0
  158. package/src/versioning.ts +553 -0
  159. package/src/wizard.ts +660 -0
  160. package/src/workspace.ts +237 -0
  161. package/templates/eval-contexts/claude-code.md.njk +6 -0
  162. package/templates/eval-contexts/cline.md.njk +6 -0
  163. package/templates/eval-contexts/copilot.md.njk +6 -0
  164. package/templates/eval-contexts/cursor.md.njk +6 -0
  165. package/templates/eval-contexts/kiro.md.njk +10 -0
  166. package/templates/eval-contexts/qdeveloper.md.njk +6 -0
  167. package/templates/eval-contexts/windsurf.md.njk +6 -0
  168. package/templates/harness-adapters/_base/attribution-footer.md.njk +17 -0
  169. package/templates/harness-adapters/_base/base.md.njk +16 -0
  170. package/templates/harness-adapters/claude-code/claude.md.njk +1 -0
  171. package/templates/harness-adapters/claude-code/mcp.json.njk +1 -0
  172. package/templates/harness-adapters/claude-code/settings.json.njk +1 -0
  173. package/templates/harness-adapters/claude-code/skill-library-index.md.njk +13 -0
  174. package/templates/harness-adapters/claude-code/skill.md.njk +19 -0
  175. package/templates/harness-adapters/cline/hook.sh.njk +4 -0
  176. package/templates/harness-adapters/cline/mcp.json.njk +1 -0
  177. package/templates/harness-adapters/cline/rule.md.njk +1 -0
  178. package/templates/harness-adapters/codex/agents-md.md.njk +6 -0
  179. package/templates/harness-adapters/codex/agents-pointer.md.njk +16 -0
  180. package/templates/harness-adapters/codex/skill.md.njk +27 -0
  181. package/templates/harness-adapters/copilot/agents.md.njk +1 -0
  182. package/templates/harness-adapters/copilot/instructions.md.njk +1 -0
  183. package/templates/harness-adapters/copilot/scoped.md.njk +6 -0
  184. package/templates/harness-adapters/cursor/mcp.json.njk +1 -0
  185. package/templates/harness-adapters/cursor/rule.md.njk +6 -0
  186. package/templates/harness-adapters/kiro/hook.json.njk +1 -0
  187. package/templates/harness-adapters/kiro/mcp.json.njk +1 -0
  188. package/templates/harness-adapters/kiro/power-steering.md.njk +3 -0
  189. package/templates/harness-adapters/kiro/power.md.njk +12 -0
  190. package/templates/harness-adapters/kiro/steering.md.njk +16 -0
  191. package/templates/harness-adapters/qdeveloper/agent.md.njk +1 -0
  192. package/templates/harness-adapters/qdeveloper/mcp.json.njk +1 -0
  193. package/templates/harness-adapters/qdeveloper/rule.md.njk +1 -0
  194. package/templates/harness-adapters/windsurf/mcp.json.njk +1 -0
  195. package/templates/harness-adapters/windsurf/rule.md.njk +1 -0
  196. package/templates/harness-adapters/windsurf/workflow.md.njk +1 -0
  197. package/templates/knowledge/hooks.yaml.njk +4 -0
  198. package/templates/knowledge/knowledge.md.njk +53 -0
  199. package/templates/knowledge/mcp-servers.yaml.njk +2 -0
@@ -0,0 +1,122 @@
1
+ /**
2
+ * Rosetta Stone — Claude Code Native Pretty-Printer
3
+ *
4
+ * Renders a canonical KnowledgeArtifact back into Claude Code native format:
5
+ * - `CLAUDE.md` body
6
+ * - `.claude/settings.json` from hooks (commands)
7
+ * - `.claude/mcp.json` from mcpServers
8
+ *
9
+ * CONSTRAINTS:
10
+ * - NO filesystem, process, clock, random, Git, or network imports
11
+ * - Pure function only
12
+ *
13
+ * Requirements: 5.4, 12.4, 16.2
14
+ */
15
+
16
+ import type {
17
+ CanonicalHook,
18
+ McpServerDefinition,
19
+ NormalizedRelativePath,
20
+ SourceDocument,
21
+ TranslationDiagnostic,
22
+ } from "../../../schemas";
23
+ import { codePointCompare, stableJsonStringify } from "../../contracts";
24
+ import type {
25
+ SourcePrintOutput,
26
+ SourceTranslatorContext,
27
+ } from "../../registry";
28
+
29
+ // ═══════════════════════════════════════════════════════════════════════════════
30
+ // Pretty-Printer
31
+ // ═══════════════════════════════════════════════════════════════════════════════
32
+
33
+ /**
34
+ * Pretty-print a canonical KnowledgeArtifact into Claude Code native format.
35
+ *
36
+ * Produces:
37
+ * - `CLAUDE.md` with the artifact body
38
+ * - `.claude/settings.json` from hooks (agent_stop → commands)
39
+ * - `.claude/mcp.json` from mcpServers
40
+ */
41
+ export function prettyPrintClaudeCodeNative(
42
+ artifact: Record<string, unknown>,
43
+ _context: SourceTranslatorContext,
44
+ ): SourcePrintOutput {
45
+ const diagnostics: TranslationDiagnostic[] = [];
46
+ const documents: SourceDocument[] = [];
47
+
48
+ const body = (artifact.body as string) ?? "";
49
+ const hooks = (artifact.hooks as CanonicalHook[]) ?? [];
50
+ const mcpServers = (artifact.mcpServers as McpServerDefinition[]) ?? [];
51
+
52
+ // Render CLAUDE.md
53
+ documents.push({
54
+ path: "CLAUDE.md" as NormalizedRelativePath,
55
+ content: `${body}\n`,
56
+ executable: false,
57
+ });
58
+
59
+ // Render .claude/settings.json from hooks (agent_stop events → commands)
60
+ const commands: string[] = [];
61
+ const sortedHooks = [...hooks].sort((a, b) =>
62
+ codePointCompare(a.name, b.name),
63
+ );
64
+
65
+ for (const hook of sortedHooks) {
66
+ if (hook.event === "agent_stop" && hook.action?.type === "run_command") {
67
+ commands.push(hook.action.command);
68
+ }
69
+ }
70
+
71
+ if (commands.length > 0) {
72
+ const settingsObj: Record<string, unknown> = { commands };
73
+ const settingsJson = stableJsonStringify(settingsObj);
74
+ documents.push({
75
+ path: ".claude/settings.json" as NormalizedRelativePath,
76
+ content: `${settingsJson}\n`,
77
+ executable: false,
78
+ });
79
+ }
80
+
81
+ // Render .claude/mcp.json from mcpServers
82
+ if (mcpServers.length > 0) {
83
+ const mcpObj: Record<string, unknown> = {};
84
+ const sortedServers = [...mcpServers].sort((a, b) =>
85
+ codePointCompare(a.name, b.name),
86
+ );
87
+
88
+ for (const server of sortedServers) {
89
+ const serverConfig: Record<string, unknown> = {};
90
+ if (server.transport === "stdio") {
91
+ serverConfig.command = server.command;
92
+ if (server.args && server.args.length > 0) {
93
+ serverConfig.args = server.args;
94
+ }
95
+ } else {
96
+ serverConfig.url = server.url;
97
+ if (server.transport === "http") {
98
+ serverConfig.type = "http";
99
+ }
100
+ }
101
+ if (server.env && Object.keys(server.env).length > 0) {
102
+ serverConfig.env = server.env;
103
+ }
104
+ if (server.timeout !== undefined) {
105
+ serverConfig.timeout = server.timeout;
106
+ }
107
+ if (server.autoApprove && server.autoApprove.length > 0) {
108
+ serverConfig.autoApprove = server.autoApprove;
109
+ }
110
+ mcpObj[server.name] = serverConfig;
111
+ }
112
+
113
+ const mcpJson = stableJsonStringify({ mcpServers: mcpObj });
114
+ documents.push({
115
+ path: ".claude/mcp.json" as NormalizedRelativePath,
116
+ content: `${mcpJson}\n`,
117
+ executable: false,
118
+ });
119
+ }
120
+
121
+ return { documents, diagnostics };
122
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Rosetta Stone — Cline Native Pretty-Printer
3
+ *
4
+ * Renders a canonical KnowledgeArtifact back into Cline native format:
5
+ * - `.clinerules` with body content
6
+ *
7
+ * CONSTRAINTS:
8
+ * - NO filesystem, process, clock, random, Git, or network imports
9
+ * - Pure function only
10
+ *
11
+ * Requirements: 5.4, 12.4, 16.2
12
+ */
13
+
14
+ import type {
15
+ NormalizedRelativePath,
16
+ SourceDocument,
17
+ TranslationDiagnostic,
18
+ } from "../../../schemas";
19
+ import type {
20
+ SourcePrintOutput,
21
+ SourceTranslatorContext,
22
+ } from "../../registry";
23
+
24
+ // ═══════════════════════════════════════════════════════════════════════════════
25
+ // Pretty-Printer
26
+ // ═══════════════════════════════════════════════════════════════════════════════
27
+
28
+ /**
29
+ * Pretty-print a canonical KnowledgeArtifact into Cline native format.
30
+ *
31
+ * Produces:
32
+ * - `.clinerules` with the artifact body
33
+ */
34
+ export function prettyPrintClineNative(
35
+ artifact: Record<string, unknown>,
36
+ _context: SourceTranslatorContext,
37
+ ): SourcePrintOutput {
38
+ const diagnostics: TranslationDiagnostic[] = [];
39
+ const documents: SourceDocument[] = [];
40
+
41
+ const body = (artifact.body as string) ?? "";
42
+
43
+ documents.push({
44
+ path: ".clinerules" as NormalizedRelativePath,
45
+ content: `${body}\n`,
46
+ executable: false,
47
+ });
48
+
49
+ return { documents, diagnostics };
50
+ }
@@ -0,0 +1,127 @@
1
+ /**
2
+ * Rosetta Stone — Codex Native Pretty-Printer
3
+ *
4
+ * Renders a canonical KnowledgeArtifact back into Codex native format:
5
+ * - `AGENTS.md` body
6
+ * - `.codex/config.toml` from mcpServers (TOML format)
7
+ *
8
+ * CONSTRAINTS:
9
+ * - NO filesystem, process, clock, random, Git, or network imports
10
+ * - Pure function only
11
+ *
12
+ * Requirements: 5.4, 12.4, 16.2
13
+ */
14
+
15
+ import type {
16
+ McpServerDefinition,
17
+ NormalizedRelativePath,
18
+ SourceDocument,
19
+ TranslationDiagnostic,
20
+ } from "../../../schemas";
21
+ import { codePointCompare } from "../../contracts";
22
+ import type {
23
+ SourcePrintOutput,
24
+ SourceTranslatorContext,
25
+ } from "../../registry";
26
+
27
+ // ═══════════════════════════════════════════════════════════════════════════════
28
+ // TOML Rendering Helper
29
+ // ═══════════════════════════════════════════════════════════════════════════════
30
+
31
+ /**
32
+ * Render MCP server definitions as TOML [mcp_servers.<name>] tables.
33
+ */
34
+ function renderMcpToml(servers: McpServerDefinition[]): string {
35
+ const lines: string[] = [];
36
+
37
+ for (const server of servers) {
38
+ lines.push(`[mcp_servers.${quoteTomlKey(server.name)}]`);
39
+
40
+ if (server.transport === "stdio") {
41
+ lines.push(`command = ${quoteTomlString(server.command ?? "")}`);
42
+ if (server.args && server.args.length > 0) {
43
+ const argsStr = server.args.map(quoteTomlString).join(", ");
44
+ lines.push(`args = [${argsStr}]`);
45
+ }
46
+ } else if (server.url) {
47
+ lines.push(`url = ${quoteTomlString(server.url)}`);
48
+ }
49
+
50
+ if (server.env && Object.keys(server.env).length > 0) {
51
+ const envEntries = Object.keys(server.env)
52
+ .sort(codePointCompare)
53
+ .map((k) => `${quoteTomlKey(k)} = ${quoteTomlString(server.env?.[k])}`)
54
+ .join(", ");
55
+ lines.push(`env = { ${envEntries} }`);
56
+ }
57
+
58
+ if (server.timeout !== undefined) {
59
+ lines.push(`startup_timeout_ms = ${server.timeout}`);
60
+ }
61
+
62
+ lines.push("");
63
+ }
64
+
65
+ return lines.join("\n");
66
+ }
67
+
68
+ /**
69
+ * Quote a string for TOML output.
70
+ */
71
+ function quoteTomlString(value: string): string {
72
+ return `"${value.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
73
+ }
74
+
75
+ /**
76
+ * Quote a TOML key if it contains special characters.
77
+ */
78
+ function quoteTomlKey(key: string): string {
79
+ if (/^[a-zA-Z0-9_-]+$/.test(key)) {
80
+ return key;
81
+ }
82
+ return quoteTomlString(key);
83
+ }
84
+
85
+ // ═══════════════════════════════════════════════════════════════════════════════
86
+ // Pretty-Printer
87
+ // ═══════════════════════════════════════════════════════════════════════════════
88
+
89
+ /**
90
+ * Pretty-print a canonical KnowledgeArtifact into Codex native format.
91
+ *
92
+ * Produces:
93
+ * - `AGENTS.md` with the artifact body
94
+ * - `.codex/config.toml` from mcpServers in TOML format
95
+ */
96
+ export function prettyPrintCodexNative(
97
+ artifact: Record<string, unknown>,
98
+ _context: SourceTranslatorContext,
99
+ ): SourcePrintOutput {
100
+ const diagnostics: TranslationDiagnostic[] = [];
101
+ const documents: SourceDocument[] = [];
102
+
103
+ const body = (artifact.body as string) ?? "";
104
+ const mcpServers = (artifact.mcpServers as McpServerDefinition[]) ?? [];
105
+
106
+ // Render AGENTS.md
107
+ documents.push({
108
+ path: "AGENTS.md" as NormalizedRelativePath,
109
+ content: `${body}\n`,
110
+ executable: false,
111
+ });
112
+
113
+ // Render .codex/config.toml from mcpServers
114
+ if (mcpServers.length > 0) {
115
+ const sortedServers = [...mcpServers].sort((a, b) =>
116
+ codePointCompare(a.name, b.name),
117
+ );
118
+ const tomlContent = renderMcpToml(sortedServers);
119
+ documents.push({
120
+ path: ".codex/config.toml" as NormalizedRelativePath,
121
+ content: tomlContent,
122
+ executable: false,
123
+ });
124
+ }
125
+
126
+ return { documents, diagnostics };
127
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Rosetta Stone — Copilot Native Pretty-Printer
3
+ *
4
+ * Renders a canonical KnowledgeArtifact back into Copilot native format:
5
+ * - `.github/copilot-instructions.md` with body content
6
+ *
7
+ * CONSTRAINTS:
8
+ * - NO filesystem, process, clock, random, Git, or network imports
9
+ * - Pure function only
10
+ *
11
+ * Requirements: 5.4, 12.4, 16.2
12
+ */
13
+
14
+ import type {
15
+ NormalizedRelativePath,
16
+ SourceDocument,
17
+ TranslationDiagnostic,
18
+ } from "../../../schemas";
19
+ import type {
20
+ SourcePrintOutput,
21
+ SourceTranslatorContext,
22
+ } from "../../registry";
23
+
24
+ // ═══════════════════════════════════════════════════════════════════════════════
25
+ // Pretty-Printer
26
+ // ═══════════════════════════════════════════════════════════════════════════════
27
+
28
+ /**
29
+ * Pretty-print a canonical KnowledgeArtifact into Copilot native format.
30
+ *
31
+ * Produces:
32
+ * - `.github/copilot-instructions.md` with the artifact body
33
+ */
34
+ export function prettyPrintCopilotNative(
35
+ artifact: Record<string, unknown>,
36
+ _context: SourceTranslatorContext,
37
+ ): SourcePrintOutput {
38
+ const diagnostics: TranslationDiagnostic[] = [];
39
+ const documents: SourceDocument[] = [];
40
+
41
+ const body = (artifact.body as string) ?? "";
42
+
43
+ documents.push({
44
+ path: ".github/copilot-instructions.md" as NormalizedRelativePath,
45
+ content: `${body}\n`,
46
+ executable: false,
47
+ });
48
+
49
+ return { documents, diagnostics };
50
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Rosetta Stone — Cursor Native Pretty-Printer
3
+ *
4
+ * Renders a canonical KnowledgeArtifact back into Cursor native format:
5
+ * - `.cursorrules` with body content
6
+ *
7
+ * CONSTRAINTS:
8
+ * - NO filesystem, process, clock, random, Git, or network imports
9
+ * - Pure function only
10
+ *
11
+ * Requirements: 5.4, 12.4, 16.2
12
+ */
13
+
14
+ import type {
15
+ NormalizedRelativePath,
16
+ SourceDocument,
17
+ TranslationDiagnostic,
18
+ } from "../../../schemas";
19
+ import type {
20
+ SourcePrintOutput,
21
+ SourceTranslatorContext,
22
+ } from "../../registry";
23
+
24
+ // ═══════════════════════════════════════════════════════════════════════════════
25
+ // Pretty-Printer
26
+ // ═══════════════════════════════════════════════════════════════════════════════
27
+
28
+ /**
29
+ * Pretty-print a canonical KnowledgeArtifact into Cursor native format.
30
+ *
31
+ * Produces:
32
+ * - `.cursorrules` with the artifact body
33
+ */
34
+ export function prettyPrintCursorNative(
35
+ artifact: Record<string, unknown>,
36
+ _context: SourceTranslatorContext,
37
+ ): SourcePrintOutput {
38
+ const diagnostics: TranslationDiagnostic[] = [];
39
+ const documents: SourceDocument[] = [];
40
+
41
+ const body = (artifact.body as string) ?? "";
42
+
43
+ documents.push({
44
+ path: ".cursorrules" as NormalizedRelativePath,
45
+ content: `${body}\n`,
46
+ executable: false,
47
+ });
48
+
49
+ return { documents, diagnostics };
50
+ }
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Rosetta Stone — Built-in Pretty-Printer Registry
3
+ *
4
+ * Exports all pretty-printers (path-based and harness-native) and a lookup
5
+ * map from format identifiers to their pretty-printer implementations.
6
+ *
7
+ * Pretty-printers exist for round-trip verification and migration inspection;
8
+ * direction still controls whether users may request that representation as
9
+ * an outbound target.
10
+ *
11
+ * CONSTRAINTS:
12
+ * - NO filesystem, process, clock, random, Git, or network imports
13
+ * - Pure re-exports only
14
+ *
15
+ * Requirements: 5.4, 12.4, 16.2
16
+ */
17
+
18
+ import type { FormatIdentifier } from "../../../schemas";
19
+ import type { PrettyPrinter } from "../../registry";
20
+ import { prettyPrintClaudeCodeNative } from "./claude-code-native";
21
+ import { prettyPrintClineNative } from "./cline-native";
22
+ import { prettyPrintCodexNative } from "./codex-native";
23
+ import { prettyPrintCopilotNative } from "./copilot-native";
24
+ import { prettyPrintCursorNative } from "./cursor-native";
25
+ import { prettyPrintKiroNative } from "./kiro-native";
26
+ import { prettyPrintKiroPower } from "./kiro-power";
27
+ import { prettyPrintKiroSkill } from "./kiro-skill";
28
+ import { prettyPrintQDeveloperNative } from "./qdeveloper-native";
29
+ import { prettyPrintSuperpowers } from "./superpowers";
30
+ import { prettyPrintWindsurfNative } from "./windsurf-native";
31
+
32
+ // ═══════════════════════════════════════════════════════════════════════════════
33
+ // Re-exports — Path-based format pretty-printers
34
+ // ═══════════════════════════════════════════════════════════════════════════════
35
+
36
+ export { prettyPrintKiroPower } from "./kiro-power";
37
+ export { prettyPrintKiroSkill } from "./kiro-skill";
38
+ export { prettyPrintSuperpowers } from "./superpowers";
39
+
40
+ // ═══════════════════════════════════════════════════════════════════════════════
41
+ // Re-exports — Harness-native pretty-printers
42
+ // ═══════════════════════════════════════════════════════════════════════════════
43
+
44
+ export { prettyPrintClaudeCodeNative } from "./claude-code-native";
45
+ export { prettyPrintCodexNative } from "./codex-native";
46
+ export { prettyPrintKiroNative } from "./kiro-native";
47
+
48
+ // ═══════════════════════════════════════════════════════════════════════════════
49
+ // Re-exports — Simple harness pretty-printers
50
+ // ═══════════════════════════════════════════════════════════════════════════════
51
+
52
+ export { prettyPrintClineNative } from "./cline-native";
53
+ export { prettyPrintCopilotNative } from "./copilot-native";
54
+ export { prettyPrintCursorNative } from "./cursor-native";
55
+ export { prettyPrintQDeveloperNative } from "./qdeveloper-native";
56
+ export { prettyPrintWindsurfNative } from "./windsurf-native";
57
+
58
+ // ═══════════════════════════════════════════════════════════════════════════════
59
+ // Pretty-Printer Lookup Map
60
+ // ═══════════════════════════════════════════════════════════════════════════════
61
+
62
+ /**
63
+ * Maps format identifiers to their corresponding pretty-printer implementations.
64
+ *
65
+ * Every source-capable built-in has a corresponding pretty-printer for
66
+ * round-trip verification and migration inspection.
67
+ */
68
+ export const PRETTY_PRINTERS: ReadonlyMap<FormatIdentifier, PrettyPrinter> =
69
+ new Map<FormatIdentifier, PrettyPrinter>([
70
+ ["kiro-power" as FormatIdentifier, prettyPrintKiroPower],
71
+ ["kiro-skill" as FormatIdentifier, prettyPrintKiroSkill],
72
+ ["superpowers" as FormatIdentifier, prettyPrintSuperpowers],
73
+ ["kiro" as FormatIdentifier, prettyPrintKiroNative],
74
+ ["claude-code" as FormatIdentifier, prettyPrintClaudeCodeNative],
75
+ ["codex" as FormatIdentifier, prettyPrintCodexNative],
76
+ ["copilot" as FormatIdentifier, prettyPrintCopilotNative],
77
+ ["cursor" as FormatIdentifier, prettyPrintCursorNative],
78
+ ["windsurf" as FormatIdentifier, prettyPrintWindsurfNative],
79
+ ["cline" as FormatIdentifier, prettyPrintClineNative],
80
+ ["qdeveloper" as FormatIdentifier, prettyPrintQDeveloperNative],
81
+ ]);
@@ -0,0 +1,166 @@
1
+ /**
2
+ * Rosetta Stone — Kiro Native Pretty-Printer
3
+ *
4
+ * Renders a canonical KnowledgeArtifact back into the Kiro native format:
5
+ * - Primary steering markdown (frontmatter + body)
6
+ * - Hook files as JSON
7
+ * - MCP server definitions as JSON
8
+ *
9
+ * CONSTRAINTS:
10
+ * - NO filesystem, process, clock, random, Git, or network imports
11
+ * - Pure function only
12
+ *
13
+ * Requirements: 5.4, 12.4, 16.2
14
+ */
15
+
16
+ import type {
17
+ CanonicalHook,
18
+ McpServerDefinition,
19
+ NormalizedRelativePath,
20
+ SourceDocument,
21
+ TranslationDiagnostic,
22
+ } from "../../../schemas";
23
+ import { renderDeterministicYaml } from "../../canonical";
24
+ import { codePointCompare, stableJsonStringify } from "../../contracts";
25
+ import type {
26
+ SourcePrintOutput,
27
+ SourceTranslatorContext,
28
+ } from "../../registry";
29
+
30
+ // ═══════════════════════════════════════════════════════════════════════════════
31
+ // Pretty-Printer
32
+ // ═══════════════════════════════════════════════════════════════════════════════
33
+
34
+ /**
35
+ * Pretty-print a canonical KnowledgeArtifact into Kiro native format.
36
+ *
37
+ * Produces:
38
+ * - Primary steering markdown with frontmatter
39
+ * - `hooks/<name>.kiro.hook` JSON files for each hook
40
+ * - `mcp.json` for MCP server definitions
41
+ */
42
+ export function prettyPrintKiroNative(
43
+ artifact: Record<string, unknown>,
44
+ _context: SourceTranslatorContext,
45
+ ): SourcePrintOutput {
46
+ const diagnostics: TranslationDiagnostic[] = [];
47
+ const documents: SourceDocument[] = [];
48
+
49
+ const fm = (artifact.frontmatter ?? {}) as Record<string, unknown>;
50
+ const body = (artifact.body as string) ?? "";
51
+ const hooks = (artifact.hooks as CanonicalHook[]) ?? [];
52
+ const mcpServers = (artifact.mcpServers as McpServerDefinition[]) ?? [];
53
+ const name = (artifact.name as string) ?? "unnamed";
54
+
55
+ // Build the primary markdown frontmatter
56
+ const steeringFm: Record<string, unknown> = {};
57
+ const STEERING_KEY_ORDER = [
58
+ "name",
59
+ "displayName",
60
+ "description",
61
+ "keywords",
62
+ "author",
63
+ "version",
64
+ "type",
65
+ "harnesses",
66
+ "inclusion",
67
+ "file_patterns",
68
+ "categories",
69
+ "ecosystem",
70
+ "depends",
71
+ "enhances",
72
+ "maturity",
73
+ "trust",
74
+ "audience",
75
+ ];
76
+
77
+ for (const key of STEERING_KEY_ORDER) {
78
+ if (fm[key] !== undefined) {
79
+ steeringFm[key] = fm[key];
80
+ }
81
+ }
82
+ // Add remaining keys in code-point order
83
+ const remainingKeys = Object.keys(fm)
84
+ .filter((k) => !STEERING_KEY_ORDER.includes(k))
85
+ .sort(codePointCompare);
86
+ for (const key of remainingKeys) {
87
+ if (fm[key] !== undefined) {
88
+ steeringFm[key] = fm[key];
89
+ }
90
+ }
91
+
92
+ // Render primary markdown
93
+ const frontmatterYaml = renderDeterministicYaml(
94
+ steeringFm,
95
+ STEERING_KEY_ORDER,
96
+ );
97
+ const primaryPath = `${name}.md`;
98
+ const primaryContent = `---\n${frontmatterYaml}---\n${body}\n`;
99
+
100
+ documents.push({
101
+ path: primaryPath as NormalizedRelativePath,
102
+ content: primaryContent,
103
+ executable: false,
104
+ });
105
+
106
+ // Render hook files as JSON
107
+ const sortedHooks = [...hooks].sort((a, b) =>
108
+ codePointCompare(a.name, b.name),
109
+ );
110
+
111
+ for (const hook of sortedHooks) {
112
+ const hookObj: Record<string, unknown> = {
113
+ name: hook.name,
114
+ event: hook.event,
115
+ };
116
+ if (hook.description) hookObj.description = hook.description;
117
+ if (hook.condition) hookObj.condition = hook.condition;
118
+ hookObj.action = hook.action;
119
+ if (hook.gate) hookObj.gate = hook.gate;
120
+ if (hook.postcondition) hookObj.postcondition = hook.postcondition;
121
+
122
+ const hookJson = stableJsonStringify(hookObj);
123
+ documents.push({
124
+ path: `hooks/${hook.name}.kiro.hook` as NormalizedRelativePath,
125
+ content: `${hookJson}\n`,
126
+ executable: false,
127
+ });
128
+ }
129
+
130
+ // Render MCP server definitions as JSON
131
+ if (mcpServers.length > 0) {
132
+ const mcpObj: Record<string, unknown> = {};
133
+ const sortedServers = [...mcpServers].sort((a, b) =>
134
+ codePointCompare(a.name, b.name),
135
+ );
136
+
137
+ for (const server of sortedServers) {
138
+ const serverConfig: Record<string, unknown> = {};
139
+ if (server.transport === "stdio") {
140
+ serverConfig.command = server.command;
141
+ if (server.args && server.args.length > 0) {
142
+ serverConfig.args = server.args;
143
+ }
144
+ } else {
145
+ serverConfig.url = server.url;
146
+ serverConfig.type = server.transport;
147
+ }
148
+ if (server.env && Object.keys(server.env).length > 0) {
149
+ serverConfig.env = server.env;
150
+ }
151
+ if (server.timeout !== undefined) {
152
+ serverConfig.timeout = server.timeout;
153
+ }
154
+ mcpObj[server.name] = serverConfig;
155
+ }
156
+
157
+ const mcpJson = stableJsonStringify({ mcpServers: mcpObj });
158
+ documents.push({
159
+ path: "mcp.json" as NormalizedRelativePath,
160
+ content: `${mcpJson}\n`,
161
+ executable: false,
162
+ });
163
+ }
164
+
165
+ return { documents, diagnostics };
166
+ }