thatgfsj-code 2.2.9 → 3.0.1
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/CHANGELOG.md +15 -67
- package/dist/app/index.d.ts +28 -5
- package/dist/app/index.d.ts.map +1 -1
- package/dist/app/index.js +76 -10
- package/dist/app/index.js.map +1 -1
- package/dist/cache/fingerprint.d.ts +49 -0
- package/dist/cache/fingerprint.d.ts.map +1 -0
- package/dist/cache/fingerprint.js +100 -0
- package/dist/cache/fingerprint.js.map +1 -0
- package/dist/cache/index.d.ts +15 -0
- package/dist/cache/index.d.ts.map +1 -0
- package/dist/cache/index.js +15 -0
- package/dist/cache/index.js.map +1 -0
- package/dist/cache/smartModel.d.ts +40 -0
- package/dist/cache/smartModel.d.ts.map +1 -0
- package/dist/cache/smartModel.js +43 -0
- package/dist/cache/smartModel.js.map +1 -0
- package/dist/cache/stats.d.ts +93 -0
- package/dist/cache/stats.d.ts.map +1 -0
- package/dist/cache/stats.js +155 -0
- package/dist/cache/stats.js.map +1 -0
- package/dist/cache/volatile.d.ts +32 -0
- package/dist/cache/volatile.d.ts.map +1 -0
- package/dist/cache/volatile.js +44 -0
- package/dist/cache/volatile.js.map +1 -0
- package/dist/cmd/index.js +49 -57
- package/dist/cmd/index.js.map +1 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +8 -0
- package/dist/config/index.js.map +1 -1
- package/dist/config/types.d.ts +14 -0
- package/dist/config/types.d.ts.map +1 -1
- package/dist/llm/anthropic.d.ts +55 -5
- package/dist/llm/anthropic.d.ts.map +1 -1
- package/dist/llm/anthropic.js +172 -26
- package/dist/llm/anthropic.js.map +1 -1
- package/dist/llm/index.d.ts +26 -8
- package/dist/llm/index.d.ts.map +1 -1
- package/dist/llm/index.js +83 -15
- package/dist/llm/index.js.map +1 -1
- package/dist/llm/openai.d.ts +28 -8
- package/dist/llm/openai.d.ts.map +1 -1
- package/dist/llm/openai.js +58 -8
- package/dist/llm/openai.js.map +1 -1
- package/dist/llm/provider.d.ts +40 -8
- package/dist/llm/provider.d.ts.map +1 -1
- package/dist/llm/provider.js +8 -1
- package/dist/llm/provider.js.map +1 -1
- package/dist/prompts/index.d.ts +32 -0
- package/dist/prompts/index.d.ts.map +1 -1
- package/dist/prompts/index.js +33 -11
- package/dist/prompts/index.js.map +1 -1
- package/dist/session/index.d.ts +32 -3
- package/dist/session/index.d.ts.map +1 -1
- package/dist/session/index.js +51 -36
- package/dist/session/index.js.map +1 -1
- package/dist/skills/brainstorming.js +33 -33
- package/dist/skills/code-review.js +35 -35
- package/dist/skills/executing-plans.js +18 -18
- package/dist/skills/frontend-design.js +25 -25
- package/dist/skills/git-workflow.js +26 -26
- package/dist/skills/improve-architecture.js +28 -28
- package/dist/skills/neuroweave.js +37 -37
- package/dist/skills/playwright.js +62 -62
- package/dist/skills/prototype.js +20 -20
- package/dist/skills/subagent.js +19 -19
- package/dist/skills/supabase.js +34 -34
- package/dist/skills/systematic-debugging.js +34 -34
- package/dist/skills/tdd.js +29 -29
- package/dist/skills/triage.js +25 -25
- package/dist/skills/verification.js +22 -22
- package/dist/skills/writing-plans.js +32 -32
- package/dist/tools/nwt.js +16 -16
- package/dist/tui/app.d.ts.map +1 -1
- package/dist/tui/app.js +9 -2
- package/dist/tui/app.js.map +1 -1
- package/dist/tui/components/Header.d.ts +8 -0
- package/dist/tui/components/Header.d.ts.map +1 -1
- package/dist/tui/components/Header.js +17 -4
- package/dist/tui/components/Header.js.map +1 -1
- package/dist/tui/components/InitWizard.d.ts +12 -1
- package/dist/tui/components/InitWizard.d.ts.map +1 -1
- package/dist/tui/components/InitWizard.js +58 -3
- package/dist/tui/components/InitWizard.js.map +1 -1
- package/dist/tui/components/ModelSelector.d.ts +3 -1
- package/dist/tui/components/ModelSelector.d.ts.map +1 -1
- package/dist/tui/components/ModelSelector.js +24 -7
- package/dist/tui/components/ModelSelector.js.map +1 -1
- package/dist/tui/components/ToolCall.d.ts.map +1 -1
- package/dist/tui/components/ToolCall.js +1 -6
- package/dist/tui/components/ToolCall.js.map +1 -1
- package/dist/tui/components/UserInput.d.ts.map +1 -1
- package/dist/tui/components/UserInput.js +20 -0
- package/dist/tui/components/UserInput.js.map +1 -1
- package/dist/tui/hooks/useChat.d.ts +22 -0
- package/dist/tui/hooks/useChat.d.ts.map +1 -1
- package/dist/tui/hooks/useChat.js +82 -46
- package/dist/tui/hooks/useChat.js.map +1 -1
- package/dist/tui/hooks/useCommands.d.ts.map +1 -1
- package/dist/tui/hooks/useCommands.js +57 -0
- package/dist/tui/hooks/useCommands.js.map +1 -1
- package/dist/tui/welcome.d.ts.map +1 -1
- package/dist/tui/welcome.js +2 -3
- package/dist/tui/welcome.js.map +1 -1
- package/dist/types.d.ts +79 -6
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -1
- package/dist/utils/stableStringify.d.ts +21 -0
- package/dist/utils/stableStringify.d.ts.map +1 -0
- package/dist/utils/stableStringify.js +53 -0
- package/dist/utils/stableStringify.js.map +1 -0
- package/dist/utils/thinking.d.ts.map +1 -1
- package/dist/utils/thinking.js +0 -3
- package/dist/utils/thinking.js.map +1 -1
- package/package.json +7 -6
- package/src/app/index.ts +189 -124
- package/src/cache/fingerprint.ts +101 -0
- package/src/cache/index.ts +15 -0
- package/src/cache/smartModel.ts +52 -0
- package/src/cache/stats.ts +199 -0
- package/src/cache/volatile.ts +47 -0
- package/src/cmd/index.tsx +288 -292
- package/src/config/index.ts +156 -148
- package/src/config/providers.ts +234 -234
- package/src/config/types.ts +67 -53
- package/src/hooks/index.ts +111 -111
- package/src/llm/anthropic.ts +388 -243
- package/src/llm/gemini.ts +169 -169
- package/src/llm/index.ts +265 -200
- package/src/llm/openai.ts +243 -196
- package/src/llm/provider.ts +66 -34
- package/src/prompts/index.ts +260 -220
- package/src/session/compactor.ts +103 -103
- package/src/session/index.ts +181 -168
- package/src/session/message.ts +42 -42
- package/src/skills/brainstorming.ts +43 -43
- package/src/skills/code-review.ts +45 -45
- package/src/skills/executing-plans.ts +27 -27
- package/src/skills/frontend-design.ts +35 -35
- package/src/skills/git-workflow.ts +36 -36
- package/src/skills/improve-architecture.ts +38 -38
- package/src/skills/index.ts +136 -136
- package/src/skills/neuroweave.ts +47 -47
- package/src/skills/playwright.ts +72 -72
- package/src/skills/prototype.ts +30 -30
- package/src/skills/subagent.ts +28 -28
- package/src/skills/supabase.ts +44 -44
- package/src/skills/systematic-debugging.ts +44 -44
- package/src/skills/tdd.ts +39 -39
- package/src/skills/triage.ts +35 -35
- package/src/skills/verification.ts +31 -31
- package/src/skills/writing-plans.ts +42 -42
- package/src/tools/nwt.ts +598 -598
- package/src/tools/types.ts +122 -122
- package/src/tui/app.tsx +200 -186
- package/src/tui/components/ChatList.tsx +41 -41
- package/src/tui/components/ChatMessage.tsx +54 -54
- package/src/tui/components/Header.tsx +56 -29
- package/src/tui/components/InitWizard.tsx +217 -132
- package/src/tui/components/Markdown.tsx +35 -35
- package/src/tui/components/ModelSelector.tsx +107 -87
- package/src/tui/components/StatusBar.tsx +30 -30
- package/src/tui/components/Thinking.tsx +17 -17
- package/src/tui/components/ToolCall.tsx +102 -107
- package/src/tui/components/UserInput.tsx +151 -131
- package/src/tui/hooks/useChat.ts +287 -238
- package/src/tui/hooks/useCommands.ts +234 -176
- package/src/tui/index.ts +6 -6
- package/src/tui/welcome.ts +177 -178
- package/src/types.ts +104 -42
- package/src/utils/diff.ts +71 -71
- package/src/utils/project.ts +99 -99
- package/src/utils/stableStringify.ts +47 -0
- package/src/utils/thinking.ts +118 -121
- package/tests/cache/fingerprint.test.ts +75 -0
- package/tests/cache/providerCatalog.test.ts +31 -0
- package/tests/cache/stableStringify.test.ts +43 -0
- package/tests/cache/stats.test.ts +146 -0
- package/tests/cache/volatile.test.ts +75 -0
- package/tests/smoke-pollution.mjs +78 -0
- package/tests/smoke-thinking.mjs +110 -0
- package/tests/smoke-tool-stream.mjs +69 -0
- package/tests/smoke-tool.mjs +117 -0
- package/.nwt/meta.json +0 -5
- package/dist/version.d.ts +0 -16
- package/dist/version.d.ts.map +0 -1
- package/dist/version.js +0 -16
- package/dist/version.js.map +0 -1
- package/src/version.ts +0 -16
package/src/hooks/index.ts
CHANGED
|
@@ -1,111 +1,111 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Hooks System - Event-driven lifecycle hooks
|
|
3
|
-
* Migrated from old src/core/hooks.ts
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type { ChatMessage, ToolCall } from '../types.js';
|
|
7
|
-
|
|
8
|
-
// ==================== Hook Types ====================
|
|
9
|
-
|
|
10
|
-
export type HookName =
|
|
11
|
-
| 'beforeToolCall'
|
|
12
|
-
| 'afterToolCall'
|
|
13
|
-
| 'beforeAgentLoop'
|
|
14
|
-
| 'afterAgentLoop'
|
|
15
|
-
| 'onError';
|
|
16
|
-
|
|
17
|
-
export interface HookContext {
|
|
18
|
-
toolName?: string;
|
|
19
|
-
toolParams?: Record<string, any>;
|
|
20
|
-
toolResult?: any;
|
|
21
|
-
messages?: ChatMessage[];
|
|
22
|
-
error?: Error;
|
|
23
|
-
iteration?: number;
|
|
24
|
-
[key: string]: any;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export type HookFn = (ctx: HookContext) => void | Promise<void>;
|
|
28
|
-
|
|
29
|
-
interface HookRegistration {
|
|
30
|
-
name: HookName;
|
|
31
|
-
fn: HookFn;
|
|
32
|
-
priority?: number;
|
|
33
|
-
once?: boolean;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// ==================== Hook Manager ====================
|
|
37
|
-
|
|
38
|
-
export class HookManager {
|
|
39
|
-
private hooks: Map<HookName, HookRegistration[]> = new Map();
|
|
40
|
-
|
|
41
|
-
constructor() {
|
|
42
|
-
const allHooks: HookName[] = ['beforeToolCall', 'afterToolCall', 'beforeAgentLoop', 'afterAgentLoop', 'onError'];
|
|
43
|
-
for (const h of allHooks) {
|
|
44
|
-
this.hooks.set(h, []);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
register(name: HookName, fn: HookFn, priority = 0, once = false): void {
|
|
49
|
-
const regs = this.hooks.get(name) || [];
|
|
50
|
-
regs.push({ name, fn, priority, once });
|
|
51
|
-
regs.sort((a, b) => (b.priority || 0) - (a.priority || 0));
|
|
52
|
-
this.hooks.set(name, regs);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
unregister(name: HookName, fn: HookFn): void {
|
|
56
|
-
const regs = this.hooks.get(name) || [];
|
|
57
|
-
this.hooks.set(name, regs.filter(r => r.fn !== fn));
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
clear(name?: HookName): void {
|
|
61
|
-
if (name) {
|
|
62
|
-
this.hooks.set(name, []);
|
|
63
|
-
} else {
|
|
64
|
-
for (const regs of this.hooks.values()) {
|
|
65
|
-
regs.length = 0;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
async emit(name: HookName, ctx: HookContext): Promise<void> {
|
|
71
|
-
const regs = this.hooks.get(name) || [];
|
|
72
|
-
for (const reg of regs) {
|
|
73
|
-
try {
|
|
74
|
-
await Promise.resolve(reg.fn(ctx));
|
|
75
|
-
} catch (error: any) {
|
|
76
|
-
console.error(`[Hook ${name}] error:`, error.message);
|
|
77
|
-
}
|
|
78
|
-
if (reg.once) {
|
|
79
|
-
this.unregister(name, reg.fn);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
hasHooks(name: HookName): boolean {
|
|
85
|
-
return (this.hooks.get(name)?.length || 0) > 0;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// ==================== Built-in Hooks ====================
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Audit logging hook - logs all tool calls
|
|
93
|
-
*/
|
|
94
|
-
export function auditLogHook(ctx: HookContext): void {
|
|
95
|
-
if (ctx.toolName) {
|
|
96
|
-
const ts = new Date().toISOString().split('T')[1].split('.')[0];
|
|
97
|
-
const status = ctx.toolResult?.success ? 'OK' : 'FAIL';
|
|
98
|
-
console.log(`[AUDIT ${ts}] ${status} | tool=${ctx.toolName} | params=${JSON.stringify(ctx.toolParams || {})}`);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// ==================== Singleton ====================
|
|
103
|
-
|
|
104
|
-
let globalHookManager: HookManager | null = null;
|
|
105
|
-
|
|
106
|
-
export function getHookManager(): HookManager {
|
|
107
|
-
if (!globalHookManager) {
|
|
108
|
-
globalHookManager = new HookManager();
|
|
109
|
-
}
|
|
110
|
-
return globalHookManager;
|
|
111
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Hooks System - Event-driven lifecycle hooks
|
|
3
|
+
* Migrated from old src/core/hooks.ts
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { ChatMessage, ToolCall } from '../types.js';
|
|
7
|
+
|
|
8
|
+
// ==================== Hook Types ====================
|
|
9
|
+
|
|
10
|
+
export type HookName =
|
|
11
|
+
| 'beforeToolCall'
|
|
12
|
+
| 'afterToolCall'
|
|
13
|
+
| 'beforeAgentLoop'
|
|
14
|
+
| 'afterAgentLoop'
|
|
15
|
+
| 'onError';
|
|
16
|
+
|
|
17
|
+
export interface HookContext {
|
|
18
|
+
toolName?: string;
|
|
19
|
+
toolParams?: Record<string, any>;
|
|
20
|
+
toolResult?: any;
|
|
21
|
+
messages?: ChatMessage[];
|
|
22
|
+
error?: Error;
|
|
23
|
+
iteration?: number;
|
|
24
|
+
[key: string]: any;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type HookFn = (ctx: HookContext) => void | Promise<void>;
|
|
28
|
+
|
|
29
|
+
interface HookRegistration {
|
|
30
|
+
name: HookName;
|
|
31
|
+
fn: HookFn;
|
|
32
|
+
priority?: number;
|
|
33
|
+
once?: boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// ==================== Hook Manager ====================
|
|
37
|
+
|
|
38
|
+
export class HookManager {
|
|
39
|
+
private hooks: Map<HookName, HookRegistration[]> = new Map();
|
|
40
|
+
|
|
41
|
+
constructor() {
|
|
42
|
+
const allHooks: HookName[] = ['beforeToolCall', 'afterToolCall', 'beforeAgentLoop', 'afterAgentLoop', 'onError'];
|
|
43
|
+
for (const h of allHooks) {
|
|
44
|
+
this.hooks.set(h, []);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
register(name: HookName, fn: HookFn, priority = 0, once = false): void {
|
|
49
|
+
const regs = this.hooks.get(name) || [];
|
|
50
|
+
regs.push({ name, fn, priority, once });
|
|
51
|
+
regs.sort((a, b) => (b.priority || 0) - (a.priority || 0));
|
|
52
|
+
this.hooks.set(name, regs);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
unregister(name: HookName, fn: HookFn): void {
|
|
56
|
+
const regs = this.hooks.get(name) || [];
|
|
57
|
+
this.hooks.set(name, regs.filter(r => r.fn !== fn));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
clear(name?: HookName): void {
|
|
61
|
+
if (name) {
|
|
62
|
+
this.hooks.set(name, []);
|
|
63
|
+
} else {
|
|
64
|
+
for (const regs of this.hooks.values()) {
|
|
65
|
+
regs.length = 0;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async emit(name: HookName, ctx: HookContext): Promise<void> {
|
|
71
|
+
const regs = this.hooks.get(name) || [];
|
|
72
|
+
for (const reg of regs) {
|
|
73
|
+
try {
|
|
74
|
+
await Promise.resolve(reg.fn(ctx));
|
|
75
|
+
} catch (error: any) {
|
|
76
|
+
console.error(`[Hook ${name}] error:`, error.message);
|
|
77
|
+
}
|
|
78
|
+
if (reg.once) {
|
|
79
|
+
this.unregister(name, reg.fn);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
hasHooks(name: HookName): boolean {
|
|
85
|
+
return (this.hooks.get(name)?.length || 0) > 0;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// ==================== Built-in Hooks ====================
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Audit logging hook - logs all tool calls
|
|
93
|
+
*/
|
|
94
|
+
export function auditLogHook(ctx: HookContext): void {
|
|
95
|
+
if (ctx.toolName) {
|
|
96
|
+
const ts = new Date().toISOString().split('T')[1].split('.')[0];
|
|
97
|
+
const status = ctx.toolResult?.success ? 'OK' : 'FAIL';
|
|
98
|
+
console.log(`[AUDIT ${ts}] ${status} | tool=${ctx.toolName} | params=${JSON.stringify(ctx.toolParams || {})}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// ==================== Singleton ====================
|
|
103
|
+
|
|
104
|
+
let globalHookManager: HookManager | null = null;
|
|
105
|
+
|
|
106
|
+
export function getHookManager(): HookManager {
|
|
107
|
+
if (!globalHookManager) {
|
|
108
|
+
globalHookManager = new HookManager();
|
|
109
|
+
}
|
|
110
|
+
return globalHookManager;
|
|
111
|
+
}
|