@ambystech/ambykit 1.0.0 → 1.1.1

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 (86) hide show
  1. package/CHANGELOG.md +103 -0
  2. package/README.md +65 -21
  3. package/dist/cli/check.d.ts +2 -0
  4. package/dist/cli/check.js +39 -0
  5. package/dist/cli/check.js.map +1 -1
  6. package/dist/cli/index.js +2 -0
  7. package/dist/cli/index.js.map +1 -1
  8. package/dist/cli/init.js +17 -3
  9. package/dist/cli/init.js.map +1 -1
  10. package/dist/cli/sync.js +10 -0
  11. package/dist/cli/sync.js.map +1 -1
  12. package/dist/cli/ui/interactive/prompt.d.ts +11 -0
  13. package/dist/cli/ui/interactive/prompt.js +37 -0
  14. package/dist/cli/ui/interactive/prompt.js.map +1 -1
  15. package/dist/cli/worktree.d.ts +18 -0
  16. package/dist/cli/worktree.js +161 -0
  17. package/dist/cli/worktree.js.map +1 -0
  18. package/dist/core/command-spec.js +2 -0
  19. package/dist/core/command-spec.js.map +1 -1
  20. package/dist/core/config.js +1 -0
  21. package/dist/core/config.js.map +1 -1
  22. package/dist/core/emit.js +2 -1
  23. package/dist/core/emit.js.map +1 -1
  24. package/dist/core/git.d.ts +33 -0
  25. package/dist/core/git.js +104 -0
  26. package/dist/core/git.js.map +1 -0
  27. package/dist/core/index.d.ts +3 -0
  28. package/dist/core/index.js +3 -0
  29. package/dist/core/index.js.map +1 -1
  30. package/dist/core/paths.d.ts +2 -0
  31. package/dist/core/paths.js +4 -0
  32. package/dist/core/paths.js.map +1 -1
  33. package/dist/core/roles.d.ts +19 -0
  34. package/dist/core/roles.js +59 -0
  35. package/dist/core/roles.js.map +1 -0
  36. package/dist/core/rules.js +6 -1
  37. package/dist/core/rules.js.map +1 -1
  38. package/dist/core/scaffold.d.ts +2 -0
  39. package/dist/core/scaffold.js +6 -1
  40. package/dist/core/scaffold.js.map +1 -1
  41. package/dist/core/types.d.ts +18 -0
  42. package/dist/core/worktree.d.ts +78 -0
  43. package/dist/core/worktree.js +121 -0
  44. package/dist/core/worktree.js.map +1 -0
  45. package/dist/emitters/base-emitter.d.ts +19 -2
  46. package/dist/emitters/base-emitter.js +43 -3
  47. package/dist/emitters/base-emitter.js.map +1 -1
  48. package/dist/emitters/claude.d.ts +3 -1
  49. package/dist/emitters/claude.js +12 -0
  50. package/dist/emitters/claude.js.map +1 -1
  51. package/dist/emitters/copilot.d.ts +3 -1
  52. package/dist/emitters/copilot.js +11 -0
  53. package/dist/emitters/copilot.js.map +1 -1
  54. package/dist/emitters/opencode.d.ts +3 -1
  55. package/dist/emitters/opencode.js +11 -0
  56. package/dist/emitters/opencode.js.map +1 -1
  57. package/docs/architecture.md +93 -0
  58. package/docs/artifacts/plan.md +31 -0
  59. package/docs/artifacts/spec.md +70 -0
  60. package/docs/artifacts/tasks.md +40 -0
  61. package/docs/artifacts/ui-design.md +59 -0
  62. package/docs/cli-reference.md +167 -0
  63. package/docs/concepts/constitution.md +35 -0
  64. package/docs/concepts/spec-driven-development.md +34 -0
  65. package/docs/contributing.md +50 -0
  66. package/docs/getting-started.md +106 -0
  67. package/docs/index.md +35 -0
  68. package/docs/tool-compatibility.md +78 -0
  69. package/docs/workflow.md +109 -0
  70. package/package.json +15 -3
  71. package/src/prompts/analyze.md +1 -0
  72. package/src/prompts/clarify.md +1 -0
  73. package/src/prompts/converge.md +27 -0
  74. package/src/prompts/design.md +1 -0
  75. package/src/prompts/implement.md +1 -0
  76. package/src/prompts/plan.md +1 -0
  77. package/src/prompts/review.md +24 -0
  78. package/src/prompts/revise.md +1 -0
  79. package/src/prompts/specify.md +6 -2
  80. package/src/prompts/tasks.md +1 -0
  81. package/src/roles/architect.md +17 -0
  82. package/src/roles/developer.md +17 -0
  83. package/src/roles/pm.md +17 -0
  84. package/src/roles/qa.md +17 -0
  85. package/src/roles/tech-lead.md +17 -0
  86. package/src/roles/ux.md +17 -0
@@ -17,6 +17,8 @@ export interface CommandSpec {
17
17
  writes: string[];
18
18
  /** Abstract tool capabilities the phase needs. */
19
19
  allowedTools: AbstractTool[];
20
+ /** Default role id this phase acts as, if any (feature 013). */
21
+ role?: string;
20
22
  /** The prompt body (Markdown), verbatim minus surrounding whitespace. */
21
23
  body: string;
22
24
  }
@@ -77,6 +79,18 @@ export interface MergePlan {
77
79
  /** Explanation for `skipped` (hand-edited) or `aborted` (unreadable/malformed). */
78
80
  reason?: string;
79
81
  }
82
+ /** A role definition from `.amby/roles/<id>.md` (feature 013). */
83
+ export interface Role {
84
+ id: string;
85
+ name: string;
86
+ /** Phases this role owns by default (informational; the binding lives on the CommandSpec). */
87
+ phases: string[];
88
+ /** Markdown body — mission, focus checklist, hand-off. */
89
+ body: string;
90
+ words: number;
91
+ /** Project-relative source path, for messages. */
92
+ source: string;
93
+ }
80
94
  /** Context an emitter needs to render rules/config for a project. */
81
95
  export interface RulesContext {
82
96
  /** Human project name. */
@@ -85,6 +99,8 @@ export interface RulesContext {
85
99
  specs: CommandSpec[];
86
100
  /** Whether the emitter should also emit the shared rules file(s). */
87
101
  manageRules: boolean;
102
+ /** Roles installed in the project; empty/absent means phases run without a role (feature 013). */
103
+ roles?: Role[];
88
104
  }
89
105
  /** Persisted project configuration at .amby/config.json. */
90
106
  export interface AmbyConfig {
@@ -93,6 +109,8 @@ export interface AmbyConfig {
93
109
  tools: string[];
94
110
  /** When false, `sync` regenerates commands only, not AGENTS.md/CLAUDE.md. Default true. */
95
111
  manageRules?: boolean;
112
+ /** When true, `/amby.specify` creates a `.worktrees/<feature>` worktree for each new feature (feature 012). */
113
+ worktrees?: boolean;
96
114
  }
97
115
  /** How a tool materializes phase prompts. */
98
116
  export type CommandSurface = "commands" | "skills" | "workflows" | "none";
@@ -0,0 +1,78 @@
1
+ import type { GitWorktree } from "./git.js";
2
+ /** Directory (relative to the project root) that holds per-feature worktrees (FR-002). */
3
+ export declare const WORKTREES_DIR = ".worktrees";
4
+ /** Feature ids = names of `specs/NNN-slug/` directories, sorted. */
5
+ export declare function featureIds(root: string): string[];
6
+ /** Absolute path of the worktree for `featureId` (FR-002). */
7
+ export declare function worktreePath(root: string, featureId: string): string;
8
+ /** Add an ignore rule for `.worktrees/` to gitignore text if absent; returns the new text. */
9
+ export declare function ensureGitignore(text: string): {
10
+ text: string;
11
+ changed: boolean;
12
+ };
13
+ /**
14
+ * Normalize a path for comparison against git's output. Git reports **canonical** paths — symlinks
15
+ * resolved (macOS `/var` → `/private/var`) and Windows 8.3 names expanded (`RUNNER~1`) — so both
16
+ * sides go through `realpath` when they exist, falling back to a plain `resolve` otherwise.
17
+ */
18
+ export declare function samePath(a: string, b: string): boolean;
19
+ /** The registered worktree whose path is `.worktrees/<featureId>`, if any. */
20
+ export declare function findWorktree(root: string, featureId: string, list: GitWorktree[]): GitWorktree | undefined;
21
+ /** Feature id when `dir` is (inside) a `.worktrees/<id>` directory of some project, else null. */
22
+ export declare function featureFromWorktreePath(dir: string): string | null;
23
+ export type CreatePlan = {
24
+ action: "exists";
25
+ path: string;
26
+ } | {
27
+ action: "create";
28
+ path: string;
29
+ branch: string;
30
+ newBranch: boolean;
31
+ base: string | null;
32
+ } | {
33
+ action: "refuse";
34
+ reason: string;
35
+ };
36
+ /**
37
+ * Decide what creating a worktree for `featureId` should do (FR-003/004/005 + edge cases). Pure:
38
+ * takes facts, returns a plan; the CLI performs it.
39
+ */
40
+ export declare function planCreate(input: {
41
+ root: string;
42
+ featureId: string;
43
+ features: string[];
44
+ worktrees: GitWorktree[];
45
+ branchExists: boolean;
46
+ defaultBranch: string | null;
47
+ dirExists: boolean;
48
+ }): CreatePlan;
49
+ export type RemovePlan = {
50
+ action: "absent";
51
+ } | {
52
+ action: "refuse";
53
+ reason: string;
54
+ path: string;
55
+ } | {
56
+ action: "remove";
57
+ path: string;
58
+ force: boolean;
59
+ };
60
+ export declare function planRemove(input: {
61
+ root: string;
62
+ featureId: string;
63
+ worktrees: GitWorktree[];
64
+ dirty: boolean;
65
+ force: boolean;
66
+ }): RemovePlan;
67
+ export interface WorktreeStatus {
68
+ feature: string;
69
+ branch: string | null;
70
+ path: string;
71
+ dirty: boolean;
72
+ stale: boolean;
73
+ }
74
+ /** Worktrees under `.worktrees/`, matched to feature ids (unknown dirs keep their dir name). */
75
+ export declare function featureWorktrees(root: string, list: GitWorktree[]): {
76
+ feature: string;
77
+ worktree: GitWorktree;
78
+ }[];
@@ -0,0 +1,121 @@
1
+ import { existsSync, readdirSync, realpathSync, statSync } from "node:fs";
2
+ import { basename, dirname, join, resolve, sep } from "node:path";
3
+ /** Directory (relative to the project root) that holds per-feature worktrees (FR-002). */
4
+ export const WORKTREES_DIR = ".worktrees";
5
+ const FEATURE_ID = /^\d{3}-[a-z0-9][a-z0-9-]*$/;
6
+ /** Feature ids = names of `specs/NNN-slug/` directories, sorted. */
7
+ export function featureIds(root) {
8
+ const dir = join(root, "specs");
9
+ if (!existsSync(dir))
10
+ return [];
11
+ return readdirSync(dir)
12
+ .filter((n) => FEATURE_ID.test(n) && statSync(join(dir, n)).isDirectory())
13
+ .sort();
14
+ }
15
+ /** Absolute path of the worktree for `featureId` (FR-002). */
16
+ export function worktreePath(root, featureId) {
17
+ return join(root, WORKTREES_DIR, featureId);
18
+ }
19
+ /** Add an ignore rule for `.worktrees/` to gitignore text if absent; returns the new text. */
20
+ export function ensureGitignore(text) {
21
+ const rule = `${WORKTREES_DIR}/`;
22
+ const has = text.split(/\r?\n/).some((l) => {
23
+ const t = l.trim();
24
+ return t === rule || t === WORKTREES_DIR || t === `/${rule}` || t === `/${WORKTREES_DIR}`;
25
+ });
26
+ if (has)
27
+ return { text, changed: false };
28
+ const sep = text.length === 0 || text.endsWith("\n") ? "" : "\n";
29
+ return { text: `${text}${sep}# AmbyKit per-feature worktrees\n${rule}\n`, changed: true };
30
+ }
31
+ /**
32
+ * Normalize a path for comparison against git's output. Git reports **canonical** paths — symlinks
33
+ * resolved (macOS `/var` → `/private/var`) and Windows 8.3 names expanded (`RUNNER~1`) — so both
34
+ * sides go through `realpath` when they exist, falling back to a plain `resolve` otherwise.
35
+ */
36
+ export function samePath(a, b) {
37
+ return canonical(a) === canonical(b);
38
+ }
39
+ function canonical(p) {
40
+ let full = resolve(p);
41
+ try {
42
+ full = realpathSync.native(full);
43
+ }
44
+ catch {
45
+ // Not on disk (e.g. a planned path): canonicalize the nearest existing ancestor so a
46
+ // symlinked or short-named parent still matches.
47
+ const parent = dirname(full);
48
+ if (parent !== full) {
49
+ try {
50
+ full = join(realpathSync.native(parent), basename(full));
51
+ }
52
+ catch {
53
+ /* keep the resolved form */
54
+ }
55
+ }
56
+ }
57
+ return full.replace(/[\\/]+/g, "/").replace(/\/$/, "").toLowerCase();
58
+ }
59
+ /** The registered worktree whose path is `.worktrees/<featureId>`, if any. */
60
+ export function findWorktree(root, featureId, list) {
61
+ const want = worktreePath(root, featureId);
62
+ return list.find((w) => samePath(w.path, want));
63
+ }
64
+ /** Feature id when `dir` is (inside) a `.worktrees/<id>` directory of some project, else null. */
65
+ export function featureFromWorktreePath(dir) {
66
+ const parts = resolve(dir).split(sep);
67
+ const i = parts.lastIndexOf(WORKTREES_DIR);
68
+ if (i === -1 || i + 1 >= parts.length)
69
+ return null;
70
+ const id = parts[i + 1] ?? "";
71
+ return FEATURE_ID.test(id) ? id : null;
72
+ }
73
+ /**
74
+ * Decide what creating a worktree for `featureId` should do (FR-003/004/005 + edge cases). Pure:
75
+ * takes facts, returns a plan; the CLI performs it.
76
+ */
77
+ export function planCreate(input) {
78
+ const { root, featureId, features } = input;
79
+ if (!features.includes(featureId)) {
80
+ const list = features.length ? features.join(", ") : "(none — run /amby.specify first)";
81
+ return { action: "refuse", reason: `No feature '${featureId}' under specs/. Valid: ${list}` };
82
+ }
83
+ const path = worktreePath(root, featureId);
84
+ const existing = findWorktree(root, featureId, input.worktrees);
85
+ if (existing)
86
+ return { action: "exists", path: existing.path };
87
+ if (input.dirExists) {
88
+ return { action: "refuse", reason: `${path} exists but is not a registered worktree — remove it (or run \`git worktree prune\`) and retry.` };
89
+ }
90
+ const elsewhere = input.worktrees.find((w) => w.branch === featureId);
91
+ if (elsewhere) {
92
+ return { action: "refuse", reason: `Branch '${featureId}' is already checked out at ${elsewhere.path}.` };
93
+ }
94
+ if (!input.branchExists && !input.defaultBranch) {
95
+ return { action: "refuse", reason: "Cannot determine the default branch (no origin/HEAD, main, or master)." };
96
+ }
97
+ return {
98
+ action: "create",
99
+ path,
100
+ branch: featureId,
101
+ newBranch: !input.branchExists,
102
+ base: input.branchExists ? null : input.defaultBranch,
103
+ };
104
+ }
105
+ export function planRemove(input) {
106
+ const existing = findWorktree(input.root, input.featureId, input.worktrees);
107
+ if (!existing)
108
+ return { action: "absent" };
109
+ if (input.dirty && !input.force) {
110
+ return { action: "refuse", path: existing.path, reason: "has uncommitted changes — commit them or pass --force." };
111
+ }
112
+ return { action: "remove", path: existing.path, force: input.force };
113
+ }
114
+ /** Worktrees under `.worktrees/`, matched to feature ids (unknown dirs keep their dir name). */
115
+ export function featureWorktrees(root, list) {
116
+ const base = resolve(root, WORKTREES_DIR);
117
+ return list
118
+ .filter((w) => samePath(resolve(w.path, ".."), base))
119
+ .map((w) => ({ feature: featureFromWorktreePath(w.path) ?? (w.path.split(/[\\/]/).pop() ?? w.path), worktree: w }));
120
+ }
121
+ //# sourceMappingURL=worktree.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worktree.js","sourceRoot":"","sources":["../../src/core/worktree.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAGlE,0FAA0F;AAC1F,MAAM,CAAC,MAAM,aAAa,GAAG,YAAY,CAAC;AAE1C,MAAM,UAAU,GAAG,4BAA4B,CAAC;AAEhD,oEAAoE;AACpE,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,M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K,CAAC,KAAK,EAAE,CAAC;AACvE,CAAC;AAUD,gGAAgG;AAChG,MAAM,UAAU,gBAAgB,CAAC,IAAY,EAAE,IAAmB;IAChE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;IAC1C,OAAO,IAAI;SACR,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC;SACpD,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,uBAAuB,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AACxH,CAAC"}
@@ -1,4 +1,4 @@
1
- import type { AbstractTool, CommandSpec, CommandSurface, EmittedFile, RulesContext } from "../core/types.js";
1
+ import type { Role, AbstractTool, CommandSpec, CommandSurface, EmittedFile, RulesContext } from "../core/types.js";
2
2
  /**
3
3
  * Abstract base for all tool emitters. Holds the shared orchestration (the `emit` template method)
4
4
  * and rendering helpers; subclasses override only what differs for their tool. Adding a tool should
@@ -17,6 +17,16 @@ export declare abstract class BaseEmitter {
17
17
  protected readonly toolNameMap: Record<AbstractTool, string>;
18
18
  /** Template method: orchestrates a full emit. Subclasses do not override this. */
19
19
  emit(specs: CommandSpec[], ctx: RulesContext): EmittedFile[];
20
+ /**
21
+ * Native persona/sub-agent files, one per role (feature 013, FR-009). Default: none — only
22
+ * targets whose agent-file format is verified in `docs/tool-compatibility.md` override this.
23
+ */
24
+ protected roleFiles(_roles: Role[], _ctx: RulesContext): EmittedFile[];
25
+ /** Persona file name stem shared by every native format: `amby-<role id>`. */
26
+ protected personaName(role: Role): string;
27
+ /** Persona system prompt: the role body plus a pointer to the shared workflow rules. */
28
+ protected personaBody(role: Role): string;
29
+ protected personaDescription(role: Role): string;
20
30
  /** Tool-specific extra rules files (e.g. Claude's CLAUDE.md bridge). Default: none. */
21
31
  protected rulesFiles(_ctx: RulesContext): EmittedFile[];
22
32
  /** Full project-relative path of a spec's command file. */
@@ -25,12 +35,19 @@ export declare abstract class BaseEmitter {
25
35
  protected commandFileName(spec: CommandSpec): string;
26
36
  /** Native frontmatter as ordered [key, serializedValue] pairs. */
27
37
  protected abstract commandFrontmatter(spec: CommandSpec): Array<[string, string]>;
28
- protected commandFile(spec: CommandSpec): EmittedFile;
38
+ protected commandFile(spec: CommandSpec, ctx?: RulesContext): EmittedFile;
29
39
  /**
30
40
  * Transform the neutral prompt body for this tool. Default: verbatim. Tools with a different
31
41
  * argument-placeholder convention override this (e.g. Copilot swaps `$ARGUMENTS` for `${input:…}`).
32
42
  */
33
43
  protected transformBody(spec: CommandSpec): string;
44
+ /**
45
+ * One sentence binding the phase to its role (feature 013, FR-003/FR-005). Emitted only when the
46
+ * project has roles installed and the spec names one; otherwise nothing, so projects without
47
+ * `.amby/roles/` get byte-identical output (FR-004). The role is referenced by path, never
48
+ * inlined (Principle 3).
49
+ */
50
+ protected roleLine(spec: CommandSpec, ctx?: RulesContext): string | null;
34
51
  protected generatedNotice(spec: CommandSpec): string;
35
52
  protected renderFrontmatter(pairs: Array<[string, string]>): string;
36
53
  /** Double-quote and escape a scalar so it is always valid YAML. */
@@ -1,4 +1,5 @@
1
1
  import { join } from "node:path/posix";
2
+ import { roleForSpec } from "../core/roles.js";
2
3
  /**
3
4
  * Abstract base for all tool emitters. Holds the shared orchestration (the `emit` template method)
4
5
  * and rendering helpers; subclasses override only what differs for their tool. Adding a tool should
@@ -17,12 +18,34 @@ export class BaseEmitter {
17
18
  const files = [];
18
19
  if (this.commandSurface !== "none") {
19
20
  for (const spec of specs)
20
- files.push(this.commandFile(spec));
21
+ files.push(this.commandFile(spec, ctx));
21
22
  }
22
23
  if (ctx.manageRules)
23
24
  files.push(...this.rulesFiles(ctx));
25
+ if (ctx.roles && ctx.roles.length > 0)
26
+ files.push(...this.roleFiles(ctx.roles, ctx));
24
27
  return files;
25
28
  }
29
+ /**
30
+ * Native persona/sub-agent files, one per role (feature 013, FR-009). Default: none — only
31
+ * targets whose agent-file format is verified in `docs/tool-compatibility.md` override this.
32
+ */
33
+ roleFiles(_roles, _ctx) {
34
+ return [];
35
+ }
36
+ /** Persona file name stem shared by every native format: `amby-<role id>`. */
37
+ personaName(role) {
38
+ return `amby-${role.id}`;
39
+ }
40
+ /** Persona system prompt: the role body plus a pointer to the shared workflow rules. */
41
+ personaBody(role) {
42
+ return `<!-- GENERATED by AmbyKit from .amby/roles/${role.id}.md — do not edit by hand; run \`ambykit sync\`. -->\n\n` +
43
+ `You are the **${role.name}** on this project.\n\n${role.body}\n\n` +
44
+ "Follow the AmbyKit workflow and rules in `AGENTS.md`; artifacts live under `specs/`.";
45
+ }
46
+ personaDescription(role) {
47
+ return `${role.name} — AmbyKit role for ${role.phases.length ? role.phases.join("/") : "reviews"}; use for that perspective.`;
48
+ }
26
49
  /** Tool-specific extra rules files (e.g. Claude's CLAUDE.md bridge). Default: none. */
27
50
  rulesFiles(_ctx) {
28
51
  return [];
@@ -36,10 +59,13 @@ export class BaseEmitter {
36
59
  commandFileName(spec) {
37
60
  return `${spec.name}.md`;
38
61
  }
39
- commandFile(spec) {
62
+ commandFile(spec, ctx) {
40
63
  const pairs = this.commandFrontmatter(spec);
41
64
  const notice = this.generatedNotice(spec);
42
- const body = this.transformBody(spec);
65
+ const roleLine = this.roleLine(spec, ctx);
66
+ // The role line is prepended *before* transformBody so tool-specific placeholder rewrites
67
+ // (e.g. Copilot's `$ARGUMENTS`) apply to its `--as` clause too.
68
+ const body = this.transformBody(roleLine ? { ...spec, body: `${roleLine}\n\n${spec.body}` } : spec);
43
69
  // Tools with no command frontmatter (e.g. Cursor plain commands) get no `---` block.
44
70
  const head = pairs.length > 0 ? `${this.renderFrontmatter(pairs)}\n` : "";
45
71
  const contents = `${head}${notice}\n\n${body}\n`;
@@ -52,6 +78,20 @@ export class BaseEmitter {
52
78
  transformBody(spec) {
53
79
  return spec.body;
54
80
  }
81
+ /**
82
+ * One sentence binding the phase to its role (feature 013, FR-003/FR-005). Emitted only when the
83
+ * project has roles installed and the spec names one; otherwise nothing, so projects without
84
+ * `.amby/roles/` get byte-identical output (FR-004). The role is referenced by path, never
85
+ * inlined (Principle 3).
86
+ */
87
+ roleLine(spec, ctx) {
88
+ const role = roleForSpec(ctx?.roles ?? [], spec.role);
89
+ if (!role)
90
+ return null;
91
+ return (`Act as the **${role.name}** in \`@.amby/roles/${role.id}.md\` and say so in your first line. ` +
92
+ "If `$ARGUMENTS` contains `--as <id>`, use `@.amby/roles/<id>.md` instead; if that file is " +
93
+ "missing, stop and list the files in `.amby/roles/`.");
94
+ }
55
95
  generatedNotice(spec) {
56
96
  return `<!-- GENERATED by AmbyKit from src/prompts/${spec.id}.md — do not edit by hand; run \`ambykit sync\`. -->`;
57
97
  }
@@ -1 +1 @@
1
- {"version":3,"file":"base-emitter.js","sourceRoot":"","sources":["../../src/emitters/base-emitter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AASvC;;;;GAIG;AACH,MAAM,OAAgB,WAAW;IAS/B,oGAAoG;IACjF,WAAW,GAAiC;QAC7D,IAAI,EAAE,MAAM;QACZ,KAAK,EAAE,OAAO;QACd,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,MAAM;KACb,CAAC;IAEF,kFAAkF;IAClF,IAAI,CAAC,KAAoB,EAAE,GAAiB;QAC1C,MAAM,KAAK,GAAkB,EAAE,CAAC;QAChC,IAAI,IAAI,CAAC,cAAc,KAAK,MAAM,EAAE,CAAC;YACnC,KAAK,MAAM,IAAI,IAAI,KAAK;gBAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CA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,IAAI,CAAC,CAAC;QACtD,IAAI,CAAC,IAAI;YAAE,OAAO,IAAI,CAAC;QACvB,OAAO,CACL,gBAAgB,IAAI,CAAC,IAAI,wBAAwB,IAAI,CAAC,EAAE,uCAAuC;YAC/F,4FAA4F;YAC5F,qDAAqD,CACtD,CAAC;IACJ,CAAC;IAES,eAAe,CAAC,IAAiB;QACzC,OAAO,8CAA8C,IAAI,CAAC,EAAE,sDAAsD,CAAC;IACrH,CAAC;IAED,yCAAyC;IAE/B,iBAAiB,CAAC,KAA8B;QACxD,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC5D,OAAO,QAAQ,IAAI,OAAO,CAAC;IAC7B,CAAC;IAED,mEAAmE;IACzD,SAAS,CAAC,KAAa;QAC/B,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC;IAClE,CAAC;IAED,qFAAqF;IAC3E,WAAW,CAAC,IAAiB;QACrC,OAAO,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACtE,CAAC;CACF"}
@@ -1,4 +1,4 @@
1
- import type { AbstractTool, CommandSpec, CommandSurface, EmittedFile, RulesContext } from "../core/types.js";
1
+ import type { AbstractTool, CommandSpec, CommandSurface, EmittedFile, Role, RulesContext } from "../core/types.js";
2
2
  import { BaseEmitter } from "./base-emitter.js";
3
3
  /**
4
4
  * Claude Code emitter. Emits slash commands to `.claude/commands/amby.*.md` and a `CLAUDE.md`
@@ -12,5 +12,7 @@ export declare class ClaudeEmitter extends BaseEmitter {
12
12
  readonly commandDir = ".claude/commands";
13
13
  protected readonly toolNameMap: Record<AbstractTool, string>;
14
14
  protected commandFrontmatter(spec: CommandSpec): Array<[string, string]>;
15
+ /** Sub-agents at `.claude/agents/<name>.md` — `name` + `description` required (verified, feature 013). */
16
+ protected roleFiles(roles: Role[], _ctx: RulesContext): EmittedFile[];
15
17
  protected rulesFiles(_ctx: RulesContext): EmittedFile[];
16
18
  }
@@ -23,6 +23,18 @@ export class ClaudeEmitter extends BaseEmitter {
23
23
  ["allowed-tools", this.mappedTools(spec)],
24
24
  ];
25
25
  }
26
+ /** Sub-agents at `.claude/agents/<name>.md` — `name` + `description` required (verified, feature 013). */
27
+ roleFiles(roles, _ctx) {
28
+ return roles.map((role) => ({
29
+ path: `.claude/agents/${this.personaName(role)}.md`,
30
+ contents: `${this.renderFrontmatter([
31
+ ["name", this.personaName(role)],
32
+ ["description", this.yamlQuote(this.personaDescription(role))],
33
+ ["tools", "Read, Grep, Glob"],
34
+ ])}\n${this.personaBody(role)}\n`,
35
+ scope: "project",
36
+ }));
37
+ }
26
38
  rulesFiles(_ctx) {
27
39
  // The `@AGENTS.md` import must stay on line 1 (Claude does not read AGENTS.md natively). It is
28
40
  // the `requiredPrefix` so a brownfield merge re-adds it if missing (FR-011); the AmbyKit body is
@@ -1 +1 @@
1
- {"version":3,"file":"claude.js","sourceRoot":"","sources":["../../src/emitters/claude.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD;;;;GAIG;AACH,MAAM,OAAO,aAAc,SAAQ,WAAW;IACnC,MAAM,GAAG,QAAQ,CAAC;IAClB,WAAW,GAAG,aAAa,CAAC;IAC5B,cAAc,GAAmB,UAAU,CAAC;IAC5C,UAAU,GAAG,kBAAkB,CAAC;IAEb,WAAW,GAAiC;QACtE,IAAI,EAAE,MAAM;QACZ,KAAK,EAAE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js";
1
+ import type { CommandSpec, CommandSurface, EmittedFile, Role, RulesContext } from "../core/types.js";
2
2
  import { BaseEmitter } from "./base-emitter.js";
3
3
  /**
4
4
  * GitHub Copilot (VS Code) emitter. Phase prompts become prompt files at
@@ -15,5 +15,7 @@ export declare class CopilotEmitter extends BaseEmitter {
15
15
  protected commandFrontmatter(spec: CommandSpec): Array<[string, string]>;
16
16
  /** Copilot substitutes `${input:name}`; map our single `$ARGUMENTS` token to it. */
17
17
  protected transformBody(spec: CommandSpec): string;
18
+ /** Custom agents at `.github/agents/<name>.agent.md` — `description` required; all environments incl. CLI (verified, feature 013). */
19
+ protected roleFiles(roles: Role[], _ctx: RulesContext): EmittedFile[];
18
20
  protected rulesFiles(_ctx: RulesContext): EmittedFile[];
19
21
  }
@@ -26,6 +26,17 @@ export class CopilotEmitter extends BaseEmitter {
26
26
  transformBody(spec) {
27
27
  return spec.body.replaceAll("$ARGUMENTS", "${input:args}");
28
28
  }
29
+ /** Custom agents at `.github/agents/<name>.agent.md` — `description` required; all environments incl. CLI (verified, feature 013). */
30
+ roleFiles(roles, _ctx) {
31
+ return roles.map((role) => ({
32
+ path: join(".github", "agents", `${this.personaName(role)}.agent.md`),
33
+ contents: `${this.renderFrontmatter([
34
+ ["name", this.personaName(role)],
35
+ ["description", this.yamlQuote(this.personaDescription(role))],
36
+ ])}\n${this.personaBody(role)}\n`,
37
+ scope: "project",
38
+ }));
39
+ }
29
40
  rulesFiles(_ctx) {
30
41
  const region = buildPointerRegion("The `/amby.*` prompts under `.github/prompts/` drive the phases.");
31
42
  const contents = `# GitHub Copilot instructions\n\n${region}`;
@@ -1 +1 @@
1
- {"version":3,"file":"copilot.js","sourceRoot":"","sources":["../../src/emitters/copilot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAEvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAA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C,CAAC,CAAC;IACN,CAAC;IAEkB,UAAU,CAAC,IAAkB;QAC9C,MAAM,MAAM,GAAG,kBAAkB,CAAC,kEAAkE,CAAC,CAAC;QACtG,MAAM,QAAQ,GAAG,oCAAoC,MAAM,EAAE,CAAC;QAC9D,OAAO;YACL,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,EAAE,yBAAyB,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE;SAClG,CAAC;IACJ,CAAC;CACF"}
@@ -1,4 +1,4 @@
1
- import type { CommandSpec, CommandSurface } from "../core/types.js";
1
+ import type { CommandSpec, CommandSurface, EmittedFile, Role, RulesContext } from "../core/types.js";
2
2
  import { BaseEmitter } from "./base-emitter.js";
3
3
  /**
4
4
  * OpenCode emitter. Commands go to `.opencode/commands/*.md` (plural dir; invoked as `/amby.*`).
@@ -11,4 +11,6 @@ export declare class OpenCodeEmitter extends BaseEmitter {
11
11
  readonly commandSurface: CommandSurface;
12
12
  readonly commandDir: string;
13
13
  protected commandFrontmatter(spec: CommandSpec): Array<[string, string]>;
14
+ /** Agents at `.opencode/agents/<id>.md` — filename is the id; `description` required (verified, feature 013). */
15
+ protected roleFiles(roles: Role[], _ctx: RulesContext): EmittedFile[];
14
16
  }
@@ -13,5 +13,16 @@ export class OpenCodeEmitter extends BaseEmitter {
13
13
  commandFrontmatter(spec) {
14
14
  return [["description", this.yamlQuote(spec.description)]];
15
15
  }
16
+ /** Agents at `.opencode/agents/<id>.md` — filename is the id; `description` required (verified, feature 013). */
17
+ roleFiles(roles, _ctx) {
18
+ return roles.map((role) => ({
19
+ path: join(".opencode", "agents", `${this.personaName(role)}.md`),
20
+ contents: `${this.renderFrontmatter([
21
+ ["description", this.yamlQuote(this.personaDescription(role))],
22
+ ["mode", "subagent"],
23
+ ])}\n${this.personaBody(role)}\n`,
24
+ scope: "project",
25
+ }));
26
+ }
16
27
  }
17
28
  //# sourceMappingURL=opencode.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"opencode.js","sourceRoot":"","sources":["../../src/emitters/opencode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAEvC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD;;;;GAIG;AACH,MAAM,OAAO,eAAgB,SAAQ,WAAW;IACrC,MAAM,GAAG,UAAU,CAAC;IACpB,WAAW,GAAG,UAAU,CAAC;IACzB,cAAc,GAAmB,UAAU,CAAC;IAC5C,UAAU,GAAG,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;IAEjC,kBAAkB,CAAC,IAAiB;QACrD,OAAO,CAAC,CAAC,aAAa,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAC7D,CAAC;CACF"}
1
+ {"version":3,"file":"opencode.js","sourceRoot":"","sources":["../../src/emitters/opencode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAEvC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD;;;;GAIG;AACH,MAAM,OAAO,eAAgB,SAAQ,WAAW;IACrC,MAAM,GAAG,UAAU,CAAC;IACpB,WAAW,GAAG,UAAU,CAAC;IACzB,cAAc,GAAmB,UAAU,CAAC;IAC5C,UAAU,GAAG,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;IAEjC,kBAAkB,CAAC,IAAiB;QACrD,OAAO,CAAC,CAAC,aAAa,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAC7D,CAAC;IAED,iHAAiH;IAC9F,SAAS,CAAC,KAAa,EAAE,IAAkB;QAC5D,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YAC1B,IAAI,EAAE,IAAI,CAAC,WAAW,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC;YACjE,QAAQ,EACN,GAAG,IAAI,CAAC,iBAAiB,CAAC;gBACxB,CAAC,aAAa,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC;gBAC9D,CAAC,MAAM,EAAE,UAAU,CAAC;aACrB,CAAC,KAAK,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI;YACnC,KAAK,EAAE,SAAS;SACjB,CAAC,CAAC,CAAC;IACN,CAAC;CACF"}
@@ -0,0 +1,93 @@
1
+ # Architecture
2
+
3
+ AmbyKit is a Node/TypeScript CLI (`@ambystech/ambykit`) built on two ideas: **author once, emit per
4
+ tool**, and **token frugality**.
5
+
6
+ ## Author once, emit per tool
7
+
8
+ There is one neutral source of truth. Emitters compile it into each assistant's native format.
9
+
10
+ ```
11
+ src/templates/ ── artifact templates (constitution, spec, ui, design-tokens, plan, tasks)
12
+ src/prompts/ ── neutral phase CommandSpecs (constitution → implement)
13
+ │
14
+ ▼ ambykit init / add / sync
15
+ ┌────────────┐
16
+ │ Emitters │ BaseEmitter + per-tool subclasses
17
+ └────────────┘
18
+ │
19
+ ├── .claude/commands/amby/*.md (ClaudeEmitter)
20
+ ├── .github/prompts/*.prompt.md (CopilotEmitter)
21
+ ├── .github/skills/amby-*/SKILL.md (CopilotCliEmitter)
22
+ ├── .opencode/commands/*.md (OpenCodeEmitter)
23
+ ├── .cursor/commands/*.md + rules (CursorEmitter / CursorCliEmitter)
24
+ ├── .agents/workflows/*.md (AntigravityEmitter / AntigravityCliEmitter)
25
+ └── AGENTS.md (+ CLAUDE.md bridge) (shared rules layer)
26
+ ```
27
+
28
+ On `init`, the neutral source is also copied into the consumer's `.amby/` so their project owns its
29
+ templates and can customize them.
30
+
31
+ ## `BaseEmitter`
32
+
33
+ An abstract class holding all shared state and behavior; each tool is a thin subclass.
34
+
35
+ - **Properties:** `toolId`, `displayName`, `commandDir`, `rulesFile`, `commandSurface`
36
+ (`'commands' | 'skills' | 'workflows' | 'none'`), `supportsAgents`, `mcpConfigPath`,
37
+ `mcpConfigScope` (`'project' | 'user'`), `mcpTopLevelKey`.
38
+ - **Template method** `emit(specs, ctx): EmittedFile[]` — orchestrates: resolve target dir → render
39
+ rules file → render each phase prompt **via `commandSurface`** → render MCP config → collect files.
40
+ Subclasses don't re-implement orchestration.
41
+ - **Overridable hooks:** `commandFrontmatter(spec)`, `commandPath(spec)`, `rulesContent(ctx)`,
42
+ `mcpConfig(servers)`. Defaults live in the base; a subclass overrides only its differences.
43
+ - **Reuse subclasses:** `CursorCliEmitter` (`commandSurface: 'none'`) and `AntigravityCliEmitter`
44
+ reuse a sibling's output; VS Code extension targets resolve to their base tool's emitter unchanged
45
+ via the **target→emitter map** in the registry.
46
+
47
+ Adding a tool = one subclass + a compatibility-matrix row + a snapshot test.
48
+
49
+ ## `BaseCommand`
50
+
51
+ The CLI verbs mirror the same pattern. An abstract `BaseCommand` holds project/`.amby/` discovery,
52
+ config load/save, emitter resolution, tool detection, logging, error handling, and `--dry-run`/
53
+ `--yes`. Its template method `run()` validates context then calls each subclass's `execute()`.
54
+ Subclasses: `InitCommand`, `AddCommand`, `SyncCommand`, `CheckCommand`, `RestoreCommand`,
55
+ `UpgradeCommand`, `DashboardCommand`.
56
+
57
+ ## Non-destructive rules merge (brownfield)
58
+
59
+ Generated **command** files are AmbyKit's alone and are overwritten. **Rules files** (`AGENTS.md`,
60
+ the `CLAUDE.md` bridge, `copilot-instructions.md`, Cursor's `.mdc`) are different: a user may have
61
+ authored them. Each such `EmittedFile` is tagged `merge: "region"`, and the writer (`applyFiles`)
62
+ reconciles it through a pure core (`src/core/merge.ts`) instead of overwriting:
63
+
64
+ - The AmbyKit-owned span is a Markdown section that opens with `### AmbyKit usage` and ends at the
65
+ next same-or-higher heading (or EOF). On a fresh file the whole emitted file is written; on an
66
+ existing file only that region is spliced in, preserving every other byte.
67
+ - A short **fingerprint** is embedded in the region footer. On re-run, a region whose body no longer
68
+ matches its fingerprint was hand-edited, so it is left untouched and reported as *skipped*.
69
+ - Before modifying an existing file, the writer copies it to `.amby/backups/<name>.<ts>.bak`
70
+ (`ambykit restore` reverses this). Backups are outside the emitted set, so `check` stays green.
71
+ - `classifyProject` (`src/core/classify.ts`) labels a project greenfield/brownfield from three
72
+ signals — an existing rules file, non-AmbyKit source files, or a git history — defaulting to the
73
+ safe (non-destructive) path when uncertain.
74
+
75
+ ## Token efficiency
76
+
77
+ Spec generation must be cheap. This is designed into the prompts and templates:
78
+
79
+ - **Progressive disclosure** — each phase loads only the artifact it needs via `@path`
80
+ (specify→constitution, plan→spec, tasks→plan, implement→one task slice). Reference material (EARS
81
+ guide, examples) lives in separate on-demand files, not inlined in every prompt.
82
+ - **Reference by stable ID** — downstream artifacts cite `US-#`/`FR-###`/`SC-###` instead of copying
83
+ text.
84
+ - **Patch, don't regenerate** — `clarify` edits only clarification markers; `implement` flips
85
+ checkboxes and updates `status:` in place.
86
+ - **Structured over prose for machine reads** — `dashboard` and `analyze` parse frontmatter and
87
+ checkboxes locally in the CLI at **zero model tokens**; only generative phases call the model.
88
+
89
+ ## Self-hosting
90
+
91
+ AmbyKit is built with AmbyKit. The repo's own `.claude/` (and other tool files) are generated by
92
+ `ambykit sync` from `src/prompts/`; CI asserts `sync` produces no diff so the repo stays a faithful
93
+ consumer of itself. See [contributing](./contributing.md).
@@ -0,0 +1,31 @@
1
+ # Artifact: `plan.md`
2
+
3
+ The plan defines **HOW** the feature is built. It is the first artifact where technology appears.
4
+ Produced by `/amby.plan` from the approved spec and UI design; must stay consistent with the
5
+ [constitution](../concepts/constitution.md).
6
+
7
+ ## Sections
8
+
9
+ 1. **Technical context** — chosen stack, key libraries, and the constraints that drove them.
10
+ 2. **Architecture** — components, boundaries, and how they interact (diagrams welcome).
11
+ 3. **Phased approach** — Phase 0 research → Phase 1 foundation (data model, contracts) → later phases.
12
+ 4. **Requirement mapping** — how the design satisfies each `FR-###`/`US-#` (reference by ID, don't
13
+ restate).
14
+ 5. **Risks & decisions** — trade-offs made and why.
15
+
16
+ ## Supporting artifacts (generated as needed)
17
+
18
+ - **`data-model.md`** — entities, fields, relationships, invariants.
19
+ - **`contracts/`** — API/interface specs (`openapi.yaml`, `events.md`, etc.).
20
+ - **`research.md`** — technology evaluations and decisions with rationale.
21
+
22
+ ## Consistency
23
+
24
+ `/amby.analyze` cross-checks the plan against the spec: every `FR-###` should be addressed, and the
25
+ plan should not introduce requirements that aren't in the spec (scope creep). Because the plan
26
+ references spec IDs rather than copying text, changes to the spec are easy to trace forward.
27
+
28
+ ## Token efficiency
29
+
30
+ The plan links to the spec and UI artifacts by `@path` and cites IDs; it does not duplicate their
31
+ content. This keeps the plan small and the downstream `tasks`/`implement` phases cheap to run.