brainclaw 0.23.0 → 0.23.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.
package/dist/cli.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import path from 'node:path';
|
|
2
3
|
import { Command } from 'commander';
|
|
3
4
|
import { runInit } from './commands/init.js';
|
|
4
5
|
import { runSetup } from './commands/setup.js';
|
|
@@ -94,15 +95,26 @@ program
|
|
|
94
95
|
.hook('preAction', (_thisCommand, actionCommand) => {
|
|
95
96
|
const root = actionCommand.optsWithGlobals();
|
|
96
97
|
initLogLevel({ verbose: root.verbose, debug: root.debug });
|
|
97
|
-
//
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
98
|
+
// Skip effective cwd resolution for commands that create the store
|
|
99
|
+
const cmdName = actionCommand.name();
|
|
100
|
+
const skipResolution = cmdName === 'init' || cmdName === 'setup';
|
|
101
|
+
if (!skipResolution) {
|
|
102
|
+
// Resolve effective cwd (--cwd > BRAINCLAW_PROJECT > active-project > process.cwd)
|
|
103
|
+
const effectiveCwd = resolveEffectiveCwd({ explicitCwd: root.cwd });
|
|
104
|
+
if (effectiveCwd !== process.cwd()) {
|
|
105
|
+
// Change process.cwd() so all commands resolve the correct store
|
|
106
|
+
// without needing individual --cwd plumbing
|
|
107
|
+
process.chdir(effectiveCwd);
|
|
108
|
+
logger.info(`Resolved effective cwd: ${effectiveCwd}`);
|
|
109
|
+
}
|
|
110
|
+
const removed = cleanOrphanFiles(memoryDir());
|
|
111
|
+
if (removed > 0) {
|
|
112
|
+
logger.info(`Cleaned ${removed} orphan lock/tmp file(s) in ${memoryDir()}`);
|
|
113
|
+
}
|
|
102
114
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
115
|
+
else if (root.cwd) {
|
|
116
|
+
// For init/setup, still respect explicit --cwd but nothing else
|
|
117
|
+
process.chdir(path.resolve(root.cwd));
|
|
106
118
|
}
|
|
107
119
|
});
|
|
108
120
|
// --- init ---
|
package/dist/commands/switch.js
CHANGED
|
@@ -106,8 +106,8 @@ function listProjects(wsRoot, json) {
|
|
|
106
106
|
});
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
|
-
// Discover child projects
|
|
110
|
-
const children = scanNestedBrainclawProjects(wsRoot,
|
|
109
|
+
// Discover child projects (depth 7 covers deep workspace layouts like /srv/dev/repos/global/applications/*/...)
|
|
110
|
+
const children = scanNestedBrainclawProjects(wsRoot, 7);
|
|
111
111
|
for (const child of children) {
|
|
112
112
|
const childPath = path.resolve(child.path);
|
|
113
113
|
if (childPath === wsRoot)
|
|
@@ -257,10 +257,29 @@ Likely persisted fields:
|
|
|
257
257
|
|
|
258
258
|
This should stay clearly separate from canonical memory items such as decisions and constraints.
|
|
259
259
|
|
|
260
|
+
## Current Implementation (v0.23.0)
|
|
261
|
+
|
|
262
|
+
`brainclaw switch` provides the first layer of project navigation:
|
|
263
|
+
|
|
264
|
+
- `brainclaw switch <name-or-path>` — set active project by name or relative path
|
|
265
|
+
- `brainclaw switch --list` — discover available projects in workspace
|
|
266
|
+
- `resolveProjectRef()` — shared resolver for CLI and MCP (name, path, registry lookup)
|
|
267
|
+
- `resolveEffectiveCwd()` — single source of truth: `--cwd` > `BRAINCLAW_PROJECT` env > active-project > cwd
|
|
268
|
+
- MCP tools automatically resolve the active project
|
|
269
|
+
|
|
270
|
+
This covers the most common agent friction (cwd-dependent resolution) without requiring the full `project_ref` model yet.
|
|
271
|
+
|
|
260
272
|
## Migration Strategy
|
|
261
273
|
|
|
262
274
|
The migration should be low-risk and incremental.
|
|
263
275
|
|
|
276
|
+
Phase 0 (done):
|
|
277
|
+
|
|
278
|
+
- `brainclaw switch` with name/path resolution
|
|
279
|
+
- global `--cwd` option
|
|
280
|
+
- `BRAINCLAW_PROJECT` environment variable
|
|
281
|
+
- `resolveEffectiveCwd()` used by CLI and MCP
|
|
282
|
+
|
|
264
283
|
Phase 1:
|
|
265
284
|
|
|
266
285
|
- introduce `project_ref` in workspace discovery/registry
|
package/docs/cli.md
CHANGED
|
@@ -11,6 +11,53 @@ For capable coding agents, prefer MCP for dynamic runtime state:
|
|
|
11
11
|
|
|
12
12
|
Use the CLI when a human operator is driving the workflow, when you are scripting setup or release operations, or when MCP is not the integration path.
|
|
13
13
|
|
|
14
|
+
## Global Options
|
|
15
|
+
|
|
16
|
+
All commands support these global options:
|
|
17
|
+
|
|
18
|
+
| Option | Description |
|
|
19
|
+
|---|---|
|
|
20
|
+
| `--cwd <path>` | Override working directory for this invocation. Bypasses active project and env var resolution. |
|
|
21
|
+
| `--verbose` | Show info-level log messages on stderr |
|
|
22
|
+
| `--debug` | Show debug-level log messages on stderr |
|
|
23
|
+
|
|
24
|
+
**Effective cwd resolution priority** (highest wins):
|
|
25
|
+
|
|
26
|
+
1. `--cwd` flag
|
|
27
|
+
2. `BRAINCLAW_PROJECT` environment variable (project name or path)
|
|
28
|
+
3. Active project set via `brainclaw switch`
|
|
29
|
+
4. `process.cwd()` (shell working directory)
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## Multi-Project Navigation
|
|
34
|
+
|
|
35
|
+
### `brainclaw switch [project]`
|
|
36
|
+
|
|
37
|
+
Set the active project for subsequent CLI and MCP commands. This eliminates the need to `cd` into a subproject directory in multi-project workspaces. The active project is persisted per-workspace in `.brainclaw/active-project.json`.
|
|
38
|
+
|
|
39
|
+
| Option | Description |
|
|
40
|
+
|---|---|
|
|
41
|
+
| `--list` | List all available projects in the workspace |
|
|
42
|
+
| `--clear` | Clear the active project (revert to cwd default) |
|
|
43
|
+
| `--json` | Output as JSON |
|
|
44
|
+
|
|
45
|
+
The `<project>` argument accepts:
|
|
46
|
+
- **Project name** — matched against the global registry and workspace config
|
|
47
|
+
- **Relative path** — resolved from the workspace root (e.g. `apps/lodestar`)
|
|
48
|
+
- **Absolute path** — used directly
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
brainclaw switch --list # discover available projects
|
|
52
|
+
brainclaw switch lodestar # switch by project name
|
|
53
|
+
brainclaw switch apps/lodestar # switch by relative path
|
|
54
|
+
brainclaw switch # show current active project
|
|
55
|
+
brainclaw switch --clear # clear, revert to cwd
|
|
56
|
+
brainclaw --cwd /other/path status # one-off override without switching
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
**MCP usage:** The active project also affects MCP tools. When `bclaw_get_context()` is called without an explicit path, it resolves context from the active project's store. Agents can also use `BRAINCLAW_PROJECT=<name>` environment variable for the same effect.
|
|
60
|
+
|
|
14
61
|
---
|
|
15
62
|
|
|
16
63
|
## Initialize and Inspect
|
|
@@ -38,3 +38,44 @@ If shared memory is absent, that should not always be interpreted as "there is n
|
|
|
38
38
|
It may simply mean the workspace has not been onboarded yet.
|
|
39
39
|
|
|
40
40
|
This lets a single machine support multiple very different workspaces without forcing one static instruction layer to fit all of them equally well.
|
|
41
|
+
|
|
42
|
+
## Multi-project workspaces
|
|
43
|
+
|
|
44
|
+
A workspace may contain multiple brainclaw-initialized child projects (each with its own `.brainclaw/` store). In this topology:
|
|
45
|
+
|
|
46
|
+
- The workspace root holds shared instructions, constraints, and coordination state
|
|
47
|
+
- Each child project holds project-specific memory (decisions, traps, plans)
|
|
48
|
+
- The store chain walks upward: child → repo → workspace → user
|
|
49
|
+
|
|
50
|
+
### Working with child projects
|
|
51
|
+
|
|
52
|
+
Agents and operators can address child projects without `cd`:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
brainclaw switch apps/lodestar # set active project
|
|
56
|
+
brainclaw plan list # now targets lodestar's store
|
|
57
|
+
brainclaw switch --clear # back to workspace root
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Or use environment variables:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
export BRAINCLAW_PROJECT=lodestar
|
|
64
|
+
brainclaw context # resolves lodestar's store
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Or one-off overrides:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
brainclaw --cwd apps/lodestar plan list
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Project discovery
|
|
74
|
+
|
|
75
|
+
`brainclaw switch --list` discovers child projects via:
|
|
76
|
+
|
|
77
|
+
1. Global project registry
|
|
78
|
+
2. Workspace config `projects.known`
|
|
79
|
+
3. Filesystem scan for subdirectories containing `.brainclaw/`
|
|
80
|
+
|
|
81
|
+
The bootstrap analysis (`analyzeRepository`) also detects brainclaw-native workspace complexity (child stores, folder strategy, known projects) alongside classic monorepo markers.
|
|
@@ -101,6 +101,41 @@ brainclaw adds all generated files to `.gitignore` automatically during init.
|
|
|
101
101
|
|
|
102
102
|
Exception: use `--shared` if you intentionally want the main instruction file (e.g., CLAUDE.md) versioned for the whole team.
|
|
103
103
|
|
|
104
|
+
## Multi-project workspaces
|
|
105
|
+
|
|
106
|
+
When a workspace contains multiple brainclaw-initialized child projects, agents need to target the correct project store. There are three mechanisms (from most to least ergonomic):
|
|
107
|
+
|
|
108
|
+
### 1. `brainclaw switch` (persistent)
|
|
109
|
+
|
|
110
|
+
An operator or agent sets the active project once, and all subsequent commands resolve against it:
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
brainclaw switch apps/lodestar # set active project
|
|
114
|
+
brainclaw plan list # targets lodestar
|
|
115
|
+
bclaw_get_context() # MCP also targets lodestar
|
|
116
|
+
brainclaw switch --clear # back to workspace root
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### 2. `BRAINCLAW_PROJECT` environment variable
|
|
120
|
+
|
|
121
|
+
Set in the shell or agent configuration. Useful for CI/CD or when the agent can control its environment:
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
export BRAINCLAW_PROJECT=lodestar
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### 3. `--cwd` flag (one-off override)
|
|
128
|
+
|
|
129
|
+
For a single command without changing the active project:
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
brainclaw --cwd apps/lodestar plan list
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
**Priority**: `--cwd` > `BRAINCLAW_PROJECT` > active project > shell cwd.
|
|
136
|
+
|
|
137
|
+
**Discovery**: use `brainclaw switch --list` to see all available projects in the workspace.
|
|
138
|
+
|
|
104
139
|
## Session lifecycle
|
|
105
140
|
|
|
106
141
|
### Starting work
|