openalmanac 0.2.54 → 0.2.56
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/dist/cli.js +0 -0
- package/dist/server.js +17 -17
- package/dist/setup.js +0 -3
- package/dist/tools/pages.d.ts +2 -0
- package/dist/tools/pages.js +351 -0
- package/dist/tools/topics.d.ts +2 -0
- package/dist/tools/topics.js +67 -0
- package/dist/tools/wikis.d.ts +2 -0
- package/dist/tools/wikis.js +94 -0
- package/dist/validate.js +5 -12
- package/package.json +1 -1
- package/dist/tools/articles.d.ts +0 -2
- package/dist/tools/articles.js +0 -508
- package/dist/tools/communities.d.ts +0 -2
- package/dist/tools/communities.js +0 -101
- package/dist/tools/people.d.ts +0 -2
- package/dist/tools/people.js +0 -20
package/package.json
CHANGED
package/dist/tools/articles.d.ts
DELETED
package/dist/tools/articles.js
DELETED
|
@@ -1,508 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import { readFileSync, writeFileSync, mkdirSync, readdirSync, statSync, existsSync, unlinkSync } from "node:fs";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
import { stringify as yamlStringify } from "yaml";
|
|
5
|
-
import { request, ARTICLES_DIR } from "../auth.js";
|
|
6
|
-
import { validateArticle, parseFrontmatter } from "../validate.js";
|
|
7
|
-
import { openBrowser } from "../browser.js";
|
|
8
|
-
const SLUG_RE = /^[a-z0-9]+(-[a-z0-9]+)*$/;
|
|
9
|
-
function slugify(title) {
|
|
10
|
-
return title
|
|
11
|
-
.toLowerCase()
|
|
12
|
-
.normalize("NFD")
|
|
13
|
-
.replace(/[\u0300-\u036f]/g, "")
|
|
14
|
-
.replace(/[^a-z0-9]+/g, "-")
|
|
15
|
-
.replace(/^-+|-+$/g, "")
|
|
16
|
-
.replace(/-{2,}/g, "-");
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Workaround for Claude Agent SDK MCP transport bug (#18260):
|
|
20
|
-
* Array/object parameters are sometimes serialized as JSON strings
|
|
21
|
-
* instead of native values. This preprocessor coerces them back.
|
|
22
|
-
*/
|
|
23
|
-
function coerceJson(schema) {
|
|
24
|
-
return z.preprocess((val) => {
|
|
25
|
-
if (typeof val === "string") {
|
|
26
|
-
try {
|
|
27
|
-
return JSON.parse(val);
|
|
28
|
-
}
|
|
29
|
-
catch {
|
|
30
|
-
return val;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return val;
|
|
34
|
-
}, schema);
|
|
35
|
-
}
|
|
36
|
-
const WRITING_GUIDE = `
|
|
37
|
-
## Article structure
|
|
38
|
-
|
|
39
|
-
\`\`\`yaml
|
|
40
|
-
---
|
|
41
|
-
article_id: the-slug
|
|
42
|
-
title: Article Title
|
|
43
|
-
sources:
|
|
44
|
-
- key: example-source-title
|
|
45
|
-
url: https://example.com
|
|
46
|
-
title: Source Title
|
|
47
|
-
accessed_date: "2025-01-15"
|
|
48
|
-
infobox:
|
|
49
|
-
header:
|
|
50
|
-
image_url: https://... # optional hero image
|
|
51
|
-
subtitle: Short tagline
|
|
52
|
-
details:
|
|
53
|
-
- key: Born
|
|
54
|
-
value: January 1, 1990
|
|
55
|
-
- key: Occupation
|
|
56
|
-
value: Scientist
|
|
57
|
-
links:
|
|
58
|
-
- https://example.com
|
|
59
|
-
sections:
|
|
60
|
-
- type: timeline # chronological events
|
|
61
|
-
title: Career Timeline
|
|
62
|
-
items:
|
|
63
|
-
- primary: "Started company"
|
|
64
|
-
period: "2010"
|
|
65
|
-
location: "San Francisco"
|
|
66
|
-
- type: list # key figures, works, features
|
|
67
|
-
title: Known For
|
|
68
|
-
items:
|
|
69
|
-
- title: First achievement
|
|
70
|
-
- title: Second achievement
|
|
71
|
-
subtitle: Additional detail
|
|
72
|
-
- type: tags # inline tags/chips
|
|
73
|
-
title: Genres
|
|
74
|
-
items:
|
|
75
|
-
- Rock
|
|
76
|
-
- Jazz
|
|
77
|
-
- type: grid # image grid
|
|
78
|
-
title: Gallery
|
|
79
|
-
items:
|
|
80
|
-
- title: Caption
|
|
81
|
-
image_url: https://...
|
|
82
|
-
- type: table # structured comparison
|
|
83
|
-
title: Statistics
|
|
84
|
-
items:
|
|
85
|
-
headers:
|
|
86
|
-
- Name
|
|
87
|
-
- Value
|
|
88
|
-
rows:
|
|
89
|
-
- cells:
|
|
90
|
-
- Height
|
|
91
|
-
- "6'2\\""
|
|
92
|
-
- type: key_value # simple key-value pairs
|
|
93
|
-
title: Quick Facts
|
|
94
|
-
items:
|
|
95
|
-
- key: Population
|
|
96
|
-
value: "1.4 billion"
|
|
97
|
-
---
|
|
98
|
-
|
|
99
|
-
Article body with [@key] citation markers...
|
|
100
|
-
\`\`\`
|
|
101
|
-
|
|
102
|
-
## Infobox
|
|
103
|
-
|
|
104
|
-
Include an infobox for any article about a person, place, organization, event, or concept. Pick the section types that fit — you don't need all six.
|
|
105
|
-
|
|
106
|
-
## Citations
|
|
107
|
-
|
|
108
|
-
- Mark claims with [@key] after punctuation: "The population is 1.4 billion.[@who-world-population]"
|
|
109
|
-
- Keys must be kebab-case with at least one hyphen (e.g. 'nytimes-climate-report', 'who-malaria-2024')
|
|
110
|
-
- Generate keys BibTeX-style: {domain}-{title-words} (e.g. 'arxiv-attention-is-all')
|
|
111
|
-
- Every source in the sources list must be referenced at least once in the body with [@key]
|
|
112
|
-
- Every [@key] marker must have a matching source with that key
|
|
113
|
-
- Display numbers are computed automatically from first-appearance order — just use the keys
|
|
114
|
-
|
|
115
|
-
## Images
|
|
116
|
-
|
|
117
|
-
Use search_images to find relevant images. Images render as figures with visible captions.
|
|
118
|
-
|
|
119
|
-
**Syntax:** \`\`
|
|
120
|
-
|
|
121
|
-
Positions: \`"right"\` (default if omitted), \`"left"\`, \`"center"\`
|
|
122
|
-
|
|
123
|
-
\`\`\`markdown
|
|
124
|
-

|
|
125
|
-
|
|
126
|
-
The early life of Alan Turing began...
|
|
127
|
-
|
|
128
|
-

|
|
129
|
-
\`\`\`
|
|
130
|
-
|
|
131
|
-
**Caption rules:**
|
|
132
|
-
- Every image MUST have a descriptive caption — it is displayed below the image
|
|
133
|
-
- Describe what the image shows: "Alan Turing in 1930, aged 18" not "Photo"
|
|
134
|
-
- Include dates, context, or attribution when relevant
|
|
135
|
-
|
|
136
|
-
**Placement:** 1-3 images per major section, spread throughout. First image near the top.
|
|
137
|
-
For the infobox hero image, use \`infobox.header.image_url\` in frontmatter instead.
|
|
138
|
-
|
|
139
|
-
External image URLs are auto-persisted on publish — no extra steps needed.
|
|
140
|
-
|
|
141
|
-
## Writing quality
|
|
142
|
-
|
|
143
|
-
- Every sentence should contain a specific fact the reader didn't know
|
|
144
|
-
- No filler phrases ("It is worth noting", "In today's world", "Throughout history")
|
|
145
|
-
- No promotional language ("revolutionary", "groundbreaking", "game-changing")
|
|
146
|
-
- No inflated significance ("one of the most important", "changed the world forever")
|
|
147
|
-
- No vague attribution ("many experts say", "it is widely regarded")
|
|
148
|
-
- No formulaic conclusions ("In conclusion", "continues to shape")
|
|
149
|
-
- Write like a concise encyclopedia, not a blog post
|
|
150
|
-
`.trim();
|
|
151
|
-
function ensureArticlesDir() {
|
|
152
|
-
mkdirSync(ARTICLES_DIR, { recursive: true });
|
|
153
|
-
}
|
|
154
|
-
function resolveArticleDir(communitySlug) {
|
|
155
|
-
return communitySlug ? join(ARTICLES_DIR, communitySlug) : ARTICLES_DIR;
|
|
156
|
-
}
|
|
157
|
-
function resolveArticlePaths(slug, communitySlug) {
|
|
158
|
-
const dir = resolveArticleDir(communitySlug);
|
|
159
|
-
return {
|
|
160
|
-
dir,
|
|
161
|
-
filePath: join(dir, `${slug}.md`),
|
|
162
|
-
originalPath: join(dir, `.${slug}.original.md`),
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
function findDraftCandidates(slug) {
|
|
166
|
-
const matches = [];
|
|
167
|
-
const root = resolveArticlePaths(slug);
|
|
168
|
-
if (existsSync(root.filePath)) {
|
|
169
|
-
matches.push({ communitySlug: null, filePath: root.filePath, originalPath: root.originalPath });
|
|
170
|
-
}
|
|
171
|
-
try {
|
|
172
|
-
const dirs = readdirSync(ARTICLES_DIR).filter((d) => {
|
|
173
|
-
try {
|
|
174
|
-
return statSync(join(ARTICLES_DIR, d)).isDirectory();
|
|
175
|
-
}
|
|
176
|
-
catch {
|
|
177
|
-
return false;
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
for (const communitySlug of dirs) {
|
|
181
|
-
const scoped = resolveArticlePaths(slug, communitySlug);
|
|
182
|
-
if (existsSync(scoped.filePath)) {
|
|
183
|
-
matches.push({ communitySlug, filePath: scoped.filePath, originalPath: scoped.originalPath });
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
catch { /* ignore readdir errors */ }
|
|
188
|
-
return matches;
|
|
189
|
-
}
|
|
190
|
-
function resolvePublishCandidate(slug, communitySlug) {
|
|
191
|
-
if (communitySlug) {
|
|
192
|
-
const paths = resolveArticlePaths(slug, communitySlug);
|
|
193
|
-
if (!existsSync(paths.filePath)) {
|
|
194
|
-
throw new Error(`File not found: ${paths.filePath}\nUse download to get an existing article or new to create a scaffold.`);
|
|
195
|
-
}
|
|
196
|
-
return { communitySlug, ...paths };
|
|
197
|
-
}
|
|
198
|
-
const matches = findDraftCandidates(slug);
|
|
199
|
-
if (matches.length === 0) {
|
|
200
|
-
const fallback = resolveArticlePaths(slug);
|
|
201
|
-
throw new Error(`File not found: ${fallback.filePath}\nUse download to get an existing article or new to create a scaffold.`);
|
|
202
|
-
}
|
|
203
|
-
if (matches.length > 1) {
|
|
204
|
-
const paths = matches.map((match) => ` - ${match.filePath}`).join("\n");
|
|
205
|
-
throw new Error(`Multiple local drafts found for slug "${slug}". Publish is ambiguous.\n${paths}\nRemove the duplicate draft or publish with community_slug set.`);
|
|
206
|
-
}
|
|
207
|
-
return matches[0];
|
|
208
|
-
}
|
|
209
|
-
export function registerArticleTools(server) {
|
|
210
|
-
server.addTool({
|
|
211
|
-
name: "search_articles",
|
|
212
|
-
description: "Search existing OpenAlmanac articles and stubs. Accepts multiple queries for batch lookup. " +
|
|
213
|
-
"Use this to check if articles or stubs exist before creating them, or to find entity slugs for wikilinks. " +
|
|
214
|
-
"Results include 'stub' field (true/false) and 'entity_type' field. No authentication needed.",
|
|
215
|
-
parameters: z.object({
|
|
216
|
-
queries: coerceJson(z.array(z.string()).min(1).max(20)).describe("Search queries (1-20)"),
|
|
217
|
-
limit: z.number().default(5).describe("Max results per query (1-50, default 5)"),
|
|
218
|
-
include_stubs: z.boolean().default(true).describe("Include stub articles in results (default true)"),
|
|
219
|
-
}),
|
|
220
|
-
async execute({ queries, limit, include_stubs }) {
|
|
221
|
-
const resp = await request("POST", "/api/search/batch", {
|
|
222
|
-
json: { queries, limit, include_stubs },
|
|
223
|
-
});
|
|
224
|
-
return JSON.stringify(await resp.json(), null, 2);
|
|
225
|
-
},
|
|
226
|
-
});
|
|
227
|
-
server.addTool({
|
|
228
|
-
name: "read",
|
|
229
|
-
description: "Read article content from OpenAlmanac. Returns the content, sources, and metadata for each slug. " +
|
|
230
|
-
"Use this to reference or summarize existing articles in conversation. " +
|
|
231
|
-
"For editing articles locally, use 'download' instead. No authentication needed.",
|
|
232
|
-
parameters: z.object({
|
|
233
|
-
slugs: coerceJson(z.array(z.string()).min(1).max(20)).describe("Article slugs to read (1-20)"),
|
|
234
|
-
community_slug: z.string().optional().describe("Community slug for reading community-owned wiki articles. Omit for global almanac articles."),
|
|
235
|
-
}),
|
|
236
|
-
async execute({ slugs, community_slug }) {
|
|
237
|
-
const json = { slugs };
|
|
238
|
-
if (community_slug)
|
|
239
|
-
json.community_slug = community_slug;
|
|
240
|
-
const resp = await request("POST", "/api/articles/batch", { json });
|
|
241
|
-
return JSON.stringify(await resp.json(), null, 2);
|
|
242
|
-
},
|
|
243
|
-
});
|
|
244
|
-
server.addTool({
|
|
245
|
-
name: "download",
|
|
246
|
-
description: "Download articles to your local workspace for editing. " +
|
|
247
|
-
"Global articles: ~/.openalmanac/articles/{slug}.md. Community wiki: ~/.openalmanac/articles/{community_slug}/{slug}.md. " +
|
|
248
|
-
"Returns a writing guide on first call. After editing, use publish to push changes.",
|
|
249
|
-
parameters: z.object({
|
|
250
|
-
slugs: coerceJson(z.array(z.string()).min(1).max(50)).describe("Article slugs to download (1-50)"),
|
|
251
|
-
community_slug: z.string().optional().describe("Community slug for community-owned wiki articles"),
|
|
252
|
-
}),
|
|
253
|
-
async execute({ slugs, community_slug }) {
|
|
254
|
-
for (const slug of slugs) {
|
|
255
|
-
if (!SLUG_RE.test(slug)) {
|
|
256
|
-
throw new Error(`Invalid slug "${slug}". Must be kebab-case (e.g. 'machine-learning').`);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
const json = { slugs };
|
|
260
|
-
if (community_slug)
|
|
261
|
-
json.community_slug = community_slug;
|
|
262
|
-
const resp = await request("POST", "/api/articles/batch-download", { json });
|
|
263
|
-
const data = (await resp.json());
|
|
264
|
-
ensureArticlesDir();
|
|
265
|
-
const lines = [];
|
|
266
|
-
for (const slug of slugs) {
|
|
267
|
-
if (data.errors[slug]) {
|
|
268
|
-
lines.push(`FAILED ${slug}: ${data.errors[slug]}`);
|
|
269
|
-
continue;
|
|
270
|
-
}
|
|
271
|
-
const markdown = data.articles[slug];
|
|
272
|
-
if (!markdown) {
|
|
273
|
-
lines.push(`FAILED ${slug}: missing from response`);
|
|
274
|
-
continue;
|
|
275
|
-
}
|
|
276
|
-
const { dir, filePath, originalPath } = resolveArticlePaths(slug, community_slug);
|
|
277
|
-
if (community_slug) {
|
|
278
|
-
mkdirSync(dir, { recursive: true });
|
|
279
|
-
}
|
|
280
|
-
writeFileSync(filePath, markdown, "utf-8");
|
|
281
|
-
writeFileSync(originalPath, markdown, "utf-8");
|
|
282
|
-
const { frontmatter, content } = parseFrontmatter(markdown);
|
|
283
|
-
const title = frontmatter.title || "(untitled)";
|
|
284
|
-
const wordCount = content.trim().split(/\s+/).filter(Boolean).length;
|
|
285
|
-
const isStub = frontmatter.stub === true;
|
|
286
|
-
const stubNote = isStub
|
|
287
|
-
? "\n\nThis is a STUB article — a placeholder that hasn't been fully written yet. " +
|
|
288
|
-
"Fill in the content body with a complete article, then push to publish."
|
|
289
|
-
: "";
|
|
290
|
-
lines.push(`Downloaded "${title}" to ${filePath}\n${wordCount} words, ${frontmatter.sources?.length ?? 0} sources.${stubNote}`);
|
|
291
|
-
}
|
|
292
|
-
return [lines.join("\n"), "", WRITING_GUIDE].join("\n");
|
|
293
|
-
},
|
|
294
|
-
});
|
|
295
|
-
server.addTool({
|
|
296
|
-
name: "new",
|
|
297
|
-
description: "Scaffold new articles locally. Creates .md files with YAML frontmatter and empty bodies. " +
|
|
298
|
-
"Provide explicit slugs when you know the canonical ID; otherwise they are auto-derived from titles. For community wiki articles, provide community_slug. " +
|
|
299
|
-
"After writing content, use publish to go live.",
|
|
300
|
-
parameters: z.object({
|
|
301
|
-
articles: coerceJson(z.array(z.object({
|
|
302
|
-
title: z.string().describe("Article title"),
|
|
303
|
-
slug: z.string().optional().describe("Optional explicit kebab-case slug. Encouraged when you know the canonical ID."),
|
|
304
|
-
topics: z.array(z.string()).optional().describe("Topic slugs for community wiki articles"),
|
|
305
|
-
})).min(1).max(50)).describe("Articles to scaffold (1-50)"),
|
|
306
|
-
community_slug: z.string().optional().describe("Community slug for community-owned wiki articles"),
|
|
307
|
-
}),
|
|
308
|
-
async execute({ articles, community_slug }) {
|
|
309
|
-
if (community_slug && !SLUG_RE.test(community_slug)) {
|
|
310
|
-
throw new Error(`Invalid community_slug "${community_slug}". Must be kebab-case.`);
|
|
311
|
-
}
|
|
312
|
-
ensureArticlesDir();
|
|
313
|
-
let dir = ARTICLES_DIR;
|
|
314
|
-
if (community_slug) {
|
|
315
|
-
dir = join(ARTICLES_DIR, community_slug);
|
|
316
|
-
mkdirSync(dir, { recursive: true });
|
|
317
|
-
}
|
|
318
|
-
const created = [];
|
|
319
|
-
const skipped = [];
|
|
320
|
-
for (const item of articles) {
|
|
321
|
-
const slug = item.slug || slugify(item.title);
|
|
322
|
-
if (!slug) {
|
|
323
|
-
skipped.push(`(empty slug from title: "${item.title}")`);
|
|
324
|
-
continue;
|
|
325
|
-
}
|
|
326
|
-
if (!SLUG_RE.test(slug)) {
|
|
327
|
-
skipped.push(`"${item.title}" → invalid slug "${slug}"`);
|
|
328
|
-
continue;
|
|
329
|
-
}
|
|
330
|
-
const filePath = join(dir, `${slug}.md`);
|
|
331
|
-
if (existsSync(filePath)) {
|
|
332
|
-
skipped.push(`${slug}.md already exists — skipped`);
|
|
333
|
-
continue;
|
|
334
|
-
}
|
|
335
|
-
const meta = { article_id: slug, title: item.title };
|
|
336
|
-
if (community_slug)
|
|
337
|
-
meta.community_slug = community_slug;
|
|
338
|
-
if (item.topics && item.topics.length > 0)
|
|
339
|
-
meta.topics = item.topics;
|
|
340
|
-
meta.sources = [];
|
|
341
|
-
const frontmatter = yamlStringify(meta);
|
|
342
|
-
const scaffold = `---\n${frontmatter}---\n\n`;
|
|
343
|
-
writeFileSync(filePath, scaffold, "utf-8");
|
|
344
|
-
created.push(filePath);
|
|
345
|
-
}
|
|
346
|
-
const parts = [
|
|
347
|
-
created.length > 0 ? `Created ${created.length} file(s):\n${created.map((p) => ` - ${p}`).join("\n")}` : "No new files created.",
|
|
348
|
-
skipped.length > 0 ? `Skipped:\n${skipped.map((s) => ` - ${s}`).join("\n")}` : "",
|
|
349
|
-
WRITING_GUIDE,
|
|
350
|
-
];
|
|
351
|
-
return parts.filter(Boolean).join("\n\n");
|
|
352
|
-
},
|
|
353
|
-
});
|
|
354
|
-
server.addTool({
|
|
355
|
-
name: "publish",
|
|
356
|
-
description: "Validate and publish articles from your local workspace. " +
|
|
357
|
-
"Provide specific slugs, or a community_slug to publish all articles in that community folder. " +
|
|
358
|
-
"Empty-body files become stubs. Dead wikilinks auto-create stubs on the server. " +
|
|
359
|
-
"Put edit_summary in frontmatter for per-article change descriptions. Requires login.",
|
|
360
|
-
parameters: z.object({
|
|
361
|
-
slugs: coerceJson(z.array(z.string()).min(1).max(50)).optional()
|
|
362
|
-
.describe("Specific article slugs to publish"),
|
|
363
|
-
community_slug: z.string().optional()
|
|
364
|
-
.describe("Publish all .md files in this community folder under ~/.openalmanac/articles/"),
|
|
365
|
-
}),
|
|
366
|
-
async execute({ slugs, community_slug }) {
|
|
367
|
-
if (!slugs?.length && !community_slug) {
|
|
368
|
-
throw new Error("Provide slugs or community_slug (explicit intent required).");
|
|
369
|
-
}
|
|
370
|
-
const tasks = [];
|
|
371
|
-
if (community_slug && !slugs?.length) {
|
|
372
|
-
if (!SLUG_RE.test(community_slug)) {
|
|
373
|
-
throw new Error(`Invalid community_slug "${community_slug}". Must be kebab-case.`);
|
|
374
|
-
}
|
|
375
|
-
const dir = join(ARTICLES_DIR, community_slug);
|
|
376
|
-
if (!existsSync(dir)) {
|
|
377
|
-
throw new Error(`Community folder not found: ${dir}`);
|
|
378
|
-
}
|
|
379
|
-
const files = readdirSync(dir).filter((f) => f.endsWith(".md") && !f.startsWith("."));
|
|
380
|
-
if (files.length === 0) {
|
|
381
|
-
throw new Error(`No .md files in ${dir}`);
|
|
382
|
-
}
|
|
383
|
-
for (const f of files) {
|
|
384
|
-
const slug = f.replace(/\.md$/i, "");
|
|
385
|
-
tasks.push({ slug, communitySlug: community_slug, ...resolveArticlePaths(slug, community_slug) });
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
else if (slugs?.length) {
|
|
389
|
-
for (const slug of slugs) {
|
|
390
|
-
if (!SLUG_RE.test(slug)) {
|
|
391
|
-
throw new Error(`Invalid slug "${slug}". Must be kebab-case (e.g. 'machine-learning').`);
|
|
392
|
-
}
|
|
393
|
-
tasks.push({ slug, ...resolvePublishCandidate(slug, community_slug ?? undefined) });
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
const validationLines = [];
|
|
397
|
-
const validArticles = [];
|
|
398
|
-
for (const task of tasks) {
|
|
399
|
-
const raw = readFileSync(task.filePath, "utf-8");
|
|
400
|
-
const errors = validateArticle(raw);
|
|
401
|
-
if (errors.length > 0) {
|
|
402
|
-
const lines = errors.map((e) => ` ${e.field}: ${e.message}`);
|
|
403
|
-
validationLines.push(`FAILED ${task.slug}: Validation failed (${errors.length} error${errors.length > 1 ? "s" : ""}):\n${lines.join("\n")}`);
|
|
404
|
-
}
|
|
405
|
-
else {
|
|
406
|
-
validArticles.push({ slug: task.slug, markdown: raw });
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
const inGui = process.env.OPENALMANAC_GUI === "1";
|
|
410
|
-
const resultLines = [...validationLines];
|
|
411
|
-
let okCount = 0;
|
|
412
|
-
if (validArticles.length > 0) {
|
|
413
|
-
const resp = await request("POST", "/api/articles/batch-publish", {
|
|
414
|
-
auth: true,
|
|
415
|
-
json: { articles: validArticles },
|
|
416
|
-
});
|
|
417
|
-
const data = (await resp.json());
|
|
418
|
-
for (const r of data.results) {
|
|
419
|
-
if (r.status === "failed") {
|
|
420
|
-
resultLines.push(`FAILED ${r.slug}: ${r.error ?? "unknown error"}`);
|
|
421
|
-
continue;
|
|
422
|
-
}
|
|
423
|
-
okCount += 1;
|
|
424
|
-
const task = tasks.find((t) => t.slug === r.slug);
|
|
425
|
-
if (task) {
|
|
426
|
-
try {
|
|
427
|
-
unlinkSync(task.filePath);
|
|
428
|
-
}
|
|
429
|
-
catch (e) {
|
|
430
|
-
if (e.code !== "ENOENT") {
|
|
431
|
-
resultLines.push(`Note: could not remove local draft for ${r.slug}: ${e.message}`);
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
try {
|
|
435
|
-
unlinkSync(task.originalPath);
|
|
436
|
-
}
|
|
437
|
-
catch (e) {
|
|
438
|
-
if (e.code !== "ENOENT") {
|
|
439
|
-
resultLines.push(`Note: could not remove original copy for ${r.slug}: ${e.message}`);
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
resultLines.push(`OK ${r.slug}: ${r.status}\n${JSON.stringify(r, null, 2)}`);
|
|
444
|
-
if (!inGui && tasks.length === 1 && r.canonical_path) {
|
|
445
|
-
const articleUrl = `https://www.openalmanac.org${r.canonical_path}?celebrate=true`;
|
|
446
|
-
openBrowser(articleUrl);
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
const urlHint = inGui
|
|
451
|
-
? "\n\nThe article(s) have been published! Let the user know they're live. Do not send them to a web URL."
|
|
452
|
-
: tasks.length > 1
|
|
453
|
-
? "\n\n(Opening browser skipped for batch publish — share URLs from results above.)"
|
|
454
|
-
: "";
|
|
455
|
-
return `Published ${okCount}/${tasks.length}.\n\n${resultLines.join("\n\n")}${urlHint}`;
|
|
456
|
-
},
|
|
457
|
-
});
|
|
458
|
-
server.addTool({
|
|
459
|
-
name: "list_articles",
|
|
460
|
-
description: "Browse a community's wiki articles. Structured listing, not fuzzy search. " +
|
|
461
|
-
"Use this to see what exists, find stubs to fill, or discover most-referenced gaps.",
|
|
462
|
-
parameters: z.object({
|
|
463
|
-
community_slug: z.string().describe("Community slug"),
|
|
464
|
-
topic: z.string().optional().describe("Filter by topic slug"),
|
|
465
|
-
sort: z.enum(["recent", "most_referenced"]).default("recent").describe("Sort order"),
|
|
466
|
-
stubs_only: z.boolean().default(false).describe("Only return stubs"),
|
|
467
|
-
limit: z.number().min(1).max(200).default(50).describe("Max results (1-200)"),
|
|
468
|
-
}),
|
|
469
|
-
async execute({ community_slug, topic, sort, stubs_only, limit }) {
|
|
470
|
-
const params = { sort, stubs_only, limit };
|
|
471
|
-
if (topic)
|
|
472
|
-
params.topic = topic;
|
|
473
|
-
const resp = await request("GET", `/api/communities/${community_slug}/wiki`, { params });
|
|
474
|
-
return JSON.stringify(await resp.json(), null, 2);
|
|
475
|
-
},
|
|
476
|
-
});
|
|
477
|
-
server.addTool({
|
|
478
|
-
name: "propose_article",
|
|
479
|
-
description: "Propose an article before writing it. Call this when you've researched enough and a specific article topic has come into focus. " +
|
|
480
|
-
"Structures your proposal with a user-facing summary and a detailed brief. " +
|
|
481
|
-
"The client environment determines what happens next — in GUI environments the user sees a plan card with options, " +
|
|
482
|
-
"in CLI environments you'll get a response telling you to proceed with writing. " +
|
|
483
|
-
"Do not start writing an article without proposing first.",
|
|
484
|
-
parameters: z.object({
|
|
485
|
-
summary: z.string().describe("User-facing summary: title, key sections, angle. Markdown. Concise — 3-5 bullet points."),
|
|
486
|
-
details: z.string().describe("Full handoff brief for the background agent. Include: all sources, key facts, user preferences, angle, what to avoid, related articles. Be thorough."),
|
|
487
|
-
title: z.string().describe("Proposed article title"),
|
|
488
|
-
slug: z.string().describe("Proposed article slug (kebab-case)"),
|
|
489
|
-
_userChoice: z.enum(["background", "here", "expired", "already_in_progress"]).optional().describe("Internal field set by GUI client. Never set this manually."),
|
|
490
|
-
}),
|
|
491
|
-
async execute({ summary, details, title, slug, _userChoice }) {
|
|
492
|
-
if (!SLUG_RE.test(slug)) {
|
|
493
|
-
throw new Error(`Invalid slug "${slug}". Must be kebab-case (e.g. 'machine-learning'). Pattern: ^[a-z0-9]+(-[a-z0-9]+)*$`);
|
|
494
|
-
}
|
|
495
|
-
if (_userChoice === "background") {
|
|
496
|
-
return `Article "${title}" is now being written in a background process. Continue exploring with the user. Do not write this article in this conversation.`;
|
|
497
|
-
}
|
|
498
|
-
if (_userChoice === "expired") {
|
|
499
|
-
return `The user navigated away before responding to the proposal. Proposal expired. Continue the conversation naturally.`;
|
|
500
|
-
}
|
|
501
|
-
if (_userChoice === "already_in_progress") {
|
|
502
|
-
return `Article "${title}" is already being generated in a background process. No action needed.`;
|
|
503
|
-
}
|
|
504
|
-
// "here" OR no _userChoice (CLI default) — proceed with writing
|
|
505
|
-
return `Article Proposal: ${title}\n\n${summary}\n\nProceed with writing this article following the writing flow in your instructions.`;
|
|
506
|
-
},
|
|
507
|
-
});
|
|
508
|
-
}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import { request } from "../auth.js";
|
|
3
|
-
export function registerCommunityTools(server) {
|
|
4
|
-
server.addTool({
|
|
5
|
-
name: "search_communities",
|
|
6
|
-
description: "Search or list OpenAlmanac communities. Returns community names, descriptions, and member counts. " +
|
|
7
|
-
"Use this to discover communities by topic. No authentication needed.",
|
|
8
|
-
parameters: z.object({
|
|
9
|
-
query: z
|
|
10
|
-
.string()
|
|
11
|
-
.optional()
|
|
12
|
-
.describe("Search term (case-insensitive match on name, slug, or description). Omit to list all."),
|
|
13
|
-
sort: z
|
|
14
|
-
.enum(["popular", "newest"])
|
|
15
|
-
.default("popular")
|
|
16
|
-
.describe("Sort order (default: popular)"),
|
|
17
|
-
limit: z
|
|
18
|
-
.number()
|
|
19
|
-
.min(1)
|
|
20
|
-
.max(100)
|
|
21
|
-
.default(20)
|
|
22
|
-
.describe("Max results (1-100, default 20)"),
|
|
23
|
-
}),
|
|
24
|
-
async execute({ query, sort, limit }) {
|
|
25
|
-
const params = { sort, limit };
|
|
26
|
-
if (query)
|
|
27
|
-
params.query = query;
|
|
28
|
-
const resp = await request("GET", "/api/communities", { params });
|
|
29
|
-
const data = (await resp.json());
|
|
30
|
-
const communities = data.communities.map((c) => ({
|
|
31
|
-
slug: c.slug,
|
|
32
|
-
name: c.name,
|
|
33
|
-
description: c.description,
|
|
34
|
-
member_count: c.member_count,
|
|
35
|
-
created_at: c.created_at,
|
|
36
|
-
}));
|
|
37
|
-
return `Found ${data.total} communities:\n\n${JSON.stringify(communities, null, 2)}`;
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
server.addTool({
|
|
41
|
-
name: "create_community",
|
|
42
|
-
description: "Create a new OpenAlmanac community. Requires login and at least 1 published article. " +
|
|
43
|
-
"Communities are spaces where articles can be curated and discussed around a topic.",
|
|
44
|
-
parameters: z.object({
|
|
45
|
-
name: z.string().min(1).max(100).describe("Community name (1-100 chars)"),
|
|
46
|
-
slug: z
|
|
47
|
-
.string()
|
|
48
|
-
.min(1)
|
|
49
|
-
.max(100)
|
|
50
|
-
.regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/)
|
|
51
|
-
.describe("Unique kebab-case identifier (e.g. 'machine-learning')"),
|
|
52
|
-
description: z
|
|
53
|
-
.string()
|
|
54
|
-
.min(1)
|
|
55
|
-
.max(2000)
|
|
56
|
-
.describe("What the community is about (1-2000 chars)"),
|
|
57
|
-
cover_image_url: z.string().url().optional().describe("Hero/banner image URL. Use search_images to find a compelling image first."),
|
|
58
|
-
cover_image_position: z.number().min(0).max(100).optional().describe("Vertical focal point of cover image (0=top, 50=center, 100=bottom)"),
|
|
59
|
-
}),
|
|
60
|
-
async execute({ name, slug, description, cover_image_url, cover_image_position }) {
|
|
61
|
-
const json = { name, slug, description };
|
|
62
|
-
if (cover_image_url)
|
|
63
|
-
json.cover_image_url = cover_image_url;
|
|
64
|
-
if (cover_image_position !== undefined)
|
|
65
|
-
json.cover_image_position = cover_image_position;
|
|
66
|
-
const resp = await request("POST", "/api/communities", {
|
|
67
|
-
auth: true,
|
|
68
|
-
json,
|
|
69
|
-
});
|
|
70
|
-
const data = (await resp.json());
|
|
71
|
-
const communityUrl = `https://www.openalmanac.org/communities/${slug}`;
|
|
72
|
-
return `Community created!\n\nURL: ${communityUrl}\n\n${JSON.stringify(data, null, 2)}`;
|
|
73
|
-
},
|
|
74
|
-
});
|
|
75
|
-
server.addTool({
|
|
76
|
-
name: "create_post",
|
|
77
|
-
description: "Create a post in an OpenAlmanac community. Requires login and community membership. " +
|
|
78
|
-
"If you get a 403 error, you need to join the community first.",
|
|
79
|
-
parameters: z.object({
|
|
80
|
-
community_slug: z.string().describe("Community slug (e.g. 'machine-learning')"),
|
|
81
|
-
title: z.string().min(1).max(300).describe("Post title (1-300 chars)"),
|
|
82
|
-
body: z.string().max(10000).default("").describe("Post body (max 10000 chars)"),
|
|
83
|
-
flair: z
|
|
84
|
-
.enum(["discussion", "article-request", "question", "announcement"])
|
|
85
|
-
.optional()
|
|
86
|
-
.describe("Post flair/category"),
|
|
87
|
-
}),
|
|
88
|
-
async execute({ community_slug, title, body, flair }) {
|
|
89
|
-
const json = { title, body };
|
|
90
|
-
if (flair)
|
|
91
|
-
json.flair = flair;
|
|
92
|
-
const resp = await request("POST", `/api/communities/${community_slug}/posts`, {
|
|
93
|
-
auth: true,
|
|
94
|
-
json,
|
|
95
|
-
});
|
|
96
|
-
const data = (await resp.json());
|
|
97
|
-
const postUrl = `https://www.openalmanac.org/communities/${community_slug}/post/${data.id}`;
|
|
98
|
-
return `Post created!\n\nURL: ${postUrl}\n\n${JSON.stringify(data, null, 2)}`;
|
|
99
|
-
},
|
|
100
|
-
});
|
|
101
|
-
}
|
package/dist/tools/people.d.ts
DELETED
package/dist/tools/people.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import { request } from "../auth.js";
|
|
3
|
-
export function registerPeopleTools(server) {
|
|
4
|
-
server.addTool({
|
|
5
|
-
name: "search_people",
|
|
6
|
-
description: "Search for people to find their canonical slug for linking. Returns candidates with name, headline, " +
|
|
7
|
-
"image, and location. Use the returned slug when creating stubs and [[links]] for people. Requires login.",
|
|
8
|
-
parameters: z.object({
|
|
9
|
-
query: z.string().describe("Search terms (e.g. 'John Smith MIT professor')"),
|
|
10
|
-
limit: z.number().min(1).max(10).default(5).describe("Max results (1-10, default 5)"),
|
|
11
|
-
}),
|
|
12
|
-
async execute({ query, limit }) {
|
|
13
|
-
const resp = await request("GET", "/api/people/search", {
|
|
14
|
-
auth: true,
|
|
15
|
-
params: { query, limit },
|
|
16
|
-
});
|
|
17
|
-
return JSON.stringify(await resp.json(), null, 2);
|
|
18
|
-
},
|
|
19
|
-
});
|
|
20
|
-
}
|