synomem 0.7.2 → 0.9.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.
Files changed (93) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/README.md +47 -68
  3. package/dist/backend.d.ts +18 -6
  4. package/dist/backend.d.ts.map +1 -1
  5. package/dist/backend.js +55 -41
  6. package/dist/backend.js.map +1 -1
  7. package/dist/cli.d.ts +20 -25
  8. package/dist/cli.d.ts.map +1 -1
  9. package/dist/cli.js +1394 -1281
  10. package/dist/cli.js.map +1 -1
  11. package/dist/configure.d.ts +12 -46
  12. package/dist/configure.d.ts.map +1 -1
  13. package/dist/configure.js +51 -192
  14. package/dist/configure.js.map +1 -1
  15. package/dist/credentials.d.ts +73 -33
  16. package/dist/credentials.d.ts.map +1 -1
  17. package/dist/credentials.js +167 -43
  18. package/dist/credentials.js.map +1 -1
  19. package/dist/discover.d.ts +10 -13
  20. package/dist/discover.d.ts.map +1 -1
  21. package/dist/discover.js +45 -30
  22. package/dist/discover.js.map +1 -1
  23. package/dist/errors.d.ts +1 -1
  24. package/dist/errors.d.ts.map +1 -1
  25. package/dist/errors.js +5 -0
  26. package/dist/errors.js.map +1 -1
  27. package/dist/import.d.ts +3 -0
  28. package/dist/import.d.ts.map +1 -1
  29. package/dist/import.js +3 -0
  30. package/dist/import.js.map +1 -1
  31. package/dist/index.d.ts +9 -7
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +6 -5
  34. package/dist/index.js.map +1 -1
  35. package/dist/mcp/index.d.ts +18 -7
  36. package/dist/mcp/index.d.ts.map +1 -1
  37. package/dist/mcp/index.js +402 -183
  38. package/dist/mcp/index.js.map +1 -1
  39. package/dist/mcp-server.d.ts +5 -1
  40. package/dist/mcp-server.d.ts.map +1 -1
  41. package/dist/mcp-server.js +27 -105
  42. package/dist/mcp-server.js.map +1 -1
  43. package/dist/oauth.d.ts +31 -33
  44. package/dist/oauth.d.ts.map +1 -1
  45. package/dist/oauth.js +178 -125
  46. package/dist/oauth.js.map +1 -1
  47. package/dist/profiles.d.ts +243 -0
  48. package/dist/profiles.d.ts.map +1 -0
  49. package/dist/profiles.js +465 -0
  50. package/dist/profiles.js.map +1 -0
  51. package/dist/project.d.ts +8 -39
  52. package/dist/project.d.ts.map +1 -1
  53. package/dist/project.js +36 -94
  54. package/dist/project.js.map +1 -1
  55. package/dist/remote.d.ts +23 -15
  56. package/dist/remote.d.ts.map +1 -1
  57. package/dist/remote.js +54 -49
  58. package/dist/remote.js.map +1 -1
  59. package/dist/resolvers.d.ts +47 -0
  60. package/dist/resolvers.d.ts.map +1 -0
  61. package/dist/resolvers.js +255 -0
  62. package/dist/resolvers.js.map +1 -0
  63. package/dist/service.d.ts +2 -0
  64. package/dist/service.d.ts.map +1 -1
  65. package/dist/skill-install.d.ts +4 -6
  66. package/dist/skill-install.d.ts.map +1 -1
  67. package/dist/skill-install.js +13 -12
  68. package/dist/skill-install.js.map +1 -1
  69. package/dist/types.d.ts +51 -0
  70. package/dist/types.d.ts.map +1 -1
  71. package/docs/cli.md +173 -196
  72. package/docs/mcp.md +69 -65
  73. package/package.json +1 -1
  74. package/skills/synomem/SKILL.md +30 -4
  75. package/skills/synomem/references/examples.md +14 -0
  76. package/src/backend.ts +66 -64
  77. package/src/cli.ts +2137 -2163
  78. package/src/configure.ts +62 -241
  79. package/src/credentials.ts +208 -84
  80. package/src/discover.ts +60 -36
  81. package/src/errors.ts +5 -0
  82. package/src/import.ts +5 -0
  83. package/src/index.ts +14 -12
  84. package/src/mcp/index.ts +473 -194
  85. package/src/mcp-server.ts +32 -114
  86. package/src/oauth.ts +229 -130
  87. package/src/profiles.ts +644 -0
  88. package/src/project.ts +42 -108
  89. package/src/remote.ts +69 -58
  90. package/src/resolvers.ts +299 -0
  91. package/src/service.ts +2 -0
  92. package/src/skill-install.ts +17 -18
  93. package/src/types.ts +46 -0
@@ -0,0 +1,465 @@
1
+ /**
2
+ * Profiles, connections, and presets — the only runtime identity interface.
3
+ *
4
+ * `<home>/profiles.json` (plan §8):
5
+ *
6
+ * {
7
+ * "version": 1,
8
+ * "credentials": { "codex-mac": { kind, apiUrl, store, secretRef, … } },
9
+ * "profiles": {
10
+ * "codex-gracie": { "credentialRef": "codex-mac", "contextId": "ctx_…" },
11
+ * "gracie-local": { "backend": "local", "actorId": "01…", "contextId": "lctx_…" }
12
+ * },
13
+ * "harnessPresets": { "codex": ["codex-gracie", "codex-astra"] },
14
+ * "defaultProfile": "gracie-local"
15
+ * }
16
+ *
17
+ * A credential entry holds only a REFERENCE to its secret (`secretRef`, an
18
+ * opaque key into the keychain or restricted-file store); the secret itself
19
+ * never appears in this file. A profile routes one stable context through one
20
+ * credential; several profiles may share a credential. Nothing here is
21
+ * authority: the API authorizes every operation against the connection's
22
+ * grant, whatever a profile says.
23
+ *
24
+ * Kept separate from `<home>/config.json`, which is the local store's own
25
+ * policy file and persistent workspace identity.
26
+ */
27
+ import { existsSync } from 'node:fs';
28
+ import { join } from 'node:path';
29
+ import { z } from 'zod';
30
+ import { localStoreWorkspaceId, readSynomemConfig } from './backend.js';
31
+ import { resolveHome } from './config.js';
32
+ import { withCredentialLock, } from './credentials.js';
33
+ import { SynomemError } from './errors.js';
34
+ import { atomicWriteFile, readJsonFile } from './fs-utils.js';
35
+ import { refreshOAuthCredential } from './oauth.js';
36
+ import { findProjectSelection } from './project.js';
37
+ import { createLocalResolver, createRemoteResolver, localContextId, } from './resolvers.js';
38
+ export const PROFILES_FILE = 'profiles.json';
39
+ const nameSchema = z
40
+ .string()
41
+ .regex(/^[a-z0-9][a-z0-9._-]{0,62}$/i, 'names use letters, digits, dot, dash and underscore (max 63)');
42
+ const credentialEntrySchema = z
43
+ .object({
44
+ kind: z.enum(['oauth', 'access-key']),
45
+ /** The Synomem API origin this credential is for. */
46
+ apiUrl: z.string().url(),
47
+ store: z.enum(['keychain', 'file', 'environment']),
48
+ /** Opaque key into the keychain/file store. Absent for `environment`. */
49
+ secretRef: z
50
+ .string()
51
+ .regex(/^[A-Za-z0-9_-]{1,100}$/)
52
+ .optional(),
53
+ issuer: z.string().optional(),
54
+ resource: z.string().optional(),
55
+ clientId: z.string().optional(),
56
+ /** The server-side connection this credential belongs to, when known. */
57
+ connectionId: z.string().optional(),
58
+ label: z.string().optional(),
59
+ createdAt: z.string(),
60
+ })
61
+ .strict()
62
+ .refine((entry) => (entry.store === 'environment') === (entry.secretRef === undefined), {
63
+ message: 'secretRef is required except for the environment store',
64
+ });
65
+ const actorSnapshotSchema = z
66
+ .object({
67
+ kind: z.enum(['human', 'agent', 'system']),
68
+ id: z.string().min(1),
69
+ displayName: z.string().optional(),
70
+ })
71
+ .strict();
72
+ const localProfileSchema = z
73
+ .object({
74
+ backend: z.literal('local'),
75
+ /** The store's home; absent means the root Synomem home. */
76
+ home: z.string().optional(),
77
+ actorId: z.string().min(1),
78
+ actorName: z.string().optional(),
79
+ contextId: z.string().regex(/^lctx_[0-9a-f]{24}$/),
80
+ })
81
+ .strict();
82
+ const remoteProfileSchema = z
83
+ .object({
84
+ backend: z.literal('remote').optional(),
85
+ credentialRef: nameSchema,
86
+ contextId: z.string().min(1),
87
+ /** Descriptive snapshots taken at creation — for display, never authority. */
88
+ workspaceId: z.string().optional(),
89
+ workspaceName: z.string().optional(),
90
+ actor: actorSnapshotSchema.optional(),
91
+ })
92
+ .strict();
93
+ export const profileSchema = z.union([localProfileSchema, remoteProfileSchema]);
94
+ export const profilesConfigSchema = z
95
+ .object({
96
+ version: z.literal(1),
97
+ credentials: z.record(nameSchema, credentialEntrySchema).default({}),
98
+ profiles: z.record(nameSchema, profileSchema).default({}),
99
+ harnessPresets: z.record(nameSchema, z.array(nameSchema).min(1)).default({}),
100
+ defaultProfile: nameSchema.optional(),
101
+ })
102
+ .strict();
103
+ export function isLocalProfile(profile) {
104
+ return profile.backend === 'local';
105
+ }
106
+ export function emptyProfilesConfig() {
107
+ return { version: 1, credentials: {}, profiles: {}, harnessPresets: {} };
108
+ }
109
+ export function assertName(name, what) {
110
+ const parsed = nameSchema.safeParse(name);
111
+ if (!parsed.success) {
112
+ throw new SynomemError('INVALID_INPUT', `Invalid ${what} name "${name}": ${parsed.error.issues[0]?.message}.`);
113
+ }
114
+ return parsed.data;
115
+ }
116
+ /** Reads and writes `<home>/profiles.json`. Injected in tests. */
117
+ export class ProfileStore {
118
+ home;
119
+ constructor(explicitHome) {
120
+ this.home = resolveHome(explicitHome);
121
+ }
122
+ get path() {
123
+ return join(this.home, PROFILES_FILE);
124
+ }
125
+ read() {
126
+ if (!existsSync(this.path)) {
127
+ // The old remote-backend configuration is refused, not migrated: the
128
+ // store's config.json reader names the replacement commands.
129
+ if (existsSync(join(this.home, 'config.json')))
130
+ readSynomemConfig(this.home, {});
131
+ return emptyProfilesConfig();
132
+ }
133
+ let raw;
134
+ try {
135
+ raw = readJsonFile(this.path);
136
+ }
137
+ catch {
138
+ throw new SynomemError('CONFIG_INVALID', `${this.path} is not readable JSON.`);
139
+ }
140
+ const parsed = profilesConfigSchema.safeParse(raw);
141
+ if (!parsed.success) {
142
+ const issue = parsed.error.issues[0];
143
+ throw new SynomemError('CONFIG_INVALID', `${this.path} is not a valid version-1 profiles file (${issue?.path.join('.') || 'root'}: ${issue?.message ?? 'invalid'}). Re-run \`synomem setup\`, or fix the file.`);
144
+ }
145
+ return parsed.data;
146
+ }
147
+ write(config) {
148
+ const parsed = profilesConfigSchema.parse(config);
149
+ atomicWriteFile(this.path, `${JSON.stringify(parsed, null, 2)}\n`, 0o600);
150
+ }
151
+ }
152
+ /**
153
+ * Which profile or preset a process acts through. One implementation, used by
154
+ * the CLI and both stdio entrypoints:
155
+ *
156
+ * 1. `--profile` / `--preset` on this invocation
157
+ * 2. `SYNOMEM_PROFILE` / `SYNOMEM_PRESET` for this process
158
+ * 3. the nearest project `.synomem/project.json` (names a profile/preset only)
159
+ * 4. `defaultProfile` in profiles.json
160
+ *
161
+ * Returns undefined when nothing selects anything. Naming something that does
162
+ * not exist is an error, never a fall-through to the next source.
163
+ */
164
+ export function resolveSelection(config, input) {
165
+ const env = input.env ?? process.env;
166
+ const pick = (profile, preset, source) => {
167
+ const profileName = profile?.trim() || undefined;
168
+ const presetName = preset?.trim() || undefined;
169
+ if (profileName && presetName) {
170
+ throw new SynomemError('INVALID_INPUT', `${source} names both a profile and a preset; choose one.`);
171
+ }
172
+ if (profileName) {
173
+ if (!config.profiles[profileName])
174
+ throw unknownName('profile', profileName, source, config);
175
+ return { kind: 'profile', name: profileName, source };
176
+ }
177
+ if (presetName) {
178
+ if (!config.harnessPresets[presetName])
179
+ throw unknownName('preset', presetName, source, config);
180
+ return { kind: 'preset', name: presetName, source };
181
+ }
182
+ return undefined;
183
+ };
184
+ return (pick(input.profile, input.preset, 'the command line') ??
185
+ pick(env.SYNOMEM_PROFILE, env.SYNOMEM_PRESET, 'SYNOMEM_PROFILE/SYNOMEM_PRESET') ??
186
+ (() => {
187
+ const project = findProjectSelection(input.cwd ?? process.cwd(), input.home);
188
+ return project ? pick(project.profile, project.preset, project.path) : undefined;
189
+ })() ??
190
+ (config.defaultProfile
191
+ ? pick(config.defaultProfile, undefined, 'defaultProfile in profiles.json')
192
+ : undefined));
193
+ }
194
+ function unknownName(kind, name, source, config) {
195
+ const known = Object.keys(kind === 'profile' ? config.profiles : config.harnessPresets);
196
+ return new SynomemError('CONFIG_INVALID', `Unknown ${kind} "${name}" (from ${source}). ${known.length ? `Known ${kind}s: ${known.join(', ')}.` : `No ${kind}s exist yet.`} See \`synomem ${kind} list\`.`);
197
+ }
198
+ export function noSelectionError() {
199
+ return new SynomemError('CONFIG_INVALID', 'No profile selected. Pass --profile <name> (or set SYNOMEM_PROFILE), or run `synomem setup --backend local` / `synomem connection login` then `synomem profile create`.');
200
+ }
201
+ export function storeFor(stores, entry) {
202
+ if (entry.store === 'environment') {
203
+ throw new SynomemError('INTERNAL_ERROR', 'The environment store holds no secrets.');
204
+ }
205
+ return stores[entry.store];
206
+ }
207
+ /**
208
+ * A connection's current bearer: an access key as stored, or an OAuth access
209
+ * token, refreshed under the cross-process lock when it has expired.
210
+ *
211
+ * After taking the lock the stored credential is re-read: if another process
212
+ * already refreshed it (a newer generation), that token is used and the
213
+ * refresh token is not spent again. A refused refresh is never retried — the
214
+ * connection must be logged in again.
215
+ */
216
+ export class ConnectionCredentialSource {
217
+ options;
218
+ cached;
219
+ cachedExpiry = 0;
220
+ pending;
221
+ constructor(options) {
222
+ this.options = options;
223
+ }
224
+ async bearer() {
225
+ if (this.cached && this.cachedExpiry > Date.now())
226
+ return this.cached;
227
+ this.pending ??= this.load().finally(() => {
228
+ this.pending = undefined;
229
+ });
230
+ return await this.pending;
231
+ }
232
+ reauthorize(detail) {
233
+ return new SynomemError('REAUTHORIZATION_REQUIRED', `${detail} Run \`synomem connection login --name ${this.options.name}\` to sign in again.`);
234
+ }
235
+ async load() {
236
+ const { entry, name } = this.options;
237
+ const env = this.options.env ?? process.env;
238
+ if (entry.store === 'environment') {
239
+ const token = env.SYNOMEM_ACCESS_TOKEN?.trim();
240
+ if (!token) {
241
+ throw new SynomemError('AUTH_REQUIRED', `Connection ${name} reads its credential from SYNOMEM_ACCESS_TOKEN, which is not set.`);
242
+ }
243
+ this.cached = token;
244
+ this.cachedExpiry = Number.MAX_SAFE_INTEGER;
245
+ return token;
246
+ }
247
+ const store = storeFor(this.options.stores, entry);
248
+ const stored = await store.get(entry.secretRef);
249
+ if (!stored) {
250
+ throw new SynomemError('AUTH_REQUIRED', `No stored credential for connection ${name}. Run \`synomem connection ${entry.kind === 'oauth' ? 'login' : 'add-key'} --name ${name}\`.`);
251
+ }
252
+ if (stored.kind === 'access-key') {
253
+ this.cached = stored.secret;
254
+ this.cachedExpiry = Number.MAX_SAFE_INTEGER;
255
+ return stored.secret;
256
+ }
257
+ if (stored.expiresAt > Date.now())
258
+ return this.remember(stored);
259
+ return await withCredentialLock(this.options.home, name, async () => {
260
+ const current = await store.get(entry.secretRef);
261
+ if (!current || current.kind !== 'oauth')
262
+ throw this.reauthorize(`Connection ${name} has no OAuth credential.`);
263
+ // Another process refreshed while we waited for the lock.
264
+ if (current.expiresAt > Date.now())
265
+ return this.remember(current);
266
+ let refreshed;
267
+ try {
268
+ refreshed = await refreshOAuthCredential(current, this.options.fetch ?? fetch);
269
+ }
270
+ catch (error) {
271
+ if (error instanceof SynomemError && error.code === 'REMOTE_UNAVAILABLE')
272
+ throw error;
273
+ throw this.reauthorize(`Connection ${name} could not be refreshed.`);
274
+ }
275
+ // Compare-and-swap: only this process may have spent the refresh token
276
+ // while holding the lock, so a different stored generation means the
277
+ // store was replaced underneath us (a fresh login) — keep that one.
278
+ const latest = await store.get(entry.secretRef);
279
+ if (latest?.kind === 'oauth' && latest.generation !== current.generation) {
280
+ return this.remember(latest);
281
+ }
282
+ await store.set(entry.secretRef, refreshed);
283
+ return this.remember(refreshed);
284
+ });
285
+ }
286
+ remember(credential) {
287
+ this.cached = credential.accessToken;
288
+ this.cachedExpiry = credential.expiresAt;
289
+ return credential.accessToken;
290
+ }
291
+ }
292
+ export function credentialSourceFor(home, config, name, deps) {
293
+ const entry = config.credentials[name];
294
+ if (!entry) {
295
+ throw new SynomemError('CONFIG_INVALID', `Unknown connection "${name}". See \`synomem connection list\`.`);
296
+ }
297
+ return new ConnectionCredentialSource({
298
+ home,
299
+ name,
300
+ entry,
301
+ stores: deps.stores,
302
+ ...(deps.env ? { env: deps.env } : {}),
303
+ ...(deps.fetch ? { fetch: deps.fetch } : {}),
304
+ });
305
+ }
306
+ /** The canonical local actor for a local profile, after checking its store. */
307
+ export function localProfileTarget(rootHome, profile) {
308
+ const home = profile.home ?? rootHome;
309
+ const actor = {
310
+ kind: 'agent',
311
+ id: profile.actorId,
312
+ ...(profile.actorName ? { displayName: profile.actorName } : {}),
313
+ };
314
+ const expected = localContextId(localStoreWorkspaceId(home), actor);
315
+ if (expected !== profile.contextId) {
316
+ throw new SynomemError('CONTEXT_FORBIDDEN', `Profile's local context ${profile.contextId} does not belong to the store at ${home}. Recreate the profile.`);
317
+ }
318
+ return { home, actor };
319
+ }
320
+ /** A fixed-mode resolver for one profile. */
321
+ export function profileResolver(rootHome, config, name, deps) {
322
+ const profile = config.profiles[name];
323
+ if (!profile)
324
+ throw unknownName('profile', name, 'the selection', config);
325
+ if (isLocalProfile(profile)) {
326
+ const target = localProfileTarget(rootHome, profile);
327
+ return (deps.createLocalResolver ?? createLocalResolver)(target);
328
+ }
329
+ const entry = config.credentials[profile.credentialRef];
330
+ if (!entry) {
331
+ throw new SynomemError('CONFIG_INVALID', `Profile ${name} uses connection "${profile.credentialRef}", which does not exist. See \`synomem connection list\`.`);
332
+ }
333
+ return (deps.createRemoteResolver ?? createRemoteResolver)({
334
+ baseUrl: entry.apiUrl,
335
+ credential: credentialSourceFor(rootHome, config, profile.credentialRef, deps),
336
+ pinnedContextId: profile.contextId,
337
+ ...(deps.fetch ? { fetch: deps.fetch } : {}),
338
+ });
339
+ }
340
+ /**
341
+ * An explicit-context resolver over a preset's profiles.
342
+ *
343
+ * Remote profiles sharing a connection share one remote resolver, restricted
344
+ * to exactly the contexts the preset names (the server still authorizes each).
345
+ * Every operation must name its context; there is no default and no switch.
346
+ */
347
+ export class PresetResolver {
348
+ name;
349
+ routes;
350
+ constructor(name, routes) {
351
+ this.name = name;
352
+ this.routes = routes;
353
+ }
354
+ mode() {
355
+ return 'explicit';
356
+ }
357
+ async resolve(contextId) {
358
+ if (!contextId) {
359
+ throw new SynomemError('CONTEXT_REQUIRED', `Preset ${this.name} serves several identities; pass contextId (see synomem_context_list). Profiles: ${this.routes
360
+ .map((route) => `${route.profile}=${route.contextId}`)
361
+ .join(', ')}.`);
362
+ }
363
+ const route = this.routes.find((candidate) => candidate.contextId === contextId);
364
+ if (!route) {
365
+ throw new SynomemError('CONTEXT_FORBIDDEN', 'That context is not available on this server.');
366
+ }
367
+ return await route.resolver.resolve(contextId);
368
+ }
369
+ async list() {
370
+ const allowed = new Set(this.routes.map((route) => route.contextId));
371
+ const seen = new Set();
372
+ const contexts = [];
373
+ for (const resolver of new Set(this.routes.map((route) => route.resolver))) {
374
+ const listing = await resolver.list();
375
+ for (const context of listing.contexts) {
376
+ if (allowed.has(context.contextId) && !seen.has(context.contextId)) {
377
+ seen.add(context.contextId);
378
+ contexts.push(context);
379
+ }
380
+ }
381
+ }
382
+ return { mode: 'explicit', fixedContextId: null, contexts };
383
+ }
384
+ async close() {
385
+ await Promise.allSettled([...new Set(this.routes.map((route) => route.resolver))].map(async (resolver) => {
386
+ await resolver.close?.();
387
+ }));
388
+ }
389
+ }
390
+ export function presetResolver(rootHome, config, name, deps) {
391
+ const members = config.harnessPresets[name];
392
+ if (!members)
393
+ throw unknownName('preset', name, 'the selection', config);
394
+ const remoteByCredential = new Map();
395
+ const routes = [];
396
+ const pendingRemote = [];
397
+ for (const member of members) {
398
+ const profile = config.profiles[member];
399
+ if (!profile) {
400
+ throw new SynomemError('CONFIG_INVALID', `Preset ${name} names profile "${member}", which does not exist.`);
401
+ }
402
+ if (routes.some((route) => route.contextId === profile.contextId) ||
403
+ pendingRemote.some((p) => p.contextId === profile.contextId)) {
404
+ throw new SynomemError('CONFIG_INVALID', `Preset ${name} lists context ${profile.contextId} twice.`);
405
+ }
406
+ if (isLocalProfile(profile)) {
407
+ routes.push({
408
+ profile: member,
409
+ contextId: profile.contextId,
410
+ resolver: (deps.createLocalResolver ?? createLocalResolver)(localProfileTarget(rootHome, profile)),
411
+ });
412
+ }
413
+ else {
414
+ const group = remoteByCredential.get(profile.credentialRef) ?? { contexts: [], profiles: [] };
415
+ group.contexts.push(profile.contextId);
416
+ group.profiles.push(member);
417
+ remoteByCredential.set(profile.credentialRef, group);
418
+ pendingRemote.push({
419
+ profile: member,
420
+ contextId: profile.contextId,
421
+ credential: profile.credentialRef,
422
+ });
423
+ }
424
+ }
425
+ for (const [credential, group] of remoteByCredential) {
426
+ const entry = config.credentials[credential];
427
+ if (!entry) {
428
+ throw new SynomemError('CONFIG_INVALID', `Preset ${name} uses connection "${credential}", which does not exist.`);
429
+ }
430
+ const resolver = (deps.createRemoteResolver ?? createRemoteResolver)({
431
+ baseUrl: entry.apiUrl,
432
+ credential: credentialSourceFor(rootHome, config, credential, deps),
433
+ allowedContextIds: group.contexts,
434
+ ...(deps.fetch ? { fetch: deps.fetch } : {}),
435
+ });
436
+ for (const pending of pendingRemote.filter((p) => p.credential === credential)) {
437
+ routes.push({ profile: pending.profile, contextId: pending.contextId, resolver });
438
+ }
439
+ }
440
+ return new PresetResolver(name, routes);
441
+ }
442
+ /**
443
+ * The single entry point for the CLI and both stdio servers: selection flags
444
+ * and environment in, one resolver out.
445
+ */
446
+ export function resolverForSelection(rootHome, config, selection, deps) {
447
+ return selection.kind === 'profile'
448
+ ? profileResolver(rootHome, config, selection.name, deps)
449
+ : presetResolver(rootHome, config, selection.name, deps);
450
+ }
451
+ /* ------------------------------------------------------------ display */
452
+ export function describeContext(context) {
453
+ const who = context.actor.displayName ?? context.actor.handle ?? context.actor.id;
454
+ const where = context.workspaceName ?? context.workspaceId;
455
+ return `${who} (${context.actor.kind}) in ${where}`;
456
+ }
457
+ /** One line describing a profile, for list/show. Never a secret. */
458
+ export function describeProfile(name, profile) {
459
+ if (isLocalProfile(profile)) {
460
+ return `${name} local ${profile.actorName ?? profile.actorId} ${profile.home ?? '(root home)'} ${profile.contextId}`;
461
+ }
462
+ const who = profile.actor?.displayName ?? profile.actor?.id ?? '?';
463
+ return `${name} remote via ${profile.credentialRef} ${who} in ${profile.workspaceName ?? profile.workspaceId ?? '?'} ${profile.contextId}`;
464
+ }
465
+ //# sourceMappingURL=profiles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profiles.js","sourceRoot":"","sources":["../src/profiles.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC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I,YAAY,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC,OAAO,KAAK,OAAO,CAAC,IAAI,IAAI,aAAa,KAAK,OAAO,CAAC,SAAS,EAAE,CAAC;IAC3H,CAAC;IACD,MAAM,GAAG,GAAG,OAAO,CAAC,KAAK,EAAE,WAAW,IAAI,OAAO,CAAC,KAAK,EAAE,EAAE,IAAI,GAAG,CAAC;IACnE,OAAO,GAAG,IAAI,gBAAgB,OAAO,CAAC,aAAa,KAAK,GAAG,OAAO,OAAO,CAAC,aAAa,IAAI,OAAO,CAAC,WAAW,IAAI,GAAG,KAAK,OAAO,CAAC,SAAS,EAAE,CAAC;AAChJ,CAAC"}
package/dist/project.d.ts CHANGED
@@ -1,51 +1,20 @@
1
1
  import { z } from 'zod';
2
2
  export declare const PROJECT_DIRECTORY = ".synomem";
3
- export declare const PROJECT_CONFIG_FILE = "config.json";
3
+ export declare const PROJECT_CONFIG_FILE = "project.json";
4
4
  export declare const projectConfigSchema: z.ZodObject<{
5
- workspace: z.ZodOptional<z.ZodString>;
6
- actor: z.ZodOptional<z.ZodString>;
7
- }, z.core.$strip>;
5
+ profile: z.ZodOptional<z.ZodString>;
6
+ preset: z.ZodOptional<z.ZodString>;
7
+ }, z.core.$strict>;
8
8
  export type ProjectConfig = z.infer<typeof projectConfigSchema>;
9
9
  export interface ProjectSelection extends ProjectConfig {
10
- /** The directory whose `.synomem` was used, so tools can say where it came from. */
11
- directory: string;
10
+ /** The file that supplied the selection, so errors can say where it came from. */
11
+ path: string;
12
12
  }
13
13
  /**
14
- * The nearest project configuration at or above `from`.
15
- *
16
- * Walking up stops at the filesystem root, and never treats the Synomem home
17
- * itself as a project: `~/.synomem/config.json` is a real Synomem config with a
18
- * different shape, and reading it as a project pointer would silently apply a
19
- * home's settings to every command run anywhere under the home directory.
14
+ * The nearest project file at or above `from`. The Synomem home itself is
15
+ * never treated as a project directory.
20
16
  */
21
17
  export declare function findProjectSelection(from?: string, home?: string): ProjectSelection | undefined;
22
18
  /** Writes the pointer for a directory, creating `.synomem/` if needed. */
23
19
  export declare function writeProjectSelection(directory: string, config: ProjectConfig): string;
24
- /**
25
- * Which workspace to act in, and as whom.
26
- *
27
- * One resolver, used by both the CLI and the stdio MCP server, so the two
28
- * cannot disagree about precedence. Order, most specific first:
29
- *
30
- * 1. `--workspace` / `--actor` — said on this invocation
31
- * 2. `SYNOMEM_WORKSPACE` / `SYNOMEM_ACTOR_ID` — set for this process
32
- * 3. `.synomem/config.json` in the project, found by walking up from the
33
- * working directory
34
- * 4. the root home, which is the default workspace
35
- *
36
- * The project file is third rather than first because a flag someone typed
37
- * should always beat a file they may have forgotten is there.
38
- */
39
- export declare function resolveWorkspaceSelection(input: {
40
- flag?: string;
41
- actorFlag?: string;
42
- env?: NodeJS.ProcessEnv;
43
- cwd?: string;
44
- explicitRoot?: string;
45
- }): {
46
- home: string;
47
- workspace?: string;
48
- actor?: string;
49
- source: string;
50
- };
51
20
  //# sourceMappingURL=project.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../src/project.ts"],"names":[],"mappings":"AA6BA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,eAAO,MAAM,iBAAiB,aAAa,CAAC;AAC5C,eAAO,MAAM,mBAAmB,gBAAgB,CAAC;AAEjD,eAAO,MAAM,mBAAmB;;;iBAK9B,CAAC;AAEH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEhE,MAAM,WAAW,gBAAiB,SAAQ,aAAa;IACrD,oFAAoF;IACpF,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,GAAE,MAAsB,EAC5B,IAAI,CAAC,EAAE,MAAM,GACZ,gBAAgB,GAAG,SAAS,CAgB9B;AAmBD,0EAA0E;AAC1E,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,MAAM,E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