orbitmap 0.4.0-next.0 → 0.4.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.
Files changed (55) hide show
  1. package/README.md +148 -45
  2. package/dist/adapters/cloud.d.ts +36 -3
  3. package/dist/adapters/cloud.js +79 -17
  4. package/dist/adapters/cloud.js.map +1 -1
  5. package/dist/adapters/factory.d.ts +8 -4
  6. package/dist/adapters/factory.js +9 -5
  7. package/dist/adapters/factory.js.map +1 -1
  8. package/dist/adapters/local/context.d.ts +4 -3
  9. package/dist/adapters/local/context.js +4 -3
  10. package/dist/adapters/local/context.js.map +1 -1
  11. package/dist/commands/assign.js +9 -4
  12. package/dist/commands/assign.js.map +1 -1
  13. package/dist/commands/create.js +1 -6
  14. package/dist/commands/create.js.map +1 -1
  15. package/dist/commands/ideas.js +1 -6
  16. package/dist/commands/ideas.js.map +1 -1
  17. package/dist/commands/init.d.ts +28 -0
  18. package/dist/commands/init.js +248 -132
  19. package/dist/commands/init.js.map +1 -1
  20. package/dist/commands/issues.js +1 -6
  21. package/dist/commands/issues.js.map +1 -1
  22. package/dist/commands/setup-agent.d.ts +16 -0
  23. package/dist/commands/setup-agent.js +38 -5
  24. package/dist/commands/setup-agent.js.map +1 -1
  25. package/dist/commands/setup-mcp.js +13 -42
  26. package/dist/commands/setup-mcp.js.map +1 -1
  27. package/dist/commands/task.js +3 -13
  28. package/dist/commands/task.js.map +1 -1
  29. package/dist/config.d.ts +69 -17
  30. package/dist/config.js +206 -32
  31. package/dist/config.js.map +1 -1
  32. package/dist/doc-cache.d.ts +21 -1
  33. package/dist/doc-cache.js +72 -12
  34. package/dist/doc-cache.js.map +1 -1
  35. package/dist/id-resolve.d.ts +61 -0
  36. package/dist/id-resolve.js +87 -0
  37. package/dist/id-resolve.js.map +1 -0
  38. package/dist/index.js +26 -12
  39. package/dist/index.js.map +1 -1
  40. package/dist/mcp-config.d.ts +36 -0
  41. package/dist/mcp-config.js +51 -0
  42. package/dist/mcp-config.js.map +1 -0
  43. package/dist/oauth.d.ts +8 -0
  44. package/dist/oauth.js +54 -15
  45. package/dist/oauth.js.map +1 -1
  46. package/dist/paths.d.ts +97 -0
  47. package/dist/paths.js +178 -0
  48. package/dist/paths.js.map +1 -0
  49. package/dist/project-config.d.ts +75 -0
  50. package/dist/project-config.js +55 -0
  51. package/dist/project-config.js.map +1 -0
  52. package/dist/workspace-resolve.d.ts +56 -24
  53. package/dist/workspace-resolve.js +106 -25
  54. package/dist/workspace-resolve.js.map +1 -1
  55. package/package.json +1 -1
package/dist/paths.js ADDED
@@ -0,0 +1,178 @@
1
+ import { existsSync, realpathSync } from 'node:fs';
2
+ import { homedir } from 'node:os';
3
+ import { dirname, join, resolve } from 'node:path';
4
+ /** Name of the per-project OrbitMap directory (`<project>/.orbitmap`). */
5
+ export const ORBITMAP_DIR = '.orbitmap';
6
+ /**
7
+ * Filename of *both* config files — `<project>/.orbitmap/config.json` (project-scoped,
8
+ * committable) and `~/.orbitmap/config.json` (machine-wide). Same name, different file:
9
+ * telling them apart is the job of {@link globalConfigPaths}, which the project walk-up
10
+ * below uses to skip the global one.
11
+ */
12
+ export const CONFIG_FILENAME = 'config.json';
13
+ /** Filename of the machine-local secret store (`~/.orbitmap/credentials.json`). */
14
+ export const CREDENTIALS_FILENAME = 'credentials.json';
15
+ let homeCache;
16
+ /**
17
+ * The resolved OrbitMap home, memoised.
18
+ *
19
+ * Deliberately a *function*, not a module-level constant: the CLI's own tests (and any
20
+ * embedder) set `ORBITMAP_CONFIG_HOME`/`XDG_CONFIG_HOME` after this module has been
21
+ * imported, and a constant captured at import time would ignore them — and would give
22
+ * `config.ts` and `oauth.ts` two independent, silently diverging copies. The memo is keyed
23
+ * on the inputs, so a later env change is picked up while repeat calls stay free.
24
+ */
25
+ export function resolveOrbitMapHome() {
26
+ const override = process.env['ORBITMAP_CONFIG_HOME'] ?? '';
27
+ const xdg = process.env['XDG_CONFIG_HOME'] ?? '';
28
+ const home = homedir();
29
+ const key = `${override}\u0000${xdg}\u0000${home}`;
30
+ if (homeCache?.key === key)
31
+ return homeCache.home;
32
+ const legacyDir = join(home, ORBITMAP_DIR);
33
+ const dir = override || (xdg ? join(xdg, 'orbitmap') : legacyDir);
34
+ const resolved = { dir, legacyDir };
35
+ homeCache = { key, home: resolved };
36
+ return resolved;
37
+ }
38
+ /**
39
+ * Path to read `filename` from: the new `home.dir` location if the file exists there,
40
+ * otherwise the legacy `~/.orbitmap` location (which may or may not exist either — callers
41
+ * still need their own existence check). When `home.dir` and `home.legacyDir` are the same
42
+ * (the common case — neither `ORBITMAP_CONFIG_HOME` nor `XDG_CONFIG_HOME` set) this is a
43
+ * no-op and just returns the one path.
44
+ */
45
+ export function resolveReadPath(home, filename) {
46
+ const primary = join(home.dir, filename);
47
+ if (home.dir === home.legacyDir || existsSync(primary))
48
+ return primary;
49
+ const legacy = join(home.legacyDir, filename);
50
+ return existsSync(legacy) ? legacy : primary;
51
+ }
52
+ /** Path to write `filename` to: always the new `home.dir` location. */
53
+ export function resolveWritePath(home, filename) {
54
+ return join(home.dir, filename);
55
+ }
56
+ /** Absolute path the global config is read from — the relocated one, or the legacy
57
+ * `~/.orbitmap/config.json` when the relocated one does not exist yet. */
58
+ export function globalConfigReadPath() {
59
+ return resolveReadPath(resolveOrbitMapHome(), CONFIG_FILENAME);
60
+ }
61
+ /** Absolute path the global config is written to — always the current home, which is not
62
+ * necessarily where {@link globalConfigReadPath} read it from. */
63
+ export function globalConfigWritePath() {
64
+ return resolveWritePath(resolveOrbitMapHome(), CONFIG_FILENAME);
65
+ }
66
+ /** Absolute path of the machine-local credential store, wherever the home now is. */
67
+ export function credentialsPath() {
68
+ return resolveWritePath(resolveOrbitMapHome(), CREDENTIALS_FILENAME);
69
+ }
70
+ /**
71
+ * Every path that is a *global* `config.json` for this machine — the current home and the
72
+ * legacy `~/.orbitmap` one, which is still read as a fallback. The project-config walk-up
73
+ * skips exactly these: same filename, different file, and pulling the global one in as if
74
+ * it were a project's own is the cross-project leak ADR 0002 exists to prevent.
75
+ */
76
+ export function globalConfigPaths() {
77
+ const home = resolveOrbitMapHome();
78
+ const paths = [join(home.dir, CONFIG_FILENAME)];
79
+ if (home.legacyDir !== home.dir)
80
+ paths.push(join(home.legacyDir, CONFIG_FILENAME));
81
+ return paths;
82
+ }
83
+ /**
84
+ * Canonical form of `path` for identity comparisons: symlinks resolved where the path
85
+ * exists, and lower-cased on Windows, whose filesystem is case-insensitive (`C:\Users\me`
86
+ * and `c:\users\me` are one directory). A plain `resolve()` string compare normalises
87
+ * neither, which is how the original `$HOME` walk-up guard silently failed.
88
+ */
89
+ function canonical(path) {
90
+ let out = resolve(path);
91
+ try {
92
+ out = realpathSync.native(out);
93
+ }
94
+ catch {
95
+ // Does not exist (yet) — the lexical form is the best we can do, and is enough:
96
+ // a path that does not exist cannot be a config file we would have read anyway.
97
+ }
98
+ return process.platform === 'win32' ? out.toLowerCase() : out;
99
+ }
100
+ /**
101
+ * True when `orbitmapDir` is an OrbitMap *home* rather than a project's `.orbitmap/`.
102
+ *
103
+ * `credentials.json` is the machine-local secret store. The CLI only ever writes it into
104
+ * the resolved home ({@link resolveOrbitMapHome}) and never into a project directory, so
105
+ * finding one next to a `config.json` means that directory is a home — whatever the current
106
+ * `$HOME` happens to say.
107
+ *
108
+ * That distinction cannot be made from the path alone once `$HOME` is not what it was when
109
+ * the home was created: an overridden `HOME`/`USERPROFILE` (CI, `sudo`, a roaming profile,
110
+ * a test harness) leaves the real `~/.orbitmap/config.json` sitting on the walk-up path as
111
+ * an ordinary ancestor directory. Skipping it is always the safe direction — the worst case
112
+ * is that a rung falls through to the next one, never that one project's settings leak into
113
+ * another.
114
+ */
115
+ function isOrbitMapHomeDir(orbitmapDir) {
116
+ return existsSync(join(orbitmapDir, CREDENTIALS_FILENAME));
117
+ }
118
+ /**
119
+ * Every existing `<dir>/.orbitmap/config.json` from `startDir` up to the user's home
120
+ * directory, **nearest first** — the same discovery behaviour as git looking for `.git`.
121
+ *
122
+ * This is the single implementation of the project-config walk-up; `project-config.ts`
123
+ * layers per-field resolution on top of it (ADR 0002 §2) and both `config.ts` and
124
+ * `workspace-resolve.ts` go through that, so a fix here applies to every ladder at once.
125
+ *
126
+ * Three invariants keep the global config out of the result:
127
+ *
128
+ * - **Any candidate equal to a {@link globalConfigPaths} entry is skipped.** That is the
129
+ * real invariant — it holds regardless of where the global config actually lives, so it
130
+ * also covers `ORBITMAP_CONFIG_HOME`/`XDG_CONFIG_HOME` relocating it somewhere in the
131
+ * middle of the walk.
132
+ * - **Any candidate sitting next to a `credentials.json` is skipped** — see
133
+ * {@link isOrbitMapHomeDir}, which catches a home the current `$HOME` no longer names.
134
+ * - **The walk stops at `$HOME`.** Nothing above a user's home is that user's project.
135
+ * Compared canonically ({@link canonical}) rather than as raw strings, so a symlinked
136
+ * `$HOME` (`/home/u` → `/data/home/u`) or a Windows case difference does not sail past it.
137
+ * The original guard was an exact `===` on `resolve()`d strings and therefore failed on
138
+ * both, silently handing the global config back as if it were a project's own.
139
+ */
140
+ export function findProjectConfigFiles(startDir = process.cwd()) {
141
+ const found = [];
142
+ const globals = new Set(globalConfigPaths().map(canonical));
143
+ const homeStop = canonical(homedir());
144
+ let dir = resolve(startDir);
145
+ for (;;) {
146
+ const orbitmapDir = join(dir, ORBITMAP_DIR);
147
+ const candidate = join(orbitmapDir, CONFIG_FILENAME);
148
+ if (existsSync(candidate) &&
149
+ !globals.has(canonical(candidate)) &&
150
+ !isOrbitMapHomeDir(orbitmapDir)) {
151
+ found.push(candidate);
152
+ }
153
+ if (canonical(dir) === homeStop)
154
+ return found;
155
+ const parent = dirname(dir);
156
+ if (parent === dir)
157
+ return found;
158
+ dir = parent;
159
+ }
160
+ }
161
+ /**
162
+ * Per-field walk-up: hand each project config file, nearest first, to `read` and return the
163
+ * first defined value together with the file it came from.
164
+ *
165
+ * "Nearest file that *sets this field* wins" — not "nearest file wins for everything".
166
+ * A monorepo package can set `agent` in its own `.orbitmap/config.json` and still inherit
167
+ * `mode`/`area` from the repository root, which is the per-field layering ADR 0002 §2
168
+ * promises (the `npm`/`git config` model).
169
+ */
170
+ export function resolveProjectField(startDir, read) {
171
+ for (const file of findProjectConfigFiles(startDir)) {
172
+ const value = read(file);
173
+ if (value !== undefined)
174
+ return { value, file };
175
+ }
176
+ return undefined;
177
+ }
178
+ //# sourceMappingURL=paths.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paths.js","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEnD,0EAA0E;AAC1E,MAAM,CAAC,MAAM,YAAY,GAAG,WAAW,CAAC;AAExC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,aAAa,CAAC;AAE7C,mFAAmF;AACnF,MAAM,CAAC,MAAM,oBAAoB,GAAG,kBAAkB,CAAC;AAkBvD,IAAI,SAA0D,CAAC;AAE/D;;;;;;;;GAQG;AACH,MAAM,UAAU,mBAAmB;IACjC,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,IAAI,EAAE,CAAC;IAC3D,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC;IACjD,MAAM,IAAI,GAAG,OAAO,EAAE,CAAC;IACvB,MAAM,GAAG,GAAG,GAAG,QAAQ,SAAS,GAAG,SAAS,IAAI,EAAE,CAAC;IAEnD,IAAI,SAAS,EAAE,GAAG,KAAK,GAAG;QAAE,OAAO,SAAS,CAAC,IAAI,CAAC;IAElD,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;IAC3C,MAAM,GAAG,GAAG,QAAQ,IAA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M,WAAW,GAAG,IAAI,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;QAC5C,MAAM,SAAS,GAAG,IAAI,CAAC,WAAW,EAAE,eAAe,CAAC,CAAC;QACrD,IACE,UAAU,CAAC,SAAS,CAAC;YACrB,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;YAClC,CAAC,iBAAiB,CAAC,WAAW,CAAC,EAC/B,CAAC;YACD,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACxB,CAAC;QAED,IAAI,SAAS,CAAC,GAAG,CAAC,KAAK,QAAQ;YAAE,OAAO,KAAK,CAAC;QAE9C,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;QAC5B,IAAI,MAAM,KAAK,GAAG;YAAE,OAAO,KAAK,CAAC;QACjC,GAAG,GAAG,MAAM,CAAC;IACf,CAAC;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,mBAAmB,CACjC,QAAgB,EAChB,IAAqC;IAErC,KAAK,MAAM,IAAI,IAAI,sBAAsB,CAAC,QAAQ,CAAC,EAAE,CAAC;QACpD,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;QACzB,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IAClD,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -0,0 +1,75 @@
1
+ /**
2
+ * The config file schema and the per-field project walk-up, in one place.
3
+ *
4
+ * This lives apart from `config.ts` (which owns the *global* file: loading it, migrating
5
+ * it, resolving credentials from it) so that both it and `workspace-resolve.ts` can use the
6
+ * one implementation without `workspace-resolve.ts` having to depend on the global-config
7
+ * machinery for it. The discovery underneath — walking up, skipping the global config,
8
+ * stopping at `$HOME` — lives in `paths.ts` and is shared with everything else.
9
+ *
10
+ * See `docs/adr/0002-project-scoped-config.md`.
11
+ */
12
+ /** Storage backend for domain data. Absent in a config file means `'cloud'`. */
13
+ export type OrbitMapMode = 'cloud' | 'local';
14
+ /**
15
+ * Shape shared by both config files: `<project>/.orbitmap/config.json` and
16
+ * `~/.orbitmap/config.json`.
17
+ *
18
+ * Per ADR 0002 a config file holds **no secrets**. The agent's API key lives in
19
+ * `~/.orbitmap/credentials.json` (see `oauth.ts`), keyed by `agent` — the project says
20
+ * *which* agent to use, the machine holds *that agent's* credential. `api_key` below is a
21
+ * read-only fallback for configs written before this change; `loadConfig()` migrates it out
22
+ * on first read so it never appears in a config the CLI itself wrote.
23
+ *
24
+ * The interface lists the fields the CLI *understands*; it is not the full set of keys a
25
+ * file may hold. Both save functions merge into whatever is already on disk, so a key
26
+ * written by a newer (or older) version survives a write from this one — a read must never
27
+ * be able to destroy data (see `mergeIntoFile` in `config.ts`).
28
+ */
29
+ export interface OrbitMapConfig {
30
+ /** On-disk format version of *this* file. `0`/absent = pre-ADR-0002. */
31
+ schema_version?: number;
32
+ /** `'cloud'` (default when absent) or `'local'`. */
33
+ mode?: OrbitMapMode;
34
+ /**
35
+ * Default local workspace directory. Global config only — a project's own workspace is
36
+ * found by the `.orbitmap/workspace.yml` / `link.json` walk-up, never by this field.
37
+ * **Must be absolute**: a relative value would resolve against the current directory and
38
+ * therefore mean a different workspace per project, which is the same cross-project leak
39
+ * ADR 0002 removes elsewhere. A relative value is ignored with a warning.
40
+ */
41
+ workspace_path?: string;
42
+ /** Name of the agent profile to use — looked up in `~/.orbitmap/credentials.json`. */
43
+ agent?: string;
44
+ /** Default area slug/id. */
45
+ area?: string;
46
+ /** @deprecated Legacy secret, read once for migration then dropped. Never written. */
47
+ api_key?: string;
48
+ }
49
+ /**
50
+ * Parse and validate a raw config object (either file) — mistyped fields drop out instead
51
+ * of propagating a garbage value into the resolution ladders. Unknown keys are not
52
+ * represented here but are never lost on write (see `mergeIntoFile` in `config.ts`).
53
+ */
54
+ export declare function parseConfig(raw: unknown): OrbitMapConfig;
55
+ /** Read and validate one project `.orbitmap/config.json`; `undefined` when it is missing or
56
+ * malformed — a broken file is treated as absent rather than throwing mid-ladder. */
57
+ export declare function readProjectConfigFile(file: string): OrbitMapConfig | undefined;
58
+ /** One field's value together with the project config file that supplied it. */
59
+ export interface ResolvedProjectField<T> {
60
+ value: T;
61
+ /** Absolute path of the `.orbitmap/config.json` the value came from. */
62
+ file: string;
63
+ }
64
+ /**
65
+ * Resolve one field by walking up from `startDir`, **per field** (ADR 0002 §2): the nearest
66
+ * `.orbitmap/config.json` that actually *sets* `field` wins, not merely the nearest file.
67
+ *
68
+ * A monorepo package that pins only its own `agent` still inherits `mode` and `area` from
69
+ * the repository root — with "nearest file wins as a unit" the root's settings would vanish
70
+ * the moment a package added a config of its own.
71
+ *
72
+ * Sync (like `findLinkFile` in `workspace-resolve.ts`) so the synchronous resolution ladders
73
+ * can use it without threading promises through every rung.
74
+ */
75
+ export declare function resolveProjectConfigField<K extends keyof OrbitMapConfig>(field: K, startDir?: string): ResolvedProjectField<NonNullable<OrbitMapConfig[K]>> | undefined;
@@ -0,0 +1,55 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { resolveProjectField } from './paths.js';
3
+ /**
4
+ * Parse and validate a raw config object (either file) — mistyped fields drop out instead
5
+ * of propagating a garbage value into the resolution ladders. Unknown keys are not
6
+ * represented here but are never lost on write (see `mergeIntoFile` in `config.ts`).
7
+ */
8
+ export function parseConfig(raw) {
9
+ if (typeof raw !== 'object' || raw === null)
10
+ return {};
11
+ const r = raw;
12
+ const config = {};
13
+ if (typeof r['schema_version'] === 'number')
14
+ config.schema_version = r['schema_version'];
15
+ if (r['mode'] === 'cloud' || r['mode'] === 'local')
16
+ config.mode = r['mode'];
17
+ if (typeof r['workspace_path'] === 'string' && r['workspace_path']) {
18
+ config.workspace_path = r['workspace_path'];
19
+ }
20
+ if (typeof r['agent'] === 'string' && r['agent'])
21
+ config.agent = r['agent'];
22
+ if (typeof r['area'] === 'string' && r['area'])
23
+ config.area = r['area'];
24
+ if (typeof r['api_key'] === 'string' && r['api_key'])
25
+ config.api_key = r['api_key'];
26
+ return config;
27
+ }
28
+ /** Read and validate one project `.orbitmap/config.json`; `undefined` when it is missing or
29
+ * malformed — a broken file is treated as absent rather than throwing mid-ladder. */
30
+ export function readProjectConfigFile(file) {
31
+ try {
32
+ return parseConfig(JSON.parse(readFileSync(file, 'utf-8')));
33
+ }
34
+ catch {
35
+ return undefined;
36
+ }
37
+ }
38
+ /**
39
+ * Resolve one field by walking up from `startDir`, **per field** (ADR 0002 §2): the nearest
40
+ * `.orbitmap/config.json` that actually *sets* `field` wins, not merely the nearest file.
41
+ *
42
+ * A monorepo package that pins only its own `agent` still inherits `mode` and `area` from
43
+ * the repository root — with "nearest file wins as a unit" the root's settings would vanish
44
+ * the moment a package added a config of its own.
45
+ *
46
+ * Sync (like `findLinkFile` in `workspace-resolve.ts`) so the synchronous resolution ladders
47
+ * can use it without threading promises through every rung.
48
+ */
49
+ export function resolveProjectConfigField(field, startDir = process.cwd()) {
50
+ const hit = resolveProjectField(startDir, (file) => readProjectConfigFile(file)?.[field]);
51
+ return hit
52
+ ? { value: hit.value, file: hit.file }
53
+ : undefined;
54
+ }
55
+ //# sourceMappingURL=project-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project-config.js","sourceRoot":"","sources":["../src/project-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAqDjD;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,GAAY;IACtC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI;QAAE,OAAO,EAAE,CAAC;IACvD,MAAM,CAAC,GAAG,GAA8B,CAAC;IACzC,MAAM,MAAM,GAAmB,EAAE,CAAC;IAElC,IAAI,OAAO,CAAC,CAAC,gBAAgB,CAAC,KAAK,QAAQ;QAAE,MAAM,CAAC,cAAc,GAAG,CAAC,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IAAI,EAAE,EAAE,CAAC,qBAAqB,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAC1F,OAAO,GAAG;QACR,CAAC,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,KAAuC,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE;QACxE,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC"}
@@ -1,7 +1,10 @@
1
1
  import { type OrbitMapConfig, type OrbitMapMode } from './config.js';
2
+ import { ORBITMAP_DIR } from './paths.js';
2
3
  export type { OrbitMapMode };
3
- /** Name of the per-project OrbitMap directory (`<project>/.orbitmap`). */
4
- export declare const ORBITMAP_DIR = ".orbitmap";
4
+ /** Name of the per-project OrbitMap directory (`<project>/.orbitmap`). Defined in
5
+ * `paths.ts` (which owns the project-config walk-up) and re-exported here, where most
6
+ * callers already look for it. */
7
+ export { ORBITMAP_DIR };
5
8
  /** Project-local pointer at a workspace living elsewhere on disk. */
6
9
  export declare const LINK_FILE = "link.json";
7
10
  /** Marker file that identifies a directory as a local workspace. */
@@ -48,18 +51,32 @@ export interface ResolveOptions {
48
51
  link?: FoundWorkspaceLink | undefined;
49
52
  }
50
53
  /**
51
- * Mode resolution (§3.3) — **per project first, global config only as a fallback**,
52
- * first match wins:
54
+ * Mode resolution (ADR 0002, extending spec §3.3) — **per project first, global config
55
+ * only as a fallback**, first match wins:
53
56
  *
54
57
  * 1. `--workspace <path>` flag → local (explicit override, no further checks)
55
58
  * 2. `ORBITMAP_MODE=local|cloud` → that mode, for this invocation
56
- * 3. local auto-detect: nearest `.orbitmap/link.json` or `.orbitmap/workspace.yml`,
59
+ * 3. nearest `.orbitmap/config.json` **that sets `mode`** → that value **[ADR 0002]**
60
+ * 4. local auto-detect: nearest `.orbitmap/link.json` or `.orbitmap/workspace.yml`,
57
61
  * walking up from cwd to the filesystem root (as git looks for `.git`) → local
58
- * 4. global config `mode` (absent or unknown ⇒ `'cloud'`)
62
+ * 5. global config `mode` (absent or unknown ⇒ `'cloud'`)
59
63
  *
60
- * Rung 3 is what keeps projects independent: a directory that ran `orbitmap init` → local
61
- * is local from then on, and a directory that never did keeps resolving through its own
62
- * config — one project's choice can never flip another's.
64
+ * Rung 3 is resolved **per field** (`resolveProjectConfigField`), not "nearest file wins":
65
+ * a `packages/api/.orbitmap/config.json` that only pins an `agent` does not shadow the
66
+ * repository root's `mode`. See ADR 0002 §2.
67
+ *
68
+ * Rung 3 exists because the whole per-project scoping mechanism (link.json,
69
+ * workspace.yml-based auto-detect) was originally built only for *local* mode — a cloud
70
+ * project had no file of its own to declare itself cloud in, so it depended entirely on
71
+ * rung 5 never being flipped by another project. `.orbitmap/config.json` gives cloud
72
+ * projects that same voice, and it outranks rung 4 on purpose: a project that explicitly
73
+ * declares `mode: "cloud"` must not be dragged back into local mode by a leftover
74
+ * `link.json`/`workspace.yml` in the same directory.
75
+ *
76
+ * Rung 4 is what keeps *un-declared* projects independent: a directory that ran
77
+ * `orbitmap init` → local is local from then on via its own marker file, and a directory
78
+ * that never did keeps resolving through its own config — one project's choice can never
79
+ * flip another's.
63
80
  */
64
81
  export declare function resolveMode(options?: ResolveOptions): OrbitMapMode;
65
82
  /**
@@ -68,36 +85,51 @@ export declare function resolveMode(options?: ResolveOptions): OrbitMapMode;
68
85
  * 2. `ORBITMAP_WORKSPACE` env var
69
86
  * 3. nearest `.orbitmap/link.json` (walking up from cwd) → its `workspace` field
70
87
  * 4. nearest `.orbitmap/workspace.yml` (walking up from cwd) → that `.orbitmap`
71
- * 5. global config `workspace_path`
72
- * 6. otherwise: `OrbitMapAPIError` with code `WORKSPACE_NOT_FOUND`
88
+ * 5. the `.orbitmap/` directory of the nearest project config that sets `mode: "local"`,
89
+ * when that directory is itself a workspace **[ADR 0002]**
90
+ * 6. global config `workspace_path` — **must be absolute** (a relative value is ignored
91
+ * with a warning; see {@link OrbitMapConfig.workspace_path})
92
+ * 7. otherwise: `OrbitMapAPIError` with code `WORKSPACE_NOT_FOUND`
73
93
  *
74
- * The returned path is absolute; its existence is not verified (except for rung 4,
75
- * which is defined by the marker file).
94
+ * Rung 5 is what makes a committed `{"mode": "local"}` usable on its own: without it, a
95
+ * project config that declares local mode has nowhere to point and every command fails with
96
+ * `WORKSPACE_NOT_FOUND`. It usually resolves to the same directory as rung 4 — the point is
97
+ * that it does not *depend* on the auto-detect walk finding the marker first, and that it
98
+ * anchors on the config file that made this project local rather than on the current
99
+ * directory.
100
+ *
101
+ * The returned path is absolute; its existence is not verified (except for rungs 4 and 5,
102
+ * which are defined by the marker file).
76
103
  */
77
104
  export declare function resolveWorkspacePath(options?: ResolveOptions): string;
78
105
  /**
79
106
  * Which rung of the area ladder produced a slug.
80
107
  *
81
- * `flag`/`env`/`link` are **explicit**: the user (or the project's own `link.json`) named
82
- * that area, so a slug that does not exist must fail loudly. `config` is the machine-wide
83
- * default the weakest rung, and the only one a local workspace is allowed to override
84
- * or ignore (see `createLocalContext`).
108
+ * `flag`/`env`/`link`/`project-config` are **explicit**: the user, the project's own
109
+ * `link.json`, or the project's own `.orbitmap/config.json` named that area, so a slug that
110
+ * does not exist must fail loudly. `config` is the machine-wide default (the deprecated
111
+ * global `~/.orbitmap/config.json` `area` — ADR 0002) — the weakest rung, and the only one
112
+ * a local workspace is allowed to override or ignore (see `createLocalContext`).
85
113
  */
86
- export type AreaSource = 'flag' | 'env' | 'link' | 'config';
114
+ export type AreaSource = 'flag' | 'env' | 'link' | 'project-config' | 'config';
87
115
  /** An area slug together with the rung it came from. */
88
116
  export interface ResolvedAreaSlug {
89
117
  area?: string;
90
118
  source?: AreaSource;
91
119
  }
92
120
  /**
93
- * Area resolution (§3.3), explicit sources only:
94
- * `--area` → `ORBITMAP_AREA` → `link.json.area` → global config `area`.
121
+ * Area resolution (ADR 0002, extending spec §3.3), explicit sources only:
122
+ * `--area` → `ORBITMAP_AREA` → `link.json.area` → nearest `.orbitmap/config.json`
123
+ * **that sets `area`** **[ADR 0002]** → global config `area` (deprecated).
124
+ *
125
+ * The project-config rung is per-field (`resolveProjectConfigField`): a nested config that
126
+ * sets only `agent` does not hide an `area` pinned by the repository root.
95
127
  *
96
128
  * The two remaining rungs — the workspace's own `workspace.yml` `default_area` (which
97
- * sits *between* `link.json` and the global config) and "workspace has exactly one area →
98
- * auto-select it" — require reading the workspace tree and therefore live in the local
99
- * adapter (`createLocalContext`); this function stays synchronous and file-store-free so
100
- * that cloud mode never touches a workspace file. The `source` lets the adapter tell an
129
+ * sits *between* the project config and the global config) and "workspace has exactly one
130
+ * area → auto-select it" — require reading the workspace tree and therefore live in the
131
+ * local adapter (`createLocalContext`); this function stays synchronous and file-store-free
132
+ * so that cloud mode never touches a workspace file. The `source` lets the adapter tell an
101
133
  * explicit request apart from the machine-wide default.
102
134
  */
103
135
  export declare function resolveArea(options?: ResolveOptions): ResolvedAreaSlug;
@@ -2,8 +2,12 @@ import { existsSync, readFileSync } from 'node:fs';
2
2
  import { dirname, isAbsolute, join, resolve } from 'node:path';
3
3
  import { loadConfig } from './config.js';
4
4
  import { OrbitMapAPIError } from './errors.js';
5
- /** Name of the per-project OrbitMap directory (`<project>/.orbitmap`). */
6
- export const ORBITMAP_DIR = '.orbitmap';
5
+ import { CONFIG_FILENAME, globalConfigReadPath, ORBITMAP_DIR } from './paths.js';
6
+ import { resolveProjectConfigField } from './project-config.js';
7
+ /** Name of the per-project OrbitMap directory (`<project>/.orbitmap`). Defined in
8
+ * `paths.ts` (which owns the project-config walk-up) and re-exported here, where most
9
+ * callers already look for it. */
10
+ export { ORBITMAP_DIR };
7
11
  /** Project-local pointer at a workspace living elsewhere on disk. */
8
12
  export const LINK_FILE = 'link.json';
9
13
  /** Marker file that identifies a directory as a local workspace. */
@@ -73,18 +77,32 @@ function readLinkFile(file) {
73
77
  }
74
78
  }
75
79
  /**
76
- * Mode resolution (§3.3) — **per project first, global config only as a fallback**,
77
- * first match wins:
80
+ * Mode resolution (ADR 0002, extending spec §3.3) — **per project first, global config
81
+ * only as a fallback**, first match wins:
78
82
  *
79
83
  * 1. `--workspace <path>` flag → local (explicit override, no further checks)
80
84
  * 2. `ORBITMAP_MODE=local|cloud` → that mode, for this invocation
81
- * 3. local auto-detect: nearest `.orbitmap/link.json` or `.orbitmap/workspace.yml`,
85
+ * 3. nearest `.orbitmap/config.json` **that sets `mode`** → that value **[ADR 0002]**
86
+ * 4. local auto-detect: nearest `.orbitmap/link.json` or `.orbitmap/workspace.yml`,
82
87
  * walking up from cwd to the filesystem root (as git looks for `.git`) → local
83
- * 4. global config `mode` (absent or unknown ⇒ `'cloud'`)
88
+ * 5. global config `mode` (absent or unknown ⇒ `'cloud'`)
84
89
  *
85
- * Rung 3 is what keeps projects independent: a directory that ran `orbitmap init` → local
86
- * is local from then on, and a directory that never did keeps resolving through its own
87
- * config — one project's choice can never flip another's.
90
+ * Rung 3 is resolved **per field** (`resolveProjectConfigField`), not "nearest file wins":
91
+ * a `packages/api/.orbitmap/config.json` that only pins an `agent` does not shadow the
92
+ * repository root's `mode`. See ADR 0002 §2.
93
+ *
94
+ * Rung 3 exists because the whole per-project scoping mechanism (link.json,
95
+ * workspace.yml-based auto-detect) was originally built only for *local* mode — a cloud
96
+ * project had no file of its own to declare itself cloud in, so it depended entirely on
97
+ * rung 5 never being flipped by another project. `.orbitmap/config.json` gives cloud
98
+ * projects that same voice, and it outranks rung 4 on purpose: a project that explicitly
99
+ * declares `mode: "cloud"` must not be dragged back into local mode by a leftover
100
+ * `link.json`/`workspace.yml` in the same directory.
101
+ *
102
+ * Rung 4 is what keeps *un-declared* projects independent: a directory that ran
103
+ * `orbitmap init` → local is local from then on via its own marker file, and a directory
104
+ * that never did keeps resolving through its own config — one project's choice can never
105
+ * flip another's.
88
106
  */
89
107
  export function resolveMode(options = {}) {
90
108
  if (options.workspace ?? workspaceFlag)
@@ -93,14 +111,15 @@ export function resolveMode(options = {}) {
93
111
  if (env === 'local' || env === 'cloud')
94
112
  return env;
95
113
  const cwd = resolve(options.cwd ?? process.cwd());
114
+ const projectMode = resolveProjectConfigField('mode', cwd)?.value;
115
+ if (projectMode)
116
+ return projectMode;
96
117
  const link = options.link !== undefined ? options.link : findLinkFile(cwd);
97
118
  if (link)
98
119
  return 'local';
99
120
  if (findWorkspaceDir(cwd))
100
121
  return 'local';
101
- return (options.config?.mode ?? '').toString().trim().toLowerCase() === 'local'
102
- ? 'local'
103
- : 'cloud';
122
+ return options.config?.mode === 'local' ? 'local' : 'cloud';
104
123
  }
105
124
  /**
106
125
  * Workspace directory resolution (§3.3), first match wins:
@@ -108,11 +127,21 @@ export function resolveMode(options = {}) {
108
127
  * 2. `ORBITMAP_WORKSPACE` env var
109
128
  * 3. nearest `.orbitmap/link.json` (walking up from cwd) → its `workspace` field
110
129
  * 4. nearest `.orbitmap/workspace.yml` (walking up from cwd) → that `.orbitmap`
111
- * 5. global config `workspace_path`
112
- * 6. otherwise: `OrbitMapAPIError` with code `WORKSPACE_NOT_FOUND`
130
+ * 5. the `.orbitmap/` directory of the nearest project config that sets `mode: "local"`,
131
+ * when that directory is itself a workspace **[ADR 0002]**
132
+ * 6. global config `workspace_path` — **must be absolute** (a relative value is ignored
133
+ * with a warning; see {@link OrbitMapConfig.workspace_path})
134
+ * 7. otherwise: `OrbitMapAPIError` with code `WORKSPACE_NOT_FOUND`
113
135
  *
114
- * The returned path is absolute; its existence is not verified (except for rung 4,
115
- * which is defined by the marker file).
136
+ * Rung 5 is what makes a committed `{"mode": "local"}` usable on its own: without it, a
137
+ * project config that declares local mode has nowhere to point and every command fails with
138
+ * `WORKSPACE_NOT_FOUND`. It usually resolves to the same directory as rung 4 — the point is
139
+ * that it does not *depend* on the auto-detect walk finding the marker first, and that it
140
+ * anchors on the config file that made this project local rather than on the current
141
+ * directory.
142
+ *
143
+ * The returned path is absolute; its existence is not verified (except for rungs 4 and 5,
144
+ * which are defined by the marker file).
116
145
  */
117
146
  export function resolveWorkspacePath(options = {}) {
118
147
  const cwd = resolve(options.cwd ?? process.cwd());
@@ -130,20 +159,50 @@ export function resolveWorkspacePath(options = {}) {
130
159
  const local = findWorkspaceDir(cwd);
131
160
  if (local)
132
161
  return local;
162
+ const declaredLocal = resolveProjectConfigField('mode', cwd);
163
+ if (declaredLocal?.value === 'local') {
164
+ const configDir = dirname(declaredLocal.file);
165
+ if (existsSync(join(configDir, WORKSPACE_FILE)))
166
+ return configDir;
167
+ }
133
168
  const configured = options.config?.workspace_path;
134
- if (configured)
135
- return resolve(cwd, configured);
169
+ if (configured) {
170
+ if (isAbsolute(configured))
171
+ return resolve(configured);
172
+ warnRelativeWorkspacePath(configured);
173
+ }
136
174
  throw OrbitMapAPIError.workspaceNotFound();
137
175
  }
176
+ let warnedRelativeWorkspacePath = false;
138
177
  /**
139
- * Area resolution (§3.3), explicit sources only:
140
- * `--area` → `ORBITMAP_AREA` → `link.json.area` → global config `area`.
178
+ * A relative global `workspace_path` is ignored, not resolved against `process.cwd()`.
179
+ *
180
+ * Resolving it against the current directory would make one machine-wide setting mean a
181
+ * different workspace in every project — the same cross-project leak ADR 0002 removes from
182
+ * `area`, and worse here because it silently points at a directory that does not exist
183
+ * rather than at someone else's data.
184
+ */
185
+ function warnRelativeWorkspacePath(configured) {
186
+ if (warnedRelativeWorkspacePath)
187
+ return;
188
+ warnedRelativeWorkspacePath = true;
189
+ console.warn(`[orbitmap] Ignoring "workspace_path": "${configured}" in the global config — it must ` +
190
+ 'be an absolute path. A relative one would mean a different directory in every ' +
191
+ 'project. Use --workspace or ORBITMAP_WORKSPACE for a per-invocation override.');
192
+ }
193
+ /**
194
+ * Area resolution (ADR 0002, extending spec §3.3), explicit sources only:
195
+ * `--area` → `ORBITMAP_AREA` → `link.json.area` → nearest `.orbitmap/config.json`
196
+ * **that sets `area`** **[ADR 0002]** → global config `area` (deprecated).
197
+ *
198
+ * The project-config rung is per-field (`resolveProjectConfigField`): a nested config that
199
+ * sets only `agent` does not hide an `area` pinned by the repository root.
141
200
  *
142
201
  * The two remaining rungs — the workspace's own `workspace.yml` `default_area` (which
143
- * sits *between* `link.json` and the global config) and "workspace has exactly one area →
144
- * auto-select it" — require reading the workspace tree and therefore live in the local
145
- * adapter (`createLocalContext`); this function stays synchronous and file-store-free so
146
- * that cloud mode never touches a workspace file. The `source` lets the adapter tell an
202
+ * sits *between* the project config and the global config) and "workspace has exactly one
203
+ * area → auto-select it" — require reading the workspace tree and therefore live in the
204
+ * local adapter (`createLocalContext`); this function stays synchronous and file-store-free
205
+ * so that cloud mode never touches a workspace file. The `source` lets the adapter tell an
147
206
  * explicit request apart from the machine-wide default.
148
207
  */
149
208
  export function resolveArea(options = {}) {
@@ -156,11 +215,33 @@ export function resolveArea(options = {}) {
156
215
  const found = options.link !== undefined ? options.link : findLinkFile(cwd);
157
216
  if (found?.link.area)
158
217
  return { area: found.link.area, source: 'link' };
218
+ const projectArea = resolveProjectConfigField('area', cwd)?.value;
219
+ if (projectArea)
220
+ return { area: projectArea, source: 'project-config' };
159
221
  const configured = options.config?.area;
160
- if (configured)
222
+ if (configured) {
223
+ warnDeprecatedGlobalArea();
161
224
  return { area: configured, source: 'config' };
225
+ }
162
226
  return {};
163
227
  }
228
+ let warnedDeprecatedGlobalArea = false;
229
+ /**
230
+ * Warn — once per process — that the deprecated machine-wide `area` rung was used.
231
+ *
232
+ * Deliberately raised from the rung itself rather than from `loadConfig()`: warning on
233
+ * every load nagged users whose global `area` is already shadowed by `ORBITMAP_AREA`, a
234
+ * project config or a `link.json` — i.e. people who have already done what the warning
235
+ * asks — and fired in local mode, where the rung is usually irrelevant.
236
+ */
237
+ function warnDeprecatedGlobalArea() {
238
+ if (warnedDeprecatedGlobalArea)
239
+ return;
240
+ warnedDeprecatedGlobalArea = true;
241
+ console.warn(`[orbitmap] The "area" in ${globalConfigReadPath()} is deprecated — move it to ` +
242
+ `${ORBITMAP_DIR}/${CONFIG_FILENAME} in the project it belongs to. Still honoured ` +
243
+ 'this version; see docs/adr/0002-project-scoped-config.md.');
244
+ }
164
245
  /** {@link resolveArea} without the rung — the historical signature. */
165
246
  export function resolveAreaSlug(options = {}) {
166
247
  return resolveArea(options).area;