@mmon-co/ncept-local 0.3.13 → 0.4.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/README.md CHANGED
@@ -15,7 +15,7 @@ const tar = await profile.pack();
15
15
  await unpackDirectory(tar, "/path/to/moved-profile", [defaultTheory]);
16
16
  ```
17
17
 
18
- `init` creates an empty personal Patch, empty log and reserved directories in an ordinary project directory. `profile.json` contains `format: 2`, `personal`, `theory` (Core's requirement), `theories` (package names, initially `@mmon-co/ncept-default-theory`) and `sessions` (surface → pi filename). Account credentials live at `credentialsPath()`, outside the Profile, in `~/.config/ncept/credentials.json`.
18
+ `init` creates an empty personal Patch, empty log and reserved directories in an ordinary project directory. `profile.json` contains `format: 2`, `personal`, `theory` (Core's requirement), `theories` (package names, initially `@mmon-co/ncept-default-theory`) and `sessions` (surface → pi filename). Account credentials live at `credentialsPath()`, outside the Profile, in `~/.config/concept/credentials.json`. The first use of the default credentials path moves an existing sign-in to that location.
19
19
 
20
20
  `openProfile` and `unpack` upgrade format 1 monolithic Patch files to Merkle manifests and chunks, relinking exact references and retained undo targets. They also migrate a stored minor pin (or an exact web-export release) with the supplied executable Theory’s `migrations` before strict resolution. Broad requirements still use strict resolution without migration. Migration writes new immutable Patch revisions and a content-addressed log snapshot, then atomically switches `profile.json`’s personal head, Theory requirement and optional `log` digest together. Interrupted writes leave the old generation active; reopening retries pure steps from that generation. Old revision/log files remain unread history. Opening also upgrades the host log: legacy Lessons enter on their Mission or target, and retired Review Sessions close. The read-only Learn panel sees the upgrade in memory; a writable open persists it. Host futures are rebuilt from the migrated Profile; captured Session transcripts are not rewritten as futures.
21
21
 
package/dist/directory.js CHANGED
@@ -9,7 +9,7 @@ import { parsePiSession, piSessionFilename, relocatePiSession, serializePiSessio
9
9
  import { PackedPatches, packedFiles } from "./packed.js";
10
10
  /** Account credentials never belong to a Profile or its exchange tar. */
11
11
  export function credentialsPath(home = homedir()) {
12
- return join(home, ".config", "ncept", "credentials.json");
12
+ return join(home, ".config", "concept", "credentials.json");
13
13
  }
14
14
  function existsError(error) {
15
15
  return error instanceof Error && "code" in error && error.code === "EEXIST";
@@ -2,6 +2,7 @@ import { type OAuthClientProvider, type OAuthDiscoveryState } from "@modelcontex
2
2
  import type { OAuthClientInformationMixed, OAuthTokens } from "@modelcontextprotocol/sdk/shared/auth.js";
3
3
  import type { HubOptions } from "./host.js";
4
4
  export declare function hubBaseUrl(value?: string): string;
5
+ export declare function clearHubCredentials(credentialsFile?: string): Promise<void>;
5
6
  export declare function hasHubCredentials(options: HubOptions): Promise<boolean>;
6
7
  export declare function beginHubBrowserSignIn(options: HubOptions): Promise<HubBrowserSignIn>;
7
8
  export declare class HubSignInRequired extends Error {
package/dist/hub-auth.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { createServer } from "node:http";
2
- import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
3
- import { dirname } from "node:path";
2
+ import { link, mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
3
+ import { homedir } from "node:os";
4
+ import { dirname, join } from "node:path";
4
5
  import { createHash, randomBytes, randomUUID } from "node:crypto";
5
6
  import { execFile } from "node:child_process";
6
7
  import { auth, UnauthorizedError, } from "@modelcontextprotocol/sdk/client/auth.js";
@@ -18,6 +19,32 @@ export function hubBaseUrl(value = defaultHub) {
18
19
  throw new Error("Hub URL must use HTTPS (or loopback HTTP)");
19
20
  return url.href.replace(/\/$/, "");
20
21
  }
22
+ async function prepareCredentialsPath() {
23
+ const home = homedir();
24
+ const current = credentialsPath(home);
25
+ const previous = join(home, ".config", "ncept", "credentials.json");
26
+ try {
27
+ await mkdir(dirname(current), { recursive: true, mode: 0o700 });
28
+ await link(previous, current);
29
+ }
30
+ catch (error) {
31
+ if (error instanceof Error && "code" in error) {
32
+ if (error.code === "ENOENT")
33
+ return current;
34
+ if (error.code !== "EEXIST")
35
+ throw error;
36
+ }
37
+ else
38
+ throw error;
39
+ }
40
+ // A new-format sign-in wins if both files exist. Retire the old file so it
41
+ // cannot be restored by a later lookup after sign-out.
42
+ await rm(previous, { force: true });
43
+ return current;
44
+ }
45
+ export async function clearHubCredentials(credentialsFile) {
46
+ await rm(credentialsFile ?? (await prepareCredentialsPath()), { force: true });
47
+ }
21
48
  export async function hasHubCredentials(options) {
22
49
  return Boolean((await HubAuth.open(hubBaseUrl(options.url) + "/mcp", options)).tokens());
23
50
  }
@@ -65,7 +92,7 @@ export class HubAuth {
65
92
  this.clientMetadataUrl = clientMetadataUrl;
66
93
  }
67
94
  static async open(resource, options) {
68
- const provider = new HubAuth(resource, options.credentialsFile ?? credentialsPath(), options.openUrl ?? browser, options.clientMetadataUrl);
95
+ const provider = new HubAuth(resource, options.credentialsFile ?? (await prepareCredentialsPath()), options.openUrl ?? browser, options.clientMetadataUrl);
69
96
  provider.credentials = (await load(provider.path))[resource] ?? {};
70
97
  return provider;
71
98
  }
package/dist/index.d.ts CHANGED
@@ -2,5 +2,5 @@ export * from "./exchange.js";
2
2
  export * from "./sessions.js";
3
3
  export * from "./directory.js";
4
4
  export * from "./host.js";
5
- export { beginHubBrowserSignIn, hasHubCredentials, HubSignInRequired, type HubBrowserSignIn } from "./hub-auth.js";
5
+ export { beginHubBrowserSignIn, clearHubCredentials, hasHubCredentials, HubSignInRequired, type HubBrowserSignIn, } from "./hub-auth.js";
6
6
  export { openLearningReader } from "./learning.js";
package/dist/index.js CHANGED
@@ -2,5 +2,5 @@ export * from "./exchange.js";
2
2
  export * from "./sessions.js";
3
3
  export * from "./directory.js";
4
4
  export * from "./host.js";
5
- export { beginHubBrowserSignIn, hasHubCredentials, HubSignInRequired } from "./hub-auth.js";
5
+ export { beginHubBrowserSignIn, clearHubCredentials, hasHubCredentials, HubSignInRequired, } from "./hub-auth.js";
6
6
  export { openLearningReader } from "./learning.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mmon-co/ncept-local",
3
- "version": "0.3.13",
3
+ "version": "0.4.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",