@ngockhoale/ckit 0.0.0-stage → 0.1.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 (244) hide show
  1. package/.env.example +42 -0
  2. package/README.md +116 -2
  3. package/dist/src/adapters/agent/claude/errors.d.ts +13 -0
  4. package/dist/src/adapters/agent/claude/errors.js +16 -0
  5. package/dist/src/adapters/agent/claude/normalize.d.ts +11 -0
  6. package/dist/src/adapters/agent/claude/normalize.js +83 -0
  7. package/dist/src/adapters/agent/errors.d.ts +13 -0
  8. package/dist/src/adapters/agent/errors.js +19 -0
  9. package/dist/src/adapters/agent/fixtures/claude-transcript.d.ts +70 -0
  10. package/dist/src/adapters/agent/fixtures/claude-transcript.js +15 -0
  11. package/dist/src/adapters/agent/fixtures/omp-transcript.d.ts +60 -0
  12. package/dist/src/adapters/agent/fixtures/omp-transcript.js +14 -0
  13. package/dist/src/adapters/agent/normalize.d.ts +18 -0
  14. package/dist/src/adapters/agent/normalize.js +77 -0
  15. package/dist/src/adapters/agent/transport.d.ts +35 -0
  16. package/dist/src/adapters/agent/transport.js +39 -0
  17. package/dist/src/adapters/agent/worker-service.d.ts +49 -0
  18. package/dist/src/adapters/agent/worker-service.js +77 -0
  19. package/dist/src/adapters/fake/fake-advisor.d.ts +15 -0
  20. package/dist/src/adapters/fake/fake-advisor.js +29 -0
  21. package/dist/src/adapters/fake/fake-agent.d.ts +12 -0
  22. package/dist/src/adapters/fake/fake-agent.js +21 -0
  23. package/dist/src/adapters/fake/fake-store.d.ts +13 -0
  24. package/dist/src/adapters/fake/fake-store.js +23 -0
  25. package/dist/src/adapters/fake/fake-web.d.ts +12 -0
  26. package/dist/src/adapters/fake/fake-web.js +21 -0
  27. package/dist/src/adapters/fake/fault-injector.d.ts +18 -0
  28. package/dist/src/adapters/fake/fault-injector.js +64 -0
  29. package/dist/src/adapters/fake/virtual-clock.d.ts +12 -0
  30. package/dist/src/adapters/fake/virtual-clock.js +35 -0
  31. package/dist/src/adapters/launch/discover.d.ts +18 -0
  32. package/dist/src/adapters/launch/discover.js +55 -0
  33. package/dist/src/adapters/launch/executor.d.ts +117 -0
  34. package/dist/src/adapters/launch/executor.js +383 -0
  35. package/dist/src/adapters/launch/profile.d.ts +35 -0
  36. package/dist/src/adapters/launch/profile.js +73 -0
  37. package/dist/src/adapters/launch/spawn.d.ts +29 -0
  38. package/dist/src/adapters/launch/spawn.js +18 -0
  39. package/dist/src/adapters/openai/openai-advisor.d.ts +56 -0
  40. package/dist/src/adapters/openai/openai-advisor.js +146 -0
  41. package/dist/src/cli/ckit.d.ts +5 -0
  42. package/dist/src/cli/ckit.js +472 -0
  43. package/dist/src/cli/demo.d.ts +1 -0
  44. package/dist/src/cli/demo.js +30 -0
  45. package/dist/src/cli/sessions.d.ts +10 -0
  46. package/dist/src/cli/sessions.js +381 -0
  47. package/dist/src/cli/setup.d.ts +11 -0
  48. package/dist/src/cli/setup.js +115 -0
  49. package/dist/src/committee/decision.d.ts +84 -0
  50. package/dist/src/committee/decision.js +167 -0
  51. package/dist/src/committee/handover.d.ts +115 -0
  52. package/dist/src/committee/handover.js +191 -0
  53. package/dist/src/committee/no-progress.d.ts +44 -0
  54. package/dist/src/committee/no-progress.js +64 -0
  55. package/dist/src/committee/primary-registry.d.ts +15 -0
  56. package/dist/src/committee/primary-registry.js +60 -0
  57. package/dist/src/committee/reply-parser.d.ts +28 -0
  58. package/dist/src/committee/reply-parser.js +53 -0
  59. package/dist/src/committee/reviewer-scheduler.d.ts +101 -0
  60. package/dist/src/committee/reviewer-scheduler.js +163 -0
  61. package/dist/src/committee/role-epoch.d.ts +91 -0
  62. package/dist/src/committee/role-epoch.js +154 -0
  63. package/dist/src/core/control.d.ts +18 -0
  64. package/dist/src/core/control.js +29 -0
  65. package/dist/src/core/entities.d.ts +166 -0
  66. package/dist/src/core/entities.js +119 -0
  67. package/dist/src/core/errors.d.ts +9 -0
  68. package/dist/src/core/errors.js +17 -0
  69. package/dist/src/core/events.d.ts +72 -0
  70. package/dist/src/core/events.js +125 -0
  71. package/dist/src/core/ids.d.ts +47 -0
  72. package/dist/src/core/ids.js +32 -0
  73. package/dist/src/core/machine.d.ts +55 -0
  74. package/dist/src/core/machine.js +110 -0
  75. package/dist/src/core/policy.d.ts +34 -0
  76. package/dist/src/core/policy.js +59 -0
  77. package/dist/src/core/provenance.d.ts +20 -0
  78. package/dist/src/core/provenance.js +21 -0
  79. package/dist/src/core/record.d.ts +35 -0
  80. package/dist/src/core/record.js +67 -0
  81. package/dist/src/core/replay.d.ts +10 -0
  82. package/dist/src/core/replay.js +36 -0
  83. package/dist/src/core/run-task.d.ts +20 -0
  84. package/dist/src/core/run-task.js +48 -0
  85. package/dist/src/diagnostics/doctor.d.ts +78 -0
  86. package/dist/src/diagnostics/doctor.js +365 -0
  87. package/dist/src/diagnostics/journal-lock.d.ts +38 -0
  88. package/dist/src/diagnostics/journal-lock.js +181 -0
  89. package/dist/src/evidence/linker.d.ts +44 -0
  90. package/dist/src/evidence/linker.js +75 -0
  91. package/dist/src/evidence/report-parser.d.ts +27 -0
  92. package/dist/src/evidence/report-parser.js +17 -0
  93. package/dist/src/evidence/store.d.ts +36 -0
  94. package/dist/src/evidence/store.js +57 -0
  95. package/dist/src/gui/server.d.ts +27 -0
  96. package/dist/src/gui/server.js +497 -0
  97. package/dist/src/host/checkpoint.d.ts +22 -0
  98. package/dist/src/host/checkpoint.js +74 -0
  99. package/dist/src/host/export.d.ts +52 -0
  100. package/dist/src/host/export.js +45 -0
  101. package/dist/src/host/ipc.d.ts +57 -0
  102. package/dist/src/host/ipc.js +124 -0
  103. package/dist/src/host/leases.d.ts +27 -0
  104. package/dist/src/host/leases.js +40 -0
  105. package/dist/src/host/retention.d.ts +47 -0
  106. package/dist/src/host/retention.js +130 -0
  107. package/dist/src/host/supervisor.d.ts +59 -0
  108. package/dist/src/host/supervisor.js +64 -0
  109. package/dist/src/intake/owner-intake.d.ts +31 -0
  110. package/dist/src/intake/owner-intake.js +97 -0
  111. package/dist/src/intake/types.d.ts +46 -0
  112. package/dist/src/intake/types.js +2 -0
  113. package/dist/src/intent/context-packet.d.ts +68 -0
  114. package/dist/src/intent/context-packet.js +76 -0
  115. package/dist/src/intent/idea-ledger.d.ts +50 -0
  116. package/dist/src/intent/idea-ledger.js +136 -0
  117. package/dist/src/intent/ledger.d.ts +35 -0
  118. package/dist/src/intent/ledger.js +40 -0
  119. package/dist/src/intent/registry.d.ts +51 -0
  120. package/dist/src/intent/registry.js +44 -0
  121. package/dist/src/intent/revision.d.ts +37 -0
  122. package/dist/src/intent/revision.js +48 -0
  123. package/dist/src/orchestration/dispatcher.d.ts +32 -0
  124. package/dist/src/orchestration/dispatcher.js +136 -0
  125. package/dist/src/orchestration/milestone-loop.d.ts +149 -0
  126. package/dist/src/orchestration/milestone-loop.js +132 -0
  127. package/dist/src/orchestration/recovery-coordinator.d.ts +74 -0
  128. package/dist/src/orchestration/recovery-coordinator.js +180 -0
  129. package/dist/src/orchestration/work-order-contract.d.ts +44 -0
  130. package/dist/src/orchestration/work-order-contract.js +85 -0
  131. package/dist/src/orchestration/work-queue.d.ts +56 -0
  132. package/dist/src/orchestration/work-queue.js +95 -0
  133. package/dist/src/ports/advisor.d.ts +33 -0
  134. package/dist/src/ports/advisor.js +2 -0
  135. package/dist/src/ports/agent.d.ts +31 -0
  136. package/dist/src/ports/agent.js +2 -0
  137. package/dist/src/ports/capabilities.d.ts +3 -0
  138. package/dist/src/ports/capabilities.js +5 -0
  139. package/dist/src/ports/clock.d.ts +5 -0
  140. package/dist/src/ports/clock.js +5 -0
  141. package/dist/src/ports/store.d.ts +13 -0
  142. package/dist/src/ports/store.js +2 -0
  143. package/dist/src/ports/web.d.ts +29 -0
  144. package/dist/src/ports/web.js +2 -0
  145. package/dist/src/run/api-run.d.ts +49 -0
  146. package/dist/src/run/api-run.js +173 -0
  147. package/dist/src/run/plan-run.d.ts +22 -0
  148. package/dist/src/run/plan-run.js +233 -0
  149. package/dist/src/run/plan.d.ts +36 -0
  150. package/dist/src/run/plan.js +119 -0
  151. package/dist/src/run/verify.d.ts +25 -0
  152. package/dist/src/run/verify.js +81 -0
  153. package/dist/src/security/redact.d.ts +7 -0
  154. package/dist/src/security/redact.js +21 -0
  155. package/dist/src/settings/env-config.d.ts +64 -0
  156. package/dist/src/settings/env-config.js +232 -0
  157. package/dist/src/storage/artifacts.d.ts +30 -0
  158. package/dist/src/storage/artifacts.js +105 -0
  159. package/dist/src/storage/audit.d.ts +6 -0
  160. package/dist/src/storage/audit.js +6 -0
  161. package/dist/src/storage/db.d.ts +9 -0
  162. package/dist/src/storage/db.js +43 -0
  163. package/dist/src/storage/events.d.ts +20 -0
  164. package/dist/src/storage/events.js +69 -0
  165. package/dist/src/storage/migrations.d.ts +8 -0
  166. package/dist/src/storage/migrations.js +48 -0
  167. package/dist/src/storage/outbox.d.ts +25 -0
  168. package/dist/src/storage/outbox.js +40 -0
  169. package/dist/src/storage/projections.d.ts +18 -0
  170. package/dist/src/storage/projections.js +40 -0
  171. package/dist/src/storage/reconcile.d.ts +14 -0
  172. package/dist/src/storage/reconcile.js +93 -0
  173. package/dist/src/storage/reservations.d.ts +12 -0
  174. package/dist/src/storage/reservations.js +80 -0
  175. package/dist/src/storage/store.d.ts +34 -0
  176. package/dist/src/storage/store.js +105 -0
  177. package/dist/src/team/attachments.d.ts +22 -0
  178. package/dist/src/team/attachments.js +211 -0
  179. package/dist/src/team/cli-models.d.ts +24 -0
  180. package/dist/src/team/cli-models.js +72 -0
  181. package/dist/src/team/config.d.ts +20 -0
  182. package/dist/src/team/config.js +111 -0
  183. package/dist/src/team/engine.d.ts +28 -0
  184. package/dist/src/team/engine.js +443 -0
  185. package/dist/src/team/journal.d.ts +30 -0
  186. package/dist/src/team/journal.js +70 -0
  187. package/dist/src/team/runners.d.ts +79 -0
  188. package/dist/src/team/runners.js +436 -0
  189. package/dist/src/team/secrets.d.ts +10 -0
  190. package/dist/src/team/secrets.js +68 -0
  191. package/dist/src/team/types.d.ts +155 -0
  192. package/dist/src/team/types.js +5 -0
  193. package/dist/src/tui/app.d.ts +29 -0
  194. package/dist/src/tui/app.js +96 -0
  195. package/dist/src/tui/control-model.d.ts +101 -0
  196. package/dist/src/tui/control-model.js +109 -0
  197. package/dist/src/tui/control-screens.d.ts +27 -0
  198. package/dist/src/tui/control-screens.js +85 -0
  199. package/dist/src/tui/graph-model.d.ts +34 -0
  200. package/dist/src/tui/graph-model.js +29 -0
  201. package/dist/src/tui/graph-screens.d.ts +13 -0
  202. package/dist/src/tui/graph-screens.js +4 -0
  203. package/dist/src/tui/inspector-model.d.ts +150 -0
  204. package/dist/src/tui/inspector-model.js +15 -0
  205. package/dist/src/tui/inspector-screens.d.ts +14 -0
  206. package/dist/src/tui/inspector-screens.js +61 -0
  207. package/dist/src/tui/live.d.ts +16 -0
  208. package/dist/src/tui/live.js +39 -0
  209. package/dist/src/tui/mission-action-screens.d.ts +15 -0
  210. package/dist/src/tui/mission-action-screens.js +105 -0
  211. package/dist/src/tui/mission-actions.d.ts +46 -0
  212. package/dist/src/tui/mission-actions.js +53 -0
  213. package/dist/src/tui/mission-model.d.ts +120 -0
  214. package/dist/src/tui/mission-model.js +164 -0
  215. package/dist/src/tui/mission-nav.d.ts +82 -0
  216. package/dist/src/tui/mission-nav.js +131 -0
  217. package/dist/src/tui/mission-plan-screens.d.ts +11 -0
  218. package/dist/src/tui/mission-plan-screens.js +40 -0
  219. package/dist/src/tui/mission-plan.d.ts +45 -0
  220. package/dist/src/tui/mission-plan.js +166 -0
  221. package/dist/src/tui/mission-screens.d.ts +7 -0
  222. package/dist/src/tui/mission-screens.js +263 -0
  223. package/dist/src/tui/provenance-label.d.ts +11 -0
  224. package/dist/src/tui/provenance-label.js +16 -0
  225. package/dist/src/tui/screens.d.ts +10 -0
  226. package/dist/src/tui/screens.js +34 -0
  227. package/dist/src/tui/session-outcome.d.ts +14 -0
  228. package/dist/src/tui/session-outcome.js +57 -0
  229. package/dist/src/tui/setup-model.d.ts +159 -0
  230. package/dist/src/tui/setup-model.js +234 -0
  231. package/dist/src/tui/setup-screens.d.ts +66 -0
  232. package/dist/src/tui/setup-screens.js +72 -0
  233. package/dist/src/tui/team/app.d.ts +24 -0
  234. package/dist/src/tui/team/app.js +228 -0
  235. package/dist/src/tui/team/demo-handle.d.ts +22 -0
  236. package/dist/src/tui/team/demo-handle.js +42 -0
  237. package/dist/src/tui/team/model.d.ts +81 -0
  238. package/dist/src/tui/team/model.js +133 -0
  239. package/gui/app.css +177 -0
  240. package/gui/app.js +675 -0
  241. package/gui/index.html +51 -0
  242. package/gui/network.js +413 -0
  243. package/package.json +45 -4
  244. package/src/storage/schema.sql +42 -0
@@ -0,0 +1,56 @@
1
+ import type { AdvisorMessage, AdvisorPort, DispatchRequest } from '../../ports/advisor.js';
2
+ import type { CkitConfig } from '../../settings/env-config.js';
3
+ export type FetchImpl = (url: string, init: {
4
+ method: string;
5
+ headers: Record<string, string>;
6
+ body?: string;
7
+ signal: AbortSignal;
8
+ }) => Promise<{
9
+ status: number;
10
+ ok: boolean;
11
+ text(): Promise<string>;
12
+ }>;
13
+ export interface ChatMessage {
14
+ readonly role: 'system' | 'user' | 'assistant';
15
+ readonly content: string;
16
+ }
17
+ export interface AdvisorThread {
18
+ readonly id: string;
19
+ readonly role: 'primary' | 'reviewer';
20
+ readonly model: string;
21
+ readonly messages: ChatMessage[];
22
+ }
23
+ /** Persists a (redacted) assistant reply and returns its artifact reference. */
24
+ export interface ThreadStore {
25
+ saveReply(thread: AdvisorThread, text: string): Promise<string>;
26
+ }
27
+ export type AdvisorConfig = Pick<CkitConfig, 'baseUrl' | 'auth' | 'apiKey' | 'timeoutMs' | 'maxTokens'>;
28
+ /** never-sent only when a cause code proves it and no code says otherwise; no code, or any other code, is unknown. */
29
+ export declare function isNeverSent(error: unknown): boolean;
30
+ export declare class OpenAiCompatibleAdvisor implements AdvisorPort {
31
+ private readonly config;
32
+ private readonly store;
33
+ private readonly fetchImpl;
34
+ readonly name = "openai-compatible";
35
+ readonly isSimulated = false;
36
+ /** Number of HTTP requests this instance has issued (for tests and audit). */
37
+ requests: number;
38
+ private readonly prompts;
39
+ constructor(config: AdvisorConfig, store: ThreadStore, fetchImpl?: FetchImpl);
40
+ createAdvisorThread(role: 'primary' | 'reviewer', id: string, model: string, system?: string): AdvisorThread;
41
+ /** Registers the prompt text a later dispatch({promptRef}) will send on `thread`. */
42
+ registerPrompt(promptRef: string, thread: AdvisorThread, text: string): void;
43
+ dispatch(req: DispatchRequest): AsyncIterable<AdvisorMessage>;
44
+ private redact;
45
+ private note;
46
+ /** Sends exactly one request. The user text is appended to the thread only when sent; the reply only when valid. */
47
+ sendTurn(thread: AdvisorThread, userText: string, opts?: {
48
+ signal?: AbortSignal;
49
+ }): AsyncIterable<AdvisorMessage>;
50
+ }
51
+ export type ConnectionStatus = 'ok' | 'auth' | 'not-found' | 'client-error' | 'server-error' | 'timeout' | 'unreachable';
52
+ /** Single GET {base}/models. Returns a status class only. Used only by `ckit doctor --check-connection`. */
53
+ export declare function checkConnection(config: Pick<CkitConfig, 'baseUrl' | 'auth' | 'apiKey'>, fetchImpl?: FetchImpl): Promise<{
54
+ status: ConnectionStatus;
55
+ http: number | null;
56
+ }>;
@@ -0,0 +1,146 @@
1
+ // OpenAI-compatible Chat Completions advisor (ADR-017). Non-streaming, one HTTP request per send, never retries.
2
+ import { redactSecretText } from '../../security/redact.js';
3
+ const defaultFetch = (url, init) => fetch(url, init);
4
+ const NOTE_MAX = 200;
5
+ /** Error codes that prove the request was never written to a server (DNS, refused connect, TLS verification before the request). */
6
+ const NEVER_SENT_CODES = new Set(['ENOTFOUND', 'EAI_AGAIN', 'ECONNREFUSED', 'CERT_HAS_EXPIRED', 'DEPTH_ZERO_SELF_SIGNED_CERT', 'SELF_SIGNED_CERT_IN_CHAIN', 'UNABLE_TO_VERIFY_LEAF_SIGNATURE', 'UNABLE_TO_GET_ISSUER_CERT_LOCALLY', 'ERR_TLS_CERT_ALTNAME_INVALID', 'CERT_NOT_YET_VALID', 'CERT_UNTRUSTED']);
7
+ function codesOf(error, depth = 0) {
8
+ if (typeof error !== 'object' || error === null || depth > 3)
9
+ return [];
10
+ const e = error;
11
+ const own = typeof e.code === 'string' ? [e.code] : [];
12
+ const nested = Array.isArray(e.errors) ? e.errors.flatMap(x => codesOf(x, depth + 1)) : [];
13
+ return [...own, ...codesOf(e.cause, depth + 1), ...nested];
14
+ }
15
+ /** never-sent only when a cause code proves it and no code says otherwise; no code, or any other code, is unknown. */
16
+ export function isNeverSent(error) {
17
+ const codes = codesOf(error?.cause ?? error);
18
+ return codes.length > 0 && codes.every(c => NEVER_SENT_CODES.has(c));
19
+ }
20
+ export class OpenAiCompatibleAdvisor {
21
+ config;
22
+ store;
23
+ fetchImpl;
24
+ name = 'openai-compatible';
25
+ isSimulated = false;
26
+ /** Number of HTTP requests this instance has issued (for tests and audit). */
27
+ requests = 0;
28
+ prompts = new Map();
29
+ constructor(config, store, fetchImpl = defaultFetch) {
30
+ this.config = config;
31
+ this.store = store;
32
+ this.fetchImpl = fetchImpl;
33
+ }
34
+ createAdvisorThread(role, id, model, system) {
35
+ return { id, role, model, messages: system === undefined ? [] : [{ role: 'system', content: system }] };
36
+ }
37
+ /** Registers the prompt text a later dispatch({promptRef}) will send on `thread`. */
38
+ registerPrompt(promptRef, thread, text) { this.prompts.set(promptRef, { thread, text }); }
39
+ async *dispatch(req) {
40
+ const entry = this.prompts.get(req.promptRef);
41
+ if (!entry) {
42
+ yield { kind: 'unknown', reason: 'adapter-fault', note: 'prompt not registered' };
43
+ return;
44
+ }
45
+ yield* this.sendTurn(entry.thread, entry.text);
46
+ }
47
+ redact(text) { return redactSecretText(text, this.config.apiKey ? [this.config.apiKey] : []); }
48
+ note(body) { return this.redact(body).replace(/\s+/g, ' ').slice(0, NOTE_MAX); }
49
+ /** Sends exactly one request. The user text is appended to the thread only when sent; the reply only when valid. */
50
+ async *sendTurn(thread, userText, opts = {}) {
51
+ const controller = new AbortController();
52
+ let timedOut = false;
53
+ const timer = setTimeout(() => { timedOut = true; controller.abort(); }, this.config.timeoutMs);
54
+ const onAbort = () => controller.abort();
55
+ if (opts.signal?.aborted)
56
+ controller.abort();
57
+ else
58
+ opts.signal?.addEventListener('abort', onAbort, { once: true });
59
+ const cleanup = () => { clearTimeout(timer); opts.signal?.removeEventListener('abort', onAbort); };
60
+ try {
61
+ const messages = [...thread.messages, { role: 'user', content: userText }];
62
+ const body = { model: thread.model, messages, stream: false };
63
+ if (this.config.maxTokens !== null)
64
+ body['max_tokens'] = this.config.maxTokens;
65
+ const headers = { 'content-type': 'application/json' };
66
+ if (this.config.auth === 'bearer')
67
+ headers['authorization'] = `Bearer ${this.config.apiKey}`;
68
+ let res;
69
+ let raw;
70
+ this.requests++;
71
+ try {
72
+ res = await this.fetchImpl(`${this.config.baseUrl}/chat/completions`, { method: 'POST', headers, body: JSON.stringify(body), signal: controller.signal });
73
+ if (res.status >= 200 && res.status < 300)
74
+ yield { kind: 'ack' };
75
+ raw = await res.text();
76
+ }
77
+ catch (error) {
78
+ if (timedOut) {
79
+ yield { kind: 'unknown', reason: 'timeout', note: `no response within ${this.config.timeoutMs}ms` };
80
+ return;
81
+ }
82
+ if (controller.signal.aborted) {
83
+ yield { kind: 'unknown', reason: 'adapter-fault', note: 'cancelled' };
84
+ return;
85
+ }
86
+ if (isNeverSent(error)) {
87
+ yield { kind: 'rejected', reason: 'connect', delivery: 'never-sent', status: null, note: `connection failed before the request was sent: ${this.note(error instanceof Error ? error.message : 'error')}` };
88
+ return;
89
+ }
90
+ yield { kind: 'unknown', reason: 'adapter-fault', note: 'transport failure; delivery unknown' };
91
+ return;
92
+ }
93
+ const status = res.status;
94
+ if (status < 200 || status >= 300) {
95
+ if (status >= 500) {
96
+ yield { kind: 'unknown', reason: 'adapter-fault', note: `http ${status}: ${this.note(raw)}` };
97
+ return;
98
+ }
99
+ const [reason, hint] = status === 401 || status === 403 ? ['auth', 'check CKIT_OPENAI_API_KEY / CKIT_OPENAI_AUTH']
100
+ : status === 404 ? ['not-found', 'check CKIT_OPENAI_BASE_URL and CKIT_OPENAI_MODEL']
101
+ : status === 429 ? ['rate-limited', 'endpoint is rate limiting; nothing was resent']
102
+ : ['client-error', 'request was rejected by the endpoint'];
103
+ yield { kind: 'rejected', reason, delivery: 'refused', status, note: `http ${status}: ${hint}: ${this.note(raw)}` };
104
+ return;
105
+ }
106
+ let content;
107
+ try {
108
+ content = JSON.parse(raw).choices?.[0]?.message?.content;
109
+ }
110
+ catch {
111
+ yield { kind: 'unknown', reason: 'adapter-fault', note: 'malformed JSON response' };
112
+ return;
113
+ }
114
+ if (typeof content !== 'string' || content.trim() === '') {
115
+ yield { kind: 'unknown', reason: 'adapter-fault', note: 'response has no choices[0].message.content' };
116
+ return;
117
+ }
118
+ thread.messages.push({ role: 'user', content: userText }, { role: 'assistant', content });
119
+ const resultRef = await this.store.saveReply(thread, this.redact(content));
120
+ yield { kind: 'completed', resultRef };
121
+ }
122
+ finally {
123
+ cleanup();
124
+ }
125
+ }
126
+ }
127
+ /** Single GET {base}/models. Returns a status class only. Used only by `ckit doctor --check-connection`. */
128
+ export async function checkConnection(config, fetchImpl = defaultFetch) {
129
+ const controller = new AbortController();
130
+ const timer = setTimeout(() => controller.abort(), 10_000);
131
+ try {
132
+ const headers = {};
133
+ if (config.auth === 'bearer')
134
+ headers['authorization'] = `Bearer ${config.apiKey}`;
135
+ const res = await fetchImpl(`${config.baseUrl}/models`, { method: 'GET', headers, signal: controller.signal });
136
+ const s = res.status;
137
+ return { http: s, status: s >= 200 && s < 300 ? 'ok' : s === 401 || s === 403 ? 'auth' : s === 404 ? 'not-found' : s >= 500 ? 'server-error' : 'client-error' };
138
+ }
139
+ catch {
140
+ return { http: null, status: controller.signal.aborted ? 'timeout' : 'unreachable' };
141
+ }
142
+ finally {
143
+ clearTimeout(timer);
144
+ }
145
+ }
146
+ //# sourceMappingURL=openai-advisor.js.map
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+ import type { MissionViewOptions } from '../tui/mission-model.js';
3
+ /** Mission options for `ckit tui`: one read-only Plan snapshot, REPLAY mode (no side effects); the Actions panel is bound to nothing, so every control is disabled with a reason. */
4
+ export declare function buildTuiMissionOptions(cwd: string, width?: number): Promise<MissionViewOptions>;
5
+ export declare function main(args?: string[]): Promise<number>;