@kodax-ai/kodax 0.7.41 → 0.7.42

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 (56) hide show
  1. package/CHANGELOG.md +89 -1
  2. package/README.md +129 -232
  3. package/README_CN.md +128 -253
  4. package/dist/chunks/chunk-3RKBXWZS.js +2 -0
  5. package/dist/chunks/chunk-7JLYVWAF.js +1033 -0
  6. package/dist/chunks/chunk-CD3R5YBH.js +16 -0
  7. package/dist/chunks/chunk-DKXUY5F2.js +209 -0
  8. package/dist/chunks/chunk-HMYEQJGT.js +31 -0
  9. package/dist/chunks/{chunk-6OB4AJOM.js → chunk-IYJ5EPRV.js} +1 -1
  10. package/dist/chunks/chunk-KUX5LRPP.js +2 -0
  11. package/dist/chunks/{chunk-EQ5DGS2W.js → chunk-OWSKU55I.js} +5 -6
  12. package/dist/chunks/chunk-ZZ4KRK2B.js +465 -0
  13. package/dist/chunks/compaction-config-FIFFP4FT.js +2 -0
  14. package/dist/chunks/{construction-bootstrap-HBCWJFHC.js → construction-bootstrap-J2WOCYEK.js} +1 -1
  15. package/dist/chunks/dist-2ZHWDXMQ.js +2 -0
  16. package/dist/chunks/dist-W4CJWLIH.js +2 -0
  17. package/dist/chunks/utils-A5MWDTWZ.js +2 -0
  18. package/dist/index.d.ts +15 -10
  19. package/dist/index.js +5 -5
  20. package/dist/kodax_cli.js +841 -833
  21. package/dist/sdk-agent.d.ts +9 -93
  22. package/dist/sdk-agent.js +1 -1
  23. package/dist/sdk-coding.d.ts +315 -250
  24. package/dist/sdk-coding.js +1 -1
  25. package/dist/sdk-llm.d.ts +6 -5
  26. package/dist/sdk-llm.js +1 -1
  27. package/dist/sdk-mcp.d.ts +17 -0
  28. package/dist/sdk-mcp.js +2 -0
  29. package/dist/sdk-repl.d.ts +342 -10
  30. package/dist/sdk-repl.js +2 -1
  31. package/dist/sdk-session.d.ts +164 -0
  32. package/dist/sdk-session.js +2 -0
  33. package/dist/sdk-skills.d.ts +72 -4
  34. package/dist/sdk-skills.js +1 -1
  35. package/dist/types-chunks/{bash-prefix-extractor.d-B2iliwdi.d.ts → bash-prefix-extractor.d-CkhaqKkg.d.ts} +237 -98
  36. package/dist/types-chunks/capability.d-3C62G8Eq.d.ts +39 -0
  37. package/dist/types-chunks/config.d-BfJUXxC0.d.ts +41 -0
  38. package/dist/types-chunks/{cost-tracker.d-C4dMlQuV.d.ts → cost-tracker.d-B6vMoLLF.d.ts} +20 -2
  39. package/dist/types-chunks/{history-cleanup.d-q1vAvCss.d.ts → history-cleanup.d-DznrzEiU.d.ts} +221 -12
  40. package/dist/types-chunks/{instance-discovery.d-DZhp77vb.d.ts → instance-discovery.d-BsKnIwpg.d.ts} +31 -258
  41. package/dist/types-chunks/{resolver.d-BwD6TKz7.d.ts → resolver.d-DX9au4NJ.d.ts} +4 -3
  42. package/dist/types-chunks/session-storage.d-Cci897iM.d.ts +68 -0
  43. package/dist/types-chunks/{storage.d-Bv9T99Qu.d.ts → storage.d-Bc5DoAwp.d.ts} +17 -69
  44. package/dist/types-chunks/transport.d-DuyjG30t.d.ts +180 -0
  45. package/dist/types-chunks/{capability.d-BxNgd1-c.d.ts → types.d-B1uGoVTE.d.ts} +72 -40
  46. package/dist/types-chunks/types.d-mM8vqvhT.d.ts +254 -0
  47. package/package.json +9 -1
  48. package/dist/chunks/chunk-5TFLMGER.js +0 -2
  49. package/dist/chunks/chunk-6QO6HWGU.js +0 -30
  50. package/dist/chunks/chunk-HYWVRTFA.js +0 -1233
  51. package/dist/chunks/chunk-SX2IS5JP.js +0 -16
  52. package/dist/chunks/chunk-ZPJPNLBK.js +0 -462
  53. package/dist/chunks/compaction-config-LT5PEXPT.js +0 -2
  54. package/dist/chunks/dist-M57GIWR4.js +0 -2
  55. package/dist/chunks/dist-V3BS2NKB.js +0 -2
  56. package/dist/chunks/utils-FAFUQJ2A.js +0 -2
@@ -0,0 +1,164 @@
1
+ import { S as SessionData } from './types-chunks/session-storage.d-Cci897iM.js';
2
+ import './types-chunks/types.d-mM8vqvhT.js';
3
+ import './types-chunks/types.d-B1uGoVTE.js';
4
+
5
+ /**
6
+ * FEATURE_173 Part B (v0.7.42) — Session Management Public SDK.
7
+ *
8
+ * Thin facades over FileSessionStorage + discoverInstances. All methods
9
+ * NEVER throw — missing sessions return null, blocked operations return
10
+ * an error envelope, missing directories return empty arrays / no-op
11
+ * watchers.
12
+ *
13
+ * The `@kodax-ai/kodax/session` SDK subpath re-exports this module.
14
+ */
15
+
16
+ interface SessionSummary {
17
+ readonly id: string;
18
+ readonly title: string;
19
+ readonly msgCount: number;
20
+ readonly createdAt?: string;
21
+ readonly runtimeInfo?: {
22
+ workspaceRoot?: string;
23
+ gitRoot?: string;
24
+ };
25
+ }
26
+ interface ListSessionsOptions {
27
+ /**
28
+ * Alias for gitRoot; backwards-compat with KodaX Space terminology.
29
+ * When provided, list() is scoped to sessions from this project root.
30
+ */
31
+ readonly projectRoot?: string;
32
+ /**
33
+ * Which session scopes to include.
34
+ * - 'user' (default): only user-initiated sessions.
35
+ * - 'managed-task-worker': only managed-task worker sessions.
36
+ * - 'all': no scope filter.
37
+ */
38
+ readonly scope?: 'user' | 'managed-task-worker' | 'all';
39
+ /**
40
+ * Whether to include archived sessions (filename starts with `archived-`).
41
+ * Default false — no archived sessions exist today; reserved for future use.
42
+ */
43
+ readonly includeArchived?: boolean;
44
+ /** Maximum number of sessions to return. Default 50. */
45
+ readonly limit?: number;
46
+ /**
47
+ * ISO date string — return only sessions whose createdAt is before this
48
+ * timestamp. Applied after list + scope filtering.
49
+ */
50
+ readonly before?: string;
51
+ }
52
+ type WatchSessionsCallback = (event: {
53
+ kind: 'change' | 'add' | 'remove';
54
+ sessionId: string;
55
+ }) => void;
56
+ interface SessionManager {
57
+ listSessions: typeof listSessions;
58
+ loadSession: typeof loadSession;
59
+ forkSession: typeof forkSession;
60
+ rewindSession: typeof rewindSession;
61
+ setActiveEntry: typeof setActiveEntry;
62
+ deleteSession: typeof deleteSession;
63
+ listRunningSessions: typeof listRunningSessions;
64
+ watchSessions: typeof watchSessions;
65
+ }
66
+ /**
67
+ * List sessions, optionally filtered by scope, limit, and date.
68
+ * NEVER throws. Returns [] when the sessions directory is empty or missing.
69
+ */
70
+ declare function listSessions(opts?: ListSessionsOptions): Promise<SessionSummary[]>;
71
+ /**
72
+ * Load full session data by ID.
73
+ * Returns null for a missing session. NEVER throws.
74
+ */
75
+ declare function loadSession(id: string): Promise<SessionData | null>;
76
+ /**
77
+ * Fork a session at an optional selector.
78
+ * Returns null for a missing session. NEVER throws.
79
+ */
80
+ declare function forkSession(id: string, opts?: {
81
+ selector?: string;
82
+ sessionId?: string;
83
+ title?: string;
84
+ }): Promise<{
85
+ sessionId: string;
86
+ data: SessionData;
87
+ } | null>;
88
+ /**
89
+ * Rewind a session to a previous user entry.
90
+ * Returns null for a missing session. NEVER throws.
91
+ */
92
+ declare function rewindSession(id: string, opts?: {
93
+ selector?: string;
94
+ }): Promise<SessionData | null>;
95
+ /**
96
+ * Set the active lineage entry by selector.
97
+ * Returns null for a missing session. NEVER throws.
98
+ */
99
+ declare function setActiveEntry(id: string, selector: string): Promise<SessionData | null>;
100
+ interface RunningSessionInfo {
101
+ readonly pid: number;
102
+ readonly startedAt: number;
103
+ readonly cwd: string;
104
+ /**
105
+ * Reserved — FEATURE_125 heartbeat schema does not yet carry sessionId.
106
+ * Will be populated in a future version once the state writer includes it.
107
+ * Consumers MUST treat undefined as valid; do not assume a running session
108
+ * always has a sessionId.
109
+ */
110
+ readonly sessionId: string | undefined;
111
+ }
112
+ /**
113
+ * Returns live KodaX sibling instances (excluding this process).
114
+ * Uses discoverInstances() from @kodax-ai/agent (FEATURE_125 Team Mode).
115
+ * NEVER throws. Returns [] when no instances directory exists.
116
+ */
117
+ declare function listRunningSessions(): Promise<RunningSessionInfo[]>;
118
+ type DeleteSessionResult = {
119
+ ok: true;
120
+ } | {
121
+ error: {
122
+ code: 'session_running';
123
+ runningProcess: {
124
+ pid: number;
125
+ startedAt: number;
126
+ };
127
+ };
128
+ };
129
+ /**
130
+ * Delete a session by ID.
131
+ * Returns { ok: true } on success (including when the session doesn't exist).
132
+ * Returns an error envelope when the session is currently running.
133
+ * NEVER throws.
134
+ */
135
+ declare function deleteSession(id: string): Promise<DeleteSessionResult>;
136
+ /**
137
+ * Watch the sessions directory for changes.
138
+ * Returns { close() } that stops the watcher / poll interval.
139
+ *
140
+ * Platform branches:
141
+ * - POSIX: fs.watch() with 100ms debounce.
142
+ * - Windows: readdir poll every 1000ms, diffed against a snapshot.
143
+ *
144
+ * NEVER throws — if the directory doesn't exist the watcher is a no-op
145
+ * until the directory is created.
146
+ */
147
+ declare function watchSessions(cb: WatchSessionsCallback): {
148
+ close: () => void;
149
+ };
150
+ /**
151
+ * Factory that returns an object with all session management methods bound.
152
+ *
153
+ * The `sessionsDir` option is accepted for API surface completeness but is
154
+ * ignored in v0.7.42 — FileSessionStorage reads KODAX_SESSIONS_DIR frozen at
155
+ * module-load time. A per-instance directory override requires a substrate-
156
+ * level `setAgentConfigHome()` call before import. The sessionsDir parameter
157
+ * will be wired in a future version (v0.7.43 follow-up).
158
+ */
159
+ declare function createSessionManager(opts?: {
160
+ sessionsDir?: string;
161
+ }): SessionManager;
162
+
163
+ export { createSessionManager, deleteSession, forkSession, listRunningSessions, listSessions, loadSession, rewindSession, setActiveEntry, watchSessions };
164
+ export type { DeleteSessionResult, ListSessionsOptions, RunningSessionInfo, SessionManager, SessionSummary, WatchSessionsCallback };
@@ -0,0 +1,2 @@
1
+ // @kodax-ai/kodax — bundled distribution. See docs/ADR.md ADR-022 + ADR-024.
2
+ import{bc as s,cc as e,dc as n,ec as i,fc as o,gc as t,hc as S,ic as a,jc as r}from"./chunks/chunk-ZZ4KRK2B.js";import"./chunks/chunk-KUX5LRPP.js";import"./chunks/chunk-IYJ5EPRV.js";import"./chunks/chunk-EVIDQWMF.js";import"./chunks/chunk-7JLYVWAF.js";import"./chunks/chunk-CD3R5YBH.js";import"./chunks/chunk-HMYEQJGT.js";import"./chunks/chunk-OWSKU55I.js";import"./chunks/chunk-DKXUY5F2.js";import"./chunks/chunk-3RKBXWZS.js";import"./chunks/chunk-V4WSBIXB.js";export{r as createSessionManager,S as deleteSession,n as forkSession,t as listRunningSessions,s as listSessions,e as loadSession,i as rewindSession,o as setActiveEntry,a as watchSessions};
@@ -116,12 +116,68 @@ interface ISkillRegistry {
116
116
  /** Number of discovered skills */
117
117
  readonly size: number;
118
118
  }
119
+ /**
120
+ * v0.7.42 — SDK-embedder hook for `!`cmd`` dynamic context resolution.
121
+ *
122
+ * Receives the literal command string and the working directory the resolver
123
+ * would have used. Must return the command's text output (which the resolver
124
+ * splices into the skill markdown in place of the `!`cmd`` token), or throw
125
+ * to deny.
126
+ *
127
+ * **Trust boundary**: when the KodaX SDK is embedded inside a host app
128
+ * (e.g. KodaX Space, IDE extensions), the host typically mediates shell
129
+ * execution through a permission broker so the end user can approve / deny
130
+ * each command. Without this hook, `VariableResolver` directly `execSync`s
131
+ * commands using its own built-in whitelist — bypassing the host's broker
132
+ * and producing OS side-effects the user never saw.
133
+ *
134
+ * Embedders should route here to:
135
+ * - prompt the user via their own UI,
136
+ * - log execution to their audit trail,
137
+ * - apply policy (e.g. block network commands),
138
+ * - or refuse outright (throw).
139
+ *
140
+ * @example
141
+ * ```ts
142
+ * const context: SkillContext = {
143
+ * workingDirectory: '/repo',
144
+ * executeDynamicContext: async (cmd, cwd) => {
145
+ * const approved = await brokerAskUser({ kind: 'skill-cmd', command: cmd, cwd });
146
+ * if (!approved) throw new Error('user denied');
147
+ * return await brokerExecute(cmd, cwd);
148
+ * },
149
+ * };
150
+ * ```
151
+ */
152
+ type SkillDynamicContextExecutor = (command: string, cwd: string) => Promise<string>;
119
153
  interface SkillContext {
120
154
  workingDirectory: string;
121
155
  projectRoot?: string;
122
- sessionId: string;
156
+ /**
157
+ * Optional. Used to substitute `${CLAUDE_SESSION_ID}` / `${KODAX_SESSION_ID}`
158
+ * template variables in skill markdown. Tool-invocation callers (e.g. the
159
+ * `skill` tool) may not have a session bound — in that case the resolver
160
+ * falls back to an empty replacement so the substitution doesn't leak the
161
+ * literal `${...}` to the LLM.
162
+ */
163
+ sessionId?: string;
123
164
  environment?: Record<string, string>;
124
165
  messages?: unknown[];
166
+ /**
167
+ * v0.7.42 — SDK-embedder hook for `!`cmd`` dynamic-context resolution.
168
+ * See {@link SkillDynamicContextExecutor} for the trust-boundary rationale.
169
+ * When present, completely replaces the built-in `execSync`-based path
170
+ * (whitelist + 5s timeout). When absent, the legacy whitelist path runs.
171
+ */
172
+ executeDynamicContext?: SkillDynamicContextExecutor;
173
+ /**
174
+ * v0.7.42 — hard-disable `!`cmd`` resolution.
175
+ * When `true`, encountering a `!`cmd`` token throws
176
+ * `[Dynamic context disabled by host]` regardless of any hook. Useful for
177
+ * embedders that want a single-flag kill switch without writing a hook.
178
+ * `executeDynamicContext` is ignored when this is `true`.
179
+ */
180
+ disableDynamicContext?: boolean;
125
181
  }
126
182
  interface SkillResult {
127
183
  success: boolean;
@@ -273,11 +329,23 @@ declare class VariableResolver implements IVariableResolver {
273
329
  */
274
330
  private resolveEnvVars;
275
331
  /**
276
- * Replace !`command` with command output (dynamic context)
332
+ * Replace !`command` with command output (dynamic context).
333
+ *
334
+ * Three-tier dispatch (v0.7.42):
335
+ * 1. `context.disableDynamicContext === true` → throw immediately,
336
+ * surfaced to the LLM as `[Error: …]`. Host-level kill switch.
337
+ * 2. `context.executeDynamicContext` provided → route there. Embedder
338
+ * mediates shell execution (broker, audit, deny).
339
+ * 3. else → legacy built-in path (`isSafeDynamicContextCommand`
340
+ * whitelist + `execSync` with 5s timeout).
341
+ *
342
+ * The resolver inlines an `[Error: …]` placeholder for any thrown
343
+ * exception so a single bad token doesn't poison the whole skill load.
277
344
  */
278
345
  private resolveDynamicContext;
279
346
  /**
280
- * Execute a dynamic context command
347
+ * Execute a dynamic context command via the appropriate dispatch tier.
348
+ * See `resolveDynamicContext` JSDoc for the 3-tier ordering rationale.
281
349
  */
282
350
  private executeDynamicCommand;
283
351
  }
@@ -489,4 +557,4 @@ declare function expandSkillForLLM(skill: Skill, args: string, context: SkillCon
489
557
  declare function formatSkillActivationMessage(skillName: string, args: string): string;
490
558
 
491
559
  export { SkillExecutor, SkillRegistry, VariableResolver, clearPluginSkillPaths, createExecutor, createResolver, discoverSkills, discoverSkillsWithMonorepo, executeSkill, expandSkillForLLM, formatSkillActivationMessage, getDefaultSkillPaths, getNestedSkillPaths, getSkillPathsFlat, getSkillRegistry, initializeSkillRegistry, listPluginSkillPaths, loadFullSkill, loadSkillFileContent, loadSkillMetadata, parseArguments, parseSkillMarkdown, registerPluginSkillPath, resetSkillRegistry, resolveSkillContent, unregisterPluginSkillPath };
492
- export type { DiscoveryResult, ExecutionMode, ExecutionOptions, ISkillRegistry, IVariableResolver, Skill, SkillArtifact, SkillContext, SkillExpansionResult, SkillFile, SkillFrontmatter, SkillHook, SkillHooks, SkillMetadata, SkillPathsConfig, SkillResult, SkillSource };
560
+ export type { DiscoveryResult, ExecutionMode, ExecutionOptions, ISkillRegistry, IVariableResolver, Skill, SkillArtifact, SkillContext, SkillDynamicContextExecutor, SkillExpansionResult, SkillFile, SkillFrontmatter, SkillHook, SkillHooks, SkillMetadata, SkillPathsConfig, SkillResult, SkillSource };
@@ -1,2 +1,2 @@
1
1
  // @kodax-ai/kodax — bundled distribution. See docs/ADR.md ADR-022 + ADR-024.
2
- import{A as w,B as y,C as z,a as o,b as r,c as e,d as f,e as m,f as p,j as t,k as x,l as a,m as b,n as c,o as d,p as g,q as h,r as i,s as j,t as k,u as l,v as n,w as q,x as s,y as u,z as v}from"./chunks/chunk-EQ5DGS2W.js";import"./chunks/chunk-V4WSBIXB.js";export{u as SkillExecutor,l as SkillRegistry,i as VariableResolver,f as clearPluginSkillPaths,v as createExecutor,j as createResolver,c as discoverSkills,g as discoverSkillsWithMonorepo,w as executeSkill,y as expandSkillForLLM,z as formatSkillActivationMessage,m as getDefaultSkillPaths,d as getNestedSkillPaths,p as getSkillPathsFlat,n as getSkillRegistry,q as initializeSkillRegistry,e as listPluginSkillPaths,a as loadFullSkill,b as loadSkillFileContent,x as loadSkillMetadata,h as parseArguments,t as parseSkillMarkdown,o as registerPluginSkillPath,s as resetSkillRegistry,k as resolveSkillContent,r as unregisterPluginSkillPath};
2
+ import{A as w,B as y,C as z,a as o,b as r,c as e,d as f,e as m,f as p,j as t,k as x,l as a,m as b,n as c,o as d,p as g,q as h,r as i,s as j,t as k,u as l,v as n,w as q,x as s,y as u,z as v}from"./chunks/chunk-OWSKU55I.js";import"./chunks/chunk-V4WSBIXB.js";export{u as SkillExecutor,l as SkillRegistry,i as VariableResolver,f as clearPluginSkillPaths,v as createExecutor,j as createResolver,c as discoverSkills,g as discoverSkillsWithMonorepo,w as executeSkill,y as expandSkillForLLM,z as formatSkillActivationMessage,m as getDefaultSkillPaths,d as getNestedSkillPaths,p as getSkillPathsFlat,n as getSkillRegistry,q as initializeSkillRegistry,e as listPluginSkillPaths,a as loadFullSkill,b as loadSkillFileContent,x as loadSkillMetadata,h as parseArguments,t as parseSkillMarkdown,o as registerPluginSkillPath,s as resetSkillRegistry,k as resolveSkillContent,r as unregisterPluginSkillPath};