@ambystech/ambykit 0.2.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -1
- package/dist/cli/add.js +3 -3
- package/dist/cli/add.js.map +1 -1
- package/dist/cli/base-command.d.ts +15 -1
- package/dist/cli/base-command.js +44 -1
- package/dist/cli/base-command.js.map +1 -1
- package/dist/cli/check.d.ts +2 -0
- package/dist/cli/check.js +41 -2
- package/dist/cli/check.js.map +1 -1
- package/dist/cli/dashboard.js +1 -1
- package/dist/cli/dashboard.js.map +1 -1
- package/dist/cli/index.js +45 -15
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/init.d.ts +2 -0
- package/dist/cli/init.js +36 -8
- package/dist/cli/init.js.map +1 -1
- package/dist/cli/io/fsops.d.ts +42 -0
- package/dist/cli/io/fsops.js +174 -0
- package/dist/cli/io/fsops.js.map +1 -0
- package/dist/cli/io/version-check.d.ts +18 -0
- package/dist/cli/io/version-check.js +73 -0
- package/dist/cli/io/version-check.js.map +1 -0
- package/dist/cli/restore.d.ts +12 -0
- package/dist/cli/restore.js +51 -0
- package/dist/cli/restore.js.map +1 -0
- package/dist/cli/sync.js +12 -2
- package/dist/cli/sync.js.map +1 -1
- package/dist/cli/{banner.d.ts → ui/banner.d.ts} +1 -1
- package/dist/cli/{banner.js → ui/banner.js} +2 -2
- package/dist/cli/ui/banner.js.map +1 -0
- package/dist/cli/ui/callout.d.ts +15 -0
- package/dist/cli/ui/callout.js +47 -0
- package/dist/cli/ui/callout.js.map +1 -0
- package/dist/cli/ui/interactive/prompt.d.ts +11 -0
- package/dist/cli/ui/interactive/prompt.js +37 -0
- package/dist/cli/ui/interactive/prompt.js.map +1 -1
- package/dist/cli/ui/theme.d.ts +10 -0
- package/dist/cli/ui/theme.js +17 -0
- package/dist/cli/ui/theme.js.map +1 -1
- package/dist/cli/{tool-options.d.ts → ui/tool-options.d.ts} +1 -1
- package/dist/cli/{tool-options.js → ui/tool-options.js} +1 -1
- package/dist/cli/ui/tool-options.js.map +1 -0
- package/dist/cli/update.d.ts +26 -0
- package/dist/cli/update.js +78 -0
- package/dist/cli/update.js.map +1 -0
- package/dist/cli/worktree.d.ts +18 -0
- package/dist/cli/worktree.js +161 -0
- package/dist/cli/worktree.js.map +1 -0
- package/dist/core/classify.d.ts +4 -0
- package/dist/core/classify.js +86 -0
- package/dist/core/classify.js.map +1 -0
- package/dist/core/command-spec.js +2 -0
- package/dist/core/command-spec.js.map +1 -1
- package/dist/core/config.js +1 -0
- package/dist/core/config.js.map +1 -1
- package/dist/{cli → core}/emit.d.ts +1 -1
- package/dist/{cli → core}/emit.js +10 -4
- package/dist/core/emit.js.map +1 -0
- package/dist/core/git.d.ts +33 -0
- package/dist/core/git.js +104 -0
- package/dist/core/git.js.map +1 -0
- package/dist/core/index.d.ts +3 -0
- package/dist/core/index.js +3 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/merge.d.ts +37 -0
- package/dist/core/merge.js +146 -0
- package/dist/core/merge.js.map +1 -0
- package/dist/core/paths.d.ts +7 -0
- package/dist/core/paths.js +11 -0
- package/dist/core/paths.js.map +1 -1
- package/dist/core/roles.d.ts +19 -0
- package/dist/core/roles.js +59 -0
- package/dist/core/roles.js.map +1 -0
- package/dist/core/rules.d.ts +14 -0
- package/dist/core/rules.js +37 -8
- package/dist/core/rules.js.map +1 -1
- package/dist/core/scaffold.d.ts +2 -0
- package/dist/core/scaffold.js +6 -1
- package/dist/core/scaffold.js.map +1 -1
- package/dist/core/types.d.ts +64 -1
- package/dist/core/version.d.ts +10 -0
- package/dist/core/version.js +33 -0
- package/dist/core/version.js.map +1 -0
- package/dist/core/worktree.d.ts +78 -0
- package/dist/core/worktree.js +121 -0
- package/dist/core/worktree.js.map +1 -0
- package/dist/emitters/base-emitter.d.ts +19 -2
- package/dist/emitters/base-emitter.js +43 -3
- package/dist/emitters/base-emitter.js.map +1 -1
- package/dist/emitters/claude.d.ts +3 -1
- package/dist/emitters/claude.js +19 -12
- package/dist/emitters/claude.js.map +1 -1
- package/dist/emitters/copilot.d.ts +3 -1
- package/dist/emitters/copilot.js +17 -8
- package/dist/emitters/copilot.js.map +1 -1
- package/dist/emitters/cursor.js +6 -5
- package/dist/emitters/cursor.js.map +1 -1
- package/dist/emitters/opencode.d.ts +3 -1
- package/dist/emitters/opencode.js +11 -0
- package/dist/emitters/opencode.js.map +1 -1
- package/package.json +4 -3
- package/src/prompts/analyze.md +1 -0
- package/src/prompts/clarify.md +1 -0
- package/src/prompts/converge.md +27 -0
- package/src/prompts/design.md +1 -0
- package/src/prompts/implement.md +1 -0
- package/src/prompts/plan.md +1 -0
- package/src/prompts/review.md +24 -0
- package/src/prompts/revise.md +36 -0
- package/src/prompts/specify.md +6 -2
- package/src/prompts/tasks.md +1 -0
- package/dist/cli/banner.js.map +0 -1
- package/dist/cli/emit.js.map +0 -1
- package/dist/cli/fsops.d.ts +0 -21
- package/dist/cli/fsops.js +0 -65
- package/dist/cli/fsops.js.map +0 -1
- package/dist/cli/tool-options.js.map +0 -1
- package/dist/cli/upgrade.d.ts +0 -7
- package/dist/cli/upgrade.js +0 -27
- package/dist/cli/upgrade.js.map +0 -1
package/dist/core/git.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
/** Run git in `cwd` and return trimmed stdout. Throws with stderr on non-zero exit. */
|
|
3
|
+
export function git(cwd, args) {
|
|
4
|
+
try {
|
|
5
|
+
return execFileSync("git", args, { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }).trim();
|
|
6
|
+
}
|
|
7
|
+
catch (err) {
|
|
8
|
+
const e = err;
|
|
9
|
+
throw new Error((e.stderr ?? e.message).trim());
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
/** Whether `git` is available on PATH. */
|
|
13
|
+
export function gitAvailable() {
|
|
14
|
+
try {
|
|
15
|
+
execFileSync("git", ["--version"], { stdio: "ignore" });
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/** Whether `dir` is inside a git working tree. */
|
|
23
|
+
export function isRepo(dir) {
|
|
24
|
+
try {
|
|
25
|
+
return git(dir, ["rev-parse", "--is-inside-work-tree"]) === "true";
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export function branchExists(cwd, branch) {
|
|
32
|
+
try {
|
|
33
|
+
git(cwd, ["rev-parse", "--verify", "--quiet", `refs/heads/${branch}`]);
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** Current branch name, or null when detached. */
|
|
41
|
+
export function currentBranch(cwd) {
|
|
42
|
+
try {
|
|
43
|
+
const name = git(cwd, ["symbolic-ref", "--short", "-q", "HEAD"]);
|
|
44
|
+
return name || null;
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The repository's default branch (FR-003): what the remote advertises as HEAD, else the first of
|
|
52
|
+
* `main`/`master` that exists locally, else null.
|
|
53
|
+
*/
|
|
54
|
+
export function defaultBranch(cwd) {
|
|
55
|
+
try {
|
|
56
|
+
const ref = git(cwd, ["symbolic-ref", "--short", "-q", "refs/remotes/origin/HEAD"]);
|
|
57
|
+
if (ref)
|
|
58
|
+
return ref.replace(/^origin\//, "");
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
/* no remote HEAD */
|
|
62
|
+
}
|
|
63
|
+
for (const b of ["main", "master"])
|
|
64
|
+
if (branchExists(cwd, b))
|
|
65
|
+
return b;
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
/** Parse `git worktree list --porcelain` output. Exported for unit tests. */
|
|
69
|
+
export function parseWorktreeList(porcelain) {
|
|
70
|
+
const out = [];
|
|
71
|
+
let cur = null;
|
|
72
|
+
for (const line of porcelain.split(/\r?\n/)) {
|
|
73
|
+
if (line.startsWith("worktree ")) {
|
|
74
|
+
if (cur?.path)
|
|
75
|
+
out.push({ path: cur.path, branch: cur.branch ?? null, head: cur.head ?? "" });
|
|
76
|
+
cur = { path: line.slice("worktree ".length) };
|
|
77
|
+
}
|
|
78
|
+
else if (cur && line.startsWith("HEAD "))
|
|
79
|
+
cur.head = line.slice(5);
|
|
80
|
+
else if (cur && line.startsWith("branch "))
|
|
81
|
+
cur.branch = line.slice(7).replace(/^refs\/heads\//, "");
|
|
82
|
+
}
|
|
83
|
+
if (cur?.path)
|
|
84
|
+
out.push({ path: cur.path, branch: cur.branch ?? null, head: cur.head ?? "" });
|
|
85
|
+
return out;
|
|
86
|
+
}
|
|
87
|
+
export function worktreeList(cwd) {
|
|
88
|
+
return parseWorktreeList(git(cwd, ["worktree", "list", "--porcelain"]));
|
|
89
|
+
}
|
|
90
|
+
/** Uncommitted changes (staged, unstaged, or untracked) in `dir`. */
|
|
91
|
+
export function isDirty(dir) {
|
|
92
|
+
return git(dir, ["status", "--porcelain"]).length > 0;
|
|
93
|
+
}
|
|
94
|
+
/** Whether `branch` is an ancestor of `base` (i.e. fully merged). */
|
|
95
|
+
export function isMerged(cwd, branch, base) {
|
|
96
|
+
try {
|
|
97
|
+
git(cwd, ["merge-base", "--is-ancestor", branch, base]);
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=git.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"git.js","sourceRoot":"","sources":["../../src/core/git.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAgBlD,uFAAuF;AACvF,MAAM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AC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
package/dist/core/index.d.ts
CHANGED
package/dist/core/index.js
CHANGED
package/dist/core/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { MergePlan, RulesRegion } from "./types.js";
|
|
2
|
+
/** Options for a region merge. */
|
|
3
|
+
export interface MergeOptions {
|
|
4
|
+
/** A line that must be the file's first line even on merge, e.g. Claude's `@AGENTS.md` bridge. */
|
|
5
|
+
requiredPrefix?: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Non-destructive region merge for brownfield rules files (feature 008).
|
|
9
|
+
*
|
|
10
|
+
* The AmbyKit-owned region is a Markdown section that opens with `### AmbyKit usage` and runs until
|
|
11
|
+
* the next heading of the same or higher level (`#`, `##`, `###`) or end-of-file (FR-003). A short
|
|
12
|
+
* fingerprint of the region's own body is embedded in a footer comment so a later run can tell
|
|
13
|
+
* whether a human edited the region since AmbyKit wrote it (FR-008a).
|
|
14
|
+
*
|
|
15
|
+
* Pure — no file-system or process access (side effects stay at the CLI edge, per the constitution).
|
|
16
|
+
*/
|
|
17
|
+
/** Heading line that opens the AmbyKit-owned region. */
|
|
18
|
+
export declare const REGION_HEADING = "### AmbyKit usage";
|
|
19
|
+
/** Short, non-cryptographic-strength content fingerprint (collision risk is immaterial here). */
|
|
20
|
+
export declare function fingerprint(regionCore: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Build a complete AmbyKit region from its core content (which must start with `REGION_HEADING`),
|
|
23
|
+
* appending the fingerprint footer. The returned block ends with a single trailing newline.
|
|
24
|
+
*/
|
|
25
|
+
export declare function buildRegion(core: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* Locate the single AmbyKit region in `text`. Returns null when absent. Throws when more than one
|
|
28
|
+
* `### AmbyKit usage` heading is present (malformed — the caller aborts that file, FR-007).
|
|
29
|
+
*/
|
|
30
|
+
export declare function findRegion(text: string): RulesRegion | null;
|
|
31
|
+
/**
|
|
32
|
+
* Plan a merge of `emitted` — a full greenfield rules file that contains exactly one AmbyKit region —
|
|
33
|
+
* into `existing` (null when the target file does not exist). On create, `emitted` is written whole
|
|
34
|
+
* (FR-002); on merge, only its `### AmbyKit usage` region is spliced into `existing`, preserving every
|
|
35
|
+
* other byte (FR-001). Pure — returns a plan; the caller performs any I/O.
|
|
36
|
+
*/
|
|
37
|
+
export declare function mergeRegion(existing: string | null, emitted: string, opts?: MergeOptions): MergePlan;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
/**
|
|
3
|
+
* Non-destructive region merge for brownfield rules files (feature 008).
|
|
4
|
+
*
|
|
5
|
+
* The AmbyKit-owned region is a Markdown section that opens with `### AmbyKit usage` and runs until
|
|
6
|
+
* the next heading of the same or higher level (`#`, `##`, `###`) or end-of-file (FR-003). A short
|
|
7
|
+
* fingerprint of the region's own body is embedded in a footer comment so a later run can tell
|
|
8
|
+
* whether a human edited the region since AmbyKit wrote it (FR-008a).
|
|
9
|
+
*
|
|
10
|
+
* Pure — no file-system or process access (side effects stay at the CLI edge, per the constitution).
|
|
11
|
+
*/
|
|
12
|
+
/** Heading line that opens the AmbyKit-owned region. */
|
|
13
|
+
export const REGION_HEADING = "### AmbyKit usage";
|
|
14
|
+
const FINGERPRINT_RE = /^<!--\s*ambykit:fingerprint\s+(\S+)\s*-->\s*$/;
|
|
15
|
+
const HEADING_RE = /^#{1,3}\s/;
|
|
16
|
+
/** Normalize to LF line endings. */
|
|
17
|
+
function toLf(text) {
|
|
18
|
+
return text.replace(/\r\n/g, "\n");
|
|
19
|
+
}
|
|
20
|
+
/** Canonical form used for hashing/comparison: LF endings, no trailing whitespace. */
|
|
21
|
+
function canonical(text) {
|
|
22
|
+
return toLf(text).replace(/\s+$/, "");
|
|
23
|
+
}
|
|
24
|
+
/** Short, non-cryptographic-strength content fingerprint (collision risk is immaterial here). */
|
|
25
|
+
export function fingerprint(regionCore) {
|
|
26
|
+
return createHash("sha256").update(canonical(regionCore)).digest("hex").slice(0, 12);
|
|
27
|
+
}
|
|
28
|
+
/** Split a region body into its content core (heading + body, no footer) and its footer fingerprint. */
|
|
29
|
+
function splitFingerprint(body) {
|
|
30
|
+
const lines = toLf(body).split("\n");
|
|
31
|
+
// Find the last non-empty line; if it is a fingerprint footer, peel it off.
|
|
32
|
+
let last = lines.length - 1;
|
|
33
|
+
while (last >= 0 && lines[last].trim() === "")
|
|
34
|
+
last--;
|
|
35
|
+
if (last >= 0) {
|
|
36
|
+
const m = FINGERPRINT_RE.exec(lines[last]);
|
|
37
|
+
if (m) {
|
|
38
|
+
return { core: canonical(lines.slice(0, last).join("\n")), fingerprint: m[1] };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return { core: canonical(body), fingerprint: null };
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Build a complete AmbyKit region from its core content (which must start with `REGION_HEADING`),
|
|
45
|
+
* appending the fingerprint footer. The returned block ends with a single trailing newline.
|
|
46
|
+
*/
|
|
47
|
+
export function buildRegion(core) {
|
|
48
|
+
const body = canonical(core);
|
|
49
|
+
return `${body}\n\n<!-- ambykit:fingerprint ${fingerprint(body)} -->\n`;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Locate the single AmbyKit region in `text`. Returns null when absent. Throws when more than one
|
|
53
|
+
* `### AmbyKit usage` heading is present (malformed — the caller aborts that file, FR-007).
|
|
54
|
+
*/
|
|
55
|
+
export function findRegion(text) {
|
|
56
|
+
const lines = toLf(text).split("\n");
|
|
57
|
+
const starts = lines.flatMap((l, i) => (l.trimEnd() === REGION_HEADING ? [i] : []));
|
|
58
|
+
if (starts.length === 0)
|
|
59
|
+
return null;
|
|
60
|
+
if (starts.length > 1) {
|
|
61
|
+
throw new Error(`found ${starts.length} "${REGION_HEADING}" regions; expected at most one`);
|
|
62
|
+
}
|
|
63
|
+
const startLine = starts[0];
|
|
64
|
+
let endLine = lines.length;
|
|
65
|
+
for (let i = startLine + 1; i < lines.length; i++) {
|
|
66
|
+
if (HEADING_RE.test(lines[i])) {
|
|
67
|
+
endLine = i;
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const body = lines.slice(startLine, endLine).join("\n");
|
|
72
|
+
return { startLine, endLine, body, fingerprint: splitFingerprint(body).fingerprint };
|
|
73
|
+
}
|
|
74
|
+
/** Ensure exactly one trailing newline. */
|
|
75
|
+
function withTrailingNewline(text) {
|
|
76
|
+
return `${text.replace(/\n+$/, "")}\n`;
|
|
77
|
+
}
|
|
78
|
+
/** Ensure `prefix` is the first line of `text`, inserting it (plus a blank line) if missing (FR-011). */
|
|
79
|
+
function ensurePrefix(text, prefix) {
|
|
80
|
+
if (!prefix)
|
|
81
|
+
return text;
|
|
82
|
+
const lines = toLf(text).split("\n");
|
|
83
|
+
if (lines[0].trim() === prefix.trim())
|
|
84
|
+
return text;
|
|
85
|
+
return `${prefix}\n\n${text.replace(/^\n+/, "")}`;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Plan a merge of `emitted` — a full greenfield rules file that contains exactly one AmbyKit region —
|
|
89
|
+
* into `existing` (null when the target file does not exist). On create, `emitted` is written whole
|
|
90
|
+
* (FR-002); on merge, only its `### AmbyKit usage` region is spliced into `existing`, preserving every
|
|
91
|
+
* other byte (FR-001). Pure — returns a plan; the caller performs any I/O.
|
|
92
|
+
*/
|
|
93
|
+
export function mergeRegion(existing, emitted, opts = {}) {
|
|
94
|
+
const { requiredPrefix } = opts;
|
|
95
|
+
// File absent → write the emitted greenfield file verbatim (FR-002).
|
|
96
|
+
if (existing === null) {
|
|
97
|
+
return { action: "created", contents: withTrailingNewline(toLf(emitted)) };
|
|
98
|
+
}
|
|
99
|
+
// Extract the fresh region from the emitted file (everything AmbyKit contributes on merge).
|
|
100
|
+
let fresh;
|
|
101
|
+
try {
|
|
102
|
+
fresh = findRegion(emitted);
|
|
103
|
+
}
|
|
104
|
+
catch (err) {
|
|
105
|
+
return { action: "aborted", reason: err.message };
|
|
106
|
+
}
|
|
107
|
+
if (fresh === null) {
|
|
108
|
+
return { action: "aborted", reason: `emitted content has no "${REGION_HEADING}" region` };
|
|
109
|
+
}
|
|
110
|
+
const freshRegion = canonical(fresh.body);
|
|
111
|
+
const existingLf = toLf(existing);
|
|
112
|
+
let found;
|
|
113
|
+
try {
|
|
114
|
+
found = findRegion(existingLf);
|
|
115
|
+
}
|
|
116
|
+
catch (err) {
|
|
117
|
+
return { action: "aborted", reason: err.message };
|
|
118
|
+
}
|
|
119
|
+
let mergedNoPrefix;
|
|
120
|
+
if (found === null) {
|
|
121
|
+
// No region yet: preserve every existing byte, append the region after a blank line (FR-001).
|
|
122
|
+
const base = existingLf.replace(/\n+$/, "");
|
|
123
|
+
mergedNoPrefix = base === "" ? freshRegion : `${base}\n\n${freshRegion}`;
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
// Region present: skip if a human edited it since AmbyKit last wrote it (FR-008a).
|
|
127
|
+
const { core, fingerprint: stored } = splitFingerprint(found.body);
|
|
128
|
+
if (stored !== null && fingerprint(core) !== stored) {
|
|
129
|
+
return { action: "skipped", reason: "AmbyKit region was hand-edited" };
|
|
130
|
+
}
|
|
131
|
+
// Splice the fresh region in place; never create a second region (FR-004).
|
|
132
|
+
const lines = existingLf.split("\n");
|
|
133
|
+
const regionLines = freshRegion.split("\n");
|
|
134
|
+
const after = lines.slice(found.endLine);
|
|
135
|
+
// Keep a blank line between the region and a following heading, for readability + stable re-runs.
|
|
136
|
+
const separator = after.length > 0 && HEADING_RE.test(after[0]) ? [""] : [];
|
|
137
|
+
const newLines = [...lines.slice(0, found.startLine), ...regionLines, ...separator, ...after];
|
|
138
|
+
mergedNoPrefix = newLines.join("\n");
|
|
139
|
+
}
|
|
140
|
+
const merged = withTrailingNewline(ensurePrefix(mergedNoPrefix, requiredPrefix));
|
|
141
|
+
if (merged === withTrailingNewline(existingLf)) {
|
|
142
|
+
return { action: "unchanged" };
|
|
143
|
+
}
|
|
144
|
+
return { action: "updated", contents: merged };
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=merge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge.js","sourceRoot":"","sources":["../../src/core/merge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AASzC;;;;;;;;;GASG;AAEH,wDAAwD;AACxD,MAAM,CAAC,MAAM,cAAc,GAAG,mBAAmB,CAAC;AAElD,MAAM,cAAc,GAAG,+CAA+C,CAAC;AACvE,MAAM,UAAU,GAAG,WAAW,CAAC;AAE/B,oCAAoC;AACpC,SAAS,IAAI,CAAC,IAAY;IACxB,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AACrC,CAAC;AAED,sFAAsF;AACtF,SAAS,SAA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GAAG,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAE,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7E,MAAM,QAAQ,GAAG,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,EAAE,GAAG,WAAW,EAAE,GAAG,SAAS,EAAE,GAAG,KAAK,CAAC,CAAC;QAC9F,cAAc,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC;IAED,MAAM,MAAM,GAAG,mBAAmB,CAAC,YAAY,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC,CAAC;IACjF,IAAI,MAAM,KAAK,mBAAmB,CAAC,UAAU,CAAC,EAAE,CAAC;QAC/C,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC;IACjC,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;AACjD,CAAC"}
|
package/dist/core/paths.d.ts
CHANGED
|
@@ -9,7 +9,14 @@ export declare function packageVersion(): string;
|
|
|
9
9
|
export declare function promptsDir(): string;
|
|
10
10
|
/** Directory containing the neutral artifact templates. */
|
|
11
11
|
export declare function templatesDir(): string;
|
|
12
|
+
/** Directory containing the shipped default role definitions (feature 013). */
|
|
13
|
+
export declare function rolesDir(): string;
|
|
12
14
|
/** Directory containing on-demand reference docs (loaded by phases when needed). */
|
|
13
15
|
export declare function referenceDir(): string;
|
|
16
|
+
/**
|
|
17
|
+
* Whether `cwd` is itself an AmbyKit project root: a `.amby/` AND a `specs/` directory directly at the
|
|
18
|
+
* invocation dir (feature 010 / FR-007). Deliberately NOT a walk-up like `findProjectRoot`.
|
|
19
|
+
*/
|
|
20
|
+
export declare function projectAtCwd(cwd: string): boolean;
|
|
14
21
|
/** Find the project root by walking up from `start` looking for an `.amby` dir. */
|
|
15
22
|
export declare function findProjectRoot(start?: string): string | null;
|
package/dist/core/paths.js
CHANGED
|
@@ -36,10 +36,21 @@ export function promptsDir() {
|
|
|
36
36
|
export function templatesDir() {
|
|
37
37
|
return join(packageRoot(), "src", "templates");
|
|
38
38
|
}
|
|
39
|
+
/** Directory containing the shipped default role definitions (feature 013). */
|
|
40
|
+
export function rolesDir() {
|
|
41
|
+
return join(packageRoot(), "src", "roles");
|
|
42
|
+
}
|
|
39
43
|
/** Directory containing on-demand reference docs (loaded by phases when needed). */
|
|
40
44
|
export function referenceDir() {
|
|
41
45
|
return join(packageRoot(), "src", "reference");
|
|
42
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Whether `cwd` is itself an AmbyKit project root: a `.amby/` AND a `specs/` directory directly at the
|
|
49
|
+
* invocation dir (feature 010 / FR-007). Deliberately NOT a walk-up like `findProjectRoot`.
|
|
50
|
+
*/
|
|
51
|
+
export function projectAtCwd(cwd) {
|
|
52
|
+
return existsSync(join(cwd, ".amby")) && existsSync(join(cwd, "specs"));
|
|
53
|
+
}
|
|
43
54
|
/** Find the project root by walking up from `start` looking for an `.amby` dir. */
|
|
44
55
|
export function findProjectRoot(start = process.cwd()) {
|
|
45
56
|
let dir = resolve(start);
|
package/dist/core/paths.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../../src/core/paths.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEnD;;;GAGG;AACH,MAAM,UAAU,WAAW;IACzB,wEAAwE;IACxE,MAAM,IAAI,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IACrD,sDAAsD;I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|
|
2
|
+
/** Project-relative directory holding role definitions (feature 013, FR-001). */
|
|
3
|
+
export declare const ROLES_DIR = ".amby/roles";
|
|
4
|
+
/** Word budget per role body; exceeding it warns at sync, never refuses (FR-010). */
|
|
5
|
+
export declare const ROLE_WORD_LIMIT = 150;
|
|
6
|
+
export declare function wordCount(text: string): number;
|
|
7
|
+
/** Parse one role file. Throws with the file name on invalid frontmatter. */
|
|
8
|
+
export declare function parseRole(raw: string, sourceName: string): Role;
|
|
9
|
+
/** Load every `*.md` under `<root>/.amby/roles/`, sorted by id. Empty when the dir is absent (FR-004). */
|
|
10
|
+
export declare function loadRoles(root: string): Role[];
|
|
11
|
+
export interface RoleValidation {
|
|
12
|
+
/** Blocking problems (duplicate ids, case-insensitively). */
|
|
13
|
+
errors: string[];
|
|
14
|
+
/** Advisory problems (over the word limit). */
|
|
15
|
+
warnings: string[];
|
|
16
|
+
}
|
|
17
|
+
export declare function validateRoles(roles: Role[]): RoleValidation;
|
|
18
|
+
/** The role a phase acts as, or undefined when the spec has none or roles are not installed. */
|
|
19
|
+
export declare function roleForSpec(roles: Role[], roleId: string | undefined): Role | undefined;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import matter from "gray-matter";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
/** Project-relative directory holding role definitions (feature 013, FR-001). */
|
|
6
|
+
export const ROLES_DIR = ".amby/roles";
|
|
7
|
+
/** Word budget per role body; exceeding it warns at sync, never refuses (FR-010). */
|
|
8
|
+
export const ROLE_WORD_LIMIT = 150;
|
|
9
|
+
const frontmatterSchema = z.object({
|
|
10
|
+
id: z.string().regex(/^[a-z][a-z0-9-]*$/, "kebab-case id"),
|
|
11
|
+
name: z.string().min(1),
|
|
12
|
+
phases: z.array(z.string()).default([]),
|
|
13
|
+
});
|
|
14
|
+
export function wordCount(text) {
|
|
15
|
+
return text.split(/\s+/).filter(Boolean).length;
|
|
16
|
+
}
|
|
17
|
+
/** Parse one role file. Throws with the file name on invalid frontmatter. */
|
|
18
|
+
export function parseRole(raw, sourceName) {
|
|
19
|
+
const parsed = matter(raw);
|
|
20
|
+
const fm = frontmatterSchema.safeParse(parsed.data);
|
|
21
|
+
if (!fm.success)
|
|
22
|
+
throw new Error(`Invalid role frontmatter in ${sourceName}: ${fm.error.message}`);
|
|
23
|
+
const body = parsed.content.trim();
|
|
24
|
+
return { id: fm.data.id, name: fm.data.name, phases: fm.data.phases, body, words: wordCount(body), source: sourceName };
|
|
25
|
+
}
|
|
26
|
+
/** Load every `*.md` under `<root>/.amby/roles/`, sorted by id. Empty when the dir is absent (FR-004). */
|
|
27
|
+
export function loadRoles(root) {
|
|
28
|
+
const dir = join(root, ROLES_DIR);
|
|
29
|
+
if (!existsSync(dir))
|
|
30
|
+
return [];
|
|
31
|
+
return readdirSync(dir)
|
|
32
|
+
.filter((f) => f.endsWith(".md"))
|
|
33
|
+
.map((f) => parseRole(readFileSync(join(dir, f), "utf8"), `${ROLES_DIR}/${f}`))
|
|
34
|
+
.sort((a, b) => a.id.localeCompare(b.id));
|
|
35
|
+
}
|
|
36
|
+
export function validateRoles(roles) {
|
|
37
|
+
const errors = [];
|
|
38
|
+
const warnings = [];
|
|
39
|
+
const seen = new Map();
|
|
40
|
+
for (const r of roles) {
|
|
41
|
+
const key = r.id.toLowerCase();
|
|
42
|
+
const prev = seen.get(key);
|
|
43
|
+
if (prev)
|
|
44
|
+
errors.push(`Duplicate role id '${r.id}' (${prev} and ${r.source}).`);
|
|
45
|
+
else
|
|
46
|
+
seen.set(key, r.source);
|
|
47
|
+
if (r.words > ROLE_WORD_LIMIT) {
|
|
48
|
+
warnings.push(`Role '${r.id}' is ${r.words} words (limit ${ROLE_WORD_LIMIT}) — phases load it every run.`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return { errors, warnings };
|
|
52
|
+
}
|
|
53
|
+
/** The role a phase acts as, or undefined when the spec has none or roles are not installed. */
|
|
54
|
+
export function roleForSpec(roles, roleId) {
|
|
55
|
+
if (!roleId || roles.length === 0)
|
|
56
|
+
return undefined;
|
|
57
|
+
return roles.find((r) => r.id === roleId);
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=roles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"roles.js","sourceRoot":"","sources":["../../src/core/roles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,iFAAiF;AACjF,MAAM,CAAC,MAAM,SAAS,GAAG,aAAa,CAAC;AAEvC,qFAAqF;AACrF,MAAM,CAAC,MAAM,eAAe,GAAG,GAAG,CAAC;AAEnC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACjC,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,mBAAmB,EAAE,eAAe,CAAC;IAC1D,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACvB,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC;CACxC,CAAC,CAAC;AAEH,MAAM,UAAU,SAAS,CAAC,IAAY;IACpC,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC;AAClD,CAAC;AAED,6EAA6E;AAC7E,MAAM,UAAU,SAAS,CAAC,GAAW,EAAE,UAAkB;IACvD,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;IAC3B,MAAM,EAAE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B,MAAM,QAAQ,GAAa,EAAE,CAAC;IAC9B,MAAM,IAAI,GAAG,IAAI,GAAG,EAAkB,CAAC;IACvC,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;QACtB,MAAM,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC,WAAW,EAAE,CAAC;QAC/B,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC3B,IAAI,IAAI;YAAE,MAAM,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC,EAAE,MAAM,IAAI,QAAQ,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC;;YAC3E,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC;QAC7B,IAAI,CAAC,CAAC,KAAK,GAAG,eAAe,EAAE,CAAC;YAC9B,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,KAAK,iBAAiB,eAAe,+BAA+B,CAAC,CAAC;QAC7G,CAAC;IACH,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;AAC9B,CAAC;AAED,gGAAgG;AAChG,MAAM,UAAU,WAAW,CAAC,KAAa,EAAE,MAA0B;IACnE,IAAI,CAAC,MAAM,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IACpD,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,MAAM,CAAC,CAAC;AAC5C,CAAC"}
|
package/dist/core/rules.d.ts
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
import type { CommandSpec } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Build the AmbyKit-owned **region** (feature 008): a `### AmbyKit usage` section carrying the
|
|
4
|
+
* workflow command list and agent rules, plus a fingerprint footer. Authored once here (Principle 1)
|
|
5
|
+
* and reused by every rules file — the shared AGENTS.md and each tool's rules file splice this same
|
|
6
|
+
* region into an existing document, preserving the user's own content around it (FR-001/003/006).
|
|
7
|
+
*/
|
|
8
|
+
export declare function buildAmbyRegion(specs: CommandSpec[]): string;
|
|
9
|
+
/**
|
|
10
|
+
* Build a short `### AmbyKit usage` **pointer** region for a per-tool rules file. Unlike the full
|
|
11
|
+
* region (which carries the workflow table), pointer regions defer to `AGENTS.md` and just note where
|
|
12
|
+
* the `/amby.*` commands live — `commandNote` supplies that tool-specific sentence.
|
|
13
|
+
*/
|
|
14
|
+
export declare function buildPointerRegion(commandNote: string): string;
|
|
2
15
|
/**
|
|
3
16
|
* Build the shared, tool-neutral AGENTS.md for a consumer project. Natively read by OpenCode,
|
|
4
17
|
* Copilot, Cursor, and Antigravity; Claude Code reads it via a CLAUDE.md `@AGENTS.md` bridge.
|
|
18
|
+
* The AmbyKit body is the region from `buildAmbyRegion`, under a project title.
|
|
5
19
|
*/
|
|
6
20
|
export declare function buildAgentsMd(projectName: string, specs: CommandSpec[]): string;
|
package/dist/core/rules.js
CHANGED
|
@@ -1,45 +1,74 @@
|
|
|
1
|
+
import { buildRegion, REGION_HEADING } from "./merge.js";
|
|
1
2
|
/**
|
|
2
|
-
* Build the
|
|
3
|
-
*
|
|
3
|
+
* Build the AmbyKit-owned **region** (feature 008): a `### AmbyKit usage` section carrying the
|
|
4
|
+
* workflow command list and agent rules, plus a fingerprint footer. Authored once here (Principle 1)
|
|
5
|
+
* and reused by every rules file — the shared AGENTS.md and each tool's rules file splice this same
|
|
6
|
+
* region into an existing document, preserving the user's own content around it (FR-001/003/006).
|
|
4
7
|
*/
|
|
5
|
-
export function
|
|
8
|
+
export function buildAmbyRegion(specs) {
|
|
6
9
|
const rows = specs
|
|
7
10
|
.slice()
|
|
8
11
|
.sort((a, b) => phaseOrder(a.phase) - phaseOrder(b.phase))
|
|
9
12
|
.map((s) => `| \`/${s.name}\` | ${s.description} |`)
|
|
10
13
|
.join("\n");
|
|
11
|
-
|
|
14
|
+
const core = `${REGION_HEADING}
|
|
12
15
|
|
|
13
16
|
This project uses **AmbyKit** for Spec-Driven Development. Build features by producing structured
|
|
14
17
|
artifacts before code: a constitution, specs (user stories + EARS requirements), UI design, a plan,
|
|
15
18
|
and an ordered task list.
|
|
16
19
|
|
|
17
|
-
|
|
20
|
+
**Workflow commands**
|
|
18
21
|
|
|
19
22
|
| Command | Purpose |
|
|
20
23
|
|---|---|
|
|
21
24
|
${rows}
|
|
22
25
|
|
|
23
|
-
|
|
26
|
+
**Rules for agents**
|
|
24
27
|
|
|
25
28
|
- Read \`.amby/constitution.md\` and honor its principles in every phase.
|
|
26
29
|
- Specs (\`specs/NNN-*/spec.md\`) capture WHAT/WHY with **no technology choices**; plans capture HOW.
|
|
27
30
|
- Requirements use EARS (WHEN/WHILE/IF…THE SYSTEM SHALL…) with Given/When/Then acceptance criteria.
|
|
28
31
|
- Reference artifacts by stable id (US-#, FR-###, SC-###); don't restate them. Patch in place.
|
|
29
32
|
- Task checkboxes in \`tasks.md\` are the source of truth for progress (\`ambykit dashboard\`).
|
|
33
|
+
- **Current feature** (when a phase gets no id): the enclosing \`.worktrees/NNN-slug/\` directory if
|
|
34
|
+
the project root is one; else the git branch, if it names a \`specs/\` dir; else the highest-numbered
|
|
35
|
+
\`specs/\` dir — say which you chose. \`ambykit worktree <id>\` gives a feature its own working copy.`;
|
|
36
|
+
return buildRegion(core);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Build a short `### AmbyKit usage` **pointer** region for a per-tool rules file. Unlike the full
|
|
40
|
+
* region (which carries the workflow table), pointer regions defer to `AGENTS.md` and just note where
|
|
41
|
+
* the `/amby.*` commands live — `commandNote` supplies that tool-specific sentence.
|
|
42
|
+
*/
|
|
43
|
+
export function buildPointerRegion(commandNote) {
|
|
44
|
+
const core = `${REGION_HEADING}
|
|
45
|
+
|
|
46
|
+
This project uses **AmbyKit** for Spec-Driven Development. Follow the workflow and rules in
|
|
47
|
+
\`AGENTS.md\`. ${commandNote}`;
|
|
48
|
+
return buildRegion(core);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Build the shared, tool-neutral AGENTS.md for a consumer project. Natively read by OpenCode,
|
|
52
|
+
* Copilot, Cursor, and Antigravity; Claude Code reads it via a CLAUDE.md `@AGENTS.md` bridge.
|
|
53
|
+
* The AmbyKit body is the region from `buildAmbyRegion`, under a project title.
|
|
54
|
+
*/
|
|
55
|
+
export function buildAgentsMd(projectName, specs) {
|
|
56
|
+
return `# AGENTS.md — ${projectName}
|
|
30
57
|
|
|
31
|
-
|
|
32
|
-
`;
|
|
58
|
+
${buildAmbyRegion(specs)}`;
|
|
33
59
|
}
|
|
34
60
|
const PHASE_SEQUENCE = [
|
|
35
61
|
"constitution",
|
|
36
62
|
"specify",
|
|
37
63
|
"clarify",
|
|
64
|
+
"revise",
|
|
38
65
|
"design",
|
|
39
66
|
"plan",
|
|
40
67
|
"tasks",
|
|
41
68
|
"analyze",
|
|
42
69
|
"implement",
|
|
70
|
+
"converge",
|
|
71
|
+
"review",
|
|
43
72
|
];
|
|
44
73
|
function phaseOrder(phase) {
|
|
45
74
|
const i = PHASE_SEQUENCE.indexOf(phase);
|
package/dist/core/rules.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rules.js","sourceRoot":"","sources":["../../src/core/rules.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rules.js","sourceRoot":"","sources":["../../src/core/rules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAGzD;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,KAAoB;IAClD,MAAM,IAAI,GAAG,KAAK;SACf,KAAK,EAAE;SACP,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;SACzD,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,IAAI,QAAQ,CAAC,CAAC,WAAW,IAAI,CAAC;SACnD,IAAI,CAAC,IAAI,CAAC,CAAC;IAEd,MAAM,IAAI,GAAG,GAAG,cAAc;;;;;;;;;;EAU9B,IAAI;;;;;;;;;;;wGAWkG,CAAC;IAEvG,OAAO,WAAW,CAAC,IAAI,CAAC,CAAC;AAC3B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,WAAmB;IACpD,MAAM,IAAI,GAAG,GAAG,cAAc;;;iBAGf,WAAW,EAAE,CAAC;IAC7B,OAAO,WAAW,CAAC,IAAI,CAAC,CAAC;AAC3B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,WAAmB,EAAE,KAAoB;IACrE,OAAO,iBAAiB,WAAW;;EAEnC,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC;AAC3B,CAAC;AAED,MAAM,cAAc,GAAG;IACrB,cAAc;IACd,SAAS;IACT,SAAS;IACT,QAAQ;IACR,QAAQ;IACR,MAAM;IACN,OAAO;IACP,SAAS;IACT,WAAW;IACX,UAAU;IACV,QAAQ;CACT,CAAC;AAEF,SAAS,UAAU,CAAC,KAAa;IAC/B,MAAM,CAAC,GAAG,cAAc,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACxC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9C,CAAC"}
|
package/dist/core/scaffold.d.ts
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
export declare const ARTIFACT_TEMPLATES: readonly ["constitution.md", "spec.md", "ui.md", "design-tokens.json", "plan.md", "tasks.md"];
|
|
3
3
|
/** On-demand reference docs installed into a consumer's `.amby/reference/`. */
|
|
4
4
|
export declare const REFERENCE_DOCS: readonly ["design-conventions.md"];
|
|
5
|
+
/** Default role definitions installed into a consumer's `.amby/roles/` (feature 013, FR-001). */
|
|
6
|
+
export declare const SHIPPED_ROLES: readonly ["pm.md", "ux.md", "architect.md", "tech-lead.md", "developer.md", "qa.md"];
|
|
5
7
|
export interface InstallResult {
|
|
6
8
|
created: string[];
|
|
7
9
|
present: string[];
|
package/dist/core/scaffold.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { dirname, join, posix } from "node:path";
|
|
3
|
-
import { referenceDir, templatesDir } from "./paths.js";
|
|
3
|
+
import { referenceDir, rolesDir, templatesDir } from "./paths.js";
|
|
4
4
|
/** Artifact templates installed into a consumer's `.amby/templates/` (referenced by the prompts). */
|
|
5
5
|
export const ARTIFACT_TEMPLATES = [
|
|
6
6
|
"constitution.md",
|
|
@@ -12,6 +12,8 @@ export const ARTIFACT_TEMPLATES = [
|
|
|
12
12
|
];
|
|
13
13
|
/** On-demand reference docs installed into a consumer's `.amby/reference/`. */
|
|
14
14
|
export const REFERENCE_DOCS = ["design-conventions.md"];
|
|
15
|
+
/** Default role definitions installed into a consumer's `.amby/roles/` (feature 013, FR-001). */
|
|
16
|
+
export const SHIPPED_ROLES = ["pm.md", "ux.md", "architect.md", "tech-lead.md", "developer.md", "qa.md"];
|
|
15
17
|
/**
|
|
16
18
|
* Install the artifact templates and reference docs into a project's `.amby/`. Uses
|
|
17
19
|
* write-if-absent semantics: existing files are never overwritten, so a project can customize its
|
|
@@ -38,6 +40,9 @@ export function installArtifactTemplates(projectRoot, dryRun = false) {
|
|
|
38
40
|
for (const name of REFERENCE_DOCS) {
|
|
39
41
|
copy(join(referenceDir(), name), posix.join(".amby", "reference", name));
|
|
40
42
|
}
|
|
43
|
+
for (const name of SHIPPED_ROLES) {
|
|
44
|
+
copy(join(rolesDir(), name), posix.join(".amby", "roles", name));
|
|
45
|
+
}
|
|
41
46
|
return result;
|
|
42
47
|
}
|
|
43
48
|
//# sourceMappingURL=scaffold.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scaffold.js","sourceRoot":"","sources":["../../src/core/scaffold.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"scaffold.js","sourceRoot":"","sources":["../../src/core/scaffold.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAElE,qGAAqG;AACrG,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,iBAAiB;IACjB,SAAS;IACT,OAAO;IACP,oBAAoB;IACpB,SAAS;IACT,UAAU;CACF,CAAC;AAEX,+EAA+E;AAC/E,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,uBAAuB,CAAU,CAAC;AAEjE,iGAAiG;AACjG,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,cAAc,EAAE,OAAO,CAAU,CAAC;AAOlH;;;;;GAKG;AACH,MAAM,UAAU,wBAAwB,CAAC,WAAmB,EAAE,MAAM,GAAG,KAAK;IAC1E,MAAM,MAAM,GAAkB,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IAE3D,MAAM,IAAI,GAAG,CAAC,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