Skip to content

Commit 2fea429

Browse files
feat: 添加对 langfuse 监控的支持 (#242)
* docs: 更新类型检查的 CLAUDE.md * feat: 添加模型 1M 上下文切换 * chore: remove prefetchOfficialMcpUrls call on startup * docs: 添加 git commit 规范 * feat: 第一次接入 langfuse * fix: 修复 generation 的计时的错误 * feat: 添加多 agent 的监控 * feat: 添加 /poor 省流模式,toggle 关闭 extract_memories 和 prompt_suggestion Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore: 修复 lock 文件 * chore: 更新类型依赖 --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 6a9da9d commit 2fea429

23 files changed

Lines changed: 1242 additions & 6 deletions

File tree

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ bunx tsc --noEmit
274274
- **tsc must pass**`bunx tsc --noEmit` 必须零错误,任何修改都不能引入新的类型错误。
275275
- **Feature flags** — 默认全部关闭(`feature()` 返回 `false`)。Dev/build 各有自己的默认启用列表。不要在 `cli.tsx` 中重定义 `feature` 函数。
276276
- **React Compiler output** — Components have decompiled memoization boilerplate (`const $ = _c(N)`). This is normal.
277-
- **`bun:bundle` import**`import { feature } from 'bun:bundle'` 是 Bun 内置模块,由运行时/构建器解析。不要用自定义函数替代它。
277+
- **`bun:bundle` import**`import { feature } from 'bun:bundle'` 是 Bun 内置模块,由运行时/构建器解析。不要用自定义函数替代它。**`feature()` 只能直接用在 `if` 语句或三元表达式的条件位置**(Bun 编译器限制),不能赋值给变量、不能放在箭头函数体里、不能作为 `&&` 链的一部分。正确:`if (feature('X')) {}``feature('X') ? a : b`
278278
- **`src/` path alias** — tsconfig maps `src/*` to `./src/*`. Imports like `import { ... } from 'src/utils/...'` are valid.
279279
- **MACRO defines** — 集中管理在 `scripts/defines.ts`。Dev mode 通过 `bun -d` 注入,build 通过 `Bun.build({ define })` 注入。修改版本号等常量只改这个文件。
280280
- **构建产物兼容 Node.js**`build.ts` 会自动后处理 `import.meta.require`,产物可直接用 `node dist/cli.js` 运行。

DEV-LOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# DEV-LOG
22

3+
## /poor 省流模式 (2026-04-11)
4+
5+
新增 `/poor` 命令,toggle 关闭 `extract_memories``prompt_suggestion`,省 token。
6+
7+
- 新增 `POOR` feature flag(build.ts + dev.ts)
8+
- `src/commands/poor/` — 命令定义 + toggle 实现 + 状态管理
9+
- `src/query/stopHooks.ts` — POOR 模式激活时跳过 extract_memories 和 prompt_suggestion
10+
11+
---
12+
313
## Daemon + Remote Control Server 还原 (2026-04-07)
414

515
**分支**: `feat/daemon-remote-control-server`

build.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ const DEFAULT_BUILD_FEATURES = [
3333
'ULTRAPLAN',
3434
// P2: daemon + remote control server
3535
'DAEMON',
36+
// P3: poor mode (disable extract_memories + prompt_suggestion)
37+
'POOR',
3638
]
3739

3840
// Collect FEATURE_* env vars → Bun.build features

bun.lock

Lines changed: 12 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,12 @@
5454
"rcs": "bun run scripts/rcs.ts"
5555
},
5656
"dependencies": {
57-
"@types/lodash-es": "^4.17.12"
57+
"@types/he": "^1.2.3"
5858
},
5959
"devDependencies": {
60+
"@langfuse/otel": "^5.1.0",
61+
"@langfuse/tracing": "^5.1.0",
62+
"@types/lodash-es": "^4.17.12",
6063
"@alcalzone/ansi-tokenize": "^0.3.0",
6164
"@ant/claude-for-chrome-mcp": "workspace:*",
6265
"@ant/computer-use-input": "workspace:*",

scripts/dev.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ const DEFAULT_FEATURES = [
3737
"KAIROS_BRIEF", "AWAY_SUMMARY", "ULTRAPLAN",
3838
// P2: daemon + remote control server
3939
"DAEMON",
40+
// P3: poor mode (disable extract_memories + prompt_suggestion)
41+
"POOR",
4042
];
4143

4244
// Any env var matching FEATURE_<NAME>=1 will also enable that feature.

src/Tool.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ import type { SpinnerMode } from './components/Spinner.js'
7676
import type { QuerySource } from './constants/querySource.js'
7777
import type { SDKStatus } from './entrypoints/agentSdkTypes.js'
7878
import type { AppState } from './state/AppState.js'
79+
import type { LangfuseSpan } from './services/langfuse/index.js'
7980
import type {
8081
HookProgress,
8182
PromptRequest,
@@ -273,6 +274,8 @@ export type ToolUseContext = {
273274
) => (request: PromptRequest) => Promise<PromptResponse>
274275
toolUseId?: string
275276
criticalSystemReminder_EXPERIMENTAL?: string
277+
/** Langfuse root trace span for this query turn. Passed down to tool execution for observability. */
278+
langfuseTrace?: LangfuseSpan | null
276279
/** When true, preserve toolUseResult on messages even for subagents.
277280
* Used by in-process teammates whose transcripts are viewable by the user. */
278281
preserveToolUseResults?: boolean

src/commands.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ const buddy = feature('BUDDY')
120120
require('./commands/buddy/index.js') as typeof import('./commands/buddy/index.js')
121121
).default
122122
: null
123+
const poor = feature('POOR')
124+
? (
125+
require('./commands/poor/index.js') as typeof import('./commands/poor/index.js')
126+
).default
127+
: null
123128
/* eslint-enable @typescript-eslint/no-require-imports */
124129
import thinkback from './commands/thinkback/index.js'
125130
import thinkbackPlay from './commands/thinkback-play/index.js'
@@ -321,6 +326,7 @@ const COMMANDS = memoize((): Command[] => [
321326
...(webCmd ? [webCmd] : []),
322327
...(forkCmd ? [forkCmd] : []),
323328
...(buddy ? [buddy] : []),
329+
...(poor ? [poor] : []),
324330
...(proactive ? [proactive] : []),
325331
...(briefCommand ? [briefCommand] : []),
326332
...(assistantCommand ? [assistantCommand] : []),

src/commands/poor/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import type { Command } from '../../commands.js'
2+
3+
const poor = {
4+
type: 'local',
5+
name: 'poor',
6+
description: 'Toggle poor mode — disable extract_memories and prompt_suggestion to save tokens',
7+
supportsNonInteractive: false,
8+
load: () => import('./poor.js'),
9+
} satisfies Command
10+
11+
export default poor

src/commands/poor/poor.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import type { LocalCommandCall } from '../../types/command.js'
2+
import { isPoorModeActive, setPoorMode } from './poorMode.js'
3+
4+
export const call: LocalCommandCall = async (_, context) => {
5+
const currentlyActive = isPoorModeActive()
6+
const newState = !currentlyActive
7+
setPoorMode(newState)
8+
9+
if (newState) {
10+
// Disable prompt suggestion in AppState
11+
context.setAppState(prev => ({
12+
...prev,
13+
promptSuggestionEnabled: false,
14+
}))
15+
} else {
16+
// Re-enable prompt suggestion
17+
context.setAppState(prev => ({
18+
...prev,
19+
promptSuggestionEnabled: true,
20+
}))
21+
}
22+
23+
const status = newState ? 'ON' : 'OFF'
24+
const details = newState
25+
? 'extract_memories and prompt_suggestion are disabled'
26+
: 'extract_memories and prompt_suggestion are restored'
27+
return { type: 'text', value: `Poor mode ${status}${details}` }
28+
}

0 commit comments

Comments
 (0)