@kodax-ai/kodax 0.7.40 → 0.7.41

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 (47) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/dist/chunks/{chunk-NDNILSTR.js → chunk-5TFLMGER.js} +1 -1
  3. package/dist/chunks/{chunk-FAVPT4P7.js → chunk-6OB4AJOM.js} +1 -1
  4. package/dist/chunks/chunk-HYWVRTFA.js +1233 -0
  5. package/dist/chunks/chunk-SX2IS5JP.js +16 -0
  6. package/dist/chunks/chunk-ZPJPNLBK.js +462 -0
  7. package/dist/chunks/{compaction-config-A7XZ6H5Y.js → compaction-config-LT5PEXPT.js} +1 -1
  8. package/dist/chunks/{construction-bootstrap-OFPUZTXQ.js → construction-bootstrap-HBCWJFHC.js} +1 -1
  9. package/dist/chunks/dist-V3BS2NKB.js +2 -0
  10. package/dist/chunks/{utils-DFMYJUTE.js → utils-FAFUQJ2A.js} +1 -1
  11. package/dist/index.d.ts +232 -7
  12. package/dist/index.js +2 -2
  13. package/dist/kodax_cli.js +922 -912
  14. package/dist/sdk-agent.d.ts +1459 -10
  15. package/dist/sdk-agent.js +1 -1
  16. package/dist/sdk-coding.d.ts +4543 -14
  17. package/dist/sdk-coding.js +1 -1
  18. package/dist/sdk-llm.d.ts +209 -10
  19. package/dist/sdk-repl.d.ts +2694 -13
  20. package/dist/sdk-repl.js +1 -1
  21. package/dist/sdk-skills.d.ts +487 -11
  22. package/dist/types-chunks/bash-prefix-extractor.d-B2iliwdi.d.ts +2432 -0
  23. package/dist/types-chunks/capability.d-BxNgd1-c.d.ts +368 -0
  24. package/dist/types-chunks/cost-tracker.d-C4dMlQuV.d.ts +342 -0
  25. package/dist/types-chunks/history-cleanup.d-q1vAvCss.d.ts +1266 -0
  26. package/dist/types-chunks/instance-discovery.d-DZhp77vb.d.ts +1217 -0
  27. package/dist/types-chunks/resolver.d-BwD6TKz7.d.ts +262 -0
  28. package/dist/types-chunks/storage.d-Bv9T99Qu.d.ts +584 -0
  29. package/dist/types-chunks/types.d-C5mHR87z.d.ts +119 -0
  30. package/package.json +8 -3
  31. package/dist/acp_events.d.ts +0 -109
  32. package/dist/acp_logger.d.ts +0 -20
  33. package/dist/acp_server.d.ts +0 -92
  34. package/dist/chunks/chunk-CLS57NPX.js +0 -460
  35. package/dist/chunks/chunk-QZEDWITG.js +0 -1226
  36. package/dist/chunks/chunk-Z5EBDA6R.js +0 -15
  37. package/dist/chunks/dist-OTUF22DA.js +0 -2
  38. package/dist/cli_commands.d.ts +0 -17
  39. package/dist/cli_option_helpers.d.ts +0 -49
  40. package/dist/cli_option_helpers.test.d.ts +0 -1
  41. package/dist/constructed_cli.d.ts +0 -82
  42. package/dist/constructed_cli.test.d.ts +0 -1
  43. package/dist/kodax_cli.d.ts +0 -7
  44. package/dist/self_modify_cli.d.ts +0 -81
  45. package/dist/self_modify_cli.test.d.ts +0 -9
  46. package/dist/skill_cli.d.ts +0 -15
  47. package/dist/skill_cli.test.d.ts +0 -1
@@ -0,0 +1,119 @@
1
+ /**
2
+ * @kodax-ai/agent/messaging — Message queue types
3
+ *
4
+ * FEATURE_115 (v0.7.36): agentId-scoped 2-tier priority queue infrastructure.
5
+ *
6
+ * Per ADR-021: messaging is a generic agent-platform primitive (not coding-
7
+ * specific). Downstream consumers:
8
+ * - @kodax-ai/coding runner-driven mid-turn drain
9
+ * - @kodax-ai/repl InkREPL ESC soft-pause + text injection (FEATURE_111 absorbed)
10
+ * - subagent task-notification routing (FEATURE_155 idle-yield wakeup)
11
+ *
12
+ * Phase 0.6 study (`c:/tmp/claude-code-actual-usage.md`): Claude Code's
13
+ * `'now'` priority has zero production usage; KodaX simplifies to 2 tiers.
14
+ */
15
+ type MessagePriority = 'user' | 'background';
16
+ type MessageMode = 'prompt' | 'task-notification' | 'system-reminder';
17
+ interface QueuedMessage {
18
+ /** Stable id for tracing / dedup. Format: `msg-<sequence>`. */
19
+ readonly id: string;
20
+ readonly priority: MessagePriority;
21
+ /**
22
+ * Routing key:
23
+ * undefined = main thread / coordinator agent
24
+ * 'agent-id-XYZ' = subagent / specific consumer
25
+ *
26
+ * Drain consumers MUST filter by agentId match — undefined matches only
27
+ * undefined-agentId messages, not "any agent".
28
+ */
29
+ readonly agentId?: string;
30
+ readonly mode: MessageMode;
31
+ readonly content: string;
32
+ /** Wall-clock timestamp (`Date.now()`) for tracing only — not used for ordering. */
33
+ readonly enqueuedAt: number;
34
+ }
35
+ interface DequeueFilter {
36
+ /**
37
+ * Only return messages with this agentId.
38
+ * undefined matches messages with no agentId (main-thread messages only).
39
+ */
40
+ readonly agentId?: string;
41
+ /**
42
+ * Highest priority level included in the drain.
43
+ * 'user' → only user priority drained, background stays queued
44
+ * 'background' → both user + background drained (Sleep-gated case)
45
+ */
46
+ readonly maxPriority: MessagePriority;
47
+ /**
48
+ * Optional cap on number of messages drained in this call.
49
+ * Defaults to unlimited (drains all matching).
50
+ */
51
+ readonly limit?: number;
52
+ /**
53
+ * FEATURE_159 (v0.7.40) — optional mode filter. Lets REPL split the
54
+ * single queue into mode-typed views (e.g. `mode:'prompt'` for user
55
+ * input vs `mode:'task-notification'` for child completion banners)
56
+ * without separate queues. When omitted, all modes match.
57
+ */
58
+ readonly mode?: MessageMode;
59
+ /**
60
+ * FEATURE_159 (v0.7.40) — optional precise-id filter. Single-message
61
+ * targeted removal — drives Esc-pop-this-uuid in REPL. When set, all
62
+ * other filters still apply (agentId / priority / mode mismatches still
63
+ * skip the message), so callers can't accidentally remove a message
64
+ * outside their scope.
65
+ */
66
+ readonly id?: string;
67
+ /**
68
+ * FEATURE_159 (v0.7.40) — optional escape-hatch predicate, AND-ed with
69
+ * the structured filters. Lets SDK consumers express conditions the
70
+ * typed fields don't cover (e.g. timestamp ranges, content-match) without
71
+ * forcing every new use case to extend `DequeueFilter`. KodaX-internal
72
+ * code should prefer the typed fields for readability; this is the
73
+ * "data-driven main path + predicate escape" pattern.
74
+ *
75
+ * Evaluated AFTER the typed filters succeed — so a `predicate` that
76
+ * inspects `message.content` never runs on messages outside the
77
+ * caller's `agentId` / `mode` / `id` scope.
78
+ */
79
+ readonly predicate?: (message: QueuedMessage) => boolean;
80
+ }
81
+ /**
82
+ * FEATURE_159 (v0.7.40) — structured queue event emitted to subscribers.
83
+ *
84
+ * Replaces the prior `() => void` bare-notify signal. Carries the kind +
85
+ * affected messages so SDK observability consumers (logging, tracing,
86
+ * metrics) can react per-event without re-diffing snapshots.
87
+ *
88
+ * Event granularity rules:
89
+ * - `enqueued` fires ONCE per `enqueue()` call (always 1 message).
90
+ * - `dequeued` fires ONCE per `dequeue()` call that removed ≥1 message,
91
+ * carrying ALL drained messages in priority+FIFO order. No-op drains
92
+ * (filter matched nothing) fire no event — quiet by design so the
93
+ * `waitForWakeEvent` 100ms poll doesn't spam idle subscribers.
94
+ * - `cleared` fires ONCE per `clear()` call that removed ≥1 message,
95
+ * carrying the pre-clear messages. Empty-queue clear fires nothing.
96
+ *
97
+ * The `useSyncExternalStore` React hook ignores the event payload (it
98
+ * only needs the change signal); SDK / tracer consumers read the event.
99
+ */
100
+ type QueueEvent = {
101
+ readonly kind: 'enqueued';
102
+ readonly message: QueuedMessage;
103
+ } | {
104
+ readonly kind: 'dequeued';
105
+ readonly messages: readonly QueuedMessage[];
106
+ } | {
107
+ readonly kind: 'cleared';
108
+ readonly messages: readonly QueuedMessage[];
109
+ };
110
+ /** FEATURE_159 — `MessageQueue.subscribe` listener signature. */
111
+ type QueueEventListener = (event: QueueEvent) => void;
112
+ interface EnqueueInput {
113
+ readonly priority: MessagePriority;
114
+ readonly mode: MessageMode;
115
+ readonly content: string;
116
+ readonly agentId?: string;
117
+ }
118
+
119
+ export type { DequeueFilter as D, EnqueueInput as E, MessageMode as M, QueueEventListener as Q, MessagePriority as a, QueuedMessage as b };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kodax-ai/kodax",
3
- "version": "0.7.40",
3
+ "version": "0.7.41",
4
4
  "description": "极致轻量化 Coding Agent - TypeScript 实现,支持 12 个 LLM 提供商,可发布为免 Node 单文件二进制",
5
5
  "type": "module",
6
6
  "workspaces": [
@@ -39,7 +39,8 @@
39
39
  "./package.json": "./package.json"
40
40
  },
41
41
  "scripts": {
42
- "build": "npm run build:packages && npm run build:bundle && tsc --emitDeclarationOnly",
42
+ "build": "npm run build:packages && npm run build:bundle && npm run build:dts",
43
+ "build:dts": "node scripts/build-dts.mjs",
43
44
  "build:packages": "tsc -b tsconfig.build.json && npm run copy:builtin -w @kodax-ai/skills",
44
45
  "build:bundle": "node scripts/build-bundle.mjs",
45
46
  "dev": "node --max-old-space-size=4096 --require ./scripts/production-env.cjs --import tsx src/kodax_cli.ts",
@@ -56,6 +57,8 @@
56
57
  "test": "vitest run",
57
58
  "test:watch": "vitest",
58
59
  "test:eval": "vitest run -c vitest.eval.config.ts",
60
+ "bench:perf": "tsx benchmark/perf/repl-render-perf.bench.ts",
61
+ "bench:perf:e2e": "tsx benchmark/perf/repl-render-engine-e2e.bench.ts",
59
62
  "clean": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\"",
60
63
  "clean:packages": "npm run clean --workspaces"
61
64
  },
@@ -87,11 +90,11 @@
87
90
  "glob": "^11.0.1",
88
91
  "iconv-lite": "^0.6.3",
89
92
  "indent-string": "^5.0.0",
90
- "jimp": "^1.6.0",
91
93
  "ink": "^6.7.0",
92
94
  "ink-spinner": "^5.0.0",
93
95
  "ink-text-input": "^6.0.0",
94
96
  "is-in-ci": "^2.0.0",
97
+ "jimp": "^1.6.0",
95
98
  "js-tiktoken": "^1.0.12",
96
99
  "openai": "^6.32.0",
97
100
  "partial-json": "^0.1.7",
@@ -120,6 +123,8 @@
120
123
  "@vitest/coverage-v8": "^3.2.4",
121
124
  "esbuild": "^0.27.7",
122
125
  "ink-testing-library": "^4.0.0",
126
+ "rollup": "^4.60.4",
127
+ "rollup-plugin-dts": "^6.4.1",
123
128
  "vitest": "^3.2.4"
124
129
  },
125
130
  "engines": {
@@ -1,109 +0,0 @@
1
- export type AcpRuntimeEvent = {
2
- type: 'server_attached';
3
- agent: string;
4
- version: string;
5
- provider: string;
6
- model: string;
7
- cwd: string;
8
- permissionMode: string;
9
- reasoningMode: string;
10
- thinking: boolean;
11
- fixedCwd: boolean;
12
- } | {
13
- type: 'connection_closed';
14
- activeSessions: number;
15
- } | {
16
- type: 'initialize_completed';
17
- protocolVersion: number;
18
- } | {
19
- type: 'session_created';
20
- sessionId: string;
21
- cwd: string;
22
- permissionMode: string;
23
- mcpServers: number;
24
- } | {
25
- type: 'session_mode_changed';
26
- sessionId: string;
27
- from: string;
28
- to: string;
29
- } | {
30
- type: 'prompt_skipped';
31
- sessionId: string;
32
- } | {
33
- type: 'prompt_started';
34
- sessionId: string;
35
- messageId: string | null;
36
- chars: number;
37
- cwd: string;
38
- queueDelayMs: number;
39
- } | {
40
- type: 'prompt_preview';
41
- sessionId: string;
42
- prompt: string;
43
- } | {
44
- type: 'prompt_finished';
45
- sessionId: string;
46
- stopReason: 'cancelled' | 'end_turn';
47
- interrupted: boolean;
48
- durationMs: number;
49
- } | {
50
- type: 'prompt_cancelled';
51
- sessionId: string;
52
- durationMs: number;
53
- } | {
54
- type: 'prompt_failed';
55
- sessionId: string;
56
- durationMs: number;
57
- error: string;
58
- } | {
59
- type: 'cancel_requested';
60
- sessionId: string;
61
- active: boolean;
62
- } | {
63
- type: 'tool_permission_evaluated';
64
- sessionId: string;
65
- tool: string;
66
- toolId: string | null;
67
- permissionMode: string;
68
- } | {
69
- type: 'tool_permission_resolved';
70
- sessionId: string;
71
- tool: string;
72
- toolId: string | null;
73
- outcome: 'auto_allowed_read_only_bash' | 'auto_allowed_remembered' | 'blocked_plan_mode' | 'auto_allowed_plan_mode' | 'auto_allowed_policy' | 'request_failed_disconnected' | 'request_failed_incomplete' | 'request_dismissed' | 'request_rejected' | 'request_granted';
74
- remember?: boolean;
75
- } | {
76
- type: 'permission_requested';
77
- sessionId: string;
78
- tool: string;
79
- toolId: string;
80
- } | {
81
- type: 'notification_failed';
82
- sessionId: string;
83
- label: string;
84
- error: string;
85
- } | {
86
- type: 'repo_intelligence_trace';
87
- sessionId: string;
88
- stage: 'routing' | 'preturn' | 'module' | 'impact' | 'task-snapshot';
89
- summary: string;
90
- mode?: string;
91
- engine?: string;
92
- bridge?: string;
93
- status?: string;
94
- daemonLatencyMs?: number;
95
- cliLatencyMs?: number;
96
- cacheHit?: boolean;
97
- capsuleEstimatedTokens?: number;
98
- };
99
- export interface AcpEventSink {
100
- handleEvent(event: AcpRuntimeEvent): void;
101
- }
102
- export interface AcpEventEmitterOptions {
103
- sinks?: AcpEventSink[];
104
- }
105
- export declare class AcpEventEmitter {
106
- private readonly sinks;
107
- constructor(options?: AcpEventEmitterOptions);
108
- emit(event: AcpRuntimeEvent): void;
109
- }
@@ -1,20 +0,0 @@
1
- import type { AcpEventSink, AcpRuntimeEvent } from './acp_events.js';
2
- export declare const ACP_LOG_LEVELS: readonly ["off", "error", "info", "debug"];
3
- export type AcpLogLevel = (typeof ACP_LOG_LEVELS)[number];
4
- export declare function resolveAcpLogLevel(value: string | undefined, fallback?: AcpLogLevel): AcpLogLevel;
5
- export interface AcpLoggerOptions {
6
- level?: AcpLogLevel;
7
- sink?: (line: string) => void;
8
- }
9
- type AcpLogFields = Record<string, string | number | boolean | null | undefined>;
10
- export declare class AcpLogger implements AcpEventSink {
11
- private readonly level;
12
- private readonly sink;
13
- constructor(options?: AcpLoggerOptions);
14
- handleEvent(event: AcpRuntimeEvent): void;
15
- error(message: string, fields?: AcpLogFields): void;
16
- info(message: string, fields?: AcpLogFields): void;
17
- debug(message: string, fields?: AcpLogFields): void;
18
- private log;
19
- }
20
- export {};
@@ -1,92 +0,0 @@
1
- import { AgentSideConnection, type Agent, type InitializeRequest, type InitializeResponse, type NewSessionRequest, type NewSessionResponse, type PromptRequest, type PromptResponse, type SetSessionModeRequest, type SetSessionModeResponse } from '@agentclientprotocol/sdk';
2
- import { type KodaXReasoningMode } from '@kodax-ai/coding';
3
- import { FileSessionStorage } from '@kodax-ai/repl';
4
- import { type AcpLogLevel } from './acp_logger.js';
5
- import { type AcpEventSink } from './acp_events.js';
6
- /**
7
- * Permission mode ids exposed to ACP clients. These are wire-protocol values
8
- * advertised in `SessionMode.id`, so the set is intentionally narrower than
9
- * the canonical `PermissionMode` from `@kodax-ai/repl`.
10
- *
11
- * Why `'auto'` (canonical FEATURE_092 v0.7.33) is **not** here:
12
- *
13
- * 1. ACP's auto-mode classifier path requires an interactive `askUser`
14
- * surface (the readline confirm prompt or Ink confirm dialog).
15
- * `KodaXAcpServer` runs out-of-process and routes confirmations through
16
- * `connection.requestPermission` — a different protocol that has no
17
- * structural place for the classifier-escalate `<reason>` payload.
18
- * 2. ACP clients that want auto-style behavior continue to use the
19
- * legacy alias `'auto-in-project'`, which goes through
20
- * `evaluateToolPermission` → `requestPermissionFromClient` (no LLM
21
- * classifier, identical pre-v0.7.33 semantics).
22
- * 3. Once an ACP-native classifier-escalate channel lands, `'auto'` will
23
- * be added here as a third id without breaking existing clients.
24
- */
25
- export declare const ACP_PERMISSION_MODE_IDS: readonly ["plan", "accept-edits", "auto-in-project"];
26
- export type AcpPermissionMode = (typeof ACP_PERMISSION_MODE_IDS)[number];
27
- export interface KodaXAcpServerOptions {
28
- /** Provider name forwarded to the coding runtime. */
29
- provider?: string;
30
- /** Optional model override forwarded to the coding runtime. */
31
- model?: string;
32
- thinking?: boolean;
33
- reasoningMode?: KodaXReasoningMode;
34
- /**
35
- * Default session working directory. When explicitly set on the server, it
36
- * becomes the fixed execution cwd for all ACP sessions and overrides any
37
- * client-provided session cwd.
38
- */
39
- cwd?: string;
40
- permissionMode?: AcpPermissionMode;
41
- logLevel?: AcpLogLevel;
42
- /** Additional sinks that receive structured ACP runtime events. */
43
- eventSinks?: AcpEventSink[];
44
- agentName?: string;
45
- agentVersion?: string;
46
- storage?: FileSessionStorage;
47
- }
48
- export declare class KodaXAcpServer implements Agent {
49
- private readonly provider;
50
- private readonly model?;
51
- private readonly thinking;
52
- private readonly reasoningMode;
53
- private readonly defaultPermissionMode;
54
- private readonly defaultCwd;
55
- private readonly hasFixedCwd;
56
- private readonly agentName;
57
- private readonly agentVersion;
58
- private readonly storage;
59
- private readonly events;
60
- /**
61
- * FEATURE_153 (v0.7.38) — LLM-backed bash prefix extractor used by
62
- * `isToolCallAllowed` to match allowlist patterns against the extracted
63
- * safe prefix instead of naive `command.startsWith`. Server-scoped (one
64
- * per `KodaXAcpServer` instance) so the LRU cache is shared across all
65
- * sessions, mirroring the REPL's session-scoped pattern.
66
- */
67
- private readonly bashPrefixExtractor;
68
- private connection;
69
- private readonly sessions;
70
- private promptQueue;
71
- private extensionRuntime?;
72
- private extensionRuntimeReady?;
73
- constructor(options?: KodaXAcpServerOptions);
74
- attach(input: ReadableStream<Uint8Array>, output: WritableStream<Uint8Array>): AgentSideConnection;
75
- waitForClose(): Promise<void>;
76
- initialize(_params: InitializeRequest): Promise<InitializeResponse>;
77
- newSession(params: NewSessionRequest): Promise<NewSessionResponse>;
78
- authenticate(): Promise<void>;
79
- setSessionMode(params: SetSessionModeRequest): Promise<SetSessionModeResponse>;
80
- prompt(params: PromptRequest): Promise<PromptResponse>;
81
- cancel(params: {
82
- sessionId: string;
83
- }): Promise<void>;
84
- private requireSession;
85
- private buildKodaXOptions;
86
- private evaluateToolPermission;
87
- private requestPermissionFromClient;
88
- private sendTextChunk;
89
- private sendSessionUpdate;
90
- private dispatchNotification;
91
- }
92
- export declare function runAcpServer(options?: KodaXAcpServerOptions): Promise<void>;