@ghostpaw/questlog 0.8.0 → 0.9.1

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,212 @@
1
+ #!/usr/bin/env node
2
+ import { openQuestlogDb } from './chunk-3B6FMHZU.js';
3
+ import { questlogMcpInstructions } from './chunk-SVWAEAKC.js';
4
+ import { validateInput, isErrorResult, questlogVersion, resolveQuestlogDbPath } from './chunk-KRQDV4KF.js';
5
+ import { questlogSurfaceTools } from './chunk-3Y5F3SMB.js';
6
+
7
+ // src/surfaces/mcp_server.ts
8
+ var MCP_LATEST_PROTOCOL_VERSION = "2026-07-28";
9
+ var MCP_SUPPORTED_PROTOCOL_VERSIONS = [
10
+ MCP_LATEST_PROTOCOL_VERSION,
11
+ "2025-11-25",
12
+ "2025-06-18",
13
+ "2025-03-26",
14
+ "2024-11-05"
15
+ ];
16
+ function createMcpServer(options) {
17
+ let initialized = false;
18
+ let context;
19
+ const serverInfo = { name: options.name, version: options.version };
20
+ const record = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
21
+ const error = (id, code, message, data) => ({
22
+ jsonrpc: "2.0",
23
+ id,
24
+ error: { code, message, ...data === void 0 ? {} : { data } }
25
+ });
26
+ const handleMessage = async (msg) => {
27
+ if (!record(msg) || msg.jsonrpc !== "2.0" || typeof msg.method !== "string" || Object.hasOwn(msg, "id") && msg.id !== null && typeof msg.id !== "string" && typeof msg.id !== "number")
28
+ return error(null, -32600, "Invalid Request");
29
+ if (!Object.hasOwn(msg, "id")) return void 0;
30
+ const id = msg.id;
31
+ if (msg.params !== void 0 && !record(msg.params)) return error(id, -32602, "Invalid params");
32
+ const params = record(msg.params) ? msg.params : {};
33
+ const meta = record(params._meta) ? params._meta : {};
34
+ const requested = meta["io.modelcontextprotocol/protocolVersion"];
35
+ const modern = requested !== void 0;
36
+ if (modern && !MCP_SUPPORTED_PROTOCOL_VERSIONS.includes(
37
+ requested
38
+ ))
39
+ return error(id, -32022, "Unsupported protocol version", {
40
+ supported: [...MCP_SUPPORTED_PROTOCOL_VERSIONS],
41
+ requested
42
+ });
43
+ const result = (value) => ({
44
+ jsonrpc: "2.0",
45
+ id,
46
+ result: modern ? {
47
+ ...value,
48
+ resultType: "complete",
49
+ _meta: { "io.modelcontextprotocol/serverInfo": serverInfo }
50
+ } : value
51
+ });
52
+ if (!modern && msg.method === "initialize") {
53
+ initialized = true;
54
+ const version = MCP_SUPPORTED_PROTOCOL_VERSIONS.slice(1).find((v) => v === params.protocolVersion) ?? "2025-11-25";
55
+ return result({
56
+ protocolVersion: version,
57
+ capabilities: { tools: { listChanged: false } },
58
+ serverInfo: { ...serverInfo, ...options.title ? { title: options.title } : {} },
59
+ ...options.instructions ? { instructions: options.instructions } : {}
60
+ });
61
+ }
62
+ if (!modern && !initialized)
63
+ return error(
64
+ id,
65
+ -32602,
66
+ `Protocol version required. Supported versions: ${MCP_SUPPORTED_PROTOCOL_VERSIONS.join(", ")}`
67
+ );
68
+ if (modern && !record(meta["io.modelcontextprotocol/clientCapabilities"]))
69
+ return error(id, -32602, "clientCapabilities must be an object");
70
+ switch (msg.method) {
71
+ case "ping":
72
+ return result({});
73
+ case "server/discover":
74
+ return result({
75
+ supportedVersions: [...MCP_SUPPORTED_PROTOCOL_VERSIONS],
76
+ capabilities: { tools: {} },
77
+ ...options.instructions ? { instructions: options.instructions } : {},
78
+ ttlMs: 6e4,
79
+ cacheScope: "public"
80
+ });
81
+ case "tools/list":
82
+ return result({
83
+ tools: options.tools.map((tool) => ({
84
+ name: tool.name,
85
+ ...tool.title ? { title: tool.title } : {},
86
+ description: tool.description + (tool.whenToUse ? `
87
+
88
+ Use when: ${tool.whenToUse}` : "") + (tool.whenNotToUse ? `
89
+ Not for: ${tool.whenNotToUse}` : ""),
90
+ inputSchema: tool.inputSchema,
91
+ annotations: options.annotations?.(tool) ?? {
92
+ readOnlyHint: tool.readOnly ?? false,
93
+ destructiveHint: !tool.readOnly,
94
+ idempotentHint: tool.readOnly ?? false,
95
+ openWorldHint: false
96
+ }
97
+ })),
98
+ ...modern ? { ttlMs: 6e4, cacheScope: "public" } : {}
99
+ });
100
+ case "tools/call": {
101
+ const tool = options.tools.find((tool2) => tool2.name === params.name);
102
+ if (!tool) return error(id, -32602, `Unknown tool: ${String(params.name)}`);
103
+ const input = params.arguments === void 0 ? {} : params.arguments;
104
+ const errors = validateInput(tool.inputSchema, input);
105
+ if (errors.length)
106
+ return result({ content: [{ type: "text", text: errors.join("\n") }], isError: true });
107
+ try {
108
+ context ??= Promise.resolve().then(options.context);
109
+ const value = await tool.handler(await context, input);
110
+ return result({
111
+ content: [{ type: "text", text: JSON.stringify(value) ?? "null" }],
112
+ ...record(value) ? { structuredContent: value } : {},
113
+ isError: (options.isErrorResult ?? isErrorResult)(value)
114
+ });
115
+ } catch (cause) {
116
+ return result({
117
+ content: [
118
+ { type: "text", text: cause instanceof Error ? cause.message : String(cause) }
119
+ ],
120
+ isError: true
121
+ });
122
+ }
123
+ }
124
+ default:
125
+ return error(id, -32601, "Method not found");
126
+ }
127
+ };
128
+ return {
129
+ handleMessage,
130
+ async handleLine(line) {
131
+ let msg;
132
+ try {
133
+ msg = JSON.parse(line);
134
+ } catch {
135
+ return JSON.stringify(error(null, -32700, "Parse error"));
136
+ }
137
+ const response = await handleMessage(msg);
138
+ return response === void 0 ? void 0 : JSON.stringify(response);
139
+ }
140
+ };
141
+ }
142
+
143
+ // src/surfaces/mcp_stdio.ts
144
+ async function serveMcpStdio(server, options = {}) {
145
+ const input = options.input ?? process.stdin;
146
+ const output = options.output ?? process.stdout;
147
+ input.setEncoding("utf8");
148
+ let buffer = "";
149
+ const respond = async (line) => {
150
+ if (!line.trim()) return;
151
+ const response = await server.handleLine(line.replace(/\r$/, ""));
152
+ if (response !== void 0)
153
+ await new Promise(
154
+ (resolve, reject) => output.write(`${response}
155
+ `, (error) => error ? reject(error) : resolve())
156
+ );
157
+ };
158
+ for await (const chunk of input) {
159
+ buffer += String(chunk);
160
+ let end = buffer.indexOf("\n");
161
+ while (end !== -1) {
162
+ const line = buffer.slice(0, end);
163
+ buffer = buffer.slice(end + 1);
164
+ await respond(line);
165
+ end = buffer.indexOf("\n");
166
+ }
167
+ }
168
+ await respond(buffer);
169
+ }
170
+
171
+ // src/surface/questlog_mcp_options.ts
172
+ function questlogMcpOptions(context) {
173
+ return {
174
+ name: "ghostpaw-questlog",
175
+ version: questlogVersion,
176
+ title: "Questlog",
177
+ instructions: questlogMcpInstructions,
178
+ tools: questlogSurfaceTools,
179
+ context,
180
+ annotations: (tool) => ({
181
+ readOnlyHint: tool.readOnly ?? false,
182
+ destructiveHint: Boolean(
183
+ tool.inputSchema.properties?.action?.enum?.some(
184
+ (action) => typeof action === "string" && /delete|retire|merge|trash|hide|remove|replace|archive|abandon|dismiss/.test(action)
185
+ )
186
+ ),
187
+ idempotentHint: tool.readOnly ?? false,
188
+ openWorldHint: false
189
+ })
190
+ };
191
+ }
192
+
193
+ // src/surface/serve_questlog_mcp.ts
194
+ async function serveQuestlogMcp(options = {}) {
195
+ let owned;
196
+ const server = createMcpServer(
197
+ questlogMcpOptions(async () => {
198
+ if (options.db) return options.db;
199
+ owned = await openQuestlogDb(
200
+ resolveQuestlogDbPath(options.dbPath === void 0 ? {} : { flag: options.dbPath })
201
+ );
202
+ return owned;
203
+ })
204
+ );
205
+ try {
206
+ await serveMcpStdio(server);
207
+ } finally {
208
+ owned?.close();
209
+ }
210
+ }
211
+
212
+ export { serveQuestlogMcp };
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/env node
2
+ // src/surfaces/skill_markdown.ts
3
+ function renderSkillMarkdown(spec, { referencesBase = "references" } = {}) {
4
+ if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(spec.name) || spec.name.length > 64)
5
+ throw new Error("Invalid skill name");
6
+ if (!spec.description.trim() || spec.description.length > 1024 || !spec.description.includes("Use when"))
7
+ throw new Error("Invalid skill description");
8
+ if (spec.compatibility && spec.compatibility.length > 500)
9
+ throw new Error("Invalid compatibility");
10
+ const lines = ["---", `name: ${spec.name}`, `description: ${JSON.stringify(spec.description)}`];
11
+ for (const key of ["license", "compatibility"])
12
+ if (spec[key]) lines.push(`${key}: ${JSON.stringify(spec[key])}`);
13
+ if (spec.metadata) {
14
+ lines.push("metadata:");
15
+ for (const key of Object.keys(spec.metadata).sort())
16
+ lines.push(` ${JSON.stringify(key)}: ${JSON.stringify(spec.metadata[key])}`);
17
+ }
18
+ lines.push(
19
+ "---",
20
+ "",
21
+ `# ${spec.name}`,
22
+ "",
23
+ spec.about,
24
+ "",
25
+ "## Calling tools",
26
+ "",
27
+ `MCP: connect to ${spec.server}, then call a tool by name with its JSON arguments.`,
28
+ "",
29
+ `CLI: \`${spec.bin} call <tool> '<JSON object>'\` or \`${spec.bin} <tool> --parameter value\`${spec.packageName ? ` (without a global install: \`npx -y ${spec.packageName} <tool> ...\`)` : ""}.`,
30
+ "",
31
+ `Inspect schemas with \`${spec.bin} describe <tool>\`. Use \`--db <path>\` to select a database.`,
32
+ ""
33
+ );
34
+ for (const tool of spec.tools) {
35
+ lines.push(
36
+ `## ${tool.name}`,
37
+ "",
38
+ tool.description,
39
+ "",
40
+ `Use when: ${tool.whenToUse ?? ""}`,
41
+ "",
42
+ `Not for: ${tool.whenNotToUse ?? ""}`,
43
+ "",
44
+ tool.readOnly ? "Read-only." : `Writes: ${tool.sideEffects ?? "state"}.`,
45
+ "",
46
+ "| Parameter | Type | Required | Values / description |",
47
+ "| --- | --- | --- | --- |"
48
+ );
49
+ for (const [name, property] of Object.entries(tool.inputSchema.properties ?? {}))
50
+ lines.push(
51
+ `| ${name} | ${property.type ?? property.oneOf?.map((branch) => branch.type).join(" / ") ?? "any"} | ${tool.inputSchema.required?.includes(name) ? "yes" : "no"} | ${(property.enum ? `${property.enum.join(", ")}. ` : "") + (property.description ?? "").replaceAll("|", "\\|").replaceAll("\n", " ")} |`
52
+ );
53
+ lines.push("");
54
+ }
55
+ lines.push(
56
+ "## Workflow guides",
57
+ "",
58
+ ...spec.workflows.map(
59
+ (workflow) => `- [${workflow.name}](${referencesBase}/${workflow.name}.md): ${workflow.description}`
60
+ ),
61
+ "",
62
+ "## Principles",
63
+ "",
64
+ ...spec.principles.map((principle) => `- ${principle}`),
65
+ ""
66
+ );
67
+ const output = lines.join("\n");
68
+ if (!spec.cheatSheet) return output;
69
+ const title = `# ${spec.name}
70
+
71
+ `;
72
+ const start = output.indexOf(title) + title.length;
73
+ return `${output.slice(0, start)}${spec.cheatSheet}
74
+
75
+ ## Appendix: MCP and tool calls
76
+
77
+ ${output.slice(start).replace(/^## /gm, "### ")}`;
78
+ }
79
+
80
+ export { renderSkillMarkdown };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ghostpaw/questlog",
3
- "version": "0.8.0",
3
+ "version": "0.9.1",
4
4
  "description": "Unified task and calendar model for Node.js — SQLite, zero dependencies, with a built-in LLM tool facade",
5
5
  "type": "module",
6
6
  "exports": {
@@ -135,7 +135,8 @@
135
135
  "typescript": "^5.9.3"
136
136
  },
137
137
  "bin": {
138
- "ghostpaw-questlog": "./dist/cli.js"
138
+ "ghostpaw-questlog": "./dist/cli.js",
139
+ "questlog": "./dist/cli.js"
139
140
  },
140
141
  "mcpName": "io.github.GhostPawJS/questlog"
141
142
  }
@@ -7,9 +7,25 @@ compatibility: "Node.js 24 or newer. MCP stdio or ghostpaw-questlog CLI."
7
7
 
8
8
  # questlog
9
9
 
10
+ No install? Use `npx -y @ghostpaw/questlog <command>`.
11
+ `questlog` and `ghostpaw-questlog` are the same binary.
12
+
13
+ - `questlog search <words>` before `add` to avoid duplicates.
14
+ - `questlog add --title "..." --tag a,b --due tomorrow`
15
+ - `questlog list [--view <view>]`: questlines, quests.active, quests.available, quests.blocked, quests.deferred, quests.due_soon, quests.in_progress, quests.missed_scheduled, quests.open, quests.overdue, quests.resolved, quests.scheduled_for_day, quests.scheduled_now, repeatables.due_anchors, rumors.
16
+ - `questlog done <id> --outcome "..."`
17
+ - `questlog search <words>`
18
+ - `questlog show <id>`
19
+ - Use `--json` on any plain command.
20
+ - Exit codes: 0 ok / 1 error / 2 usage / 3 needs input.
21
+ - Database: `~/.ghostpaw/questlog.db`; override with `--db` or `GHOSTPAW_QUESTLOG_DB`.
22
+ - Use one database per agent or project.
23
+
24
+ ## Appendix: MCP and tool calls
25
+
10
26
  Questlog manages local tasks, calendar commitments, and recurring work. Search before creating work, inspect before changing it, and keep uncertain work as rumors. Use unlock prerequisites to sequence work. run_quest refuses blocked starts unless force is true. Review commitments and resolve work with an honest outcome.
11
27
 
12
- ## Calling tools
28
+ ### Calling tools
13
29
 
14
30
  MCP: connect to ghostpaw-questlog, then call a tool by name with its JSON arguments.
15
31
 
@@ -17,7 +33,7 @@ CLI: `ghostpaw-questlog call <tool> '<JSON object>'` or `ghostpaw-questlog <tool
17
33
 
18
34
  Inspect schemas with `ghostpaw-questlog describe <tool>`. Use `--db <path>` to select a database.
19
35
 
20
- ## search_questlog
36
+ ### search_questlog
21
37
 
22
38
  Search quests and rumors by text when you need to find an existing item before inspecting or changing it.
23
39
 
@@ -34,7 +50,7 @@ Read-only.
34
50
  | kinds | array | no | Optional entity kinds to search. |
35
51
  | mode | string | no | browse, identify_one. Whether to browse results normally or ask for clarification when several matches are found. |
36
52
 
37
- ## review_questlog
53
+ ### review_questlog
38
54
 
39
55
  Review one operational questlog surface such as available quests, open rumors, blocked work, or due repeatable anchors.
40
56
 
@@ -50,7 +66,7 @@ Read-only.
50
66
  | filters | object | no | Optional filters for supported review surfaces. |
51
67
  | now | integer | no | Optional evaluation timestamp for time-sensitive views. |
52
68
 
53
- ## inspect_questlog_item
69
+ ### inspect_questlog_item
54
70
 
55
71
  Inspect one specific questlog item in depth and return its richer structured detail and important related refs.
56
72
 
@@ -66,7 +82,7 @@ Read-only.
66
82
  | detailLevel | string | no | compact, full. How much detail to return. |
67
83
  | now | integer | no | Optional evaluation timestamp for time-sensitive detail. |
68
84
 
69
- ## capture_rumor
85
+ ### capture_rumor
70
86
 
71
87
  Capture uncertain incoming work as a rumor so it can be triaged later without prematurely turning it into committed execution.
72
88
 
@@ -82,7 +98,7 @@ Writes: writes_state.
82
98
  | details | string | no | Optional supporting context that explains why the rumor might matter. |
83
99
  | now | integer | no | Optional creation timestamp for the rumor. |
84
100
 
85
- ## shape_work
101
+ ### shape_work
86
102
 
87
103
  Create a quest (with timing, tags, and objective in one call), create a questline, settle a rumor into concrete work, or manage quest-questline membership. Use create_quest for clear commitments — include tags and timing directly to avoid follow-up calls.
88
104
 
@@ -107,7 +123,7 @@ Writes: writes_state.
107
123
  | title | string | no | New title for the update_rumor action. |
108
124
  | details | string | no | New or enriched context text for the update_rumor action. |
109
125
 
110
- ## plan_quest
126
+ ### plan_quest
111
127
 
112
128
  Refine a quest by revising its objective before actual start or by changing its temporal planning fields.
113
129
 
@@ -130,7 +146,7 @@ Writes: writes_state.
130
146
  | estimateSeconds | integer | no | Optional active-effort estimate in seconds. |
131
147
  | now | integer | no | Optional update timestamp. |
132
148
 
133
- ## run_quest
149
+ ### run_quest
134
150
 
135
151
  Run quest lifecycle actions such as starting, logging effort, finishing, abandoning, or abandoning and spawning follow-up quests atomically.
136
152
 
@@ -152,7 +168,7 @@ Writes: writes_state.
152
168
  | resolvedAt | integer | no | Optional resolved timestamp for finish or abandon actions. |
153
169
  | followups | array | no | Follow-up quests to create atomically. Required for abandon_and_spawn_followups. |
154
170
 
155
- ## organize_work
171
+ ### organize_work
156
172
 
157
173
  Organize grouping and dependency structure by updating questlines or changing hard unlock prerequisites between concrete quests.
158
174
 
@@ -176,7 +192,7 @@ Writes: writes_state.
176
192
  | fromQuestIds | array | no | Full prerequisite quest id set. |
177
193
  | now | integer | no | Optional timestamp. |
178
194
 
179
- ## manage_repeatable
195
+ ### manage_repeatable
180
196
 
181
197
  Manage recurring work definitions by creating, updating, previewing, spawning, or archiving repeatable quests.
182
198
 
@@ -205,7 +221,7 @@ Writes: writes_state.
205
221
  | archivedAt | integer | no | Optional archive timestamp. |
206
222
  | now | integer | no | Evaluation or update timestamp. |
207
223
 
208
- ## tag_work
224
+ ### tag_work
209
225
 
210
226
  Classify work by adding, removing, or replacing tags on quests and by replacing the future tag template set on repeatable quests.
211
227
 
@@ -222,7 +238,7 @@ Writes: writes_state.
222
238
  | tagNames | array | yes | Tag names to add, remove, or replace. |
223
239
  | now | integer | no | Optional timestamp for the tag mutation. |
224
240
 
225
- ## reward_work
241
+ ### reward_work
226
242
 
227
243
  Manage rewards by adding, updating, removing, or claiming quest rewards, or by replacing future reward templates on repeatable quests.
228
244
 
@@ -241,7 +257,7 @@ Writes: writes_state.
241
257
  | claimedAt | integer | no | Optional claim timestamp. |
242
258
  | now | integer | no | Optional timestamp for removal or template replacement. |
243
259
 
244
- ## retire_work
260
+ ### retire_work
245
261
 
246
262
  Hide an item from normal active operation without rewriting history by soft-deleting a rumor, quest, questline, or repeatable quest.
247
263
 
@@ -257,7 +273,7 @@ Writes: writes_state.
257
273
  | target | object | yes | The target to hide. |
258
274
  | deletedAt | integer | no | Optional timestamp to record when the item became hidden. |
259
275
 
260
- ## Workflow guides
276
+ ### Workflow guides
261
277
 
262
278
  - [archive-delete-and-prune](references/archive-delete-and-prune.md): Choose the right retirement action for each kind of work so history stays honest and hiding does not get confused with archival or terminal execution truth.
263
279
  - [choose-work-shape](references/choose-work-shape.md): Choose the right structure for new work by separating uncertainty, one-shot execution, multi-step arcs, and recurring patterns.
@@ -285,7 +301,7 @@ Writes: writes_state.
285
301
  - [settle-rumor-into-structure](references/settle-rumor-into-structure.md): Turn a ready rumor into committed quest or questline structure without losing provenance or pretending vague intake is settled.
286
302
  - [tag-and-filter-portfolios](references/tag-and-filter-portfolios.md): Use tags for cross-cutting classification and portfolio filtering without confusing tags for status, timing, or dependency modeling.
287
303
 
288
- ## Principles
304
+ ### Principles
289
305
 
290
306
  - Store the least committed truth first.
291
307
  - Read before you prescribe.