clementine-agent 1.0.99 → 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.
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Migration 0004: Backfill `schemaVersion: 1` into CRON.md and agent.md frontmatter.
|
|
3
|
+
*
|
|
4
|
+
* First multi-target migration — uses the new MigrationContext shape
|
|
5
|
+
* shipped in Phase 7a. Establishes the convention so future format changes
|
|
6
|
+
* (a v2 migration) can target files known to be at v1.
|
|
7
|
+
*
|
|
8
|
+
* Idempotent: parses with gray-matter, only writes when schemaVersion is
|
|
9
|
+
* missing or not equal to 1.
|
|
10
|
+
*/
|
|
11
|
+
import type { Migration } from './types.js';
|
|
12
|
+
export declare const migration: Migration;
|
|
13
|
+
//# sourceMappingURL=0004-backfill-schema-versions.d.ts.map
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Migration 0004: Backfill `schemaVersion: 1` into CRON.md and agent.md frontmatter.
|
|
3
|
+
*
|
|
4
|
+
* First multi-target migration — uses the new MigrationContext shape
|
|
5
|
+
* shipped in Phase 7a. Establishes the convention so future format changes
|
|
6
|
+
* (a v2 migration) can target files known to be at v1.
|
|
7
|
+
*
|
|
8
|
+
* Idempotent: parses with gray-matter, only writes when schemaVersion is
|
|
9
|
+
* missing or not equal to 1.
|
|
10
|
+
*/
|
|
11
|
+
import { existsSync, readFileSync, readdirSync, writeFileSync } from 'node:fs';
|
|
12
|
+
import path from 'node:path';
|
|
13
|
+
import matter from 'gray-matter';
|
|
14
|
+
function backfillFile(filePath) {
|
|
15
|
+
if (!existsSync(filePath))
|
|
16
|
+
return 'missing';
|
|
17
|
+
let parsed;
|
|
18
|
+
try {
|
|
19
|
+
parsed = matter(readFileSync(filePath, 'utf-8'));
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return 'invalid';
|
|
23
|
+
}
|
|
24
|
+
const data = (parsed.data ?? {});
|
|
25
|
+
if (data.schemaVersion === 1)
|
|
26
|
+
return 'already-set';
|
|
27
|
+
data.schemaVersion = 1;
|
|
28
|
+
// gray-matter's stringify preserves the original frontmatter style.
|
|
29
|
+
writeFileSync(filePath, matter.stringify(parsed.content, data));
|
|
30
|
+
return 'updated';
|
|
31
|
+
}
|
|
32
|
+
function findAgentMdFiles(vaultDir) {
|
|
33
|
+
const out = [];
|
|
34
|
+
const agentsDir = path.join(vaultDir, '00-System', 'agents');
|
|
35
|
+
if (!existsSync(agentsDir))
|
|
36
|
+
return out;
|
|
37
|
+
for (const entry of readdirSync(agentsDir, { withFileTypes: true })) {
|
|
38
|
+
if (!entry.isDirectory())
|
|
39
|
+
continue;
|
|
40
|
+
const candidate = path.join(agentsDir, entry.name, 'agent.md');
|
|
41
|
+
if (existsSync(candidate))
|
|
42
|
+
out.push(candidate);
|
|
43
|
+
}
|
|
44
|
+
return out;
|
|
45
|
+
}
|
|
46
|
+
export const migration = {
|
|
47
|
+
kind: 'vault',
|
|
48
|
+
id: '0004-backfill-schema-versions',
|
|
49
|
+
description: 'Backfill schemaVersion: 1 into CRON.md and agent.md frontmatter',
|
|
50
|
+
apply(ctx) {
|
|
51
|
+
const targets = [];
|
|
52
|
+
const cronPath = path.join(ctx.vaultDir, '00-System', 'CRON.md');
|
|
53
|
+
if (existsSync(cronPath))
|
|
54
|
+
targets.push(cronPath);
|
|
55
|
+
targets.push(...findAgentMdFiles(ctx.vaultDir));
|
|
56
|
+
if (targets.length === 0) {
|
|
57
|
+
return { applied: false, skipped: true, details: 'No CRON.md or agent.md files found' };
|
|
58
|
+
}
|
|
59
|
+
const stats = { updated: 0, alreadySet: 0, invalid: 0, missing: 0 };
|
|
60
|
+
for (const f of targets) {
|
|
61
|
+
const r = backfillFile(f);
|
|
62
|
+
if (r === 'updated')
|
|
63
|
+
stats.updated++;
|
|
64
|
+
else if (r === 'already-set')
|
|
65
|
+
stats.alreadySet++;
|
|
66
|
+
else if (r === 'invalid')
|
|
67
|
+
stats.invalid++;
|
|
68
|
+
else
|
|
69
|
+
stats.missing++;
|
|
70
|
+
}
|
|
71
|
+
if (stats.updated === 0) {
|
|
72
|
+
return {
|
|
73
|
+
applied: false,
|
|
74
|
+
skipped: true,
|
|
75
|
+
details: `All ${targets.length} files already have schemaVersion (alreadySet=${stats.alreadySet}, invalid=${stats.invalid})`,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
applied: true,
|
|
80
|
+
skipped: false,
|
|
81
|
+
details: `Updated ${stats.updated}/${targets.length} files (alreadySet=${stats.alreadySet}, invalid=${stats.invalid})`,
|
|
82
|
+
};
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
//# sourceMappingURL=0004-backfill-schema-versions.js.map
|