drafted 1.24.5 → 1.24.6
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 +34 -15
- package/agent-instructions/global.md +3 -0
- package/cli/google-setup.sh +186 -0
- package/cli/mail-watch.mjs +237 -0
- package/cli/open-url.mjs +17 -0
- package/cli/repo-scan.mjs +240 -0
- package/cli/skill-setup-trust.mjs +17 -0
- package/install-mcp.sh +1440 -0
- package/mcp/active-project-store.mjs +81 -0
- package/mcp/gates.mjs +206 -0
- package/mcp/gws-status.mjs +31 -0
- package/mcp/repo-address.mjs +215 -0
- package/mcp/server.mjs +1 -1
- package/mcp/test-file-path-text.mjs +58 -0
- package/mcp/test-org-guards.mjs +234 -0
- package/mcp/test-project-index.mjs +88 -0
- package/mcp/test-search-terms.mjs +79 -0
- package/mcp/test-skill-paths.mjs +29 -0
- package/mcp/widgets/canvas-overview.html +229 -0
- package/mcp/widgets/frame-preview.html +162 -0
- package/package.json +29 -23
- package/plugin/commands/create-project.md +20 -0
- package/plugin/commands/create-skill.md +18 -0
- package/plugin/commands/extract.md +16 -0
- package/plugin/commands/improve-project-harness.md +16 -0
- package/plugin/commands/improve-skill.md +14 -0
- package/plugin/commands/improve-wiki.md +14 -0
- package/plugin/commands/ingest.md +20 -0
- package/plugin/commands/onboard-drafted.md +18 -0
- package/plugin/skills/drafted/SKILL.md +102 -0
- package/server/lib/umami.mjs +164 -0
- package/src/shared/anchor-scope.mjs +98 -0
- package/src/shared/excalidraw.mjs +94 -0
- package/src/shared/folder-path.mjs +176 -0
- package/src/shared/gate-budget.mjs +30 -0
- package/src/shared/minion-presets.mjs +67 -0
- package/src/shared/okf-log.mjs +62 -0
- package/src/shared/record-conformance.mjs +167 -0
- package/src/shared/root-route.mjs +45 -0
- package/src/shared/task-id.mjs +54 -0
- package/src/shared/test-excalidraw-merge.mjs +52 -0
- package/src/shared/wiki-excalidraw.mjs +90 -0
- package/skills/import-website-to-drafted.md +0 -329
- /package/{shared → src/shared}/constants.mjs +0 -0
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
// Repo `.agents/` scanner (org substrate normalization, Move C).
|
|
2
|
+
//
|
|
3
|
+
// Pure filesystem scan — no network, no DB. The CLI runs this against a repo
|
|
4
|
+
// checkout (cloned to a temp dir for a URL, or a local path directly) and POSTs
|
|
5
|
+
// the catalog to /api/repos. Content stays in git; only metadata + pointers are
|
|
6
|
+
// sent. Mirrors the Agent Skills open format: `.agents/skills/<name>/SKILL.md`
|
|
7
|
+
// (name + description frontmatter) and `.agents/identities/<slug>/identity.yaml`
|
|
8
|
+
// (slug + name). See docs/plans/org-substrate-normalization.md.
|
|
9
|
+
|
|
10
|
+
import { readFileSync, readdirSync, existsSync, mkdtempSync } from 'fs';
|
|
11
|
+
import { join, relative, sep } from 'path';
|
|
12
|
+
import { tmpdir } from 'os';
|
|
13
|
+
import { execSync } from 'child_process';
|
|
14
|
+
import { parse as parseYaml } from 'yaml';
|
|
15
|
+
|
|
16
|
+
// ── Frontmatter ────────────────────────────────────────────────────
|
|
17
|
+
|
|
18
|
+
/** Parse a YAML frontmatter block (`---\n...\n---`) from text. null if absent/invalid. */
|
|
19
|
+
export function parseFrontmatter(text) {
|
|
20
|
+
const m = text.match(/^---\r?\n([\s\S]*?)\r?\n---/);
|
|
21
|
+
if (!m) return null;
|
|
22
|
+
try {
|
|
23
|
+
const parsed = parseYaml(m[1]);
|
|
24
|
+
return parsed && typeof parsed === 'object' ? parsed : null;
|
|
25
|
+
} catch {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// ── Scan ────────────────────────────────────────────────────────────
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Scan <dir>/.agents/skills/<name>/SKILL.md, <dir>/.agents/identities/<slug>/
|
|
34
|
+
* identity.yaml and <dir>/.wiki/**.md. Returns { skills, identities, wiki }
|
|
35
|
+
* catalog entries (metadata + pointers only — no file content). A skill with no
|
|
36
|
+
* frontmatter still indexes (name falls back to the dir). Identities index
|
|
37
|
+
* {slug, name} from identity.yaml. A wiki page's slug is its `.wiki/`-relative
|
|
38
|
+
* path with `.md` stripped, which is exactly its Drafted wiki path.
|
|
39
|
+
*/
|
|
40
|
+
export function scanRepoAgents(dir) {
|
|
41
|
+
const skills = [];
|
|
42
|
+
const identities = [];
|
|
43
|
+
const agentsDir = join(dir, '.agents');
|
|
44
|
+
|
|
45
|
+
const skillsDir = join(agentsDir, 'skills');
|
|
46
|
+
if (existsSync(skillsDir)) {
|
|
47
|
+
for (const name of readdirSafe(skillsDir)) {
|
|
48
|
+
const skillMd = join(skillsDir, name, 'SKILL.md');
|
|
49
|
+
if (!existsSync(skillMd)) continue;
|
|
50
|
+
const fm = parseFrontmatter(readFileSync(skillMd, 'utf8')) || {};
|
|
51
|
+
// README gate (Phase 1): a skill with no README.md still imports (foreign
|
|
52
|
+
// skills in the open Agent Skills format may legitimately omit one), but
|
|
53
|
+
// is flagged warn so the gap is visible. Never dropped.
|
|
54
|
+
const hasReadme = existsSync(join(skillsDir, name, 'README.md'));
|
|
55
|
+
skills.push({
|
|
56
|
+
kind: 'skill',
|
|
57
|
+
name: String(fm.name || name),
|
|
58
|
+
slug: name,
|
|
59
|
+
description: fm.description != null ? String(fm.description) : '',
|
|
60
|
+
sourcePath: `.agents/skills/${name}`,
|
|
61
|
+
readmePath: hasReadme ? `.agents/skills/${name}/README.md` : null,
|
|
62
|
+
status: hasReadme ? 'ok' : 'warn',
|
|
63
|
+
statusReason: hasReadme ? null : 'no README',
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const identDir = join(agentsDir, 'identities');
|
|
69
|
+
if (existsSync(identDir)) {
|
|
70
|
+
for (const name of readdirSafe(identDir)) {
|
|
71
|
+
const idYaml = join(identDir, name, 'identity.yaml');
|
|
72
|
+
if (!existsSync(idYaml)) continue;
|
|
73
|
+
let fm = null;
|
|
74
|
+
try {
|
|
75
|
+
fm = parseYaml(readFileSync(idYaml, 'utf8')) || {};
|
|
76
|
+
} catch {
|
|
77
|
+
fm = {};
|
|
78
|
+
}
|
|
79
|
+
identities.push({
|
|
80
|
+
kind: 'identity',
|
|
81
|
+
name: String(fm.name || fm.slug || name),
|
|
82
|
+
slug: String(fm.slug || name),
|
|
83
|
+
description: null,
|
|
84
|
+
sourcePath: `.agents/identities/${name}`,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return { skills, identities, wiki: scanRepoWiki(dir) };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Scan <dir>/.wiki/**.md. One entry per page; `index.md` is skipped at every
|
|
94
|
+
* level because Drafted SYNTHESIZES it on read (a reserved path, never a stored
|
|
95
|
+
* page) — indexing it would shadow the synthesis with a stale copy.
|
|
96
|
+
*/
|
|
97
|
+
export function scanRepoWiki(dir) {
|
|
98
|
+
const root = join(dir, '.wiki');
|
|
99
|
+
if (!existsSync(root)) return [];
|
|
100
|
+
const pages = [];
|
|
101
|
+
for (const file of walkMarkdown(root)) {
|
|
102
|
+
const rel = relative(root, file).split(sep).join('/');
|
|
103
|
+
if (rel.split('/').pop() === 'index.md') continue;
|
|
104
|
+
const text = readFileSync(file, 'utf8');
|
|
105
|
+
const fm = parseFrontmatter(text) || {};
|
|
106
|
+
const slug = rel.replace(/\.md$/, '');
|
|
107
|
+
pages.push({
|
|
108
|
+
kind: 'wiki',
|
|
109
|
+
name: String(fm.title || firstHeading(text) || slug.split('/').pop()),
|
|
110
|
+
slug,
|
|
111
|
+
description: fm.description != null ? String(fm.description) : '',
|
|
112
|
+
sourcePath: `.wiki/${rel}`,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
return pages.sort((a, b) => a.slug.localeCompare(b.slug));
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function firstHeading(text) {
|
|
119
|
+
const m = text.match(/^#\s+(.+)$/m);
|
|
120
|
+
return m ? m[1].trim() : null;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Recursively yield every `.md` file under dir, skipping dot-entries. */
|
|
124
|
+
function* walkMarkdown(dir) {
|
|
125
|
+
let entries;
|
|
126
|
+
try {
|
|
127
|
+
entries = readdirSync(dir, { withFileTypes: true });
|
|
128
|
+
} catch {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
for (const e of entries) {
|
|
132
|
+
if (e.name.startsWith('.')) continue;
|
|
133
|
+
const full = join(dir, e.name);
|
|
134
|
+
if (e.isDirectory()) yield* walkMarkdown(full);
|
|
135
|
+
else if (e.isFile() && e.name.endsWith('.md')) yield full;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function readdirSafe(dir) {
|
|
140
|
+
try {
|
|
141
|
+
return readdirSync(dir).filter((n) => !n.startsWith('.'));
|
|
142
|
+
} catch {
|
|
143
|
+
return [];
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// ── Seed-on-link ────────────────────────────────────────────────────
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Classify what seeding a folder's wiki + skills onto a branch would do.
|
|
151
|
+
*
|
|
152
|
+
* Linking is a MIGRATION, not a flag flip: the folder's existing content must
|
|
153
|
+
* land in git BEFORE the folder flips to repo-owned, or every page and skill it
|
|
154
|
+
* already holds becomes unauthorable and shadowed. So a path already on the
|
|
155
|
+
* branch is a CONFLICT — refuse the link and list them — unless the content is
|
|
156
|
+
* identical, which makes it a no-op and keeps `link -> detach -> link` idempotent.
|
|
157
|
+
*
|
|
158
|
+
* @param {Map<string,string>|object} existing branch path -> file content
|
|
159
|
+
* @param {{path:string, content:string}[]} seed what the folder would write
|
|
160
|
+
* @returns {{creates:string[], identical:string[], conflicts:string[]}}
|
|
161
|
+
*/
|
|
162
|
+
export function classifySeed(existing, seed) {
|
|
163
|
+
const get = existing instanceof Map ? (p) => existing.get(p) : (p) => existing?.[p];
|
|
164
|
+
const out = { creates: [], identical: [], conflicts: [] };
|
|
165
|
+
for (const f of seed || []) {
|
|
166
|
+
const there = get(f.path);
|
|
167
|
+
if (there === undefined || there === null) out.creates.push(f.path);
|
|
168
|
+
else if (sameContent(there, f.content)) out.identical.push(f.path);
|
|
169
|
+
else out.conflicts.push(f.path);
|
|
170
|
+
}
|
|
171
|
+
return out;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// ponytail: byte equality modulo line endings and trailing blank space. Enough
|
|
175
|
+
// to make a re-link a no-op; if a semantic (frontmatter-order) diff ever matters,
|
|
176
|
+
// compare parsed OKF instead.
|
|
177
|
+
function sameContent(a, b) {
|
|
178
|
+
const norm = (s) => String(s ?? '').replace(/\r\n/g, '\n').replace(/\s+$/, '');
|
|
179
|
+
return norm(a) === norm(b);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** Best-effort default branch of a git checkout. 'main' if git is unavailable. */
|
|
183
|
+
export function detectDefaultBranch(dir) {
|
|
184
|
+
try {
|
|
185
|
+
const out = execSync('git rev-parse --abbrev-ref HEAD', {
|
|
186
|
+
cwd: dir,
|
|
187
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
188
|
+
encoding: 'utf8',
|
|
189
|
+
});
|
|
190
|
+
const branch = out.trim();
|
|
191
|
+
return branch || 'main';
|
|
192
|
+
} catch {
|
|
193
|
+
return 'main';
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** Remote origin URL of a git checkout, or null. */
|
|
198
|
+
export function detectRemoteUrl(dir) {
|
|
199
|
+
try {
|
|
200
|
+
const out = execSync('git config --get remote.origin.url', {
|
|
201
|
+
cwd: dir,
|
|
202
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
203
|
+
encoding: 'utf8',
|
|
204
|
+
});
|
|
205
|
+
const url = out.trim();
|
|
206
|
+
return url || null;
|
|
207
|
+
} catch {
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** True if the argument looks like a git URL (not a local path). */
|
|
213
|
+
export function isGitUrl(s) {
|
|
214
|
+
return /^(https?:|git@|ssh:\/\/|git:\/\/)/.test(s);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** Clone a git URL into a fresh temp dir, returning { dir, cleanup }.
|
|
218
|
+
* When `branch` is given, clone that branch only (--branch --single-branch) so a
|
|
219
|
+
* missing branch fails loudly instead of silently landing on the default. */
|
|
220
|
+
export function cloneToTemp(url, branch) {
|
|
221
|
+
const dir = mkdtempSync(join(tmpdir(), 'drafted-repo-'));
|
|
222
|
+
const branchArgs = branch ? `--branch ${shquote(branch)} --single-branch` : '';
|
|
223
|
+
execSync(`git clone --depth 1 ${branchArgs} ${shquote(url)} ${shquote(dir)}`, {
|
|
224
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
225
|
+
encoding: 'utf8',
|
|
226
|
+
});
|
|
227
|
+
return {
|
|
228
|
+
dir,
|
|
229
|
+
cleanup: () => {
|
|
230
|
+
try { execSync(`rm -rf ${shquote(dir)}`, { stdio: 'ignore' }); } catch { /* best effort */ }
|
|
231
|
+
},
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// Minimal shell quoting — clone targets are user-supplied URLs. We only pass
|
|
236
|
+
// them to git as a single argv via execSync through a shell string, so quote to
|
|
237
|
+
// avoid metacharacter injection. (The URL is also validated by git itself.)
|
|
238
|
+
function shquote(s) {
|
|
239
|
+
return `'${String(s).replace(/'/g, "'\\''")}'`;
|
|
240
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether `drafted skill sync` may run a skill's `setup:` (shell on this machine)
|
|
3
|
+
* without --allow-untrusted-setup.
|
|
4
|
+
*
|
|
5
|
+
* Only when YOU were the last to change the setup or any supporting file
|
|
6
|
+
* (`setupBy`, recorded by the server), the skill is not a fork (a fork carries
|
|
7
|
+
* another author's setup), and — if the ref pinned a hash — the bytes still match
|
|
8
|
+
* it. `createdBy` is not enough: any org member can edit another author's setup
|
|
9
|
+
* while createdBy stays the author (audit 2026-10-13). No setupBy (an older server,
|
|
10
|
+
* or an edit with no known editor) fails closed.
|
|
11
|
+
*/
|
|
12
|
+
export function setupTrusted(skill, { userId, pinnedHash } = {}) {
|
|
13
|
+
if (!userId || !skill?.setupBy || skill.setupBy !== userId) return false;
|
|
14
|
+
if (skill.forkedFrom) return false;
|
|
15
|
+
if (pinnedHash && !String(skill.hash || '').startsWith(pinnedHash)) return false;
|
|
16
|
+
return true;
|
|
17
|
+
}
|