mnotes-cli 1.10.0 → 1.11.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.
- package/dist/commands/connect/__tests__/connect.test.js +15 -0
- package/dist/commands/connect/__tests__/wizard.test.js +13 -0
- package/dist/commands/connect/index.js +37 -3
- package/dist/templates/claude-code.js +32 -0
- package/dist/templates/codex.js +26 -0
- package/dist/templates/openclaw.js +22 -0
- package/package.json +1 -1
|
@@ -43,6 +43,21 @@ const config_utils_1 = require("../config-utils");
|
|
|
43
43
|
const claude_code_1 = require("../../../templates/claude-code");
|
|
44
44
|
const codex_1 = require("../../../templates/codex");
|
|
45
45
|
const openclaw_1 = require("../../../templates/openclaw");
|
|
46
|
+
// Mock createClient so resolveWorkspace can validate workspaces without a real server
|
|
47
|
+
vitest_1.vi.mock("../../../client", () => ({
|
|
48
|
+
createClient: () => ({
|
|
49
|
+
listWorkspaces: async () => ({
|
|
50
|
+
data: [
|
|
51
|
+
{ id: "ws-123", name: "Test", slug: "test-123", isDefault: true },
|
|
52
|
+
{ id: "ws-explicit-id", name: "Explicit", slug: "explicit-id", isDefault: false },
|
|
53
|
+
{ id: "ws-new", name: "New", slug: "new", isDefault: false },
|
|
54
|
+
],
|
|
55
|
+
}),
|
|
56
|
+
createWorkspace: async (name) => ({
|
|
57
|
+
data: { id: name, name, slug: name, isDefault: false },
|
|
58
|
+
}),
|
|
59
|
+
}),
|
|
60
|
+
}));
|
|
46
61
|
// -- Helper: capture stdout --
|
|
47
62
|
function captureStdout(fn) {
|
|
48
63
|
const chunks = [];
|
|
@@ -41,6 +41,19 @@ const wizard_1 = require("../wizard");
|
|
|
41
41
|
const hooks_1 = require("../../../templates/claude-code/hooks");
|
|
42
42
|
const skills_1 = require("../../../templates/claude-code/skills");
|
|
43
43
|
const agents_1 = require("../../../templates/claude-code/agents");
|
|
44
|
+
// Mock createClient so resolveWorkspace can validate workspaces without a real server
|
|
45
|
+
vitest_1.vi.mock("../../../client", () => ({
|
|
46
|
+
createClient: () => ({
|
|
47
|
+
listWorkspaces: async () => ({
|
|
48
|
+
data: [
|
|
49
|
+
{ id: "ws-123", name: "Test", slug: "test-123", isDefault: true },
|
|
50
|
+
],
|
|
51
|
+
}),
|
|
52
|
+
createWorkspace: async (name) => ({
|
|
53
|
+
data: { id: name, name, slug: name, isDefault: false },
|
|
54
|
+
}),
|
|
55
|
+
}),
|
|
56
|
+
}));
|
|
44
57
|
function makeTmpDir() {
|
|
45
58
|
return fs.mkdtempSync(path.join(os.tmpdir(), "mnotes-wizard-test-"));
|
|
46
59
|
}
|
|
@@ -38,9 +38,11 @@ exports.handleClaudeCode = handleClaudeCode;
|
|
|
38
38
|
exports.registerConnectCommand = registerConnectCommand;
|
|
39
39
|
const fs = __importStar(require("fs"));
|
|
40
40
|
const path = __importStar(require("path"));
|
|
41
|
+
const readline = __importStar(require("readline"));
|
|
41
42
|
const config_utils_1 = require("./config-utils");
|
|
42
43
|
const workspace_prompt_1 = require("./workspace-prompt");
|
|
43
44
|
const config_1 = require("../../config");
|
|
45
|
+
const client_1 = require("../../client");
|
|
44
46
|
const claude_code_1 = require("../../templates/claude-code");
|
|
45
47
|
const codex_1 = require("../../templates/codex");
|
|
46
48
|
const openclaw_1 = require("../../templates/openclaw");
|
|
@@ -90,13 +92,45 @@ function printConnectionStatus() {
|
|
|
90
92
|
/**
|
|
91
93
|
* Resolves the workspace ID — uses --workspace flag if provided, otherwise
|
|
92
94
|
* prompts interactively after validating the connection.
|
|
95
|
+
*
|
|
96
|
+
* When a workspace value is provided (flag, env, or config), validates it
|
|
97
|
+
* against the API by matching on ID or slug. If not found, prompts to create.
|
|
93
98
|
*/
|
|
94
99
|
async function resolveWorkspace(opts) {
|
|
95
100
|
// Check flag, env, dir map, global config
|
|
96
101
|
const fromConfig = (0, config_1.resolveConfig)({ workspaceId: opts.workspace });
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
102
|
+
const candidate = fromConfig.workspaceId;
|
|
103
|
+
if (candidate) {
|
|
104
|
+
// Validate the candidate against the API
|
|
105
|
+
const client = (0, client_1.createClient)(opts.url, opts.apiKey);
|
|
106
|
+
let workspaces;
|
|
107
|
+
try {
|
|
108
|
+
const res = await client.listWorkspaces();
|
|
109
|
+
workspaces = res.data;
|
|
110
|
+
}
|
|
111
|
+
catch (err) {
|
|
112
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
113
|
+
throw new Error(`Failed to fetch workspaces: ${message}`);
|
|
114
|
+
}
|
|
115
|
+
// Match by ID or slug
|
|
116
|
+
const match = workspaces.find((ws) => ws.id === candidate || ws.slug === candidate);
|
|
117
|
+
if (match) {
|
|
118
|
+
return match.id;
|
|
119
|
+
}
|
|
120
|
+
// Not found — ask user to create
|
|
121
|
+
process.stderr.write(`\nWorkspace "${candidate}" not found.\n`);
|
|
122
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stderr });
|
|
123
|
+
const answer = await new Promise((resolve) => rl.question(`Create workspace "${candidate}"? [Y/n] `, resolve));
|
|
124
|
+
rl.close();
|
|
125
|
+
if (answer.trim() === "" || answer.trim().toLowerCase() === "y") {
|
|
126
|
+
const created = await client.createWorkspace(candidate);
|
|
127
|
+
process.stderr.write(`Created workspace "${created.data.name}" (${created.data.id})\n`);
|
|
128
|
+
return created.data.id;
|
|
129
|
+
}
|
|
130
|
+
// User declined — fall through to interactive
|
|
131
|
+
process.stderr.write("Falling back to interactive workspace selection.\n");
|
|
132
|
+
}
|
|
133
|
+
// Nothing stored or user declined — interactive selection/creation
|
|
100
134
|
const resolved = await (0, workspace_prompt_1.resolveWorkspaceInteractively)(opts.url, opts.apiKey);
|
|
101
135
|
return resolved.id;
|
|
102
136
|
}
|
|
@@ -27,6 +27,38 @@ function generateClaudeCodeTemplate(opts) {
|
|
|
27
27
|
7. **READ schema before editing.** Before creating or updating notes, call \`search_notes\` for \`type:config\` notes. Follow their conventions. If none exist, offer to create a starter schema note.
|
|
28
28
|
8. **EVERY note must link.** Outbound \`[[wikilinks]]\` are mandatory — an orphan note is invisible.
|
|
29
29
|
|
|
30
|
+
## Non-Negotiable Checklist
|
|
31
|
+
|
|
32
|
+
These are not suggestions. Skip any step and the wiki degrades.
|
|
33
|
+
|
|
34
|
+
### Session Start (before ANY work)
|
|
35
|
+
- [ ] Call \`project_context_load\` with workspaceId "${opts.workspaceId}"
|
|
36
|
+
- [ ] Call \`recall_knowledge\` for the user's topic — past you already figured things out
|
|
37
|
+
- [ ] Call \`search_notes\` for related wiki pages
|
|
38
|
+
- [ ] If the graph is empty, call \`populate_graph\` (idempotent)
|
|
39
|
+
- [ ] Read any \`type:config\` schema notes before editing the wiki
|
|
40
|
+
|
|
41
|
+
Do not skip this. Do not say "I'll check later." Do not assume you know what's in the wiki.
|
|
42
|
+
|
|
43
|
+
### During Work (every time you learn something)
|
|
44
|
+
- [ ] Non-obvious discovery? → \`knowledge_store\` immediately, do not batch
|
|
45
|
+
- [ ] User drops a URL/paste/file? → run the **ingest loop** (below), not a single note dump
|
|
46
|
+
- [ ] Made an architecture or design decision? → store with key \`arch/{component}\`
|
|
47
|
+
- [ ] Fixed a bug? → store with key \`bug/{id}\`, include root cause
|
|
48
|
+
- [ ] Found a gotcha or footgun? → store with key \`gotcha/{description}\`
|
|
49
|
+
- [ ] User corrected you or clarified a requirement? → store it
|
|
50
|
+
|
|
51
|
+
### What NOT to Store
|
|
52
|
+
- Trivial changes (typo fixes, formatting)
|
|
53
|
+
- Information obvious from reading the code
|
|
54
|
+
- Duplicates — call \`recall_knowledge\` first to check
|
|
55
|
+
|
|
56
|
+
### Session End (before finishing)
|
|
57
|
+
- [ ] Call \`session_log\` with summary, decisions made, and follow-up actions
|
|
58
|
+
- [ ] If you did meaningful work and didn't store anything yet — you forgot. Go back and store it.
|
|
59
|
+
|
|
60
|
+
If you think "this isn't worth saving" — save it anyway. Future you has no context.
|
|
61
|
+
|
|
30
62
|
## The Ingest Loop
|
|
31
63
|
|
|
32
64
|
When the user supplies a source (URL, paste, file):
|
package/dist/templates/codex.js
CHANGED
|
@@ -18,6 +18,32 @@ You are the author and maintainer of a living wiki. Raw sources are immutable in
|
|
|
18
18
|
- If the graph is empty, call \`populate_graph\` (idempotent).
|
|
19
19
|
- Read any notes tagged \`type:config\` before editing.
|
|
20
20
|
|
|
21
|
+
### Non-Negotiable Checklist
|
|
22
|
+
|
|
23
|
+
These are not suggestions. Skip any step and the wiki degrades.
|
|
24
|
+
|
|
25
|
+
**Session Start (before ANY work):**
|
|
26
|
+
- [ ] \`project_context_load\` with workspaceId "${opts.workspaceId}"
|
|
27
|
+
- [ ] \`recall_knowledge\` for the user's topic
|
|
28
|
+
- [ ] \`search_notes\` for related pages
|
|
29
|
+
- [ ] \`populate_graph\` if graph is empty
|
|
30
|
+
- [ ] Read \`type:config\` schema notes before editing
|
|
31
|
+
|
|
32
|
+
Do not skip this. Do not assume you know what's in the wiki.
|
|
33
|
+
|
|
34
|
+
**During Work (every time you learn something):**
|
|
35
|
+
- [ ] Non-obvious discovery → \`knowledge_store\` immediately
|
|
36
|
+
- [ ] Architecture/design decision → \`arch/{component}\`
|
|
37
|
+
- [ ] Bug fix → \`bug/{id}\` with root cause
|
|
38
|
+
- [ ] Gotcha/footgun → \`gotcha/{description}\`
|
|
39
|
+
- [ ] User correction → store it
|
|
40
|
+
|
|
41
|
+
**What NOT to store:** trivial changes, info obvious from code, duplicates (check \`recall_knowledge\` first).
|
|
42
|
+
|
|
43
|
+
**Session End:**
|
|
44
|
+
- [ ] \`session_log\` with summary, decisions, follow-ups
|
|
45
|
+
- [ ] If you did meaningful work and stored nothing — go back and store it
|
|
46
|
+
|
|
21
47
|
### During Work
|
|
22
48
|
- Recall before researching: \`recall_knowledge\`, \`search_notes\`.
|
|
23
49
|
- Store discoveries via \`knowledge_store\` (key: \`<category>/<name>\`, tags: [category]).
|
|
@@ -10,6 +10,28 @@ function generateOpenClawTemplate(opts) {
|
|
|
10
10
|
|
|
11
11
|
You are the author of a living wiki. Notes are interlinked with \`[[wikilinks]]\`. Sources are immutable; your writing is the wiki.
|
|
12
12
|
|
|
13
|
+
## Non-Negotiable Checklist
|
|
14
|
+
|
|
15
|
+
Skip any step and the wiki degrades.
|
|
16
|
+
|
|
17
|
+
**Session Start (before ANY work):**
|
|
18
|
+
- [ ] \`recall_knowledge\` for the user's topic
|
|
19
|
+
- [ ] \`search_notes\` for related pages
|
|
20
|
+
- [ ] \`populate_graph\` if graph is empty
|
|
21
|
+
|
|
22
|
+
Do not skip this. Do not assume you know what's in the wiki.
|
|
23
|
+
|
|
24
|
+
**During Work:**
|
|
25
|
+
- [ ] Non-obvious discovery → \`knowledge_store\` immediately
|
|
26
|
+
- [ ] Decision made → \`decision/{topic}\`
|
|
27
|
+
- [ ] Bug fixed → \`bug/{id}\` with root cause
|
|
28
|
+
- [ ] User correction → store it
|
|
29
|
+
|
|
30
|
+
**What NOT to store:** trivial changes, info obvious from code, duplicates.
|
|
31
|
+
|
|
32
|
+
**Session End:**
|
|
33
|
+
- [ ] If you did meaningful work and stored nothing — go back and store it
|
|
34
|
+
|
|
13
35
|
## Core Loops
|
|
14
36
|
|
|
15
37
|
**Ingest** — when given a source (URL/paste): find 3+ related notes via \`recall_knowledge\`, update or create, link them with \`[[wikilinks]]\`, tag each with \`source/<slug>\`.
|