@pleri/olam-cli 0.1.196 → 0.1.198

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 (139) hide show
  1. package/README.md +52 -0
  2. package/dist/ask/knowledge-pack.generated.d.ts.map +1 -1
  3. package/dist/ask/knowledge-pack.generated.js +10 -8
  4. package/dist/ask/knowledge-pack.generated.js.map +1 -1
  5. package/dist/commands/auth-list-json.d.ts +34 -0
  6. package/dist/commands/auth-list-json.d.ts.map +1 -1
  7. package/dist/commands/auth-list-json.js +24 -0
  8. package/dist/commands/auth-list-json.js.map +1 -1
  9. package/dist/commands/auth-migrate.d.ts +212 -0
  10. package/dist/commands/auth-migrate.d.ts.map +1 -0
  11. package/dist/commands/auth-migrate.js +465 -0
  12. package/dist/commands/auth-migrate.js.map +1 -0
  13. package/dist/commands/auth.d.ts.map +1 -1
  14. package/dist/commands/auth.js +239 -184
  15. package/dist/commands/auth.js.map +1 -1
  16. package/dist/commands/bootstrap.d.ts +4 -0
  17. package/dist/commands/bootstrap.d.ts.map +1 -1
  18. package/dist/commands/bootstrap.js +6 -0
  19. package/dist/commands/bootstrap.js.map +1 -1
  20. package/dist/commands/dispatch.d.ts.map +1 -1
  21. package/dist/commands/dispatch.js +11 -1
  22. package/dist/commands/dispatch.js.map +1 -1
  23. package/dist/commands/doctor.d.ts +33 -0
  24. package/dist/commands/doctor.d.ts.map +1 -1
  25. package/dist/commands/doctor.js +299 -12
  26. package/dist/commands/doctor.js.map +1 -1
  27. package/dist/commands/kg-mirror.d.ts +18 -2
  28. package/dist/commands/kg-mirror.d.ts.map +1 -1
  29. package/dist/commands/kg-mirror.js +78 -3
  30. package/dist/commands/kg-mirror.js.map +1 -1
  31. package/dist/commands/mcp/complete.d.ts +36 -0
  32. package/dist/commands/mcp/complete.d.ts.map +1 -0
  33. package/dist/commands/mcp/complete.js +66 -0
  34. package/dist/commands/mcp/complete.js.map +1 -0
  35. package/dist/commands/mcp/index.d.ts +1 -1
  36. package/dist/commands/mcp/index.d.ts.map +1 -1
  37. package/dist/commands/mcp/index.js +3 -1
  38. package/dist/commands/mcp/index.js.map +1 -1
  39. package/dist/commands/memory/bridge.d.ts +1 -1
  40. package/dist/commands/memory/bridge.d.ts.map +1 -1
  41. package/dist/commands/memory/bridge.js +2 -6
  42. package/dist/commands/memory/bridge.js.map +1 -1
  43. package/dist/commands/memory/secret.d.ts.map +1 -1
  44. package/dist/commands/memory/secret.js +4 -3
  45. package/dist/commands/memory/secret.js.map +1 -1
  46. package/dist/commands/observe.d.ts +3 -3
  47. package/dist/commands/observe.d.ts.map +1 -1
  48. package/dist/commands/observe.js +11 -8
  49. package/dist/commands/observe.js.map +1 -1
  50. package/dist/commands/runbooks.d.ts.map +1 -1
  51. package/dist/commands/runbooks.js +77 -10
  52. package/dist/commands/runbooks.js.map +1 -1
  53. package/dist/commands/services-tls.d.ts.map +1 -1
  54. package/dist/commands/services-tls.js +41 -0
  55. package/dist/commands/services-tls.js.map +1 -1
  56. package/dist/commands/services.d.ts +35 -1
  57. package/dist/commands/services.d.ts.map +1 -1
  58. package/dist/commands/services.js +153 -32
  59. package/dist/commands/services.js.map +1 -1
  60. package/dist/commands/setup-phase-8-kg-hook.d.ts +48 -0
  61. package/dist/commands/setup-phase-8-kg-hook.d.ts.map +1 -0
  62. package/dist/commands/setup-phase-8-kg-hook.js +93 -0
  63. package/dist/commands/setup-phase-8-kg-hook.js.map +1 -0
  64. package/dist/commands/setup-phase-9-memory-bridge.d.ts +36 -0
  65. package/dist/commands/setup-phase-9-memory-bridge.d.ts.map +1 -0
  66. package/dist/commands/setup-phase-9-memory-bridge.js +59 -0
  67. package/dist/commands/setup-phase-9-memory-bridge.js.map +1 -0
  68. package/dist/commands/setup.d.ts +34 -1
  69. package/dist/commands/setup.d.ts.map +1 -1
  70. package/dist/commands/setup.js +328 -23
  71. package/dist/commands/setup.js.map +1 -1
  72. package/dist/commands/update.d.ts +24 -0
  73. package/dist/commands/update.d.ts.map +1 -1
  74. package/dist/commands/update.js +53 -0
  75. package/dist/commands/update.js.map +1 -1
  76. package/dist/commands/upgrade.d.ts +5 -0
  77. package/dist/commands/upgrade.d.ts.map +1 -1
  78. package/dist/commands/upgrade.js +31 -8
  79. package/dist/commands/upgrade.js.map +1 -1
  80. package/dist/image-digests.json +8 -8
  81. package/dist/index.js +4193 -2426
  82. package/dist/lib/auth-backend.d.ts +168 -0
  83. package/dist/lib/auth-backend.d.ts.map +1 -0
  84. package/dist/lib/auth-backend.js +172 -0
  85. package/dist/lib/auth-backend.js.map +1 -0
  86. package/dist/lib/auth-list-cache.d.ts +67 -0
  87. package/dist/lib/auth-list-cache.d.ts.map +1 -0
  88. package/dist/lib/auth-list-cache.js +84 -0
  89. package/dist/lib/auth-list-cache.js.map +1 -0
  90. package/dist/lib/auth-list.d.ts +107 -0
  91. package/dist/lib/auth-list.d.ts.map +1 -0
  92. package/dist/lib/auth-list.js +123 -0
  93. package/dist/lib/auth-list.js.map +1 -0
  94. package/dist/lib/auth-login.d.ts +92 -0
  95. package/dist/lib/auth-login.d.ts.map +1 -0
  96. package/dist/lib/auth-login.js +124 -0
  97. package/dist/lib/auth-login.js.map +1 -0
  98. package/dist/lib/auth-mutator-backend.d.ts +54 -0
  99. package/dist/lib/auth-mutator-backend.d.ts.map +1 -0
  100. package/dist/lib/auth-mutator-backend.js +62 -0
  101. package/dist/lib/auth-mutator-backend.js.map +1 -0
  102. package/dist/lib/auth-remote.d.ts +50 -0
  103. package/dist/lib/auth-remote.d.ts.map +1 -1
  104. package/dist/lib/auth-remote.js +84 -2
  105. package/dist/lib/auth-remote.js.map +1 -1
  106. package/dist/lib/bootstrap-kubernetes.d.ts +69 -10
  107. package/dist/lib/bootstrap-kubernetes.d.ts.map +1 -1
  108. package/dist/lib/bootstrap-kubernetes.js +264 -46
  109. package/dist/lib/bootstrap-kubernetes.js.map +1 -1
  110. package/dist/lib/config.d.ts +7 -0
  111. package/dist/lib/config.d.ts.map +1 -1
  112. package/dist/lib/config.js.map +1 -1
  113. package/dist/lib/health-probes.d.ts +0 -22
  114. package/dist/lib/health-probes.d.ts.map +1 -1
  115. package/dist/lib/health-probes.js +23 -2
  116. package/dist/lib/health-probes.js.map +1 -1
  117. package/dist/lib/peripheral-registry.d.ts +11 -0
  118. package/dist/lib/peripheral-registry.d.ts.map +1 -1
  119. package/dist/lib/peripheral-registry.js +5 -0
  120. package/dist/lib/peripheral-registry.js.map +1 -1
  121. package/dist/lib/plans-client.d.ts.map +1 -1
  122. package/dist/lib/plans-client.js +6 -3
  123. package/dist/lib/plans-client.js.map +1 -1
  124. package/dist/mcp-server.js +14 -3
  125. package/hermes-bundle/version.json +1 -1
  126. package/host-cp/k8s/manifests/30-configmap.yaml +4 -0
  127. package/host-cp/k8s/manifests/50-deployment.yaml +13 -1
  128. package/host-cp/k8s/manifests/auth-service/50-deployment.yaml +1 -1
  129. package/host-cp/k8s/manifests/kg-service/50-deployment.yaml +1 -1
  130. package/host-cp/k8s/manifests/mcp-auth-service/50-deployment.yaml +1 -1
  131. package/host-cp/k8s/manifests/memory-service/50-deployment.yaml +1 -1
  132. package/host-cp/src/dispatch-persister.mjs +157 -0
  133. package/host-cp/src/pr-nanny.mjs +7 -0
  134. package/host-cp/src/server.mjs +175 -3
  135. package/host-cp/src/world-watchdog-pid-lookup.mjs +119 -0
  136. package/host-cp/src/world-watchdog-probes.mjs +271 -0
  137. package/host-cp/src/world-watchdog-recovery.mjs +192 -0
  138. package/host-cp/src/world-watchdog.mjs +313 -0
  139. package/package.json +1 -1
@@ -0,0 +1,123 @@
1
+ /**
2
+ * auth-list — testable orchestration for `olam auth list` and `auth list --json`.
3
+ *
4
+ * Phase B (cloud-only-vault) Decision D5: `olam auth list` defaults to the
5
+ * cloud auth-worker (cf. B1 / B2). This module:
6
+ *
7
+ * 1. Resolves the backend via B1's `requireBackend`.
8
+ * 2. Resolves the remote URL via the same precedence used by `auth login`
9
+ * (explicit `--remote <url>` > env > file > hard-coded fallback).
10
+ * 3. Consults the in-process TTL cache (30 s per D5) when backend='remote'
11
+ * and `--no-cache` was NOT passed.
12
+ * 4. Falls back to the stale cache when a fresh fetch fails (offline UX).
13
+ * 5. Routes to `AuthClient.status()` on the local backend.
14
+ *
15
+ * The Commander.js action handler in `packages/cli/src/commands/auth.ts`
16
+ * binds the IO touchpoints (cache helpers, fetch, AuthClient) via the
17
+ * `AuthListDeps` struct and consumes the structured `AuthListResult` to
18
+ * render the table or JSON output.
19
+ *
20
+ * Coupling note: the result object holds the raw remote payload (when
21
+ * backend='remote') OR the AuthAccountSummary[] (when backend='local'). The
22
+ * caller picks the right renderer (`renderAuthListJson` for local-JSON,
23
+ * `renderRemoteAuthListJson` for remote-JSON, or a text table for either).
24
+ * This keeps the IO + presentation concerns out of this module while still
25
+ * giving the action a single decision-tree entrypoint.
26
+ */
27
+ import { resolveRemoteUrl } from './auth-login.js';
28
+ import { requireBackend, emitDeprecationWarning, ConflictingBackendFlags, } from './auth-backend.js';
29
+ import { getCachedAuthList, setCachedAuthList, getStaleAuthList, AUTH_LIST_CACHE_TTL_MS, } from './auth-list-cache.js';
30
+ /**
31
+ * Compose the cache key for a (baseUrl, cookie) pair. The cookie value is
32
+ * included because two operators on the same host (sharing the CLI process,
33
+ * unlikely but possible in CI) may target the same baseUrl with different
34
+ * identities — caching across that boundary would leak one operator's
35
+ * accounts to the other.
36
+ */
37
+ export function authListCacheKey(baseUrl, cookie) {
38
+ const normalisedBase = baseUrl.replace(/\/+$/, '');
39
+ return cookie ? `${normalisedBase}|${cookie}` : normalisedBase;
40
+ }
41
+ /**
42
+ * Run the `olam auth list` decision tree. Tests inject `fetchRemoteAccounts`
43
+ * and `fetchLocalStatus` to capture orchestration.
44
+ */
45
+ export async function runAuthList(opts, deps) {
46
+ const stderr = deps.stderr ?? process.stderr;
47
+ const now = deps.now ?? Date.now;
48
+ // (1) Backend resolution.
49
+ let resolution;
50
+ try {
51
+ resolution = requireBackend({ local: opts.local, remote: opts.remote });
52
+ }
53
+ catch (err) {
54
+ if (err instanceof ConflictingBackendFlags) {
55
+ return { mode: 'error', exitCode: 1, message: err.message };
56
+ }
57
+ throw err;
58
+ }
59
+ // (2) Local opt-out.
60
+ if (resolution.backend === 'local') {
61
+ if (resolution.emitDeprecationWarning) {
62
+ emitDeprecationWarning(stderr);
63
+ }
64
+ const status = await deps.fetchLocalStatus();
65
+ return { mode: 'local', reachable: status.reachable, accounts: status.accounts };
66
+ }
67
+ // (3) Remote default path.
68
+ const baseUrl = resolveRemoteUrl(resolution, {
69
+ readEnv: deps.readEnv,
70
+ readAuthWorkerUrlFile: deps.readAuthWorkerUrlFile,
71
+ });
72
+ const cacheKey = authListCacheKey(baseUrl, opts.cookie);
73
+ // (3a) Cache hit (unless --no-cache).
74
+ if (opts.noCache !== true) {
75
+ const hit = getCachedAuthList(cacheKey, now());
76
+ if (hit) {
77
+ return {
78
+ mode: 'remote',
79
+ baseUrl,
80
+ accounts: hit.result,
81
+ stale: false,
82
+ fetchedAt: hit.fetchedAt,
83
+ };
84
+ }
85
+ }
86
+ // (3b) Fresh fetch attempt.
87
+ try {
88
+ const accounts = await deps.fetchRemoteAccounts(baseUrl, opts.cookie);
89
+ setCachedAuthList(cacheKey, accounts, now());
90
+ return {
91
+ mode: 'remote',
92
+ baseUrl,
93
+ accounts,
94
+ stale: false,
95
+ fetchedAt: now(),
96
+ };
97
+ }
98
+ catch (err) {
99
+ const message = err instanceof Error ? err.message : String(err);
100
+ // (3c) Stale fallback when offline / fetch failed.
101
+ const stale = getStaleAuthList(cacheKey);
102
+ if (stale) {
103
+ return {
104
+ mode: 'remote',
105
+ baseUrl,
106
+ accounts: stale.result,
107
+ stale: true,
108
+ fetchedAt: stale.fetchedAt,
109
+ fetchError: message,
110
+ };
111
+ }
112
+ // (3d) No cache, no fresh — surface error.
113
+ return {
114
+ mode: 'error',
115
+ exitCode: 1,
116
+ message: `Failed to list remote accounts (${baseUrl}): ${message}`,
117
+ };
118
+ }
119
+ }
120
+ // Re-export the TTL constant so callers can reference it without importing
121
+ // the cache module directly.
122
+ export { AUTH_LIST_CACHE_TTL_MS };
123
+ //# sourceMappingURL=auth-list.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-list.js","sourceRoot":"","sources":["../../src/lib/auth-list.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EACL,cAAc,EACd,sBAAsB,EACtB,uBAAuB,GAExB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,sBAAsB,CAAC;AA4E9B;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAe,EAAE,MAAe;IAC/D,MAAM,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACnD,OAAO,MAAM,CAAC,CAAC,CAAC,GAAG,cAAc,IAAI,MAAM,EAAE,CAAC,CAAC,CAAC,cAAc,CAAC;AACjE,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,IAAqB,EACrB,IAAkB;IAElB,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC;IAC7C,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC;IAEjC,0BAA0B;IAC1B,IAAI,UAA6B,CAAC;IAClC,IAAI,CAAC;QACH,UAAU,GAAG,cAAc,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IAC1E,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,GAAG,YAAY,uBAAuB,EAAE,CAAC;YAC3C,OAAO,EAAE,IAAI,EAAE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AiB,CAAC,QAAQ,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,CAAC;QAC7C,OAAO;YACL,IAAI,EAAE,QAAQ;YACd,OAAO;YACP,QAAQ;YACR,KAAK,EAAE,KAAK;YACZ,SAAS,EAAE,GAAG,EAAE;SACjB,CAAC;IACJ,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACjE,mDAAmD;QACnD,MAAM,KAAK,GAAG,gBAAgB,CAA8B,QAAQ,CAAC,CAAC;QACtE,IAAI,KAAK,EAAE,CAAC;YACV,OAAO;gBACL,IAAI,EAAE,QAAQ;gBACd,OAAO;gBACP,QAAQ,EAAE,KAAK,CAAC,MAAM;gBACtB,KAAK,EAAE,IAAI;gBACX,SAAS,EAAE,KAAK,CAAC,SAAS;gBAC1B,UAAU,EAAE,OAAO;aACpB,CAAC;QACJ,CAAC;QACD,2CAA2C;QAC3C,OAAO;YACL,IAAI,EAAE,OAAO;YACb,QAAQ,EAAE,CAAC;YACX,OAAO,EAAE,mCAAmC,OAAO,MAAM,OAAO,EAAE;SACnE,CAAC;IACJ,CAAC;AACH,CAAC;AAED,2EAA2E;AAC3E,6BAA6B;AAC7B,OAAO,EAAE,sBAAsB,EAAE,CAAC"}
@@ -0,0 +1,92 @@
1
+ /**
2
+ * auth-login — testable extraction of the `olam auth login` action body.
3
+ *
4
+ * The Commander action callback in `packages/cli/src/commands/auth.ts` is too
5
+ * deeply coupled to live IO (browser opener, readline prompts, AuthClient
6
+ * against 127.0.0.1:9999, remote OAuth start) for direct unit-test mocking.
7
+ * B2 splits the decision logic out into `runAuthLogin`, which:
8
+ *
9
+ * - Resolves the backend via B1's `requireBackend`.
10
+ * - Emits the deprecation warning when --local is the explicit opt-out.
11
+ * - Asks the interactive confirm prompt before flipping to remote (skips
12
+ * on non-TTY for CI safety; --yes also bypasses).
13
+ * - Delegates the actual flow (remote URL print / local PKCE) to injected
14
+ * functions, so tests can assert on the orchestration without spawning
15
+ * real OAuth round-trips.
16
+ *
17
+ * Resolution of the default remote URL:
18
+ *
19
+ * 1. `--remote <url>` explicit string form (`resolution.explicitRemoteUrl`).
20
+ * 2. `OLAM_AUTH_WORKER_URL` env var.
21
+ * 3. `~/.olam/auth-worker-url` file (trimmed; one URL per file).
22
+ * 4. Hard-coded fallback `https://auth-worker.kaluga.co`.
23
+ *
24
+ * Step (4) matches the canonical Olam zone documented in
25
+ * `docs/plans/cloud-only-vault/phase-b-tasks.md` B2 acceptance criteria.
26
+ * Operators with a private deployment override via (2) or (3).
27
+ */
28
+ import { type BackendResolution } from './auth-backend.js';
29
+ /** Canonical fallback when no other URL source is configured. */
30
+ export declare const DEFAULT_AUTH_WORKER_URL = "https://auth-worker.kaluga.co";
31
+ /**
32
+ * Options parsed from Commander for `olam auth login`. Mirrors the option
33
+ * declarations in `auth.ts`; new in B2 are `--local` and `--yes`.
34
+ */
35
+ export interface AuthLoginOptions {
36
+ readonly local?: boolean;
37
+ readonly remote?: boolean | string;
38
+ readonly label?: string;
39
+ readonly printUrl?: boolean;
40
+ readonly serviceToken?: string;
41
+ /** Skip the first-time interactive confirm prompt. */
42
+ readonly yes?: boolean;
43
+ }
44
+ /**
45
+ * Injection seam — every IO touchpoint is funneled through this struct so the
46
+ * unit tests can assert on orchestration without real OAuth round-trips,
47
+ * filesystem writes, or stdin reads.
48
+ */
49
+ export interface AuthLoginDeps {
50
+ /** Reads the OLAM_AUTH_WORKER_URL env var. Defaults to `process.env`. */
51
+ readonly readEnv?: (key: string) => string | undefined;
52
+ /** Reads the home-config file `~/.olam/auth-worker-url`. */
53
+ readonly readAuthWorkerUrlFile?: () => string | null;
54
+ /** True when stdin is a TTY (interactive prompt is meaningful). */
55
+ readonly isTty?: () => boolean;
56
+ /** Returns `'y'` / `'n'` (case-insensitive) — the operator's answer. */
57
+ readonly promptConfirm?: (question: string) => Promise<string>;
58
+ /** Runs the remote OAuth-URL print flow against the resolved URL. */
59
+ readonly executeRemoteLogin: (baseUrl: string, opts: AuthLoginOptions) => Promise<void>;
60
+ /** Runs the legacy local PKCE flow against the auth-service container. */
61
+ readonly executeLocalLogin: (opts: AuthLoginOptions) => Promise<void>;
62
+ /** Where deprecation + confirm warnings are written. Defaults to process.stderr. */
63
+ readonly stderr?: NodeJS.WritableStream;
64
+ /** Where success / banner messages are written. Defaults to process.stdout. */
65
+ readonly stdout?: NodeJS.WritableStream;
66
+ }
67
+ /** Result of `runAuthLogin` — drives the action's `process.exitCode`. */
68
+ export interface AuthLoginResult {
69
+ readonly exitCode: 0 | 1;
70
+ /** Surfaced for tests; not used by the action. */
71
+ readonly backend?: 'local' | 'remote';
72
+ /** Surfaced for tests; URL the remote flow was dispatched to. */
73
+ readonly resolvedRemoteUrl?: string;
74
+ }
75
+ /**
76
+ * Resolve the remote auth-worker URL the login flow should target. Pure
77
+ * function modulo the injected `readEnv` + `readAuthWorkerUrlFile`.
78
+ */
79
+ export declare function resolveRemoteUrl(resolution: BackendResolution, deps: Pick<AuthLoginDeps, 'readEnv' | 'readAuthWorkerUrlFile'>): string;
80
+ /**
81
+ * Run the `olam auth login` decision tree. Tests inject `executeRemoteLogin`
82
+ * and `executeLocalLogin` to capture the orchestration without firing real
83
+ * OAuth.
84
+ *
85
+ * Decision tree (high-level):
86
+ *
87
+ * 1. requireBackend(opts) — throws ConflictingBackendFlags on dual-flag.
88
+ * 2. backend = 'local' → optional deprecation warning + local PKCE flow.
89
+ * 3. backend = 'remote' → resolve URL → optional confirm prompt → remote flow.
90
+ */
91
+ export declare function runAuthLogin(opts: AuthLoginOptions, deps: AuthLoginDeps): Promise<AuthLoginResult>;
92
+ //# sourceMappingURL=auth-login.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-login.d.ts","sourceRoot":"","sources":["../../src/lib/auth-login.ts"],"names":[],"mappings":"AAAA;;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,EAAE,MAAM,CAAC,cAAc,CAAC;IACxC,+EAA+E;IAC/E,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,cAAc,CAAC;CACzC;AAED,yEAAyE;AACzE,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAC;IACzB,kDAAkD;IAClD,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,QAAQ,CAAC;IACtC,iEAAiE;IACjE,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC;CACrC;AAkBD;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,iBAAiB,EAC7B,IAAI,EAAE,IAAI,CAAC,aAAa,EAAE,SAAS,GAAG,uBAAuB,CAAC,GAC7D,MAAM,CAYR;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,YAAY,CAChC,IAAI,EAAE,gBAAgB,EACtB,IAAI,EAAE,aAAa,GAClB,OAAO,CAAC,eAAe,CAAC,CAuD1B"}
@@ -0,0 +1,124 @@
1
+ /**
2
+ * auth-login — testable extraction of the `olam auth login` action body.
3
+ *
4
+ * The Commander action callback in `packages/cli/src/commands/auth.ts` is too
5
+ * deeply coupled to live IO (browser opener, readline prompts, AuthClient
6
+ * against 127.0.0.1:9999, remote OAuth start) for direct unit-test mocking.
7
+ * B2 splits the decision logic out into `runAuthLogin`, which:
8
+ *
9
+ * - Resolves the backend via B1's `requireBackend`.
10
+ * - Emits the deprecation warning when --local is the explicit opt-out.
11
+ * - Asks the interactive confirm prompt before flipping to remote (skips
12
+ * on non-TTY for CI safety; --yes also bypasses).
13
+ * - Delegates the actual flow (remote URL print / local PKCE) to injected
14
+ * functions, so tests can assert on the orchestration without spawning
15
+ * real OAuth round-trips.
16
+ *
17
+ * Resolution of the default remote URL:
18
+ *
19
+ * 1. `--remote <url>` explicit string form (`resolution.explicitRemoteUrl`).
20
+ * 2. `OLAM_AUTH_WORKER_URL` env var.
21
+ * 3. `~/.olam/auth-worker-url` file (trimmed; one URL per file).
22
+ * 4. Hard-coded fallback `https://auth-worker.kaluga.co`.
23
+ *
24
+ * Step (4) matches the canonical Olam zone documented in
25
+ * `docs/plans/cloud-only-vault/phase-b-tasks.md` B2 acceptance criteria.
26
+ * Operators with a private deployment override via (2) or (3).
27
+ */
28
+ import * as fs from 'node:fs';
29
+ import * as os from 'node:os';
30
+ import * as path from 'node:path';
31
+ import { requireBackend, emitDeprecationWarning, ConflictingBackendFlags, } from './auth-backend.js';
32
+ /** Canonical fallback when no other URL source is configured. */
33
+ export const DEFAULT_AUTH_WORKER_URL = 'https://auth-worker.kaluga.co';
34
+ // ── Defaults for the deps that touch real IO ────────────────────────────────
35
+ function defaultReadAuthWorkerUrlFile() {
36
+ try {
37
+ const file = path.join(os.homedir(), '.olam', 'auth-worker-url');
38
+ const content = fs.readFileSync(file, 'utf-8').trim();
39
+ return content.length > 0 ? content : null;
40
+ }
41
+ catch {
42
+ return null;
43
+ }
44
+ }
45
+ function defaultIsTty() {
46
+ return Boolean(process.stdin.isTTY);
47
+ }
48
+ /**
49
+ * Resolve the remote auth-worker URL the login flow should target. Pure
50
+ * function modulo the injected `readEnv` + `readAuthWorkerUrlFile`.
51
+ */
52
+ export function resolveRemoteUrl(resolution, deps) {
53
+ if (resolution.explicitRemoteUrl)
54
+ return resolution.explicitRemoteUrl;
55
+ const readEnv = deps.readEnv ?? ((k) => process.env[k]);
56
+ const fromEnv = readEnv('OLAM_AUTH_WORKER_URL');
57
+ if (fromEnv && fromEnv.length > 0)
58
+ return fromEnv;
59
+ const readFile = deps.readAuthWorkerUrlFile ?? defaultReadAuthWorkerUrlFile;
60
+ const fromFile = readFile();
61
+ if (fromFile && fromFile.length > 0)
62
+ return fromFile;
63
+ return DEFAULT_AUTH_WORKER_URL;
64
+ }
65
+ /**
66
+ * Run the `olam auth login` decision tree. Tests inject `executeRemoteLogin`
67
+ * and `executeLocalLogin` to capture the orchestration without firing real
68
+ * OAuth.
69
+ *
70
+ * Decision tree (high-level):
71
+ *
72
+ * 1. requireBackend(opts) — throws ConflictingBackendFlags on dual-flag.
73
+ * 2. backend = 'local' → optional deprecation warning + local PKCE flow.
74
+ * 3. backend = 'remote' → resolve URL → optional confirm prompt → remote flow.
75
+ */
76
+ export async function runAuthLogin(opts, deps) {
77
+ const stderr = deps.stderr ?? process.stderr;
78
+ const stdout = deps.stdout ?? process.stdout;
79
+ // (1) Backend resolution.
80
+ let resolution;
81
+ try {
82
+ resolution = requireBackend({ local: opts.local, remote: opts.remote });
83
+ }
84
+ catch (err) {
85
+ if (err instanceof ConflictingBackendFlags) {
86
+ stderr.write(`error: ${err.message}\n`);
87
+ return { exitCode: 1 };
88
+ }
89
+ throw err;
90
+ }
91
+ // (2) Local opt-out path.
92
+ if (resolution.backend === 'local') {
93
+ if (resolution.emitDeprecationWarning) {
94
+ emitDeprecationWarning(stderr);
95
+ }
96
+ await deps.executeLocalLogin(opts);
97
+ return { exitCode: 0, backend: 'local' };
98
+ }
99
+ // (3) Remote default path.
100
+ const remoteUrl = resolveRemoteUrl(resolution, deps);
101
+ const isTty = (deps.isTty ?? defaultIsTty)();
102
+ // First-time confirm prompt — only when interactive AND --yes not passed
103
+ // AND no explicit URL was on the CLI (an explicit URL means the operator
104
+ // already knows where they're going).
105
+ const needsConfirm = isTty && opts.yes !== true && resolution.explicitRemoteUrl === undefined;
106
+ if (needsConfirm) {
107
+ const prompt = deps.promptConfirm;
108
+ if (prompt) {
109
+ const ans = (await prompt(`About to log into cloud auth-worker (${remoteUrl}). Continue? [Y/n] `))
110
+ .trim()
111
+ .toLowerCase();
112
+ if (ans === 'n' || ans === 'no') {
113
+ stderr.write('Cancelled by operator. Pass --local to opt out, or --yes to skip this prompt.\n');
114
+ return { exitCode: 1 };
115
+ }
116
+ }
117
+ // If no promptConfirm injected we assume the caller doesn't want a
118
+ // confirm (the action handler always wires one in production).
119
+ }
120
+ stdout.write(`Logging into cloud auth-worker at ${remoteUrl} ...\n`);
121
+ await deps.executeRemoteLogin(remoteUrl, opts);
122
+ return { exitCode: 0, backend: 'remote', resolvedRemoteUrl: remoteUrl };
123
+ }
124
+ //# sourceMappingURL=auth-login.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-login.js","sourceRoot":"","sources":["../../src/lib/auth-login.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EACL,cAAc,EACd,sBAAsB,EACtB,uBAAuB,GAExB,MAAM,mBAAmB,CAAC;AAE3B,iEAAiE;AACjE,MAAM,CAAC,MAAM,uBAAuB,GAAG,+BAA+B,CAAC;AAiDvE,+EAA+E;AAE/E,SAAS,4BAA4B;IACnC,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,iBAAiB,CAAC,CAAC;QACjE,MAAM,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;QACtD,OAAO,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;IAC7C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,SAAS,YAAY;IACnB,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AACtC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAC9B,UAA6B,EAC7B,IAA8D;IAE9D,IAAI,UAAU,CAAC,iBAAiB;QAAE,OAAO,UAAU,CAAC,iBAAiB,CAAC;IAEtE,MAAM,OAAO,GAAG,IAAI,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AAC"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * auth-mutator-backend — backend resolver for `olam auth refresh / disable /
3
+ * enable` under B4 (narrowed scope).
4
+ *
5
+ * Phase A6 architecturally ruled out adding `/v1/credentials/*` mutators to
6
+ * the cloud DO. As a result, refresh / disable / enable currently have ONE
7
+ * valid backend (local). This helper exists so the three subcommand handlers
8
+ * share identical flag-parsing + identical "remote-unsupported" exit
9
+ * semantics:
10
+ *
11
+ * - default (no flag) → proceed (local)
12
+ * - --local → proceed (local) — no deprecation warning emitted; warning the
13
+ * operator against the only working backend would be hostile until OQ7
14
+ * ships a cloud-side equivalent.
15
+ * - --remote (any form) → exit code 2 + structured message pointing to OQ7
16
+ * - --local --remote → exit code 1 (ConflictingBackendFlags semantic)
17
+ *
18
+ * Exit code 2 is the marker callers parse to distinguish "this subcommand
19
+ * has no cloud equivalent yet" from a generic local failure (exit 1).
20
+ * Wrapping scripts can branch on it to either fall back to --local or
21
+ * surface a clear "this needs OQ7" message.
22
+ *
23
+ * The message body uses a `%s` placeholder for the subcommand name so the
24
+ * three callers share one string.
25
+ */
26
+ /** Discriminant for the mutator-backend resolution outcome. */
27
+ export type MutatorBackendOutcome = {
28
+ readonly outcome: 'proceed-local';
29
+ } | {
30
+ readonly outcome: 'conflict';
31
+ readonly message: string;
32
+ } | {
33
+ readonly outcome: 'remote-unsupported';
34
+ readonly message: string;
35
+ readonly exitCode: 2;
36
+ };
37
+ /** Parsed CLI flags for a mutator subcommand. */
38
+ export interface MutatorBackendArgs {
39
+ readonly local?: boolean;
40
+ readonly remote?: boolean | string;
41
+ }
42
+ /** Structured message body for the remote-unsupported path. */
43
+ export declare const REMOTE_MUTATOR_UNSUPPORTED_MESSAGE_TEMPLATE: string;
44
+ /**
45
+ * Render the remote-unsupported message for a specific subcommand.
46
+ */
47
+ export declare function renderRemoteUnsupportedMessage(subcommand: string): string;
48
+ /**
49
+ * Resolve which path a mutator subcommand should take given the operator's
50
+ * flags. Pure function — caller is responsible for printing the message +
51
+ * setting the process.exitCode.
52
+ */
53
+ export declare function resolveMutatorBackend(subcommand: string, args: MutatorBackendArgs): MutatorBackendOutcome;
54
+ //# sourceMappingURL=auth-mutator-backend.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-mutator-backend.d.ts","sourceRoot":"","sources":["../../src/lib/auth-mutator-backend.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,+DAA+D;AAC/D,MAAM,MAAM,qBAAqB,GAC7B;IAAE,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAA;CAAE,GACrC;IAAE,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAC1D;IAAE,QAAQ,CAAC,OAAO,EAAE,oBAAoB,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAA;CAAE,CAAC;AAE/F,iDAAiD;AACjD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;CACpC;AAED,+DAA+D;AAC/D,eAAO,MAAM,2CAA2C,QAKT,CAAC;AAEhD;;GAEG;AACH,wBAAgB,8BAA8B,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAEzE;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,kBAAkB,GACvB,qBAAqB,CAoBvB"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * auth-mutator-backend — backend resolver for `olam auth refresh / disable /
3
+ * enable` under B4 (narrowed scope).
4
+ *
5
+ * Phase A6 architecturally ruled out adding `/v1/credentials/*` mutators to
6
+ * the cloud DO. As a result, refresh / disable / enable currently have ONE
7
+ * valid backend (local). This helper exists so the three subcommand handlers
8
+ * share identical flag-parsing + identical "remote-unsupported" exit
9
+ * semantics:
10
+ *
11
+ * - default (no flag) → proceed (local)
12
+ * - --local → proceed (local) — no deprecation warning emitted; warning the
13
+ * operator against the only working backend would be hostile until OQ7
14
+ * ships a cloud-side equivalent.
15
+ * - --remote (any form) → exit code 2 + structured message pointing to OQ7
16
+ * - --local --remote → exit code 1 (ConflictingBackendFlags semantic)
17
+ *
18
+ * Exit code 2 is the marker callers parse to distinguish "this subcommand
19
+ * has no cloud equivalent yet" from a generic local failure (exit 1).
20
+ * Wrapping scripts can branch on it to either fall back to --local or
21
+ * surface a clear "this needs OQ7" message.
22
+ *
23
+ * The message body uses a `%s` placeholder for the subcommand name so the
24
+ * three callers share one string.
25
+ */
26
+ /** Structured message body for the remote-unsupported path. */
27
+ export const REMOTE_MUTATOR_UNSUPPORTED_MESSAGE_TEMPLATE = 'olam auth %s has no cloud equivalent yet.\n' +
28
+ "Phase A's architectural decision keeps the cloud DO's credential\n" +
29
+ 'surface proxy-only. Tracked follow-up: docs/plans/cloud-only-vault/\n' +
30
+ 'README.md § Open questions → admin mutator UX.\n\n' +
31
+ 'Use --local to operate on the legacy vault.';
32
+ /**
33
+ * Render the remote-unsupported message for a specific subcommand.
34
+ */
35
+ export function renderRemoteUnsupportedMessage(subcommand) {
36
+ return REMOTE_MUTATOR_UNSUPPORTED_MESSAGE_TEMPLATE.replace('%s', subcommand);
37
+ }
38
+ /**
39
+ * Resolve which path a mutator subcommand should take given the operator's
40
+ * flags. Pure function — caller is responsible for printing the message +
41
+ * setting the process.exitCode.
42
+ */
43
+ export function resolveMutatorBackend(subcommand, args) {
44
+ const localFlag = args.local === true;
45
+ const remoteFlag = args.remote === true ||
46
+ (typeof args.remote === 'string' && args.remote.length > 0);
47
+ if (localFlag && remoteFlag) {
48
+ return {
49
+ outcome: 'conflict',
50
+ message: 'Cannot specify both --local and --remote. Pick one.',
51
+ };
52
+ }
53
+ if (remoteFlag) {
54
+ return {
55
+ outcome: 'remote-unsupported',
56
+ message: renderRemoteUnsupportedMessage(subcommand),
57
+ exitCode: 2,
58
+ };
59
+ }
60
+ return { outcome: 'proceed-local' };
61
+ }
62
+ //# sourceMappingURL=auth-mutator-backend.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-mutator-backend.js","sourceRoot":"","sources":["../../src/lib/auth-mutator-backend.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAcH,+DAA+D;AAC/D,MAAM,CAAC,MAAM,2CAA2C,GACtD,6CAA6C;IAC7C,oEAAoE;IACpE,uEAAuE;IACvE,oDAAoD;IACpD,6CAA6C,CAAC;AAEhD;;GAEG;AACH,MAAM,UAAU,8BAA8B,CAAC,UAAkB;IAC/D,OAAO,2CAA2C,CAAC,OAAO,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;AAC/E,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CACnC,UAAkB,EAClB,IAAwB;IAExB,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,KAAK,IAAI,CAAC;IACtC,MAAM,UAAU,GACd,IAAI,CAAC,MAAM,KAAK,IAAI;QACpB,CAAC,OAAO,IAAI,CAAC,MAAM,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAE9D,IAAI,SAAS,IAAI,UAAU,EAAE,CAAC;QAC5B,OAAO;YACL,OAAO,EAAE,UAAU;YACnB,OAAO,EAAE,qDAAqD;SAC/D,CAAC;IACJ,CAAC;IACD,IAAI,UAAU,EAAE,CAAC;QACf,OAAO;YACL,OAAO,EAAE,oBAAoB;YAC7B,OAAO,EAAE,8BAA8B,CAAC,UAAU,CAAC;YACnD,QAAQ,EAAE,CAAC;SACZ,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,CAAC;AACtC,CAAC"}
@@ -30,11 +30,52 @@ export interface ServiceToken {
30
30
  label: string;
31
31
  created_at?: string;
32
32
  }
33
+ /**
34
+ * Per-account row returned by the cloud auth-worker's `GET /v1/accounts`
35
+ * (B4 narrowed). The wire shape MUST stay aligned with the server's
36
+ * handleListAccounts response in `packages/auth-worker/src/auth-worker-do.ts`.
37
+ *
38
+ * Backward-compat fields (`label`, `expiresIn`) are populated by
39
+ * `remoteListAccounts` from the raw server payload so existing call sites
40
+ * (pre-B4 `olam auth list --remote <url>` text rendering) keep rendering.
41
+ */
33
42
  export interface AccountEntry {
34
43
  id: string;
44
+ /** Friendly label — accountLabel from server, falling back to id. */
35
45
  label?: string;
46
+ /** 'active' | 'cooldown' | 'disabled' (server-derived). */
36
47
  state?: string;
48
+ /** Pre-B4 free-form expiry hint; populated post-B4 from `expiresAt` epoch ms. */
37
49
  expiresIn?: string;
50
+ /** B4: provider — usually 'claude'. */
51
+ provider?: string;
52
+ /** B4: email, may be null. */
53
+ email?: string | null;
54
+ /** B4: ISO timestamp the cooldown / rate-limit window resets at. */
55
+ rateLimitResetsAt?: string | null;
56
+ /** B4: ISO timestamp the weekly rate-limit window resets at. */
57
+ weeklyResetsAt?: string | null;
58
+ }
59
+ /** B4: server response wire shape for GET /v1/accounts. */
60
+ export interface ListAccountsResponse {
61
+ accounts: ReadonlyArray<{
62
+ id: string;
63
+ provider: string;
64
+ email: string | null;
65
+ accountLabel: string | null;
66
+ state: 'active' | 'cooldown' | 'disabled';
67
+ rateLimited: boolean;
68
+ rateLimitResetsAt: string | null;
69
+ weeklyResetsAt: string | null;
70
+ expiresAt: number;
71
+ addedAt: string;
72
+ lastRefreshed: string;
73
+ lastUsed: string | null;
74
+ plan: string | null;
75
+ organization: string | null;
76
+ scopes: ReadonlyArray<string>;
77
+ }>;
78
+ count: number;
38
79
  }
39
80
  export interface AnthropicTokenIssueResponse {
40
81
  secret: string;
@@ -78,6 +119,15 @@ export declare function remoteOAuthStart(opts: RemoteClientOptions): Promise<OAu
78
119
  export declare function remoteListServiceTokens(opts: RemoteClientOptions): Promise<ServiceToken[]>;
79
120
  /**
80
121
  * GET /v1/accounts — list registered accounts (Anthropic OAuth sessions).
122
+ *
123
+ * B4 (narrowed): the server response is `{accounts, count}`. We map it back to
124
+ * the AccountEntry[] shape pre-existing call sites expect, and we never trust
125
+ * the server to omit secret fields — see the explicit field whitelist below.
126
+ *
127
+ * Defensive shape handling: the server contract is `{accounts: [...], count}`,
128
+ * but the legacy pre-B4 mock and older server builds may have returned a bare
129
+ * array. Both shapes are accepted (array OR envelope) so a partial roll-out
130
+ * never blocks the CLI from rendering useful output.
81
131
  */
82
132
  export declare function remoteListAccounts(opts: RemoteClientOptions): Promise<AccountEntry[]>;
83
133
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"auth-remote.d.ts","sourceRoot":"","sources":["../../src/lib/auth-remote.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,MAAM,OAAO,GAAG,OAAO,KAAK,CAAC;AAEnC,MAAM,WAAW,mBAAmB;IAClC,kEAAkE;IAClE,OAAO,EAAE,MAAM,CAAC;IAChB,8EAA8E;IAC9E,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,4EAA4E;IAC5E,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,4DAA4D;IAC5D,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAOD,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,2BAA2B;IAC1C,MAAM,EAAE,MAAM,CAAC;IACf,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