@suwujs/king-ai 0.2.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 (104) hide show
  1. package/README.md +96 -0
  2. package/dist/src/agent-config-validation.d.ts +9 -0
  3. package/dist/src/agent-config-validation.js +30 -0
  4. package/dist/src/api.d.ts +4 -0
  5. package/dist/src/api.js +48 -0
  6. package/dist/src/attachments.d.ts +45 -0
  7. package/dist/src/attachments.js +322 -0
  8. package/dist/src/cli.d.ts +20 -0
  9. package/dist/src/cli.js +1697 -0
  10. package/dist/src/config.d.ts +3 -0
  11. package/dist/src/config.js +20 -0
  12. package/dist/src/cron.d.ts +11 -0
  13. package/dist/src/cron.js +65 -0
  14. package/dist/src/daemon.d.ts +36 -0
  15. package/dist/src/daemon.js +373 -0
  16. package/dist/src/engine.d.ts +32 -0
  17. package/dist/src/engine.js +1014 -0
  18. package/dist/src/heartbeat.d.ts +18 -0
  19. package/dist/src/heartbeat.js +28 -0
  20. package/dist/src/host-api.d.ts +40 -0
  21. package/dist/src/host-api.js +59 -0
  22. package/dist/src/host-control.d.ts +48 -0
  23. package/dist/src/host-control.js +1279 -0
  24. package/dist/src/host-export.d.ts +50 -0
  25. package/dist/src/host-export.js +187 -0
  26. package/dist/src/host-feedback.d.ts +78 -0
  27. package/dist/src/host-feedback.js +178 -0
  28. package/dist/src/host-home.d.ts +13 -0
  29. package/dist/src/host-home.js +54 -0
  30. package/dist/src/host-ledger.d.ts +261 -0
  31. package/dist/src/host-ledger.js +554 -0
  32. package/dist/src/host-loop-events.d.ts +69 -0
  33. package/dist/src/host-loop-events.js +288 -0
  34. package/dist/src/host-permission.d.ts +36 -0
  35. package/dist/src/host-permission.js +180 -0
  36. package/dist/src/host-policy.d.ts +15 -0
  37. package/dist/src/host-policy.js +36 -0
  38. package/dist/src/host-run-executor.d.ts +13 -0
  39. package/dist/src/host-run-executor.js +221 -0
  40. package/dist/src/host-run-heartbeat.d.ts +40 -0
  41. package/dist/src/host-run-heartbeat.js +103 -0
  42. package/dist/src/host-run-layout.d.ts +17 -0
  43. package/dist/src/host-run-layout.js +387 -0
  44. package/dist/src/host-run-meta.d.ts +41 -0
  45. package/dist/src/host-run-meta.js +115 -0
  46. package/dist/src/host-run-spec.d.ts +149 -0
  47. package/dist/src/host-run-spec.js +465 -0
  48. package/dist/src/host-runs.d.ts +77 -0
  49. package/dist/src/host-runs.js +195 -0
  50. package/dist/src/host-sdk.d.ts +412 -0
  51. package/dist/src/host-sdk.js +628 -0
  52. package/dist/src/host-server.d.ts +26 -0
  53. package/dist/src/host-server.js +921 -0
  54. package/dist/src/host-timeline.d.ts +24 -0
  55. package/dist/src/host-timeline.js +161 -0
  56. package/dist/src/jsonl.d.ts +13 -0
  57. package/dist/src/jsonl.js +47 -0
  58. package/dist/src/lifecycle.d.ts +5 -0
  59. package/dist/src/lifecycle.js +18 -0
  60. package/dist/src/message-routing.d.ts +32 -0
  61. package/dist/src/message-routing.js +119 -0
  62. package/dist/src/paths.d.ts +19 -0
  63. package/dist/src/paths.js +26 -0
  64. package/dist/src/project-profile.d.ts +49 -0
  65. package/dist/src/project-profile.js +356 -0
  66. package/dist/src/remediation.d.ts +14 -0
  67. package/dist/src/remediation.js +114 -0
  68. package/dist/src/remote-devices.d.ts +41 -0
  69. package/dist/src/remote-devices.js +156 -0
  70. package/dist/src/remote-diagnostics.d.ts +39 -0
  71. package/dist/src/remote-diagnostics.js +199 -0
  72. package/dist/src/remote-ssh.d.ts +39 -0
  73. package/dist/src/remote-ssh.js +129 -0
  74. package/dist/src/run-stream.d.ts +57 -0
  75. package/dist/src/run-stream.js +119 -0
  76. package/dist/src/runner.d.ts +131 -0
  77. package/dist/src/runner.js +1161 -0
  78. package/dist/src/runtime-data.d.ts +68 -0
  79. package/dist/src/runtime-data.js +172 -0
  80. package/dist/src/service.d.ts +114 -0
  81. package/dist/src/service.js +631 -0
  82. package/dist/src/shared-skills.d.ts +26 -0
  83. package/dist/src/shared-skills.js +85 -0
  84. package/dist/src/shim.d.ts +1 -0
  85. package/dist/src/shim.js +64 -0
  86. package/dist/src/skill-check.d.ts +17 -0
  87. package/dist/src/skill-check.js +158 -0
  88. package/dist/src/sse.d.ts +9 -0
  89. package/dist/src/sse.js +36 -0
  90. package/dist/src/team-routing.d.ts +55 -0
  91. package/dist/src/team-routing.js +131 -0
  92. package/dist/src/team-workflow.d.ts +78 -0
  93. package/dist/src/team-workflow.js +253 -0
  94. package/dist/src/text.d.ts +7 -0
  95. package/dist/src/text.js +27 -0
  96. package/dist/src/types.d.ts +98 -0
  97. package/dist/src/types.js +1 -0
  98. package/dist/src/usage.d.ts +116 -0
  99. package/dist/src/usage.js +350 -0
  100. package/dist/src/workspace.d.ts +9 -0
  101. package/dist/src/workspace.js +56 -0
  102. package/dist/src/worktree.d.ts +47 -0
  103. package/dist/src/worktree.js +201 -0
  104. package/package.json +63 -0
@@ -0,0 +1,24 @@
1
+ export type HostTimelineEventType = "host.command";
2
+ export interface HostTimelineEvent {
3
+ at: string;
4
+ type: HostTimelineEventType;
5
+ command: string;
6
+ ok: boolean;
7
+ exitCode: number;
8
+ destructive: boolean;
9
+ durationMs: number;
10
+ actorRole?: string;
11
+ textPreview?: string;
12
+ jsonSummary?: unknown;
13
+ error?: string;
14
+ }
15
+ export interface HostTimelineReadOptions {
16
+ path?: string;
17
+ limit?: number;
18
+ }
19
+ export declare function hostTimelinePath(path?: string): string;
20
+ export declare function appendHostTimelineEvent(event: HostTimelineEvent, path?: string): Promise<void>;
21
+ export declare function readHostTimeline(options?: HostTimelineReadOptions): Promise<HostTimelineEvent[]>;
22
+ export declare function formatHostTimeline(events: HostTimelineEvent[]): string;
23
+ export declare function summarizeHostCommandJson(command: string, json: unknown): unknown;
24
+ export declare function previewText(value: string, maxLength?: number): string | undefined;
@@ -0,0 +1,161 @@
1
+ import { appendFile, mkdir, readFile } from "node:fs/promises";
2
+ import { dirname } from "node:path";
3
+ import { HOST_EVENTS_PATH } from "./paths.js";
4
+ export function hostTimelinePath(path = HOST_EVENTS_PATH) {
5
+ return path;
6
+ }
7
+ export async function appendHostTimelineEvent(event, path = HOST_EVENTS_PATH) {
8
+ await mkdir(dirname(path), { recursive: true });
9
+ await appendFile(path, `${JSON.stringify(event)}\n`, "utf8");
10
+ }
11
+ export async function readHostTimeline(options = {}) {
12
+ const path = options.path ?? HOST_EVENTS_PATH;
13
+ const limit = normalizeLimit(options.limit);
14
+ let content = "";
15
+ try {
16
+ content = await readFile(path, "utf8");
17
+ }
18
+ catch (err) {
19
+ if (err && typeof err === "object" && err.code === "ENOENT")
20
+ return [];
21
+ throw err;
22
+ }
23
+ const events = content
24
+ .split(/\r?\n/)
25
+ .map((line) => line.trim())
26
+ .filter(Boolean)
27
+ .flatMap((line) => {
28
+ try {
29
+ const parsed = JSON.parse(line);
30
+ return isHostTimelineEvent(parsed) ? [parsed] : [];
31
+ }
32
+ catch {
33
+ return [];
34
+ }
35
+ });
36
+ return limit ? events.slice(-limit) : events;
37
+ }
38
+ export function formatHostTimeline(events) {
39
+ if (events.length === 0)
40
+ return "no host command events";
41
+ return events.map((event) => {
42
+ const status = event.ok ? "ok" : "failed";
43
+ const role = event.actorRole ? ` role=${event.actorRole}` : "";
44
+ const destructive = event.destructive ? " destructive" : "";
45
+ const error = event.error ? ` error=${event.error}` : "";
46
+ return `${event.at} ${event.command} ${status} exit=${event.exitCode}${role}${destructive} ${event.durationMs}ms${error}`;
47
+ }).join("\n");
48
+ }
49
+ export function summarizeHostCommandJson(command, json) {
50
+ if (!json || typeof json !== "object")
51
+ return undefined;
52
+ const value = json;
53
+ if (command === "status") {
54
+ return {
55
+ ok: value.ok,
56
+ computerId: value.computerId,
57
+ agents: Array.isArray(value.agents) ? value.agents.length : undefined,
58
+ events: Array.isArray(value.events) ? value.events.length : undefined
59
+ };
60
+ }
61
+ if (command === "usage") {
62
+ return {
63
+ agents: value.agents,
64
+ totalTokens: value.totalTokens,
65
+ budget: value.budget
66
+ };
67
+ }
68
+ if (command === "events") {
69
+ return { events: Array.isArray(value.events) ? value.events.length : undefined };
70
+ }
71
+ if (command === "timeline") {
72
+ return { events: Array.isArray(value.events) ? value.events.length : undefined };
73
+ }
74
+ if (command === "doctor") {
75
+ return {
76
+ exitCode: value.exitCode,
77
+ results: Array.isArray(value.results) ? value.results.length : undefined
78
+ };
79
+ }
80
+ if (command === "plan-run" || command === "preflight") {
81
+ return {
82
+ ready: value.ready,
83
+ mode: value.options?.mode,
84
+ engine: value.options?.engine,
85
+ errors: Array.isArray(value.errors) ? value.errors.length : undefined,
86
+ warnings: Array.isArray(value.warnings) ? value.warnings.length : undefined
87
+ };
88
+ }
89
+ if (command === "submit-run") {
90
+ const request = value.request;
91
+ return {
92
+ requestId: request?.id,
93
+ status: request?.status,
94
+ ready: request?.ready,
95
+ effectiveEngine: request?.effectiveEngine
96
+ };
97
+ }
98
+ if (command === "run-requests") {
99
+ return { requests: Array.isArray(value.requests) ? value.requests.length : undefined };
100
+ }
101
+ if (command === "run-request" || command === "update-run") {
102
+ const request = value.request;
103
+ return {
104
+ requestId: request?.id,
105
+ status: request?.status,
106
+ ready: request?.ready,
107
+ effectiveEngine: request?.effectiveEngine
108
+ };
109
+ }
110
+ if (command === "execute-run") {
111
+ const request = value.request;
112
+ return {
113
+ requestId: request?.id,
114
+ status: request?.status,
115
+ resultCommand: request?.result?.command,
116
+ resultOk: request?.result?.ok,
117
+ resultExitCode: request?.result?.exitCode
118
+ };
119
+ }
120
+ if (command === "plan-export") {
121
+ return {
122
+ runId: value.runId,
123
+ exportDir: value.exportDir,
124
+ workspaceFileCount: value.workspaceFileCount,
125
+ repoPatchFiles: Array.isArray(value.repoPatchFiles) ? value.repoPatchFiles.length : undefined
126
+ };
127
+ }
128
+ if (command === "export") {
129
+ return {
130
+ runId: value.runId,
131
+ exportDir: value.exportDir,
132
+ writtenFiles: Array.isArray(value.writtenFiles) ? value.writtenFiles.length : undefined
133
+ };
134
+ }
135
+ return undefined;
136
+ }
137
+ export function previewText(value, maxLength = 240) {
138
+ const text = value.replace(/\s+/g, " ").trim();
139
+ if (!text)
140
+ return undefined;
141
+ return text.length > maxLength ? `${text.slice(0, maxLength - 3)}...` : text;
142
+ }
143
+ function normalizeLimit(value) {
144
+ if (value === undefined)
145
+ return undefined;
146
+ if (!Number.isFinite(value) || value < 1)
147
+ return undefined;
148
+ return Math.floor(value);
149
+ }
150
+ function isHostTimelineEvent(value) {
151
+ if (!value || typeof value !== "object")
152
+ return false;
153
+ const event = value;
154
+ return event.type === "host.command" &&
155
+ typeof event.at === "string" &&
156
+ typeof event.command === "string" &&
157
+ typeof event.ok === "boolean" &&
158
+ typeof event.exitCode === "number" &&
159
+ typeof event.destructive === "boolean" &&
160
+ typeof event.durationMs === "number";
161
+ }
@@ -0,0 +1,13 @@
1
+ export declare function appendJsonl(path: string, value: unknown): Promise<void>;
2
+ export declare function readJsonl(path: string): Promise<unknown[]>;
3
+ export interface CompactJsonlResult {
4
+ path: string;
5
+ records: number;
6
+ written: number;
7
+ }
8
+ /**
9
+ * Rewrite an append-only JSONL file into the reduced snapshot returned by `reduce` (typically the
10
+ * merged latest state). The rewrite is atomic (temp file + rename) and holds the same write lock
11
+ * as appendJsonl, so a compaction never races a concurrent append.
12
+ */
13
+ export declare function compactJsonl(path: string, reduce: (records: unknown[]) => unknown[]): Promise<CompactJsonlResult>;
@@ -0,0 +1,47 @@
1
+ import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
2
+ import { dirname } from "node:path";
3
+ /**
4
+ * Per-path write chain. Appends and compactions to the same append-only JSONL file are
5
+ * serialized through this map so concurrent role activity (multiple agents writing the same
6
+ * ledger) cannot interleave partial lines or race a compaction rewrite.
7
+ */
8
+ const writeChains = new Map();
9
+ function withPathLock(path, fn) {
10
+ const prev = writeChains.get(path) ?? Promise.resolve();
11
+ // Run after the previous mutation settles, whether it resolved or rejected, so one failed
12
+ // write never deadlocks the queue.
13
+ const run = prev.then(fn, fn);
14
+ writeChains.set(path, run.then(() => undefined, () => undefined));
15
+ return run;
16
+ }
17
+ export async function appendJsonl(path, value) {
18
+ await withPathLock(path, async () => {
19
+ await mkdir(dirname(path), { recursive: true });
20
+ await writeFile(path, `${JSON.stringify(value)}\n`, { encoding: "utf8", flag: "a" });
21
+ });
22
+ }
23
+ export async function readJsonl(path) {
24
+ const text = await readFile(path, "utf8").catch((err) => {
25
+ if (err && typeof err === "object" && "code" in err && err.code === "ENOENT")
26
+ return "";
27
+ throw err;
28
+ });
29
+ return text.split(/\r?\n/).map((line) => line.trim()).filter(Boolean).map((line) => JSON.parse(line));
30
+ }
31
+ /**
32
+ * Rewrite an append-only JSONL file into the reduced snapshot returned by `reduce` (typically the
33
+ * merged latest state). The rewrite is atomic (temp file + rename) and holds the same write lock
34
+ * as appendJsonl, so a compaction never races a concurrent append.
35
+ */
36
+ export async function compactJsonl(path, reduce) {
37
+ return withPathLock(path, async () => {
38
+ const records = await readJsonl(path);
39
+ const compacted = reduce(records);
40
+ await mkdir(dirname(path), { recursive: true });
41
+ const tmp = `${path}.compact-${process.pid}-${Date.now()}.tmp`;
42
+ const body = compacted.map((record) => JSON.stringify(record)).join("\n");
43
+ await writeFile(tmp, body.length ? `${body}\n` : "", "utf8");
44
+ await rename(tmp, path);
45
+ return { path, records: records.length, written: compacted.length };
46
+ });
47
+ }
@@ -0,0 +1,5 @@
1
+ import type { AgentLifecycle } from "./types.js";
2
+ export declare const DEFAULT_AGENT_LIFECYCLE: AgentLifecycle;
3
+ export declare function normalizeAgentLifecycle(value: unknown): AgentLifecycle;
4
+ export declare function shouldHostAgent(lifecycle: AgentLifecycle): boolean;
5
+ export declare function runtimeLifecycleNote(lifecycle: AgentLifecycle): string;
@@ -0,0 +1,18 @@
1
+ export const DEFAULT_AGENT_LIFECYCLE = "on-demand";
2
+ export function normalizeAgentLifecycle(value) {
3
+ return value === "24/7" || value === "idle_cached" || value === "disabled" || value === "on-demand"
4
+ ? value
5
+ : DEFAULT_AGENT_LIFECYCLE;
6
+ }
7
+ export function shouldHostAgent(lifecycle) {
8
+ return lifecycle !== "disabled";
9
+ }
10
+ export function runtimeLifecycleNote(lifecycle) {
11
+ if (lifecycle === "disabled")
12
+ return "disabled - not hosted by this daemon";
13
+ if (lifecycle === "idle_cached")
14
+ return "idle_cached - event-triggered; session reuse is best-effort through the selected engine";
15
+ if (lifecycle === "24/7")
16
+ return "24/7 - hosted continuously, but turns remain runtime-event driven in this daemon";
17
+ return "on-demand - hosted and woken by runtime activity";
18
+ }
@@ -0,0 +1,32 @@
1
+ export type RuntimeMessagePriority = "normal" | "steer" | "urgent";
2
+ export type RuntimeMessageType = "message" | "decision" | "blocker" | "approval" | "system";
3
+ export type RuntimeRouteHint = "ignore" | "monitor" | "respond" | "steer";
4
+ export interface RuntimeMessageLike {
5
+ id?: string;
6
+ conversation_id?: string;
7
+ conversation_title?: string;
8
+ conversation_kind?: string;
9
+ conversation_topic?: string;
10
+ author_name?: string;
11
+ author_kind?: string;
12
+ kind?: string;
13
+ body?: string;
14
+ priority?: string;
15
+ message_type?: string;
16
+ to_agent_id?: string;
17
+ created_at?: number;
18
+ }
19
+ export interface RoutedRuntimeMessage<T extends RuntimeMessageLike = RuntimeMessageLike> {
20
+ row: T;
21
+ score: number;
22
+ priority: RuntimeMessagePriority;
23
+ type: RuntimeMessageType;
24
+ route: RuntimeRouteHint;
25
+ reasons: string[];
26
+ }
27
+ export declare function normalizeMessageType(row: RuntimeMessageLike): RuntimeMessageType;
28
+ export declare function normalizeMessagePriority(row: RuntimeMessageLike): RuntimeMessagePriority;
29
+ export declare function routeRuntimeMessage(row: RuntimeMessageLike, agentId: string): RoutedRuntimeMessage;
30
+ export declare function sortRuntimeMessages<T extends RuntimeMessageLike>(rows: T[], agentId: string): RoutedRuntimeMessage<T>[];
31
+ export declare function messageRouteTag(routed: Pick<RoutedRuntimeMessage, "priority" | "type" | "route">): string;
32
+ export declare function formatMessageRouteSummary<T extends RuntimeMessageLike>(rows: T[], agentId: string, max?: number): string;
@@ -0,0 +1,119 @@
1
+ function lower(value) {
2
+ return (value ?? "").toLowerCase();
3
+ }
4
+ function isMentioned(row, agentId) {
5
+ const body = row.body ?? "";
6
+ return body.includes(`@${agentId}`);
7
+ }
8
+ export function normalizeMessageType(row) {
9
+ const explicit = lower(row.message_type);
10
+ if (explicit === "decision" || explicit === "blocker" || explicit === "approval" || explicit === "message")
11
+ return explicit;
12
+ if (explicit === "system")
13
+ return "system";
14
+ if (row.kind === "system" || row.author_kind === "system")
15
+ return "system";
16
+ const body = lower(row.body);
17
+ if (/\bapproval required\b|\bapproval requested\b|\bapprove\b|\bdeny\b/.test(body))
18
+ return "approval";
19
+ if (/\bblocked\b|\bblocker\b|\bstuck\b|\bwaiting on\b/.test(body))
20
+ return "blocker";
21
+ if (/\bdecision\b|\bdecide\b|\bapproved\b|\brejected\b/.test(body))
22
+ return "decision";
23
+ return "message";
24
+ }
25
+ export function normalizeMessagePriority(row) {
26
+ const explicit = lower(row.priority);
27
+ if (explicit === "urgent" || explicit === "steer")
28
+ return explicit;
29
+ const type = normalizeMessageType(row);
30
+ if (type === "approval" || type === "blocker")
31
+ return "urgent";
32
+ if (type === "decision")
33
+ return "steer";
34
+ return "normal";
35
+ }
36
+ export function routeRuntimeMessage(row, agentId) {
37
+ const type = normalizeMessageType(row);
38
+ const priority = normalizeMessagePriority(row);
39
+ const reasons = [];
40
+ let score = 0;
41
+ if (row.to_agent_id === agentId) {
42
+ score += 70;
43
+ reasons.push("targeted");
44
+ }
45
+ else if (row.to_agent_id) {
46
+ score -= 100;
47
+ reasons.push("targeted elsewhere");
48
+ }
49
+ if (row.conversation_kind === "direct") {
50
+ score += 45;
51
+ reasons.push("direct");
52
+ }
53
+ if (row.author_kind === "human") {
54
+ score += 30;
55
+ reasons.push("human");
56
+ }
57
+ if (isMentioned(row, agentId)) {
58
+ score += 35;
59
+ reasons.push("mention");
60
+ }
61
+ if (priority === "urgent") {
62
+ score += 60;
63
+ reasons.push("urgent");
64
+ }
65
+ else if (priority === "steer") {
66
+ score += 45;
67
+ reasons.push("steer");
68
+ }
69
+ if (type === "approval") {
70
+ score += 55;
71
+ reasons.push("approval");
72
+ }
73
+ else if (type === "blocker") {
74
+ score += 45;
75
+ reasons.push("blocker");
76
+ }
77
+ else if (type === "decision") {
78
+ score += 30;
79
+ reasons.push("decision");
80
+ }
81
+ else if (type === "system") {
82
+ score -= 15;
83
+ reasons.push("system");
84
+ }
85
+ const route = score < 0
86
+ ? "ignore"
87
+ : priority === "urgent" || priority === "steer" || row.conversation_kind === "direct" || isMentioned(row, agentId)
88
+ ? "steer"
89
+ : row.author_kind === "human"
90
+ ? "respond"
91
+ : "monitor";
92
+ return { row, score, priority, type, route, reasons };
93
+ }
94
+ export function sortRuntimeMessages(rows, agentId) {
95
+ return rows
96
+ .map((row) => routeRuntimeMessage(row, agentId))
97
+ .sort((a, b) => {
98
+ if (b.score !== a.score)
99
+ return b.score - a.score;
100
+ return (a.row.created_at ?? 0) - (b.row.created_at ?? 0);
101
+ });
102
+ }
103
+ export function messageRouteTag(routed) {
104
+ const type = routed.type === "message" ? "msg" : routed.type;
105
+ return `${routed.route}/${routed.priority}/${type}`;
106
+ }
107
+ export function formatMessageRouteSummary(rows, agentId, max = 8) {
108
+ const routed = sortRuntimeMessages(rows, agentId).slice(0, max);
109
+ if (routed.length === 0)
110
+ return "";
111
+ return routed
112
+ .map((item) => {
113
+ const id = item.row.id ?? "?";
114
+ const who = item.row.author_name ?? "someone";
115
+ const body = item.row.kind === "system" ? "[system]" : (item.row.body ?? "").replace(/\s+/g, " ").slice(0, 120);
116
+ return `[${messageRouteTag(item)} score=${item.score}] ${id} ${who}: ${body}`;
117
+ })
118
+ .join("\n");
119
+ }
@@ -0,0 +1,19 @@
1
+ export declare const APP_NAME = "king-ai";
2
+ export type CommandName = "king-ai";
3
+ export declare function normalizeCommandName(raw?: string): CommandName;
4
+ export declare function commandNameFromProcess(argv0?: string): CommandName;
5
+ export declare function resolveConfigDir(_commandName?: "king-ai"): string;
6
+ export declare const CONFIG_DIR: string;
7
+ export declare const LEGACY_CONFIG_DIR: string;
8
+ export declare const CONFIG_PATH: string;
9
+ export declare const LEGACY_CONFIG_PATH: string;
10
+ export declare const AGENTS_ROOT: string;
11
+ export declare const SESSIONS_DIR: string;
12
+ export declare const TRIAGE_DIR: string;
13
+ export declare const RUNNING_STATE_PATH: string;
14
+ export declare const HEARTBEAT_PATH: string;
15
+ export declare const HOST_EVENTS_PATH: string;
16
+ export declare const HOST_RUNS_PATH: string;
17
+ export declare const SERVICE_LABEL = "dev.king-ai";
18
+ export declare const CURRENT_VERSION = "0.1.0";
19
+ export declare const DEFAULT_SERVER: string;
@@ -0,0 +1,26 @@
1
+ import { homedir } from "node:os";
2
+ import { join } from "node:path";
3
+ export const APP_NAME = "king-ai";
4
+ export function normalizeCommandName(raw) {
5
+ return "king-ai";
6
+ }
7
+ export function commandNameFromProcess(argv0 = process.argv[1]) {
8
+ return normalizeCommandName(argv0);
9
+ }
10
+ export function resolveConfigDir(_commandName = commandNameFromProcess()) {
11
+ return process.env.KING_AI_CONFIG_DIR || join(homedir(), ".king-ai");
12
+ }
13
+ export const CONFIG_DIR = resolveConfigDir();
14
+ export const LEGACY_CONFIG_DIR = join(homedir(), ".king");
15
+ export const CONFIG_PATH = join(CONFIG_DIR, "computer.json");
16
+ export const LEGACY_CONFIG_PATH = join(LEGACY_CONFIG_DIR, "computer.json");
17
+ export const AGENTS_ROOT = join(CONFIG_DIR, "agents");
18
+ export const SESSIONS_DIR = join(CONFIG_DIR, "sessions");
19
+ export const TRIAGE_DIR = join(CONFIG_DIR, "triage");
20
+ export const RUNNING_STATE_PATH = join(CONFIG_DIR, "running.json");
21
+ export const HEARTBEAT_PATH = join(CONFIG_DIR, "heartbeat.json");
22
+ export const HOST_EVENTS_PATH = join(CONFIG_DIR, "host-events.ndjson");
23
+ export const HOST_RUNS_PATH = join(CONFIG_DIR, "host-runs.ndjson");
24
+ export const SERVICE_LABEL = "dev.king-ai";
25
+ export const CURRENT_VERSION = "0.1.0";
26
+ export const DEFAULT_SERVER = process.env.KING_AI_SERVER_URL || "https://api.king-ai.ai";
@@ -0,0 +1,49 @@
1
+ export type ProjectDocumentKind = "readme" | "roadmap" | "docs" | "manifest" | "notes";
2
+ export interface ProjectDocument {
3
+ path: string;
4
+ kind: ProjectDocumentKind;
5
+ title: string;
6
+ excerpt: string;
7
+ headings: string[];
8
+ score: number;
9
+ }
10
+ export interface ProjectProfile {
11
+ path: string;
12
+ languages: string[];
13
+ packageManagers: string[];
14
+ frameworks: string[];
15
+ ci: string[];
16
+ testFrameworks: string[];
17
+ hasReadme: boolean;
18
+ hasAgentsMd: boolean;
19
+ hasDocs: boolean;
20
+ issueTracker: "github" | "none";
21
+ githubRemote?: string;
22
+ readmeExcerpt?: string;
23
+ codeRoots: string[];
24
+ packageScripts: string[];
25
+ }
26
+ export interface ProjectIntent {
27
+ projectName: string;
28
+ summary: string;
29
+ canonicalDocs: ProjectDocument[];
30
+ roadmapDocs: ProjectDocument[];
31
+ codeRoots: string[];
32
+ packageScripts: string[];
33
+ strategicThemes: string[];
34
+ mission: string;
35
+ }
36
+ export declare function detectLanguages(projectPath: string): string[];
37
+ export declare function detectPackageManagers(projectPath: string): string[];
38
+ export declare function detectFrameworks(projectPath: string): string[];
39
+ export declare function detectCI(projectPath: string): string[];
40
+ export declare function detectTests(projectPath: string): string[];
41
+ export declare function detectGitHubRemote(projectPath: string): string | undefined;
42
+ export declare function scanReadme(projectPath: string): string | undefined;
43
+ export declare function detectCodeRoots(projectPath: string): string[];
44
+ export declare function detectPackageScripts(projectPath: string): string[];
45
+ export declare function collectProjectDocs(projectPath: string): ProjectDocument[];
46
+ export declare function scanProject(projectPath: string): ProjectProfile;
47
+ export declare function buildProjectIntent(profile: ProjectProfile): ProjectIntent;
48
+ export declare function formatProjectProfile(profile: ProjectProfile, intent?: ProjectIntent): string;
49
+ export declare function runProjectProfile(projectPath: string): void;