laohuang 0.4.2 → 0.5.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.
Files changed (85) hide show
  1. package/README.md +13 -141
  2. package/dist/bin.js +12028 -0
  3. package/dist/bin.js.map +7 -0
  4. package/package.json +28 -18
  5. package/dist/agent.d.ts +0 -166
  6. package/dist/agent.js +0 -858
  7. package/dist/agent.js.map +0 -1
  8. package/dist/bash-runner.d.ts +0 -79
  9. package/dist/bash-runner.js +0 -464
  10. package/dist/bash-runner.js.map +0 -1
  11. package/dist/cancellation.d.ts +0 -36
  12. package/dist/cancellation.js +0 -123
  13. package/dist/cancellation.js.map +0 -1
  14. package/dist/cli.d.ts +0 -117
  15. package/dist/cli.js +0 -1307
  16. package/dist/cli.js.map +0 -1
  17. package/dist/client.d.ts +0 -21
  18. package/dist/client.js +0 -17
  19. package/dist/client.js.map +0 -1
  20. package/dist/commands.d.ts +0 -123
  21. package/dist/commands.js +0 -660
  22. package/dist/commands.js.map +0 -1
  23. package/dist/config.d.ts +0 -51
  24. package/dist/config.js +0 -183
  25. package/dist/config.js.map +0 -1
  26. package/dist/credentials.d.ts +0 -12
  27. package/dist/credentials.js +0 -102
  28. package/dist/credentials.js.map +0 -1
  29. package/dist/events.d.ts +0 -288
  30. package/dist/events.js +0 -838
  31. package/dist/events.js.map +0 -1
  32. package/dist/model-adapter.d.ts +0 -138
  33. package/dist/model-adapter.js +0 -244
  34. package/dist/model-adapter.js.map +0 -1
  35. package/dist/model-selection.d.ts +0 -67
  36. package/dist/model-selection.js +0 -148
  37. package/dist/model-selection.js.map +0 -1
  38. package/dist/model-stream.d.ts +0 -128
  39. package/dist/model-stream.js +0 -582
  40. package/dist/model-stream.js.map +0 -1
  41. package/dist/project-instructions.d.ts +0 -99
  42. package/dist/project-instructions.js +0 -348
  43. package/dist/project-instructions.js.map +0 -1
  44. package/dist/providers.d.ts +0 -9
  45. package/dist/providers.js +0 -26
  46. package/dist/providers.js.map +0 -1
  47. package/dist/routing.d.ts +0 -170
  48. package/dist/routing.js +0 -669
  49. package/dist/routing.js.map +0 -1
  50. package/dist/semantic-classifier.d.ts +0 -66
  51. package/dist/semantic-classifier.js +0 -86
  52. package/dist/semantic-classifier.js.map +0 -1
  53. package/dist/session.d.ts +0 -162
  54. package/dist/session.js +0 -871
  55. package/dist/session.js.map +0 -1
  56. package/dist/system-prompt.d.ts +0 -16
  57. package/dist/system-prompt.js +0 -42
  58. package/dist/system-prompt.js.map +0 -1
  59. package/dist/terminal/editor.d.ts +0 -161
  60. package/dist/terminal/editor.js +0 -1060
  61. package/dist/terminal/editor.js.map +0 -1
  62. package/dist/terminal/input.d.ts +0 -61
  63. package/dist/terminal/input.js +0 -276
  64. package/dist/terminal/input.js.map +0 -1
  65. package/dist/terminal/markdown.d.ts +0 -20
  66. package/dist/terminal/markdown.js +0 -621
  67. package/dist/terminal/markdown.js.map +0 -1
  68. package/dist/terminal/screen.d.ts +0 -66
  69. package/dist/terminal/screen.js +0 -624
  70. package/dist/terminal/screen.js.map +0 -1
  71. package/dist/terminal/theme.d.ts +0 -23
  72. package/dist/terminal/theme.js +0 -101
  73. package/dist/terminal/theme.js.map +0 -1
  74. package/dist/terminal/ui.d.ts +0 -287
  75. package/dist/terminal/ui.js +0 -1819
  76. package/dist/terminal/ui.js.map +0 -1
  77. package/dist/tools.d.ts +0 -95
  78. package/dist/tools.js +0 -444
  79. package/dist/tools.js.map +0 -1
  80. package/dist/ui-state.d.ts +0 -51
  81. package/dist/ui-state.js +0 -194
  82. package/dist/ui-state.js.map +0 -1
  83. package/dist/web.d.ts +0 -56
  84. package/dist/web.js +0 -247
  85. package/dist/web.js.map +0 -1
package/package.json CHANGED
@@ -1,39 +1,49 @@
1
1
  {
2
2
  "name": "laohuang",
3
- "version": "0.4.2",
3
+ "version": "0.5.1",
4
4
  "description": "A minimal coding agent CLI built on the official openai SDK and Chat Completions native tool calling.",
5
5
  "type": "module",
6
- "repository": {
7
- "type": "git",
8
- "url": "https://github.com/hxr223/laoHuangCode"
9
- },
10
- "homepage": "https://github.com/hxr223/laoHuangCode#readme",
11
- "bugs": "https://github.com/hxr223/laoHuangCode/issues",
12
- "publishConfig": {
13
- "access": "public"
14
- },
15
6
  "bin": {
16
- "laohuang": "dist/cli.js"
7
+ "laohuang": "dist/bin.js"
17
8
  },
18
9
  "engines": {
19
10
  "node": ">=18"
20
11
  },
21
12
  "scripts": {
22
- "build": "tsc",
23
- "test": "node --test \"test/**/*.test.ts\"",
24
- "prepack": "npm run build"
13
+ "build": "tsc -b",
14
+ "bundle": "node build.mjs",
15
+ "prepack": "npm run bundle"
25
16
  },
26
17
  "files": [
27
- "dist",
18
+ "dist/bin.js",
19
+ "dist/bin.js.map",
28
20
  "README.md",
29
21
  "LICENSE"
30
22
  ],
31
23
  "dependencies": {
32
- "openai": "^4.0.0"
24
+ "openai": "^6.49.0"
33
25
  },
34
26
  "devDependencies": {
35
- "@types/node": "^22.0.0",
36
- "typescript": "^5.5.0"
27
+ "@laohuang/agent-runtime": "0.0.0",
28
+ "@laohuang/llm": "0.0.0",
29
+ "@laohuang/llm-openai-compatible": "0.0.0",
30
+ "@laohuang/local-config": "0.0.0",
31
+ "@laohuang/project-instructions": "0.0.0",
32
+ "@laohuang/runtime-protocol": "0.0.0",
33
+ "@laohuang/session-runtime": "0.0.0",
34
+ "@laohuang/tool-bash": "0.0.0",
35
+ "@laohuang/tool-fs": "0.0.0",
36
+ "@laohuang/tools": "0.0.0",
37
+ "@laohuang/tui": "0.0.0"
38
+ },
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "https://github.com/hxr223/laoHuangCode"
42
+ },
43
+ "homepage": "https://github.com/hxr223/laoHuangCode#readme",
44
+ "bugs": "https://github.com/hxr223/laoHuangCode/issues",
45
+ "publishConfig": {
46
+ "access": "public"
37
47
  },
38
48
  "license": "MIT"
39
49
  }
package/dist/agent.d.ts DELETED
@@ -1,166 +0,0 @@
1
- /**
2
- * The model/tool loop at the heart of laoHuangCode.
3
- *
4
- * One user turn streams model completions through the provider-neutral
5
- * adapter boundary (model-adapter.ts), commits
6
- * only fully validated attempts to history (atomically, via the owning
7
- * session's commit hooks when present), executes tool-call batches
8
- * (read-only tools and multiple bash calls concurrently; any write/edit or
9
- * sequential-mode tool makes the whole batch serial), and enforces the
10
- * runtime guard rails: repeated-identical-tool-call detection plus token and
11
- * duration budgets. A triggered guard disables tools and asks the model for
12
- * one final answer from the information already gathered.
13
- */
14
- import { CancelToken } from "./cancellation.ts";
15
- import { EventKind, EventSource, type EventBus } from "./events.ts";
16
- import { type ChatClientLike } from "./model-adapter.ts";
17
- import type { ToolDefinition, ToolExecutionContextLike, ToolExecutionMode, ToolResult, ToolSpec } from "./tools.ts";
18
- import { ProjectInstructionState } from "./project-instructions.ts";
19
- export declare const FORCED_FINAL_PROMPT = "Tool use has been stopped by the runtime safety guard.\nDo not call any tools. Give the user the best concise answer possible from the\ninformation already available. Clearly state any limitation caused by stopping\ntool use, but do not mention internal implementation details unless useful.";
20
- /** Raised when the model response cannot drive the agent loop. */
21
- export declare class AgentError extends Error {
22
- constructor(message: string, options?: {
23
- cause?: unknown;
24
- });
25
- }
26
- /** Raised when the active agent task is cooperatively cancelled. */
27
- export declare class AgentCancelled extends AgentError {
28
- constructor(message: string, options?: {
29
- cause?: unknown;
30
- });
31
- }
32
- export type AgentEventCallback = (eventType: string, payload: Record<string, unknown>) => void;
33
- export type ToolEventCallback = (name: string, args: Record<string, unknown>, result: ToolResult) => void;
34
- export type { ChatClientLike } from "./model-adapter.ts";
35
- /** Structural minimum of ToolRegistry (tools.ts) the agent relies on. */
36
- export interface AgentToolRegistry {
37
- readonly definitions: readonly ToolDefinition[];
38
- readonly orderedSpecs: readonly ToolSpec[];
39
- executionMode(name: string): ToolExecutionMode | undefined;
40
- execute(name: string, args: Record<string, unknown>, context?: ToolExecutionContextLike): Promise<ToolResult> | ToolResult;
41
- }
42
- /** Pending user input handed over at a session safe point. */
43
- export interface PendingInputBatchLike {
44
- content?: string | undefined;
45
- eventIds?: readonly string[] | undefined;
46
- }
47
- /** Options for the session-owned publish hook. */
48
- export interface AgentEventPublishOptions {
49
- source: EventSource;
50
- correlation_id: string | null;
51
- payload: Record<string, unknown>;
52
- }
53
- /**
54
- * Capabilities the owning session (session.ts) exposes to one agent run.
55
- * Every member is optional; without a context the agent runs standalone and
56
- * manages its own history commits and cancellation checks.
57
- */
58
- export interface AgentContext {
59
- readonly sessionId?: string | null;
60
- readonly taskId?: string | null;
61
- readonly cancelToken?: CancelToken | null;
62
- readonly eventBus?: EventBus | null;
63
- publish?(kind: EventKind, options: AgentEventPublishOptions): unknown;
64
- /** Return false to cancel before the model request is sent. */
65
- modelStarted?(): boolean | void;
66
- /** Called once the SDK acknowledged the streaming request. */
67
- modelRequestOpened?(): boolean | void;
68
- toolsStarted?(): void;
69
- safePoint?(): PendingInputBatchLike | null | undefined;
70
- /** Atomically commit the user message; rollback undoes a failed commit. */
71
- commitInput?(append: () => void, rollback: () => void): boolean;
72
- commitPending?(batch: PendingInputBatchLike, append: () => void, rollback: () => void): boolean;
73
- /** Atomically reject history commits once cancellation has won. */
74
- commitIfActive?(callback: () => void): boolean;
75
- }
76
- export interface RunOptions {
77
- cancelToken?: CancelToken | null;
78
- requestId?: string | null;
79
- isRequestActive?: ((requestId: string) => boolean) | null;
80
- }
81
- export interface CodingAgentOptions {
82
- client: ChatClientLike;
83
- model: string;
84
- tools: AgentToolRegistry;
85
- maxTotalTokens?: number;
86
- maxElapsedSeconds?: number;
87
- repeatedToolCallLimit?: number;
88
- onToolEvent?: ToolEventCallback | null;
89
- onAgentEvent?: AgentEventCallback | null;
90
- provider?: string | null;
91
- toolExecution?: ToolExecutionMode;
92
- /**
93
- * Project root used only for project-instruction loading (both this and
94
- * `startupCwd` must be set; omit both to disable instruction injection).
95
- */
96
- projectRoot?: string | null;
97
- /** Startup cwd for project-instruction discovery. */
98
- startupCwd?: string | null;
99
- }
100
- /** Execution context handed to every tool call in a batch. */
101
- export interface AgentToolContext extends ToolExecutionContextLike {
102
- readonly sessionId: string | null;
103
- readonly taskId: string | null;
104
- readonly toolCallId: string | null;
105
- readonly cancelToken: CancelToken | null;
106
- }
107
- export declare class CodingAgent {
108
- client: ChatClientLike;
109
- model: string;
110
- provider: string | null;
111
- /** Provider-neutral model access; resolved from `provider`. */
112
- private adapter;
113
- readonly tools: AgentToolRegistry;
114
- readonly maxTotalTokens: number;
115
- readonly maxElapsedSeconds: number;
116
- readonly repeatedToolCallLimit: number;
117
- readonly toolExecution: ToolExecutionMode;
118
- /** Conversation history in Chat Completions wire shape. */
119
- messages: Array<Record<string, unknown>>;
120
- private readonly onToolEvent;
121
- private readonly onAgentEvent;
122
- private readonly instructionRoot;
123
- private readonly startupCwd;
124
- private baselineInstructionsLoaded;
125
- private instructionState;
126
- private turn;
127
- private activeContext;
128
- private activeRequestId;
129
- constructor(options: CodingAgentOptions);
130
- /** Bookkeeping for loaded project instructions (never model-visible). */
131
- get projectInstructionState(): ProjectInstructionState | null;
132
- /** Swap the model client mid-conversation, keeping portable history. */
133
- switchModel(options: {
134
- client: unknown;
135
- model: string;
136
- provider: string;
137
- }): void;
138
- /** Run one user turn, committing only fully validated model attempts. */
139
- run(userInput: string, context?: AgentContext | null, options?: RunOptions): Promise<string>;
140
- private budgetGuardReason;
141
- private guardPayload;
142
- private recordRepeatedToolCalls;
143
- private executeToolBatch;
144
- private executeTool;
145
- private finishToolEvent;
146
- /**
147
- * Append the rendered baseline project instructions once per session,
148
- * right after the first direct user message and before the first model
149
- * request. Append-only: the system prompt and committed history are never
150
- * rebuilt, and nothing is appended when no instruction files exist.
151
- */
152
- private injectBaselineInstructions;
153
- /**
154
- * DSH-style dynamic descendant discovery: for every parent directory from
155
- * the instruction root to each successfully touched path's directory,
156
- * render instructions from scopes not already represented by the
157
- * instruction state as one additional reminder message. Append-only and
158
- * duplicate-suppressed by ProjectInstructionState; a no-op when
159
- * instruction loading is not configured.
160
- */
161
- private discoverForTouchedPaths;
162
- private commitContextMessage;
163
- private emit;
164
- private emitLegacy;
165
- private publishRuntimeEvent;
166
- }