@orderful/droid 0.48.0 → 0.51.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +2 -1
  3. package/CHANGELOG.md +34 -0
  4. package/bun.lock +137 -3
  5. package/dist/bin/droid.js +355 -90
  6. package/dist/commands/pack.d.ts +5 -0
  7. package/dist/commands/pack.d.ts.map +1 -0
  8. package/dist/index.js +11 -0
  9. package/dist/lib/pack.d.ts +31 -0
  10. package/dist/lib/pack.d.ts.map +1 -0
  11. package/dist/lib/types.d.ts +17 -0
  12. package/dist/lib/types.d.ts.map +1 -1
  13. package/dist/tools/brain/.claude-plugin/plugin.json +1 -1
  14. package/dist/tools/brain/TOOL.yaml +3 -1
  15. package/dist/tools/brain/skills/brain/SKILL.md +4 -0
  16. package/dist/tools/brain/skills/brain/references/workflows.md +21 -7
  17. package/dist/tools/coach/TOOL.yaml +4 -0
  18. package/dist/tools/code-review/.claude-plugin/plugin.json +3 -2
  19. package/dist/tools/code-review/TOOL.yaml +4 -1
  20. package/dist/tools/code-review/agents/codex-context-researcher.md +99 -0
  21. package/dist/tools/code-review/skills/code-review/SKILL.md +20 -1
  22. package/dist/tools/codex/.claude-plugin/plugin.json +1 -1
  23. package/dist/tools/codex/TOOL.yaml +3 -1
  24. package/dist/tools/codex/skills/codex/SKILL.md +5 -1
  25. package/dist/tools/codex/skills/codex/scripts/normalize-frontmatter.d.ts +61 -0
  26. package/dist/tools/codex/skills/codex/scripts/normalize-frontmatter.d.ts.map +1 -0
  27. package/dist/tools/codex/skills/codex/scripts/normalize-frontmatter.ts +402 -0
  28. package/dist/tools/comments/TOOL.yaml +2 -0
  29. package/dist/tools/droid/.claude-plugin/plugin.json +1 -1
  30. package/dist/tools/droid/TOOL.yaml +3 -1
  31. package/dist/tools/droid/skills/droid/SKILL.md +48 -2
  32. package/dist/tools/droid/skills/droid/references/new-tool-workflow.md +234 -0
  33. package/dist/tools/edi-schema/TOOL.yaml +2 -0
  34. package/dist/tools/excalidraw/TOOL.yaml +2 -0
  35. package/dist/tools/meeting/TOOL.yaml +2 -0
  36. package/dist/tools/pii/TOOL.yaml +2 -0
  37. package/dist/tools/plan/.claude-plugin/plugin.json +1 -1
  38. package/dist/tools/plan/TOOL.yaml +5 -1
  39. package/dist/tools/plan/commands/plan.md +3 -2
  40. package/dist/tools/plan/skills/plan/SKILL.md +31 -10
  41. package/dist/tools/plan/skills/plan/references/workflows.md +44 -14
  42. package/dist/tools/project/.claude-plugin/plugin.json +1 -1
  43. package/dist/tools/project/TOOL.yaml +7 -1
  44. package/dist/tools/project/skills/project/SKILL.md +32 -1
  45. package/dist/tools/project/skills/project/references/loading.md +1 -0
  46. package/dist/tools/project/skills/project/references/pulling.md +57 -0
  47. package/dist/tools/project/skills/project/references/pushing.md +79 -0
  48. package/dist/tools/release/TOOL.yaml +2 -0
  49. package/dist/tools/share/TOOL.yaml +2 -0
  50. package/dist/tools/status-update/TOOL.yaml +4 -0
  51. package/dist/tools/tech-design/TOOL.yaml +2 -0
  52. package/dist/tools/wrapup/TOOL.yaml +2 -0
  53. package/package.json +3 -1
  54. package/scripts/build.ts +3 -2
  55. package/src/bin/droid.ts +9 -0
  56. package/src/commands/pack.ts +77 -0
  57. package/src/lib/pack.test.ts +85 -0
  58. package/src/lib/pack.ts +293 -0
  59. package/src/lib/types.ts +19 -0
  60. package/src/tools/brain/.claude-plugin/plugin.json +1 -1
  61. package/src/tools/brain/TOOL.yaml +3 -1
  62. package/src/tools/brain/skills/brain/SKILL.md +4 -0
  63. package/src/tools/brain/skills/brain/references/workflows.md +21 -7
  64. package/src/tools/coach/TOOL.yaml +4 -0
  65. package/src/tools/code-review/.claude-plugin/plugin.json +3 -2
  66. package/src/tools/code-review/TOOL.yaml +4 -1
  67. package/src/tools/code-review/agents/codex-context-researcher.md +99 -0
  68. package/src/tools/code-review/skills/code-review/SKILL.md +20 -1
  69. package/src/tools/codex/.claude-plugin/plugin.json +1 -1
  70. package/src/tools/codex/TOOL.yaml +3 -1
  71. package/src/tools/codex/skills/codex/SKILL.md +5 -1
  72. package/src/tools/codex/skills/codex/scripts/normalize-frontmatter.test.ts +331 -0
  73. package/src/tools/codex/skills/codex/scripts/normalize-frontmatter.ts +402 -0
  74. package/src/tools/comments/TOOL.yaml +2 -0
  75. package/src/tools/droid/.claude-plugin/plugin.json +1 -1
  76. package/src/tools/droid/TOOL.yaml +3 -1
  77. package/src/tools/droid/skills/droid/SKILL.md +48 -2
  78. package/src/tools/droid/skills/droid/references/new-tool-workflow.md +234 -0
  79. package/src/tools/edi-schema/TOOL.yaml +2 -0
  80. package/src/tools/excalidraw/TOOL.yaml +2 -0
  81. package/src/tools/meeting/TOOL.yaml +2 -0
  82. package/src/tools/pii/TOOL.yaml +2 -0
  83. package/src/tools/plan/.claude-plugin/plugin.json +1 -1
  84. package/src/tools/plan/TOOL.yaml +5 -1
  85. package/src/tools/plan/commands/plan.md +3 -2
  86. package/src/tools/plan/skills/plan/SKILL.md +31 -10
  87. package/src/tools/plan/skills/plan/references/workflows.md +44 -14
  88. package/src/tools/project/.claude-plugin/plugin.json +1 -1
  89. package/src/tools/project/TOOL.yaml +7 -1
  90. package/src/tools/project/skills/project/SKILL.md +32 -1
  91. package/src/tools/project/skills/project/references/loading.md +1 -0
  92. package/src/tools/project/skills/project/references/pulling.md +57 -0
  93. package/src/tools/project/skills/project/references/pushing.md +79 -0
  94. package/src/tools/release/TOOL.yaml +2 -0
  95. package/src/tools/share/TOOL.yaml +2 -0
  96. package/src/tools/status-update/TOOL.yaml +4 -0
  97. package/src/tools/tech-design/TOOL.yaml +2 -0
  98. package/src/tools/wrapup/TOOL.yaml +2 -0
  99. package/dist/tools/codex/skills/codex/scripts/git-scripts.test.ts +0 -364
  100. package/dist/tools/pii/skills/pii/scripts/presidio.test.ts +0 -444
@@ -1,7 +1,9 @@
1
1
  name: brain
2
2
  description: "Your scratchpad (or brain) - a collaborative space for planning and research. Create docs with /brain plan, /brain research, or /brain review. Use @mentions for async discussion. Docs persist across sessions."
3
- version: 0.4.2
3
+ version: 0.4.3
4
4
  status: beta
5
+ audience:
6
+ - all
5
7
 
6
8
  includes:
7
9
  skills:
@@ -34,6 +34,8 @@ Your **scratchpad** (or **brain**) - a collaborative space for planning, researc
34
34
  | `inbox_folder` | (empty) | Root folder for new docs (e.g., `0-Inbox`) |
35
35
  | `override` | (none) | User-defined behaviour overrides |
36
36
 
37
+ **Optional dependency:** `droid config --get tools.project` → `save_related_in_project` (for project-aware routing)
38
+
37
39
  **If not configured:** Ask the user:
38
40
  > "Where would you like to store brain docs? Common choices:
39
41
  > - `~/Documents/brain` - Easy to find in Finder
@@ -107,6 +109,8 @@ Full procedure: `references/workflows.md` § Opening
107
109
 
108
110
  Templates vary by category (see `references/templates.md`), but all follow the same creation flow.
109
111
 
112
+ **Project-aware routing:** When a `/project` is active and `save_related_in_project` is true (check `droid config --get tools.project`), ALL new docs route to `{project_folder}/{category}s/` instead of the brain inbox — no category filtering. Plans, research, ideas, thoughts, spikes, whatever the user creates. If it's related to the project, it lives with the project. Disable with `save_related_in_project: false` in project config.
113
+
110
114
  **Note:** `idea` category docs do NOT become active (fire-and-forget capture).
111
115
 
112
116
  Full procedure: `references/workflows.md` § Creating
@@ -62,13 +62,27 @@ Detailed procedures for each brain operation.
62
62
  - Example: `auth-refactor.md` or `caching-strategies.md`
63
63
 
64
64
  3. **Determine target path based on category:**
65
- - Base: `{brain_dir}/{inbox_folder}` (or just `{brain_dir}` if no inbox_folder)
66
- - Category becomes plural folder: `{base}/{category}s/{filename}`
67
- - Examples:
68
- - `plan` `{base}/plans/{filename}`
69
- - `research` `{base}/research/{filename}`
70
- - `spike` `{base}/spikes/{filename}`
71
- - `meeting` `{base}/meetings/{filename}`
65
+
66
+ a. **Check for active project:**
67
+ - If `/project` is active in session AND `save_related_in_project` is true
68
+ (run `droid config --get tools.project` to check):
69
+ - Route ALL categories to project folder: `{projects_dir}/{project}/{category}s/{filename}`
70
+ - No category filtering — plans, research, ideas, thoughts, spikes, anything goes
71
+ - Example: `/brain research caching` with project "droid" active
72
+ → `{projects_dir}/droid/research/caching.md`
73
+ - Example: `/brain idea wild-thought` with project "droid" active
74
+ → `{projects_dir}/droid/ideas/wild-thought.md`
75
+ - If `/project` active but `save_related_in_project` is false (default), OR no project active:
76
+ - Fall through to default routing below
77
+
78
+ b. **Default routing (no active project or opt-out):**
79
+ - Base: `{brain_dir}/{inbox_folder}` (or just `{brain_dir}` if no inbox_folder)
80
+ - Category becomes plural folder: `{base}/{category}s/{filename}`
81
+ - Examples:
82
+ - `plan` → `{base}/plans/{filename}`
83
+ - `research` → `{base}/research/{filename}`
84
+ - `spike` → `{base}/spikes/{filename}`
85
+ - `meeting` → `{base}/meetings/{filename}`
72
86
 
73
87
  4. **Create directory** if needed (category folder may not exist yet)
74
88
 
@@ -2,6 +2,10 @@ name: coach
2
2
  description: "Learning-mode AI assistance - AI as coach, not crutch. Use /coach plan for co-authored planning, /coach scaffold for structure with hints, /coach review for Socratic questions."
3
3
  version: 0.3.0
4
4
  status: beta
5
+ audience:
6
+ - engineering
7
+ - product
8
+ - design
5
9
 
6
10
  includes:
7
11
  skills:
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "droid-code-review",
3
- "version": "0.2.4",
3
+ "version": "0.3.0",
4
4
  "description": "Comprehensive code review using specialized agents. Reviews PRs, staged changes, branches, or specific files with confidence scoring.",
5
5
  "author": {
6
6
  "name": "Orderful",
@@ -23,6 +23,7 @@
23
23
  "./agents/edi-standards-reviewer.md",
24
24
  "./agents/error-handling-reviewer.md",
25
25
  "./agents/test-coverage-analyzer.md",
26
- "./agents/type-reviewer.md"
26
+ "./agents/type-reviewer.md",
27
+ "./agents/codex-context-researcher.md"
27
28
  ]
28
29
  }
@@ -1,7 +1,9 @@
1
1
  name: code-review
2
2
  description: "Comprehensive code review using specialized agents. Reviews PRs, staged changes, branches, or specific files with confidence scoring."
3
- version: 0.2.4
3
+ version: 0.3.0
4
4
  status: alpha
5
+ audience:
6
+ - engineering
5
7
 
6
8
  includes:
7
9
  skills:
@@ -15,5 +17,6 @@ includes:
15
17
  - error-handling-reviewer
16
18
  - test-coverage-analyzer
17
19
  - type-reviewer
20
+ - codex-context-researcher
18
21
 
19
22
  dependencies: []
@@ -0,0 +1,99 @@
1
+ ---
2
+ name: codex-context-researcher
3
+ description: "Search codex for domain knowledge relevant to code changes. Enriches code review findings with organisational context from PRDs, tech designs, and architectural decisions."
4
+ tools:
5
+ - Read
6
+ - Grep
7
+ - Glob
8
+ - Bash
9
+ color: cyan
10
+ ---
11
+
12
+ You are a codex research agent that finds organisational domain knowledge relevant to a set of code changes. Your output enriches code review findings — you do NOT review code yourself.
13
+
14
+ ## Inputs
15
+
16
+ You will receive:
17
+
18
+ - A list of changed file paths
19
+ - A brief summary of the diff (module names, domain concepts)
20
+ - Optionally, custom instructions from the user
21
+
22
+ ## Procedure
23
+
24
+ ### Step 1: Check Codex Availability
25
+
26
+ Run: `droid config --get tools.codex`
27
+
28
+ Parse the output for `codex_repo`. If not set or the command fails, return:
29
+
30
+ ```json
31
+ {
32
+ "status": "not_configured",
33
+ "entries_searched": 0,
34
+ "entries_matched": 0,
35
+ "domain_context": "",
36
+ "sources": []
37
+ }
38
+ ```
39
+
40
+ ### Step 2: Read Index
41
+
42
+ Read `{codex_repo}/index.yaml` — this is the codex inventory. It lists every entry by category (projects, patterns, topics, domains, proposals) with names, titles, and aliases.
43
+
44
+ If the index doesn't exist or is empty, return `status: "not_configured"`.
45
+
46
+ ### Step 3: Extract Search Terms
47
+
48
+ From the changed file paths, extract terms to match against the index:
49
+
50
+ - **Module/service names** from paths (e.g., `transactionTemplate` from `src/modules/transactionTemplate/`)
51
+ - **Directory segments** that suggest feature areas (e.g., `billing`, `partnership`, `webhook`)
52
+
53
+ Do NOT hardcode domain concepts — let the index be the source of truth for what knowledge exists.
54
+
55
+ ### Step 4: Match Against Index
56
+
57
+ Match extracted terms against index entry names, titles, and aliases across all categories. Select up to **5** most relevant entries. Prioritise:
58
+
59
+ 1. Exact name/alias matches
60
+ 2. Partial matches on entry titles
61
+ 3. Related entries where extracted terms appear in the name or title
62
+
63
+ If no entries match, return `status: "no_relevant_entries"`.
64
+
65
+ ### Step 5: Read and Extract
66
+
67
+ For each matched entry, read the full content. Extract **only**:
68
+
69
+ - Key patterns and conventions
70
+ - Architectural decisions and their rationale
71
+ - Gotchas, constraints, and explicit rules
72
+ - Domain-specific validation requirements
73
+
74
+ **Skip** generic content, background sections, and anything not actionable for a code reviewer.
75
+
76
+ ### Step 6: Return Structured Output
77
+
78
+ Return a JSON block:
79
+
80
+ ```json
81
+ {
82
+ "status": "ok",
83
+ "entries_searched": 12,
84
+ "entries_matched": 3,
85
+ "domain_context": "Bullet points of reviewer-actionable domain knowledge (~300 words max)",
86
+ "sources": ["entry-name-1", "entry-name-2"]
87
+ }
88
+ ```
89
+
90
+ - `entries_searched`: total entries in index
91
+ - `entries_matched`: entries that matched search terms
92
+ - `domain_context`: concise, reviewer-actionable bullet points. Focus on what a reviewer should look for or verify. Max ~300 words
93
+ - `sources`: entry names used (for citation in the review report)
94
+
95
+ ## Important
96
+
97
+ - Do NOT review code. Your job is context retrieval only.
98
+ - Keep `domain_context` focused and actionable — reviewers will read this alongside their own findings.
99
+ - If codex isn't configured or has no relevant entries, return early with the appropriate status. Don't fabricate context.
@@ -15,6 +15,8 @@ Code-review has no configuration of its own. Optional integration with other too
15
15
 
16
16
  - **Brain skill** (optional): If installed, offers to save review results to a `/brain review` doc
17
17
  - Check with: `droid config --get tools.brain` to see if `brain_dir` is configured
18
+ - **Codex skill** (optional): If configured, enriches EDI findings with organisational domain knowledge
19
+ - Check with: `droid config --get tools.codex` to see if `codex_repo` is configured
18
20
 
19
21
  **Overrides:** This skill supports user-defined overrides. See `/droid` skill § Skill Overrides.
20
22
 
@@ -32,6 +34,7 @@ The `/code-review` command orchestrates multiple specialized agents in parallel:
32
34
  2. **test-coverage-analyzer** - Test completeness and edge cases
33
35
  3. **error-handling-reviewer** - Silent failures, missing error handling
34
36
  4. **type-reviewer** - TypeScript type design, interface contracts
37
+ 5. **codex-context-researcher** (optional) - Domain knowledge from codex for EDI enrichment
35
38
 
36
39
  Each agent returns issues with confidence scores (0-100). Issues below 80% confidence are filtered out to reduce noise.
37
40
 
@@ -117,14 +120,19 @@ For PR reviews, also fetch:
117
120
 
118
121
  ### Step 3: Parallel Agent Reviews
119
122
 
123
+ **Check codex availability** before launching agents:
124
+
125
+ Run `droid config --get tools.codex`. If `codex_repo` is configured, you will launch 5 agents. If not, launch the standard 4.
126
+
120
127
  Launch these agents in parallel using the Task tool with `run_in_background: true`:
121
128
 
122
129
  1. **edi-standards-reviewer**: EDI patterns, partnership handling, billing concerns
123
130
  2. **test-coverage-analyzer**: Test completeness and edge cases
124
131
  3. **error-handling-reviewer**: Silent failures, missing error handling
125
132
  4. **type-reviewer**: Type design, interface contracts
133
+ 5. **codex-context-researcher** (only if codex is configured): Pass changed file paths and a brief summary of the diff (module names, domain concepts extracted from paths and PR description). Do NOT pass full diff content — this agent reads codex, not code.
126
134
 
127
- Pass each agent:
135
+ Pass agents 1–4:
128
136
 
129
137
  1. The diff content
130
138
  2. The full file content for changed files (for context)
@@ -139,6 +147,17 @@ Filter out issues with confidence < 80.
139
147
 
140
148
  ### Step 5: Synthesize Report
141
149
 
150
+ **Codex enrichment** (if codex-context-researcher returned `status: "ok"` with non-empty `domain_context`):
151
+
152
+ Before compiling the EDI findings, prefix the EDI section with a "Domain Context" block:
153
+
154
+ > **Domain context** (from codex: entry-name-1, entry-name-2)
155
+ > - Bullet points from the researcher's domain_context
156
+
157
+ Use this context to strengthen or re-prioritise EDI findings. For example, if codex says "partnership billing events must always include account_id" and the EDI reviewer flagged a missing field, elevate that finding's priority.
158
+
159
+ If codex returned `status: "not_configured"` or `"no_relevant_entries"`, omit the domain context block silently.
160
+
142
161
  Compile findings into a prioritized report:
143
162
 
144
163
  **PR #123: "Add partnership billing events"** (if reviewing a PR)
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "droid-codex",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "Shared organizational knowledge - PRDs, tech designs, domains, proposals, patterns, and explored topics. Self-describing: structure and workflows defined in codex repo. Use when loading project context, searching codex, capturing decisions, or creating new entries.",
5
5
  "author": {
6
6
  "name": "Orderful",
@@ -1,7 +1,9 @@
1
1
  name: codex
2
2
  description: "Shared organizational knowledge - PRDs, tech designs, domains, proposals, patterns, and explored topics. Self-describing: structure and workflows defined in codex repo. Use when loading project context, searching codex, capturing decisions, or creating new entries."
3
- version: 0.3.1
3
+ version: 0.4.0
4
4
  status: beta
5
+ audience:
6
+ - all
5
7
 
6
8
  includes:
7
9
  skills:
@@ -145,6 +145,7 @@ The codex skill includes three git scripts. **Always use these instead of raw gi
145
145
  |--------|---------|-------------|
146
146
  | git-preamble | Ensure clean main + pull latest | Before ANY operation |
147
147
  | git-start-write | Preamble + create branch | Before write operations |
148
+ | normalize-frontmatter | Normalize YAML frontmatter format | After writing, before commit |
148
149
  | git-finish-write | Commit + PR + return to main | After write operations |
149
150
 
150
151
  ### Read Operations
@@ -159,7 +160,10 @@ The codex skill includes three git scripts. **Always use these instead of raw gi
159
160
 
160
161
  # 2. Make your changes (write files)
161
162
 
162
- # 3. Finish write (commit + PR + return to main)
163
+ # 3. Normalize frontmatter (prevents fix-frontmatter PRs)
164
+ droid config --get tools.codex | droid exec codex normalize-frontmatter --config -
165
+
166
+ # 4. Finish write (commit + PR + return to main)
163
167
  droid config --get tools.codex | droid exec codex git-finish-write --config - \
164
168
  --message "{commit message}" \
165
169
  --pr-title "{PR title}" \
@@ -0,0 +1,331 @@
1
+ import { describe, it, expect } from 'bun:test';
2
+ import {
3
+ extractFrontmatter,
4
+ needsQuoting,
5
+ quoteValue,
6
+ unquoteDate,
7
+ normalizeFrontmatter,
8
+ normalizeFile,
9
+ } from './normalize-frontmatter';
10
+
11
+ describe('extractFrontmatter', () => {
12
+ it('extracts frontmatter from valid markdown', () => {
13
+ const content = '---\ntitle: Test\nstatus: active\n---\n\n# Body';
14
+ const { frontmatter, body } = extractFrontmatter(content);
15
+ expect(frontmatter).toEqual(['title: Test', 'status: active']);
16
+ expect(body).toBe('\n\n# Body');
17
+ });
18
+
19
+ it('returns null for files without frontmatter', () => {
20
+ const content = '# Just a heading\n\nSome text.';
21
+ const { frontmatter, body } = extractFrontmatter(content);
22
+ expect(frontmatter).toBeNull();
23
+ expect(body).toBe(content);
24
+ });
25
+
26
+ it('returns null for unclosed frontmatter', () => {
27
+ const content = '---\ntitle: Test\nstatus: active\n';
28
+ const { frontmatter } = extractFrontmatter(content);
29
+ expect(frontmatter).toBeNull();
30
+ });
31
+ });
32
+
33
+ describe('needsQuoting', () => {
34
+ it('does not quote simple strings', () => {
35
+ expect(needsQuoting('active')).toBe(false);
36
+ expect(needsQuoting('hello world')).toBe(false);
37
+ });
38
+
39
+ it('does not quote booleans or null', () => {
40
+ expect(needsQuoting('true')).toBe(false);
41
+ expect(needsQuoting('false')).toBe(false);
42
+ expect(needsQuoting('null')).toBe(false);
43
+ });
44
+
45
+ it('does not quote dates', () => {
46
+ expect(needsQuoting('2026-03-04')).toBe(false);
47
+ });
48
+
49
+ it('quotes strings with em dashes', () => {
50
+ expect(needsQuoting('AI-powered — fast delivery')).toBe(true);
51
+ });
52
+
53
+ it('quotes strings with en dashes', () => {
54
+ expect(needsQuoting('pages 1\u20135')).toBe(true);
55
+ });
56
+
57
+ it('quotes strings with accented characters', () => {
58
+ expect(needsQuoting('résumé of changes')).toBe(true);
59
+ });
60
+
61
+ it('quotes strings with @ symbol', () => {
62
+ expect(needsQuoting('@tylerfry')).toBe(true);
63
+ });
64
+
65
+ it('quotes strings with colon-space', () => {
66
+ expect(needsQuoting('Note: this is important')).toBe(true);
67
+ });
68
+
69
+ it('quotes strings with inline # comment', () => {
70
+ expect(needsQuoting('value #comment')).toBe(true);
71
+ });
72
+
73
+ it('quotes strings starting with special YAML chars', () => {
74
+ expect(needsQuoting('*bold*')).toBe(true);
75
+ expect(needsQuoting('!important')).toBe(true);
76
+ });
77
+ });
78
+
79
+ describe('quoteValue', () => {
80
+ it('wraps value in double quotes', () => {
81
+ expect(quoteValue('hello')).toBe('"hello"');
82
+ });
83
+
84
+ it('escapes internal double quotes', () => {
85
+ expect(quoteValue('say "hello"')).toBe('"say \\"hello\\""');
86
+ });
87
+
88
+ it('does not double-quote already quoted values', () => {
89
+ expect(quoteValue('"already quoted"')).toBe('"already quoted"');
90
+ expect(quoteValue("'single quoted'")).toBe("'single quoted'");
91
+ });
92
+ });
93
+
94
+ describe('unquoteDate', () => {
95
+ it('unquotes a quoted date', () => {
96
+ expect(unquoteDate('"2026-03-04"')).toBe('2026-03-04');
97
+ expect(unquoteDate("'2026-03-04'")).toBe('2026-03-04');
98
+ });
99
+
100
+ it('leaves non-date quoted values alone', () => {
101
+ expect(unquoteDate('"not a date"')).toBe('"not a date"');
102
+ });
103
+
104
+ it('leaves bare dates alone', () => {
105
+ expect(unquoteDate('2026-03-04')).toBe('2026-03-04');
106
+ });
107
+ });
108
+
109
+ describe('normalizeFrontmatter', () => {
110
+ it('flattens folded scalar (>) into single line', () => {
111
+ const lines = [
112
+ 'title: >',
113
+ ' This is a long',
114
+ ' description that spans',
115
+ ' multiple lines',
116
+ 'status: active',
117
+ ];
118
+ const result = normalizeFrontmatter(lines);
119
+ expect(result).toEqual([
120
+ 'title: This is a long description that spans multiple lines',
121
+ 'status: active',
122
+ ]);
123
+ });
124
+
125
+ it('flattens literal scalar (|) into single line', () => {
126
+ const lines = [
127
+ 'description: |',
128
+ ' Line one',
129
+ ' Line two',
130
+ 'status: active',
131
+ ];
132
+ const result = normalizeFrontmatter(lines);
133
+ expect(result).toEqual([
134
+ 'description: Line one Line two',
135
+ 'status: active',
136
+ ]);
137
+ });
138
+
139
+ it('flattens >- (strip) into single line', () => {
140
+ const lines = [
141
+ 'title: >-',
142
+ ' Stripped trailing',
143
+ ' newline content',
144
+ 'status: active',
145
+ ];
146
+ const result = normalizeFrontmatter(lines);
147
+ expect(result).toEqual([
148
+ 'title: Stripped trailing newline content',
149
+ 'status: active',
150
+ ]);
151
+ });
152
+
153
+ it('quotes values with em dashes after flattening', () => {
154
+ const lines = [
155
+ 'description: >',
156
+ ' AI-powered platform —',
157
+ ' fast and reliable',
158
+ ];
159
+ const result = normalizeFrontmatter(lines);
160
+ expect(result).toEqual([
161
+ 'description: "AI-powered platform \u2014 fast and reliable"',
162
+ ]);
163
+ });
164
+
165
+ it('quotes inline values with special characters', () => {
166
+ const lines = [
167
+ 'title: Overview — EDI Platform',
168
+ 'author: @tylerfry',
169
+ ];
170
+ const result = normalizeFrontmatter(lines);
171
+ expect(result).toEqual([
172
+ 'title: "Overview \u2014 EDI Platform"',
173
+ 'author: "@tylerfry"',
174
+ ]);
175
+ });
176
+
177
+ it('unquotes dates that are wrapped in quotes', () => {
178
+ const lines = [
179
+ 'created: "2026-03-04"',
180
+ "updated: '2026-01-15'",
181
+ ];
182
+ const result = normalizeFrontmatter(lines);
183
+ expect(result).toEqual([
184
+ 'created: 2026-03-04',
185
+ 'updated: 2026-01-15',
186
+ ]);
187
+ });
188
+
189
+ it('preserves already-correct frontmatter', () => {
190
+ const lines = [
191
+ 'title: Simple Title',
192
+ 'type: domain',
193
+ 'status: active',
194
+ 'created: 2026-03-04',
195
+ ];
196
+ const result = normalizeFrontmatter(lines);
197
+ expect(result).toEqual(lines);
198
+ });
199
+
200
+ it('preserves list items', () => {
201
+ const lines = [
202
+ 'related_domains:',
203
+ '- overview',
204
+ '- transaction',
205
+ ];
206
+ const result = normalizeFrontmatter(lines);
207
+ expect(result).toEqual([
208
+ 'related_domains:',
209
+ '- overview',
210
+ '- transaction',
211
+ ]);
212
+ });
213
+
214
+ it('preserves comments', () => {
215
+ const lines = [
216
+ '# This is a comment',
217
+ 'title: Test',
218
+ ];
219
+ const result = normalizeFrontmatter(lines);
220
+ expect(result).toEqual(lines);
221
+ });
222
+
223
+ it('preserves blank lines', () => {
224
+ const lines = [
225
+ 'title: Test',
226
+ '',
227
+ 'status: active',
228
+ ];
229
+ const result = normalizeFrontmatter(lines);
230
+ expect(result).toEqual(lines);
231
+ });
232
+
233
+ it('handles key with empty value (list follows)', () => {
234
+ const lines = [
235
+ 'codebase_paths:',
236
+ '- ~/src/app',
237
+ '- ~/src/lib',
238
+ ];
239
+ const result = normalizeFrontmatter(lines);
240
+ expect(result).toEqual(lines);
241
+ });
242
+
243
+ it('quotes list items with special characters', () => {
244
+ const lines = [
245
+ 'participants:',
246
+ '- @tylerfry',
247
+ '- @thea',
248
+ ];
249
+ const result = normalizeFrontmatter(lines);
250
+ expect(result).toEqual([
251
+ 'participants:',
252
+ '- "@tylerfry"',
253
+ '- "@thea"',
254
+ ]);
255
+ });
256
+ });
257
+
258
+ describe('normalizeFile', () => {
259
+ it('returns null when no changes needed', () => {
260
+ const content = '---\ntitle: Test\nstatus: active\ncreated: 2026-03-04\n---\n\n# Body';
261
+ expect(normalizeFile(content)).toBeNull();
262
+ });
263
+
264
+ it('returns null when no frontmatter exists', () => {
265
+ const content = '# Just a heading';
266
+ expect(normalizeFile(content)).toBeNull();
267
+ });
268
+
269
+ it('normalizes and reassembles the file', () => {
270
+ const content = '---\ntitle: "2026-03-04"\ndescription: >\n A long\n description\n---\n\n# Body';
271
+ const result = normalizeFile(content);
272
+ expect(result).toBe('---\ntitle: 2026-03-04\ndescription: A long description\n---\n\n# Body');
273
+ });
274
+
275
+ it('is idempotent — second run returns null', () => {
276
+ const content = '---\ntitle: >\n Hello — world\nstatus: active\n---\n\n# Body';
277
+ const first = normalizeFile(content);
278
+ expect(first).not.toBeNull();
279
+
280
+ const second = normalizeFile(first!);
281
+ expect(second).toBeNull();
282
+ });
283
+
284
+ it('handles real-world codex frontmatter', () => {
285
+ const content = [
286
+ '---',
287
+ 'title: Droid - AI Workflow Toolkit',
288
+ 'type: context',
289
+ 'status: active',
290
+ 'created: 2025-12-09',
291
+ 'updated: 2026-01-29',
292
+ 'source: implementation',
293
+ 'participants:',
294
+ ' tech_lead: tylerfry',
295
+ 'codebase_paths:',
296
+ '- ~/src/github.com/droid',
297
+ 'slack:',
298
+ ' channel: \'#droid\'',
299
+ ' canvas_id: F0AD41VF71V',
300
+ '---',
301
+ '',
302
+ '# Droid',
303
+ ].join('\n');
304
+
305
+ // Already well-formed — should return null
306
+ expect(normalizeFile(content)).toBeNull();
307
+ });
308
+
309
+ it('normalizes multiline scalar in real-world pattern', () => {
310
+ const content = [
311
+ '---',
312
+ 'title: >',
313
+ ' Automated Partner Testing —',
314
+ ' End-to-end EDI validation',
315
+ 'type: project',
316
+ 'status: active',
317
+ 'created: 2026-02-01',
318
+ '---',
319
+ '',
320
+ '# Content',
321
+ ].join('\n');
322
+
323
+ const result = normalizeFile(content);
324
+ expect(result).toContain('title: "Automated Partner Testing \u2014 End-to-end EDI validation"');
325
+ expect(result).toContain('type: project');
326
+ expect(result).toContain('created: 2026-02-01');
327
+
328
+ // Idempotent
329
+ expect(normalizeFile(result!)).toBeNull();
330
+ });
331
+ });