@hmharness/kernel 0.9.6 → 0.9.8

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/dist/config.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { HmhConfig } from './types.ts';
1
+ import type { HmhConfig } from './types.js';
2
2
  export declare const STATE_DIRS: readonly ["sessions", "memory", "skills", "insights", "bench"];
3
3
  export declare function homeDir(): string;
4
4
  export declare function defaultConfig(): HmhConfig;
package/dist/context.d.ts CHANGED
@@ -12,7 +12,7 @@
12
12
  * instead of being dropped. Without the hook, behaviour is byte-identical
13
13
  * to the legacy prune.
14
14
  */
15
- import type { ChatMessage } from './types.ts';
15
+ import type { ChatMessage } from './types.js';
16
16
  export declare const DEFAULT_CONTEXT_CHARS = 160000;
17
17
  export declare function transcriptChars(messages: ChatMessage[]): number;
18
18
  export declare const DIGEST_MARK = "[rolling digest of earlier context]";
package/dist/index.d.ts CHANGED
@@ -1,15 +1,15 @@
1
- export * from './types.ts';
2
- export * from './shellgate.ts';
3
- export * from './capability.ts';
4
- export * from './registry.ts';
5
- export * from './provider.ts';
6
- export * from './window.ts';
7
- export * from './loop.ts';
8
- export * from './session.ts';
9
- export * from './router.ts';
10
- export * from './config.ts';
11
- export * from './context.ts';
12
- export * from './mcp.ts';
13
- export * from './goal.ts';
14
- export * from './mcp2026.ts';
15
- export * from './adaptive-router.ts';
1
+ export * from './types.js';
2
+ export * from './shellgate.js';
3
+ export * from './capability.js';
4
+ export * from './registry.js';
5
+ export * from './provider.js';
6
+ export * from './window.js';
7
+ export * from './loop.js';
8
+ export * from './session.js';
9
+ export * from './router.js';
10
+ export * from './config.js';
11
+ export * from './context.js';
12
+ export * from './mcp.js';
13
+ export * from './goal.js';
14
+ export * from './mcp2026.js';
15
+ export * from './adaptive-router.js';
@@ -3,7 +3,7 @@
3
3
  * Structural typing for the registry the loop needs (avoids a hard import
4
4
  * cycle and lets tests pass a stub registry).
5
5
  */
6
- import type { Tool } from './types.ts';
6
+ import type { Tool } from './types.js';
7
7
  export interface ChatMessage {
8
8
  role: 'system' | 'user' | 'assistant' | 'tool';
9
9
  content: string | null;
package/dist/loop.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import type { ChatMessage, RegistryLike } from './loop-types.ts';
2
- import { chat, type DeltaKind } from './provider.ts';
3
- import type { ProviderConfig, ToolContext } from './types.ts';
1
+ import type { ChatMessage, RegistryLike } from './loop-types.js';
2
+ import { chat, type DeltaKind } from './provider.js';
3
+ import type { ProviderConfig, ToolContext } from './types.js';
4
4
  export interface LoopEvents {
5
5
  onAssistant?(m: ChatMessage): void;
6
6
  onDelta?(kind: DeltaKind, chunk: string): void;
package/dist/mcp.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Tool } from './types.ts';
1
+ import type { Tool } from './types.js';
2
2
  export type McpServerConfig = {
3
3
  type: 'stdio';
4
4
  command: string;
@@ -6,7 +6,7 @@
6
6
  * surfaced separately so frontends can show the model thinking. One retry on
7
7
  * transient 429/5xx before the stream starts; mid-stream failures surface.
8
8
  */
9
- import type { ChatMessage, ProviderConfig } from './types.ts';
9
+ import type { ChatMessage, ProviderConfig } from './types.js';
10
10
  export interface ChatResponse {
11
11
  message: ChatMessage;
12
12
  usage?: {
@@ -4,7 +4,7 @@
4
4
  * projection. Boring on purpose: 2026 consensus is that the loop+registry
5
5
  * core should stay simple while capability volume grows around it.
6
6
  */
7
- import type { Tool } from './types.ts';
7
+ import type { Tool } from './types.js';
8
8
  export declare class Registry {
9
9
  #private;
10
10
  register(tool: Tool): this;
package/dist/session.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ChatMessage } from './types.ts';
1
+ import type { ChatMessage } from './types.js';
2
2
  export type SessionEvent = {
3
3
  t: 'session/start';
4
4
  id: string;
@@ -71,6 +71,13 @@ export interface SessionTranscript {
71
71
  file: string;
72
72
  messages: ChatMessage[];
73
73
  }
74
+ /** One-click export (2026-09-25, user request): render a transcript as a
75
+ * readable, self-contained Markdown document - full user inputs and model
76
+ * replies, tool calls as compact name+args+truncated-output blocks. Pure;
77
+ * shared by `hmh export` (TUI/CLI) and the web session export endpoint. */
78
+ export declare function exportSessionMarkdown(t: SessionTranscript, opts?: {
79
+ maxToolChars?: number;
80
+ }): string;
74
81
  /** Head summary of a rollout without a full parse: ONE 64KB read extracts the
75
82
  * session_meta line plus the first user event (the list title). Codex reads
76
83
  * HEAD_RECORD_LIMIT(10)+USER_EVENT_SCAN_LIMIT(200) lines for the same fields;
package/dist/session.js CHANGED
@@ -12,7 +12,7 @@
12
12
  */
13
13
  import { appendFile, mkdir, open as fopen, readdir, readFile, stat } from 'node:fs/promises';
14
14
  import { readFileSync, statSync } from 'node:fs';
15
- import { join } from 'node:path';
15
+ import { join, basename as pathBasename } from 'node:path';
16
16
  /** codex-rs/rollout list.rs MAX_SCAN_FILES: hard cap bounding worst-case scan work. */
17
17
  export const MAX_SCAN_FILES = 10_000;
18
18
  /** codex-rs/tui resume_picker PAGE_SIZE: sessions per listSessions page. */
@@ -135,6 +135,70 @@ export class Session {
135
135
  }
136
136
  }
137
137
  function pad2(n) { return String(n).padStart(2, '0'); }
138
+ /** One-click export (2026-09-25, user request): render a transcript as a
139
+ * readable, self-contained Markdown document - full user inputs and model
140
+ * replies, tool calls as compact name+args+truncated-output blocks. Pure;
141
+ * shared by `hmh export` (TUI/CLI) and the web session export endpoint. */
142
+ export function exportSessionMarkdown(t, opts = {}) {
143
+ const maxTool = opts.maxToolChars ?? 4000;
144
+ const out = [];
145
+ out.push('# hmharness 会话导出');
146
+ out.push('');
147
+ out.push('- 会话 ID:`' + (t.id || pathBasename(t.file)) + '`');
148
+ if (t.model)
149
+ out.push('- 模型:' + t.model);
150
+ if (t.cwd)
151
+ out.push('- 工作目录:`' + t.cwd + '`');
152
+ out.push('- 导出时间:' + new Date().toISOString());
153
+ out.push('');
154
+ for (const m of t.messages) {
155
+ if (m.role === 'user') {
156
+ out.push('## 👤 用户');
157
+ out.push('');
158
+ out.push(String(m.content ?? ''));
159
+ out.push('');
160
+ }
161
+ else if (m.role === 'assistant') {
162
+ const text = String(m.content ?? '').trim();
163
+ const calls = (m.tool_calls ?? []);
164
+ if (text) {
165
+ out.push('## 🤖 助手');
166
+ out.push('');
167
+ out.push(text);
168
+ out.push('');
169
+ }
170
+ for (const c of calls) {
171
+ const name = c.function?.name ?? 'tool';
172
+ let args = '';
173
+ try {
174
+ const parsed = JSON.parse(c.function?.arguments ?? '{}');
175
+ args = Object.entries(parsed).map(([k, v]) => k + '=' + String(typeof v === 'string' ? v : JSON.stringify(v)).slice(0, 120)).join(' ');
176
+ }
177
+ catch {
178
+ args = String(c.function?.arguments ?? '').slice(0, 120);
179
+ }
180
+ out.push('> 🔧 **' + name + '**' + (args ? ' `' + args + '`' : ''));
181
+ out.push('');
182
+ }
183
+ }
184
+ else if (m.role === 'tool') {
185
+ const name = m.name ?? 'tool';
186
+ const content = String(m.content ?? '');
187
+ const shown = content.length > maxTool ? content.slice(0, maxTool) + '\n…(输出过长已截断,完整内容见会话记录)' : content;
188
+ out.push('<details><summary>🔧 ' + name + ' 输出</summary>');
189
+ out.push('');
190
+ out.push('```');
191
+ out.push(shown);
192
+ out.push('```');
193
+ out.push('');
194
+ out.push('</details>');
195
+ out.push('');
196
+ }
197
+ }
198
+ out.push('---');
199
+ out.push('*由 hmharness 导出*');
200
+ return out.join('\n') + '\n';
201
+ }
138
202
  export async function readSessionHead(file) {
139
203
  try {
140
204
  const fh = await fopen(file, 'r');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hmharness/kernel",
3
- "version": "0.9.6",
3
+ "version": "0.9.8",
4
4
  "description": "hmharness kernel: tool registry, provider adapters, the agent loop, session log, config. Zero runtime dependencies (Node >=22 native fetch).",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",