@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.
- package/README.md +96 -0
- package/dist/src/agent-config-validation.d.ts +9 -0
- package/dist/src/agent-config-validation.js +30 -0
- package/dist/src/api.d.ts +4 -0
- package/dist/src/api.js +48 -0
- package/dist/src/attachments.d.ts +45 -0
- package/dist/src/attachments.js +322 -0
- package/dist/src/cli.d.ts +20 -0
- package/dist/src/cli.js +1697 -0
- package/dist/src/config.d.ts +3 -0
- package/dist/src/config.js +20 -0
- package/dist/src/cron.d.ts +11 -0
- package/dist/src/cron.js +65 -0
- package/dist/src/daemon.d.ts +36 -0
- package/dist/src/daemon.js +373 -0
- package/dist/src/engine.d.ts +32 -0
- package/dist/src/engine.js +1014 -0
- package/dist/src/heartbeat.d.ts +18 -0
- package/dist/src/heartbeat.js +28 -0
- package/dist/src/host-api.d.ts +40 -0
- package/dist/src/host-api.js +59 -0
- package/dist/src/host-control.d.ts +48 -0
- package/dist/src/host-control.js +1279 -0
- package/dist/src/host-export.d.ts +50 -0
- package/dist/src/host-export.js +187 -0
- package/dist/src/host-feedback.d.ts +78 -0
- package/dist/src/host-feedback.js +178 -0
- package/dist/src/host-home.d.ts +13 -0
- package/dist/src/host-home.js +54 -0
- package/dist/src/host-ledger.d.ts +261 -0
- package/dist/src/host-ledger.js +554 -0
- package/dist/src/host-loop-events.d.ts +69 -0
- package/dist/src/host-loop-events.js +288 -0
- package/dist/src/host-permission.d.ts +36 -0
- package/dist/src/host-permission.js +180 -0
- package/dist/src/host-policy.d.ts +15 -0
- package/dist/src/host-policy.js +36 -0
- package/dist/src/host-run-executor.d.ts +13 -0
- package/dist/src/host-run-executor.js +221 -0
- package/dist/src/host-run-heartbeat.d.ts +40 -0
- package/dist/src/host-run-heartbeat.js +103 -0
- package/dist/src/host-run-layout.d.ts +17 -0
- package/dist/src/host-run-layout.js +387 -0
- package/dist/src/host-run-meta.d.ts +41 -0
- package/dist/src/host-run-meta.js +115 -0
- package/dist/src/host-run-spec.d.ts +149 -0
- package/dist/src/host-run-spec.js +465 -0
- package/dist/src/host-runs.d.ts +77 -0
- package/dist/src/host-runs.js +195 -0
- package/dist/src/host-sdk.d.ts +412 -0
- package/dist/src/host-sdk.js +628 -0
- package/dist/src/host-server.d.ts +26 -0
- package/dist/src/host-server.js +921 -0
- package/dist/src/host-timeline.d.ts +24 -0
- package/dist/src/host-timeline.js +161 -0
- package/dist/src/jsonl.d.ts +13 -0
- package/dist/src/jsonl.js +47 -0
- package/dist/src/lifecycle.d.ts +5 -0
- package/dist/src/lifecycle.js +18 -0
- package/dist/src/message-routing.d.ts +32 -0
- package/dist/src/message-routing.js +119 -0
- package/dist/src/paths.d.ts +19 -0
- package/dist/src/paths.js +26 -0
- package/dist/src/project-profile.d.ts +49 -0
- package/dist/src/project-profile.js +356 -0
- package/dist/src/remediation.d.ts +14 -0
- package/dist/src/remediation.js +114 -0
- package/dist/src/remote-devices.d.ts +41 -0
- package/dist/src/remote-devices.js +156 -0
- package/dist/src/remote-diagnostics.d.ts +39 -0
- package/dist/src/remote-diagnostics.js +199 -0
- package/dist/src/remote-ssh.d.ts +39 -0
- package/dist/src/remote-ssh.js +129 -0
- package/dist/src/run-stream.d.ts +57 -0
- package/dist/src/run-stream.js +119 -0
- package/dist/src/runner.d.ts +131 -0
- package/dist/src/runner.js +1161 -0
- package/dist/src/runtime-data.d.ts +68 -0
- package/dist/src/runtime-data.js +172 -0
- package/dist/src/service.d.ts +114 -0
- package/dist/src/service.js +631 -0
- package/dist/src/shared-skills.d.ts +26 -0
- package/dist/src/shared-skills.js +85 -0
- package/dist/src/shim.d.ts +1 -0
- package/dist/src/shim.js +64 -0
- package/dist/src/skill-check.d.ts +17 -0
- package/dist/src/skill-check.js +158 -0
- package/dist/src/sse.d.ts +9 -0
- package/dist/src/sse.js +36 -0
- package/dist/src/team-routing.d.ts +55 -0
- package/dist/src/team-routing.js +131 -0
- package/dist/src/team-workflow.d.ts +78 -0
- package/dist/src/team-workflow.js +253 -0
- package/dist/src/text.d.ts +7 -0
- package/dist/src/text.js +27 -0
- package/dist/src/types.d.ts +98 -0
- package/dist/src/types.js +1 -0
- package/dist/src/usage.d.ts +116 -0
- package/dist/src/usage.js +350 -0
- package/dist/src/workspace.d.ts +9 -0
- package/dist/src/workspace.js +56 -0
- package/dist/src/worktree.d.ts +47 -0
- package/dist/src/worktree.js +201 -0
- package/package.json +63 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface HeartbeatData {
|
|
2
|
+
pid: number;
|
|
3
|
+
runId: string;
|
|
4
|
+
lastTick: string;
|
|
5
|
+
loopCount: number;
|
|
6
|
+
version?: string;
|
|
7
|
+
computerId?: string;
|
|
8
|
+
serverUrl?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class FileHeartbeat {
|
|
11
|
+
private readonly path;
|
|
12
|
+
private readonly data;
|
|
13
|
+
private loopCount;
|
|
14
|
+
constructor(path: string, data: Omit<HeartbeatData, "lastTick" | "loopCount">);
|
|
15
|
+
get count(): number;
|
|
16
|
+
write(): HeartbeatData;
|
|
17
|
+
tick(): HeartbeatData;
|
|
18
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname } from "node:path";
|
|
3
|
+
export class FileHeartbeat {
|
|
4
|
+
path;
|
|
5
|
+
data;
|
|
6
|
+
loopCount = 0;
|
|
7
|
+
constructor(path, data) {
|
|
8
|
+
this.path = path;
|
|
9
|
+
this.data = data;
|
|
10
|
+
mkdirSync(dirname(this.path), { recursive: true });
|
|
11
|
+
}
|
|
12
|
+
get count() {
|
|
13
|
+
return this.loopCount;
|
|
14
|
+
}
|
|
15
|
+
write() {
|
|
16
|
+
const data = {
|
|
17
|
+
...this.data,
|
|
18
|
+
lastTick: new Date().toISOString(),
|
|
19
|
+
loopCount: this.loopCount
|
|
20
|
+
};
|
|
21
|
+
writeFileSync(this.path, JSON.stringify(data, null, 2) + "\n", { mode: 0o600 });
|
|
22
|
+
return data;
|
|
23
|
+
}
|
|
24
|
+
tick() {
|
|
25
|
+
this.loopCount += 1;
|
|
26
|
+
return this.write();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { RunningEvent, RunningState } from "./service.js";
|
|
2
|
+
import type { UsagePricingRule, UsageSummary } from "./usage.js";
|
|
3
|
+
import type { WorktreePlan } from "./worktree.js";
|
|
4
|
+
import type { RemediationAdvice } from "./remediation.js";
|
|
5
|
+
import type { AgentConfigWarning } from "./agent-config-validation.js";
|
|
6
|
+
export interface HostAgentStatus {
|
|
7
|
+
id: string;
|
|
8
|
+
name: string;
|
|
9
|
+
engine: string;
|
|
10
|
+
lifecycle?: string;
|
|
11
|
+
status?: string;
|
|
12
|
+
model?: string;
|
|
13
|
+
workspaceRoot?: string;
|
|
14
|
+
sharedSkillSnapshotId?: string;
|
|
15
|
+
hostHomeEntries?: Array<{
|
|
16
|
+
name: string;
|
|
17
|
+
linked: boolean;
|
|
18
|
+
reason?: string;
|
|
19
|
+
}>;
|
|
20
|
+
remediation?: Pick<RemediationAdvice, "category" | "severity" | "summary" | "actions"> | null;
|
|
21
|
+
configWarnings?: AgentConfigWarning[];
|
|
22
|
+
}
|
|
23
|
+
export interface HostStatusSnapshot {
|
|
24
|
+
ok: boolean;
|
|
25
|
+
version?: string;
|
|
26
|
+
pid?: number;
|
|
27
|
+
startedAt?: string;
|
|
28
|
+
serverUrl?: string;
|
|
29
|
+
computerId?: string;
|
|
30
|
+
capabilities: {
|
|
31
|
+
workspaces: string[];
|
|
32
|
+
};
|
|
33
|
+
agents: HostAgentStatus[];
|
|
34
|
+
usage: UsageSummary;
|
|
35
|
+
worktrees: WorktreePlan[];
|
|
36
|
+
events: RunningEvent[];
|
|
37
|
+
text: string;
|
|
38
|
+
}
|
|
39
|
+
export declare function buildHostStatusSnapshot(state: RunningState | null, budget?: number | null, pricingRules?: UsagePricingRule[]): HostStatusSnapshot;
|
|
40
|
+
export declare function formatHostStatusSnapshot(snapshot: HostStatusSnapshot): string;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { formatRunningStateSnapshot } from "./service.js";
|
|
2
|
+
import { summarizeAgentUsage } from "./usage.js";
|
|
3
|
+
import { worktreePlansFromRunningState } from "./service.js";
|
|
4
|
+
export function buildHostStatusSnapshot(state, budget, pricingRules = []) {
|
|
5
|
+
return {
|
|
6
|
+
ok: Boolean(state),
|
|
7
|
+
version: state?.version,
|
|
8
|
+
pid: state?.pid,
|
|
9
|
+
startedAt: state?.startedAt,
|
|
10
|
+
serverUrl: state?.serverUrl,
|
|
11
|
+
computerId: state?.computerId,
|
|
12
|
+
capabilities: {
|
|
13
|
+
workspaces: state?.capabilities?.workspaces ?? []
|
|
14
|
+
},
|
|
15
|
+
agents: (state?.agents ?? []).map((agent) => ({
|
|
16
|
+
id: agent.id,
|
|
17
|
+
name: agent.name,
|
|
18
|
+
engine: agent.engine,
|
|
19
|
+
lifecycle: agent.lifecycle,
|
|
20
|
+
status: agent.status,
|
|
21
|
+
model: agent.model,
|
|
22
|
+
workspaceRoot: agent.workspaceRoot,
|
|
23
|
+
sharedSkillSnapshotId: agent.sharedSkillSnapshot?.id,
|
|
24
|
+
hostHomeEntries: agent.hostHomeEntries?.map((entry) => ({
|
|
25
|
+
name: entry.name,
|
|
26
|
+
linked: entry.linked,
|
|
27
|
+
reason: entry.reason
|
|
28
|
+
})),
|
|
29
|
+
remediation: agent.remediation
|
|
30
|
+
? {
|
|
31
|
+
category: agent.remediation.category,
|
|
32
|
+
severity: agent.remediation.severity,
|
|
33
|
+
summary: agent.remediation.summary,
|
|
34
|
+
actions: agent.remediation.actions
|
|
35
|
+
}
|
|
36
|
+
: null,
|
|
37
|
+
configWarnings: agent.configWarnings ?? []
|
|
38
|
+
})),
|
|
39
|
+
usage: summarizeAgentUsage(state?.agents ?? [], budget, pricingRules),
|
|
40
|
+
worktrees: worktreePlansFromRunningState(state),
|
|
41
|
+
events: state?.events?.slice(-20) ?? [],
|
|
42
|
+
text: formatRunningStateSnapshot(state)
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export function formatHostStatusSnapshot(snapshot) {
|
|
46
|
+
if (!snapshot.ok)
|
|
47
|
+
return "host status: daemon is not running or running.json is unavailable";
|
|
48
|
+
const lines = [
|
|
49
|
+
`host status: ${snapshot.version ?? "unknown"} pid=${snapshot.pid ?? "unknown"}`,
|
|
50
|
+
snapshot.computerId || snapshot.serverUrl
|
|
51
|
+
? `paired: ${snapshot.computerId ?? "unknown"} @ ${snapshot.serverUrl ?? "unknown"}`
|
|
52
|
+
: "paired: unknown",
|
|
53
|
+
`agents=${snapshot.agents.length} workspaces=${snapshot.capabilities.workspaces.length} worktrees=${snapshot.worktrees.length}`,
|
|
54
|
+
`usage: runs=${snapshot.usage.turns} failed=${snapshot.usage.failed} tokens=${snapshot.usage.totalTokens}`
|
|
55
|
+
];
|
|
56
|
+
if (snapshot.text)
|
|
57
|
+
lines.push(snapshot.text);
|
|
58
|
+
return lines.join("\n");
|
|
59
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { DoctorResult } from "./daemon.js";
|
|
2
|
+
import type { HostWorkflowCard } from "./host-ledger.js";
|
|
3
|
+
import type { HandoffAction } from "./team-routing.js";
|
|
4
|
+
import type { KingTeamSpec } from "./team-workflow.js";
|
|
5
|
+
import type { RunningState } from "./service.js";
|
|
6
|
+
import type { UsagePricingRule } from "./usage.js";
|
|
7
|
+
export type HostCommandName = "status" | "usage" | "expenses" | "events" | "timeline" | "policy" | "doctor" | "plan-run" | "preflight" | "prepare-run-layout" | "submit-run" | "run-requests" | "run-request" | "update-run" | "cancel-run" | "execute-run" | "task-create" | "task-list" | "task-update" | "agenda" | "capsule-create" | "capsule-list" | "capsule-update" | "workflow-create" | "workflow-list" | "workflow-update" | "initiative-create" | "handoff-create" | "review-create" | "decision-create" | "artifact-create" | "feedback-record" | "feedback-list" | "feedback-summary" | "cron-check" | "emit-run-event" | "watch-run" | "run-results" | "run-heartbeat" | "run-meta" | "plan-export" | "export" | "compact-ledger" | "remote-config-get" | "remote-config-save" | "remote-list" | "remote-save-device" | "remote-delete-device" | "remote-default-device" | "remote-probe" | "remote-profile" | "remote-run" | "remote-logs" | "remote-find-logs" | "remote-pg" | "remote-redis";
|
|
8
|
+
export type HostCommandFormat = "text" | "json";
|
|
9
|
+
export interface HostCommandDefinition {
|
|
10
|
+
name: HostCommandName;
|
|
11
|
+
description: string;
|
|
12
|
+
destructive: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface HostCommandRequest {
|
|
15
|
+
command: string;
|
|
16
|
+
format?: HostCommandFormat;
|
|
17
|
+
input?: unknown;
|
|
18
|
+
actorRole?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface HostCommandResult {
|
|
21
|
+
ok: boolean;
|
|
22
|
+
command: string;
|
|
23
|
+
exitCode: number;
|
|
24
|
+
text: string;
|
|
25
|
+
json?: unknown;
|
|
26
|
+
error?: string;
|
|
27
|
+
}
|
|
28
|
+
export interface HostCommandRunnerDeps {
|
|
29
|
+
readState?: () => Promise<RunningState | null>;
|
|
30
|
+
tokenBudget?: () => number | null | undefined;
|
|
31
|
+
usagePricing?: () => UsagePricingRule[];
|
|
32
|
+
collectDoctorResults?: () => Promise<DoctorResult[]>;
|
|
33
|
+
availableEngines?: () => string[];
|
|
34
|
+
recordTimeline?: boolean;
|
|
35
|
+
timelinePath?: string;
|
|
36
|
+
runsPath?: string;
|
|
37
|
+
teamSpec?: () => KingTeamSpec | null | undefined;
|
|
38
|
+
enforcePermission?: boolean;
|
|
39
|
+
autoHandoff?: boolean;
|
|
40
|
+
now?: () => Date;
|
|
41
|
+
}
|
|
42
|
+
export declare function listHostCommands(): HostCommandDefinition[];
|
|
43
|
+
export declare function normalizeHostCommandName(raw: string): HostCommandName | null;
|
|
44
|
+
export declare function runHostCommand(request: HostCommandRequest, deps?: HostCommandRunnerDeps): Promise<HostCommandResult>;
|
|
45
|
+
export interface HostHandoffResult {
|
|
46
|
+
reason: HandoffAction["reason"];
|
|
47
|
+
card: HostWorkflowCard;
|
|
48
|
+
}
|