@oleksandr.rudnychenko/sync_loop 0.2.5 → 0.3.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 (54) hide show
  1. package/README.md +25 -4
  2. package/bin/cli.js +3 -128
  3. package/bin/cli.ts +171 -0
  4. package/dist/bin/cli.d.ts +15 -0
  5. package/dist/bin/cli.js +137 -0
  6. package/dist/bin/cli.js.map +1 -0
  7. package/dist/src/init.d.ts +24 -0
  8. package/dist/src/init.js +410 -0
  9. package/dist/src/init.js.map +1 -0
  10. package/dist/src/server.d.ts +13 -0
  11. package/dist/src/server.js +265 -0
  12. package/dist/src/server.js.map +1 -0
  13. package/dist/src/template/.agent-loop/README.md +75 -0
  14. package/dist/src/template/.agent-loop/feedback.md +395 -0
  15. package/dist/src/template/.agent-loop/glossary.md +113 -0
  16. package/dist/src/template/.agent-loop/patterns/api-standards.md +132 -0
  17. package/dist/src/template/.agent-loop/patterns/code-patterns.md +300 -0
  18. package/dist/src/template/.agent-loop/patterns/refactoring-workflow.md +114 -0
  19. package/dist/src/template/.agent-loop/patterns/testing-guide.md +258 -0
  20. package/dist/src/template/.agent-loop/patterns.md +256 -0
  21. package/dist/src/template/.agent-loop/reasoning-kernel.md +521 -0
  22. package/dist/src/template/.agent-loop/validate-env.md +332 -0
  23. package/dist/src/template/.agent-loop/validate-n.md +321 -0
  24. package/dist/src/template/AGENTS.md +157 -0
  25. package/dist/src/template/README.md +144 -0
  26. package/dist/src/template/bootstrap-prompt.md +37 -0
  27. package/dist/src/template/protocol-summary.md +54 -0
  28. package/dist/src/template/wiring/agents-claude.md +203 -0
  29. package/dist/src/template/wiring/agents-github.md +211 -0
  30. package/dist/src/template/wiring/api-standards.md +15 -0
  31. package/dist/src/template/wiring/code-patterns.md +15 -0
  32. package/dist/src/template/wiring/feedback.md +18 -0
  33. package/dist/src/template/wiring/glossary.md +11 -0
  34. package/dist/src/template/wiring/patterns.md +18 -0
  35. package/dist/src/template/wiring/reasoning-kernel.md +18 -0
  36. package/dist/src/template/wiring/refactoring-workflow.md +15 -0
  37. package/dist/src/template/wiring/testing-guide.md +15 -0
  38. package/dist/src/template/wiring/validate-env.md +17 -0
  39. package/dist/src/template/wiring/validate-n.md +17 -0
  40. package/package.json +48 -34
  41. package/src/template/wiring/agents-claude.md +203 -0
  42. package/src/template/wiring/agents-github.md +211 -0
  43. package/src/template/wiring/api-standards.md +15 -0
  44. package/src/template/wiring/code-patterns.md +15 -0
  45. package/src/template/wiring/feedback.md +18 -0
  46. package/src/template/wiring/glossary.md +11 -0
  47. package/src/template/wiring/patterns.md +18 -0
  48. package/src/template/wiring/reasoning-kernel.md +18 -0
  49. package/src/template/wiring/refactoring-workflow.md +15 -0
  50. package/src/template/wiring/testing-guide.md +15 -0
  51. package/src/template/wiring/validate-env.md +17 -0
  52. package/src/template/wiring/validate-n.md +17 -0
  53. package/src/init.js +0 -569
  54. package/src/server.js +0 -292
@@ -0,0 +1,265 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
3
+ import { z } from "zod";
4
+ import { existsSync, readFileSync } from "node:fs";
5
+ import { join, dirname, resolve, posix } from "node:path";
6
+ import { fileURLToPath, pathToFileURL } from "node:url";
7
+ import { init, detectStacks } from "./init.js";
8
+ const __dirname = dirname(fileURLToPath(import.meta.url));
9
+ const TEMPLATE_DIR = join(__dirname, "template");
10
+ function resolvePackageVersion() {
11
+ const candidatePaths = [
12
+ join(__dirname, "..", "package.json"),
13
+ join(__dirname, "..", "..", "package.json"),
14
+ ];
15
+ for (const candidatePath of candidatePaths) {
16
+ if (!existsSync(candidatePath))
17
+ continue;
18
+ const parsed = JSON.parse(readFileSync(candidatePath, "utf-8"));
19
+ if (parsed.version)
20
+ return parsed.version;
21
+ }
22
+ return "0.0.0";
23
+ }
24
+ const PACKAGE_JSON = { version: resolvePackageVersion() };
25
+ const DOCS = {
26
+ overview: {
27
+ path: ".agent-loop/README.md",
28
+ name: "Protocol Overview",
29
+ description: "SyncLoop file index and framework overview",
30
+ },
31
+ "agents-md": {
32
+ path: "AGENTS.md",
33
+ name: "AGENTS.md Template",
34
+ description: "Root entrypoint template for AI agents - project identity, protocol, guardrails",
35
+ },
36
+ "protocol-summary": {
37
+ path: "protocol-summary.md",
38
+ name: "Protocol Summary",
39
+ description: "Condensed 7-stage reasoning loop overview (~50 lines)",
40
+ },
41
+ "reasoning-kernel": {
42
+ path: ".agent-loop/reasoning-kernel.md",
43
+ name: "Reasoning Kernel",
44
+ description: "Core 7-stage loop, transition map, context clearage, micro/macro classification",
45
+ },
46
+ feedback: {
47
+ path: ".agent-loop/feedback.md",
48
+ name: "Feedback Loop",
49
+ description: "Failure diagnosis, patch protocol, micro-loop, branch pruning, learning persistence",
50
+ },
51
+ "validate-env": {
52
+ path: ".agent-loop/validate-env.md",
53
+ name: "Validate Environment (Stage 1)",
54
+ description: "NFR gates: type safety, tests, layer integrity, complexity, debug hygiene",
55
+ },
56
+ "validate-n": {
57
+ path: ".agent-loop/validate-n.md",
58
+ name: "Validate Neighbors (Stage 2)",
59
+ description: "Shape compatibility, boundary integrity, bridge contracts",
60
+ },
61
+ patterns: {
62
+ path: ".agent-loop/patterns.md",
63
+ name: "Pattern Registry",
64
+ description: "Pattern routing index, architecture baseline, learned patterns, pruning records",
65
+ },
66
+ glossary: {
67
+ path: ".agent-loop/glossary.md",
68
+ name: "Domain Glossary",
69
+ description: "Canonical terminology, naming rules, deprecated aliases",
70
+ },
71
+ "code-patterns": {
72
+ path: ".agent-loop/patterns/code-patterns.md",
73
+ name: "Code Patterns (P1-P11)",
74
+ description: "Port/adapter, domain modules, tasks, routes, DI, config, types, error handling",
75
+ },
76
+ "testing-guide": {
77
+ path: ".agent-loop/patterns/testing-guide.md",
78
+ name: "Testing Guide (R2)",
79
+ description: "Test pyramid, fixtures, factories, mocks, parametrized tests, naming",
80
+ },
81
+ "refactoring-workflow": {
82
+ path: ".agent-loop/patterns/refactoring-workflow.md",
83
+ name: "Refactoring Workflow (R1)",
84
+ description: "4-phase checklist for safe file moves and module restructuring",
85
+ },
86
+ "api-standards": {
87
+ path: ".agent-loop/patterns/api-standards.md",
88
+ name: "API Standards (R3)",
89
+ description: "Boundary contracts, typed models, error envelopes, versioning strategy",
90
+ },
91
+ };
92
+ const DOC_ID_BY_PATH = {};
93
+ for (const [id, doc] of Object.entries(DOCS)) {
94
+ DOC_ID_BY_PATH[doc.path] = id;
95
+ }
96
+ function readTemplate(relativePath) {
97
+ return readFileSync(join(TEMPLATE_DIR, relativePath), "utf-8");
98
+ }
99
+ export function pathDir(value) {
100
+ const dir = posix.dirname(value);
101
+ return dir === "." ? "" : dir;
102
+ }
103
+ export function splitHash(link) {
104
+ const idx = link.indexOf("#");
105
+ if (idx === -1)
106
+ return { pathPart: link, hash: "" };
107
+ return {
108
+ pathPart: link.slice(0, idx),
109
+ hash: link.slice(idx),
110
+ };
111
+ }
112
+ export function isExternalLink(link) {
113
+ return /^([a-z]+:|#)/i.test(link);
114
+ }
115
+ export function rewriteMarkdownLinks(content, transform) {
116
+ let inFence = false;
117
+ return content
118
+ .split("\n")
119
+ .map((line) => {
120
+ if (line.trimStart().startsWith("```")) {
121
+ inFence = !inFence;
122
+ return line;
123
+ }
124
+ if (inFence)
125
+ return line;
126
+ return line.replace(/\]\(([^)]+)\)/g, (_match, linkPath) => `](${transform(linkPath)})`);
127
+ })
128
+ .join("\n");
129
+ }
130
+ export function rewriteResourceLinks(content, sourcePath) {
131
+ return rewriteMarkdownLinks(content, (linkPath) => {
132
+ if (isExternalLink(linkPath))
133
+ return linkPath;
134
+ const { pathPart, hash } = splitHash(linkPath);
135
+ if (!pathPart)
136
+ return linkPath;
137
+ let canonical = posix.normalize(posix.join(pathDir(sourcePath) || ".", pathPart)).replace(/^\.\//, "");
138
+ if (canonical === ".agent-loop/patterns")
139
+ canonical = ".agent-loop/patterns.md";
140
+ if (canonical === "../AGENTS.md" || canonical === "AGENTS.md")
141
+ canonical = "AGENTS.md";
142
+ if (canonical === "../README.md")
143
+ return linkPath;
144
+ const docId = DOC_ID_BY_PATH[canonical];
145
+ if (!docId)
146
+ return linkPath;
147
+ return `syncloop://docs/${docId}${hash}`;
148
+ });
149
+ }
150
+ export function formatStacks(stacks) {
151
+ return stacks
152
+ .map((stack) => [
153
+ `\n### ${stack.name}${stack.path ? ` (${stack.path})` : ""}`,
154
+ `- Languages: ${stack.languages.join(", ")}`,
155
+ `- Frameworks: ${stack.frameworks.join(", ")}`,
156
+ stack.testRunner ? `- Test runner: ${stack.testRunner}` : null,
157
+ stack.typeChecker ? `- Type checker: ${stack.typeChecker}` : null,
158
+ stack.linter ? `- Linter: ${stack.linter}` : null,
159
+ stack.packageManager ? `- Package manager: ${stack.packageManager}` : null,
160
+ ].filter(Boolean).join("\n"))
161
+ .join("\n");
162
+ }
163
+ export function createServer() {
164
+ const server = new McpServer({
165
+ name: "sync_loop",
166
+ version: PACKAGE_JSON.version,
167
+ });
168
+ for (const [id, doc] of Object.entries(DOCS)) {
169
+ server.registerResource(doc.name, `syncloop://docs/${id}`, { description: doc.description, mimeType: "text/markdown" }, async (uri) => {
170
+ const raw = readTemplate(doc.path);
171
+ const rewritten = rewriteResourceLinks(raw, doc.path);
172
+ return {
173
+ contents: [{
174
+ uri: uri.href,
175
+ mimeType: "text/markdown",
176
+ text: rewritten,
177
+ }],
178
+ };
179
+ });
180
+ }
181
+ const StackSchema = z.object({
182
+ name: z.string().describe("Stack/layer name (for example: backend, frontend, worker)"),
183
+ languages: z.array(z.string()).describe("Programming languages used by this stack"),
184
+ frameworks: z.array(z.string()).describe("Frameworks/libraries for this stack"),
185
+ testRunner: z.string().optional().describe("Test runner command"),
186
+ typeChecker: z.string().optional().describe("Type checker command"),
187
+ linter: z.string().optional().describe("Lint/format command"),
188
+ packageManager: z.string().optional().describe("Package manager name"),
189
+ path: z.string().optional().describe("Root directory of this stack relative to project root"),
190
+ });
191
+ server.registerTool("init", {
192
+ description: "Scaffold SyncLoop protocol files into a project. If target is not explicitly provided, default to all. If stacks are not provided, auto-detect them by scanning the repository.",
193
+ inputSchema: {
194
+ projectPath: z.string().optional().describe("Project root path. Defaults to current working directory."),
195
+ target: z.enum(["copilot", "cursor", "claude", "all"]).optional().default("all"),
196
+ stacks: z.array(StackSchema).optional().describe("Optional stack definitions. Auto-detected when omitted."),
197
+ dryRun: z.boolean().optional().default(false).describe("Preview file writes without modifying files."),
198
+ overwrite: z.boolean().optional().default(true).describe("Overwrite existing generated files."),
199
+ },
200
+ }, async ({ projectPath, target = "all", stacks, dryRun = false, overwrite = true }) => {
201
+ try {
202
+ const resolvedProjectPath = resolve(projectPath ?? process.cwd());
203
+ const effectiveStacks = stacks?.length ? stacks : detectStacks(resolvedProjectPath);
204
+ const initResult = init(resolvedProjectPath, target, effectiveStacks, { dryRun, overwrite });
205
+ const bootstrapPrompt = readTemplate("bootstrap-prompt.md");
206
+ const stackSummary = formatStacks(initResult.stacks);
207
+ return {
208
+ content: [
209
+ { type: "text", text: `SyncLoop initialized for ${target}:\n\n${initResult.results.join("\n")}` },
210
+ { type: "text", text: `\n---\n\n## Options\n- dryRun: ${dryRun}\n- overwrite: ${overwrite}` },
211
+ { type: "text", text: `\n---\n\n## Detected stacks\n${stackSummary}` },
212
+ {
213
+ type: "text",
214
+ text: `\n---\n\n**IMPORTANT: Now scan the codebase and wire the generated SyncLoop files to this project.**\n\n${bootstrapPrompt}`,
215
+ },
216
+ { type: "text", text: `\n---\n\n## Machine-readable result\n\`\`\`json\n${JSON.stringify(initResult, null, 2)}\n\`\`\`` },
217
+ ],
218
+ };
219
+ }
220
+ catch (err) {
221
+ const message = err instanceof Error ? err.message : String(err);
222
+ return {
223
+ content: [{ type: "text", text: `Error initializing SyncLoop: ${message}` }],
224
+ isError: true,
225
+ };
226
+ }
227
+ });
228
+ server.registerPrompt("bootstrap", { description: "Bootstrap prompt - wire SyncLoop protocol to an existing project by scanning its codebase" }, async () => ({
229
+ description: "Scan the project codebase and wire SyncLoop protocol references to real project structure",
230
+ messages: [{
231
+ role: "user",
232
+ content: {
233
+ type: "text",
234
+ text: readTemplate("bootstrap-prompt.md"),
235
+ },
236
+ }],
237
+ }));
238
+ server.registerPrompt("protocol", { description: "SyncLoop reasoning protocol summary - inject as system context for any AI coding task" }, async () => ({
239
+ description: "The SyncLoop 7-stage reasoning protocol for self-correcting agent behavior",
240
+ messages: [{
241
+ role: "user",
242
+ content: {
243
+ type: "text",
244
+ text: readTemplate("protocol-summary.md"),
245
+ },
246
+ }],
247
+ }));
248
+ return server;
249
+ }
250
+ export async function startServer() {
251
+ const server = createServer();
252
+ const transport = new StdioServerTransport();
253
+ await server.connect(transport);
254
+ return server;
255
+ }
256
+ function isMainModule(metaUrl) {
257
+ const entryFile = process.argv[1];
258
+ if (!entryFile)
259
+ return false;
260
+ return metaUrl === pathToFileURL(entryFile).href;
261
+ }
262
+ if (isMainModule(import.meta.url)) {
263
+ await startServer();
264
+ }
265
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,YAAY,EAAyC,MAAM,WAAW,CAAC;AAEtF,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAA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AAC,KAAK,UAAU,WAAW;IAC/B,MAAM,MAAM,GAAG,YAAY,EAAE,CAAC;IAC9B,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAChC,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,YAAY,CAAC,OAAe;IACnC,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClC,IAAI,CAAC,SAAS;QAAE,OAAO,KAAK,CAAC;IAC7B,OAAO,OAAO,KAAK,aAAa,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC;AACnD,CAAC;AAED,IAAI,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;IAClC,MAAM,WAAW,EAAE,CAAC;AACtB,CAAC"}
@@ -0,0 +1,75 @@
1
+ # Agent Loop Prompts
2
+
3
+ Modular prompts for AI coding agents to run a reusable, self-correcting delivery loop.
4
+
5
+ Project bootstrap workflow and setup prompt are documented in [../README.md](../README.md).
6
+
7
+ ## Overview
8
+
9
+ The framework uses a **7-stage protocol** with **2-stage validation**, **feedback integration**, and **session persistence**:
10
+
11
+ ```
12
+ ┌─────────┐ ┌─────────┐
13
+ │ 1 SENSE │◄───►│ 2 GKP │ ◄── inner loop: gather + compress
14
+ └────┬────┘ └────┬────┘
15
+ └───────┬───────┘
16
+
17
+ ┌──────────────┐
18
+ │ 3 DECIDE+ACT │ ← select mode, plan, execute
19
+ └──────┬───────┘
20
+
21
+ ┌───────────────────────┐
22
+ │ 4 CHALLENGE-TEST │ ◄── inner loop: validate + fix (max 5)
23
+ │ ├ Stage 1: ENV │ ← NFRs (types, tests, layers)
24
+ │ └ Stage 2: NEIGHBOR │ ← Shapes, boundaries, bridges
25
+ └──────────┬────────────┘
26
+ │ On FAIL → FEEDBACK → patch → retry
27
+
28
+ ┌──────────┐
29
+ │ 5 UPDATE │ ← commit state transitions
30
+ └─────┬────┘
31
+
32
+ ┌──────────┐
33
+ │ 6 LEARN │ ← persist to patterns.md / patterns/ specs
34
+ └────┬─────┘
35
+
36
+ ┌──────────┐
37
+ │ 7 REPORT │ ← store session log to docs/reports/
38
+ └──────────┘ (skip if trivial)
39
+ ```
40
+
41
+ ## Prompt Files
42
+
43
+ | File | Purpose | When to Use |
44
+ |------|---------|-------------|
45
+ | [reasoning-kernel.md](reasoning-kernel.md) | Core 7-stage loop with integrated validation | Every turn — master orchestrator |
46
+ | [patterns.md](patterns.md) | Pattern registry + learned fixes | GKP phase (read), LEARN phase (write) |
47
+ | [patterns/](patterns/) | Detailed implementation specs | GKP routes here for examples |
48
+ | [glossary.md](glossary.md) | Canonical domain terminology | Naming, resolving ambiguous terms |
49
+ | [validate-env.md](validate-env.md) | Stage 1: NFRs (types, tests, layers, complexity) | CHALLENGE-TEST Stage 1 |
50
+ | [validate-n.md](validate-n.md) | Stage 2: Neighbors (shapes, boundaries, bridges) | CHALLENGE-TEST Stage 2 |
51
+ | [feedback.md](feedback.md) | Behavioral patches, learning, spec persistence | On validation failure; LEARN phase routing |
52
+
53
+ ## Pattern Specs (patterns/)
54
+
55
+ | Spec File | Pattern IDs | Content |
56
+ |-----------|-------------|---------|
57
+ | [code-patterns.md](patterns/code-patterns.md) | P1–P11 | Ports, modules, tasks, routes, DI, config, types, errors |
58
+ | [testing-guide.md](patterns/testing-guide.md) | R2 | Test patterns, fixtures, mocks, naming, 3-layer strategy |
59
+ | [refactoring-workflow.md](patterns/refactoring-workflow.md) | R1 | 4-phase refactoring checklist |
60
+ | [api-standards.md](patterns/api-standards.md) | R3 | Boundary contract standards, endpoint workflow |
61
+
62
+ ## Validation Structure
63
+
64
+ Each gate follows: **CHECK → FEEDBACK (if failed) → RETRY**
65
+
66
+ | Stage | File | Scope |
67
+ |-------|------|-------|
68
+ | Stage 1: ENV | [validate-env.md](validate-env.md) | Non-functional requirements |
69
+ | Stage 2: NEIGHBOR | [validate-n.md](validate-n.md) | Compatibility and integration surfaces |
70
+ | Failure flow | [feedback.md](feedback.md) | Diagnosis, patching, escalation |
71
+
72
+ ## Entrypoint
73
+
74
+ The root entrypoint is [AGENTS.md](../AGENTS.md).
75
+ It provides architecture rules, operational modes, and routing into this folder.