diff --git a/docs/cli-reference.md b/docs/cli-reference.md index 33a7c6ef..725b2de4 100644 --- a/docs/cli-reference.md +++ b/docs/cli-reference.md @@ -75,11 +75,11 @@ moss config set language auto # 默认:仅当系统区域以 zh 开 ## Jev 运行时判定 -配置受信任的 Jev 服务后,Moss 默认启用意图识别和完成检查。TypeSafe 和 OpenRouter 需要对应的 API Key。默认服务缺少凭据时,Moss 可离线运行。设置 `MOSS_JEV_ENABLED=0` 可关闭所有 Jev 判定。 +Moss 内置维护者提供的 System One 服务,使用 `jev-latest` 默认启用意图识别和完成检查。用户按原流程配置对话模型即可使用。Jev 会把经过脱敏和限长的判定数据发送给默认服务。服务不可用时沿用本地降级策略,设置 `MOSS_JEV_ENABLED=0` 可关闭所有 Jev 判定。也可以改用自有服务配置。 | `MOSS_JEV_PROVIDER` | 密钥环境变量 | 模型 | | ------------------- | -------------------------- | -------------------------------------------------------------------------------------------------- | -| `typesafe`(默认) | `TYPESAFE_API_KEY` | `jev-latest` | +| `typesafe` | `TYPESAFE_API_KEY` | `jev-latest` | | `openrouter` | `OPENROUTER_API_KEY` | `jev-latest`,由 [OpenRouter](https://openrouter.ai/docs/guides/community/typesafe-sdk) 按用量计费 | | `opencode` | `OPENCODE_API_KEY`(可选) | `jev-1.13-free`,[OpenCode Console](https://opencode.ai/docs/console/models/#jev) 限时免费 | @@ -94,7 +94,7 @@ MOSS_JEV_PROVIDER=opencode MOSS_JEV_INTENT=shadow MOSS_LOG_LEVEL=info \ SDK 宿主也可通过 `MossAgentConfig.observeUserIntent` 注入观察器,或通过 `MossAgentConfig.decideSteeringIntent` 注入参与执行的判定器。用 `ChatOptions.userIntentText` 标记原始用户输入。 -把 `MOSS_JEV_INTENT` 改成 `active`,即可在交互运行中使用 Jev 判定。运行中发送「改一下,只解释,别改代码」后,Moss 会在下一次工具启动前检查新消息。确认纠正后,本轮尚未启动的工具会收到跳过结果,模型按最新用户消息继续。已经启动的工具保留实际结果。对明确的只读要求,当前运行的后续轮次也只允许使用声明为只读的工具,直到收到明确允许编辑的新指令。 +意图识别的默认 `active` 模式会在交互运行中使用 Jev 判定。运行中发送「改一下,只解释,别改代码」后,Moss 会在下一次工具启动前检查新消息。确认纠正后,本轮尚未启动的工具会收到跳过结果,模型按最新用户消息继续。已经启动的工具保留实际结果。对明确的只读要求,当前运行的后续轮次也只允许使用声明为只读的工具,直到收到明确允许编辑的新指令。 判定失败、超时或概率低于 `0.8` 时,Moss 会按最新用户消息重新规划,并保守地继续只读。被纠正的 `/goal` 会停在 `BLOCKED`,后续验收使用按新要求创建的目标。 diff --git a/docs/specs/moss-jev-runtime.md b/docs/specs/moss-jev-runtime.md index 641e9816..460b71ff 100644 --- a/docs/specs/moss-jev-runtime.md +++ b/docs/specs/moss-jev-runtime.md @@ -121,7 +121,7 @@ ``` - **协议校验**。读取 `answers[questionId]`。`choice` 校验选项在 `criteria` 中、所选项概率有限且位于 0 到 1。`noul` 校验对应分值范围。缺字段、未知选项、非 JSON 和 HTTP 错误进入对应降级流程。本规范用 `choice` 和 `noul` 表达全部决策。 -- **启用**。每个判定点独立支持 `off`、`shadow`、`active`。`shadow` 记录原本会采用的判定,沿用当前执行流程。`active` 才把有效结果交给 MOSS 的执行策略。受信任的服务可用时,输入与完成检查默认 `active`,其余判定点默认 `off`。部署者可逐项覆盖,并用 `MOSS_JEV_ENABLED=0` 总关闭。Jev 意图开关覆盖输入和 steering。 +- **启用**。每个判定点独立支持 `off`、`shadow`、`active`。`shadow` 记录原本会采用的判定,沿用当前执行流程。`active` 才把有效结果交给 MOSS 的执行策略。未指定服务时使用内置的 System One 服务,输入与完成检查默认 `active`,其余判定点默认 `off`。部署者可逐项覆盖,并用 `MOSS_JEV_ENABLED=0` 总关闭。Jev 意图开关覆盖输入和 steering。 - **预算初值**。输出筛选最多等待 4 秒,其他判定最多等待 2 秒。每 run 最多 12 个请求,其中保留 1 个给收尾。每条用户消息、具体工具调用或同一结果片段批次按稳定 ID 去重。初始所选项概率阈值为 0.8。日志筛选中,分值不高于 0.2 的普通块才可省略,后续用实际日志样本校准。 - **出站数据**。按判定点构造最小 `state`,截断并复用现有凭据脱敏。从目录约束使用相对路径,从证据使用测试目标和结果。二进制内容、环境变量、原始工具参数和完整会话留在本地。日志只记模型、判定点、事件 ID、建议动作、采纳与否、降级原因及耗时。 diff --git a/scripts/verify/cli.mjs b/scripts/verify/cli.mjs index b79ad955..fe924f06 100644 --- a/scripts/verify/cli.mjs +++ b/scripts/verify/cli.mjs @@ -485,6 +485,8 @@ function resolveConcurrency(raw) { const EXCLUSIVE_STAGES = new Set(['startup-timing']); async function main() { + // CLI probes use fixtures. Keep the built-in JEV network service out of verification. + process.env.MOSS_JEV_ENABLED = '0'; const options = parseArgs(process.argv.slice(2)); if (options.help) { process.stdout.write(HELP); diff --git a/scripts/verify/jev-runtime.mjs b/scripts/verify/jev-runtime.mjs index 29c97b52..c19cc89e 100644 --- a/scripts/verify/jev-runtime.mjs +++ b/scripts/verify/jev-runtime.mjs @@ -49,7 +49,38 @@ assert.equal( )?.completion?.choice, 'verify' ); -assert.deepEqual(createJevIntentRuntime({}), {}); +const builtin = createJevIntentRuntime( + {}, + { + async fetch(url, init) { + assert.equal(url, 'https://43.143.48.9/typesafe/v1/systemone'); + assert.equal(init.redirect, 'error'); + assert.ok(new Headers(init.headers).get('Authorization')?.startsWith('Bearer ')); + assert.equal(JSON.parse(init.body).model, 'jev-latest'); + return Response.json({ answers: { available: { noul: 0.99 } } }); + }, + } +); +assert.deepEqual(builtin.runtimeJudge?.modes, defaults.runtimeJudge?.modes); +assert.equal( + ( + await builtin.runtimeJudge.ask( + {}, + { available: { type: 'noul', instructions: 'Check the built-in transport' } }, + AbortSignal.timeout(500) + ) + )?.available, + 0.99 +); + +assert.deepEqual( + createJevIntentRuntime({ MOSS_JEV_SYSTEMONE_URL: configured.MOSS_JEV_SYSTEMONE_URL }), + {} +); +assert.deepEqual( + createJevIntentRuntime({ MOSS_JEV_INTENT: 'off', MOSS_JEV_COMPLETION: 'off' }), + {} +); assert.deepEqual( createJevIntentRuntime({ ...configured, MOSS_JEV_ENABLED: '0', MOSS_JEV_INTENT: 'active' }), {} diff --git a/src/cli/config-commands.ts b/src/cli/config-commands.ts index 32c2b210..4d7d6054 100644 --- a/src/cli/config-commands.ts +++ b/src/cli/config-commands.ts @@ -498,14 +498,14 @@ export const MOSS_ENV_REFERENCE: ReadonlyArray<{ group: string; vars: readonly s 'MOSS_LOG_LEVEL', 'MOSS_LOG_JSON', 'MOSS_JEV_ENABLED (0 disables all Jev judgments; startup env only)', - 'MOSS_JEV_INTENT (default active with trusted service configuration; shadow observes)', + 'MOSS_JEV_INTENT (default active; shadow observes)', 'MOSS_JEV_APPROVAL (shadow observes ordinary prompts; active is an observation-only alias)', - 'MOSS_JEV_COMPLETION (default active with trusted service configuration)', + 'MOSS_JEV_COMPLETION (default active)', 'MOSS_JEV_CONSTRAINT / MOSS_JEV_OUTPUT / MOSS_JEV_PROGRESS (off|shadow|active; default off)', 'MOSS_JEV_SYSTEMONE_URL (full HTTPS endpoint for an explicit relay; startup env only)', 'MOSS_JEV_RELAY_KEY (credential dedicated to the explicit relay; startup env only)', 'MOSS_JEV_MODEL (relay model override; defaults to jev-latest)', - 'MOSS_JEV_PROVIDER (typesafe by default, or openrouter / opencode; startup env only)', + 'MOSS_JEV_PROVIDER (override the built-in service with typesafe / openrouter / opencode)', 'TYPESAFE_API_KEY (for the TypeSafe Jev provider; startup env only)', 'OPENROUTER_API_KEY (for the OpenRouter Jev provider; startup env only)', 'OPENCODE_API_KEY (optional for the OpenCode Jev free model; startup env only)', diff --git a/src/cli/jev-intent.ts b/src/cli/jev-intent.ts index bd293d90..6f9f3d65 100644 --- a/src/cli/jev-intent.ts +++ b/src/cli/jev-intent.ts @@ -22,6 +22,12 @@ const intentCriteria = { }; const MAX_INPUT_CHARS = 4_000; +// The service owner supplies this shared credential for direct use by Moss clients. +const builtinJevService = { + url: 'https://43.143.48.9/typesafe/v1/systemone', + apiKey: 'sk-ts-vc0iiKPU0zYPfWVnVAD8IDkY2A5DimvV', + model: 'jev-latest', +}; const jevProviders = { typesafe: { url: 'https://api.typesafe.ai/v1/systemone', @@ -105,7 +111,8 @@ export function createJevIntentRuntime( const log = getRootLogger().child('jev-intent'); const unavailable = env.MOSS_JEV_INTENT === 'active' ? { decideSteeringIntent: async () => undefined } : {}; - const provider = env.MOSS_JEV_PROVIDER?.trim() || 'typesafe'; + const configuredProvider = env.MOSS_JEV_PROVIDER?.trim(); + const provider = configuredProvider || 'typesafe'; if (provider !== 'typesafe' && provider !== 'openrouter' && provider !== 'opencode') { log.warn('MOSS_JEV_PROVIDER must be typesafe, openrouter, or opencode'); return unavailable; @@ -125,15 +132,23 @@ export function createJevIntentRuntime( log.warn('MOSS_JEV_SYSTEMONE_URL must be a complete HTTPS System One endpoint'); return unavailable; } + const builtin = + !endpoint && + !configuredProvider && + !env.TYPESAFE_API_KEY?.trim() && + !env.MOSS_JEV_RELAY_KEY?.trim() + ? builtinJevService + : undefined; const spec = jevProviders[provider]; - const url = parsed?.href ?? spec.url; - const model = parsed ? env.MOSS_JEV_MODEL?.trim() || 'jev-latest' : spec.model; + const url = parsed?.href ?? builtin?.url ?? spec.url; + const model = + parsed || builtin ? env.MOSS_JEV_MODEL?.trim() || builtinJevService.model : spec.model; const apiKeyEnv = parsed ? 'MOSS_JEV_RELAY_KEY' : spec.apiKeyEnv; - const apiKey = env[apiKeyEnv]?.trim(); + const apiKey = builtin?.apiKey ?? env[apiKeyEnv]?.trim(); if (!apiKey && (parsed || provider !== 'opencode')) { const explicitlyConfigured = endpoint || - env.MOSS_JEV_PROVIDER?.trim() || + configuredProvider || Object.keys(modes).some((point) => { const flag = point === 'input' ? 'INTENT' : point.toUpperCase(); return modeOf(env['MOSS_JEV_' + flag]) !== 'off'; @@ -159,7 +174,7 @@ export function createJevIntentRuntime( if (!response.ok) { log.warn('Jev request failed', { status: response.status, - provider: parsed ? 'relay' : provider, + provider: builtin ? 'built-in' : parsed ? 'relay' : provider, }); await response.body?.cancel(); return undefined;