mirror of
https://github.com/garrytan/gbrain.git
synced 2026-08-16 01:42:23 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d8cba9a76b |
@@ -22,7 +22,6 @@
|
||||
*/
|
||||
|
||||
import { resolveRecipe } from './model-resolver.ts';
|
||||
import { listRecipes } from './recipes/index.ts';
|
||||
import { AIConfigError } from './errors.ts';
|
||||
|
||||
export interface ProviderCapabilities {
|
||||
@@ -78,10 +77,7 @@ export function getProviderCapabilities(modelString: string): ProviderCapabiliti
|
||||
if (!chat) {
|
||||
throw new AIConfigError(
|
||||
`Provider "${recipe.id}" does not offer a chat touchpoint.`,
|
||||
// Computed from the registry so the hint can't drift into listing
|
||||
// chat-less providers (the pre-fix list falsely included embedding-only
|
||||
// recipes, sending users in circles — #1157).
|
||||
`Known providers with chat: ${listRecipes().filter(r => r.touchpoints.chat).map(r => r.id).join(', ')}. Pick one for models.tier.subagent.`,
|
||||
`Known providers with chat: openai, anthropic, google, openrouter, litellm-proxy, deepseek, groq, together, azure-openai, dashscope, minimax, zhipu, ollama, llama-server. Pick one for models.tier.subagent.`,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import type { Recipe } from '../types.ts';
|
||||
|
||||
/**
|
||||
* Zhipu AI (智谱AI) BigModel Open Platform. OpenAI-compatible /embeddings and
|
||||
* /chat/completions endpoints at open.bigmodel.cn. Hosts embedding-2 (1024d),
|
||||
* embedding-3 (Matryoshka up to 2048d), and the GLM chat family (glm-5.1 etc.)
|
||||
* with native tool calling — usable for models.tier.subagent (#1157).
|
||||
* Zhipu AI (智谱AI) BigModel Open Platform. OpenAI-compatible /embeddings
|
||||
* endpoint at open.bigmodel.cn. Hosts embedding-2 (1024d) and embedding-3
|
||||
* (Matryoshka up to 2048d).
|
||||
*
|
||||
* embedding-3 at 2048 dims exceeds pgvector's HNSW cap of 2000 — those
|
||||
* brains fall back to exact vector scans (see
|
||||
@@ -26,20 +25,6 @@ export const zhipu: Recipe = {
|
||||
setup_url: 'https://open.bigmodel.cn/',
|
||||
},
|
||||
touchpoints: {
|
||||
chat: {
|
||||
// Informational list (openai-compat tier: assertTouchpoint doesn't
|
||||
// enforce it), so newer GLM ids pass without a recipe edit.
|
||||
models: ['glm-5.1', 'glm-4.6', 'glm-4.5'],
|
||||
supports_tools: true,
|
||||
// gbrain-side stable tool ids (v0.38 D11) decoupled the loop from
|
||||
// Anthropic response formats; GLM tool calling is stable through the
|
||||
// OpenAI-compat path, same as deepseek/groq.
|
||||
supports_subagent_loop: true,
|
||||
// Anthropic-style cache_control markers are not honored on the
|
||||
// OpenAI-compat path — the loop runs hot (degraded:no_caching warn).
|
||||
supports_prompt_cache: false,
|
||||
max_context_tokens: 128000,
|
||||
},
|
||||
embedding: {
|
||||
models: ['embedding-3', 'embedding-2'],
|
||||
default_dims: 1024,
|
||||
@@ -51,5 +36,5 @@ export const zhipu: Recipe = {
|
||||
},
|
||||
},
|
||||
setup_hint:
|
||||
'Get an API key at https://open.bigmodel.cn/, then `export ZHIPUAI_API_KEY=...`. Chat/subagent: use `zhipu:glm-5.1`.',
|
||||
'Get an API key at https://open.bigmodel.cn/, then `export ZHIPUAI_API_KEY=...`',
|
||||
};
|
||||
|
||||
@@ -453,7 +453,14 @@ function resolveActivity(
|
||||
* every `assemble()` call. 1 MB is generous for a human-edited task list. */
|
||||
const MAX_TASKS_MD_BYTES = 1_000_000;
|
||||
|
||||
/** Extract open tasks from ops/tasks.md "## Today" section. */
|
||||
/** Extract open tasks from ops/tasks.md Today section.
|
||||
*
|
||||
* The daily-task-manager skill's documented Output Format uses priority
|
||||
* headings (`## P1 — Today`) with plain `- [ ] task` lines; older fixtures
|
||||
* used a bare `## Today` heading with bold task names. Accept both so the
|
||||
* live-context reader matches the documented writer contract instead of
|
||||
* silently surfacing no tasks (#2186).
|
||||
*/
|
||||
function resolveTodayTasks(workspaceDir: string): string[] {
|
||||
try {
|
||||
const path = join(workspaceDir, 'ops', 'tasks.md');
|
||||
@@ -461,14 +468,18 @@ function resolveTodayTasks(workspaceDir: string): string[] {
|
||||
// statSync throws if the file doesn't exist; that lands in the outer catch.
|
||||
if (statSync(path).size > MAX_TASKS_MD_BYTES) return [];
|
||||
const raw = readFileSync(path, 'utf8');
|
||||
const todayMatch = raw.match(/## Today[\s\S]*?(?=\n## |$)/);
|
||||
const todayMatch = raw.match(/^##\s+(?:P\d\s*[—–-]\s*)?Today\b[\s\S]*?(?=\n##\s|$(?![\s\S]))/m);
|
||||
if (!todayMatch) return [];
|
||||
|
||||
const lines = todayMatch[0].split('\n');
|
||||
const open: string[] = [];
|
||||
for (const line of lines) {
|
||||
// Match unchecked task lines: - [ ] **task name** ...
|
||||
const m = line.match(/^\s*-\s*\[ \]\s*\*\*(.+?)\*\*/);
|
||||
// Match unchecked task lines. Legacy bold form first (extracts just
|
||||
// the task name, dropping trailing metadata), then the documented
|
||||
// plain form (whole line body is the task).
|
||||
const m =
|
||||
line.match(/^\s*-\s*\[ \]\s*\*\*(.+?)\*\*/) ??
|
||||
line.match(/^\s*-\s*\[ \]\s*(.+?)\s*$/);
|
||||
if (m) open.push(sanitizeForPrompt(m[1].trim()));
|
||||
}
|
||||
return open.slice(0, 5); // cap at 5 to keep prompt lean
|
||||
|
||||
@@ -69,45 +69,6 @@ describe('recipe: zhipu', () => {
|
||||
expect(sql.toLowerCase()).toContain('hnsw');
|
||||
});
|
||||
|
||||
test('chat touchpoint declares GLM models with tool + subagent-loop support (#1157)', () => {
|
||||
const r = getRecipe('zhipu')!;
|
||||
expect(r.touchpoints.chat).toBeDefined();
|
||||
expect(r.touchpoints.chat!.models).toContain('glm-5.1');
|
||||
expect(r.touchpoints.chat!.supports_tools).toBe(true);
|
||||
expect(r.touchpoints.chat!.supports_subagent_loop).toBe(true);
|
||||
expect(r.touchpoints.chat!.supports_prompt_cache).toBe(false);
|
||||
});
|
||||
|
||||
test('zhipu:glm-5.1 passes the subagent capability gate (degraded:no_caching, not refused)', async () => {
|
||||
// Pre-fix: getProviderCapabilities threw "does not offer a chat touchpoint"
|
||||
// and classifyCapabilities returned 'unknown' → subagent submit refused.
|
||||
const { getProviderCapabilities, classifyCapabilities } =
|
||||
await import('../../src/core/ai/capabilities.ts');
|
||||
const caps = getProviderCapabilities('zhipu:glm-5.1');
|
||||
expect(caps.supportsToolCalling).toBe(true);
|
||||
expect(classifyCapabilities('zhipu:glm-5.1')).toBe('degraded:no_caching');
|
||||
});
|
||||
|
||||
test('no-chat-touchpoint error hint lists only providers that actually have chat', async () => {
|
||||
// The hint is computed from the registry; every provider it names must
|
||||
// really carry a chat touchpoint (pre-fix it hardcoded zhipu/dashscope/
|
||||
// minimax, all embedding-only at the time).
|
||||
const { getProviderCapabilities } = await import('../../src/core/ai/capabilities.ts');
|
||||
const { listRecipes } = await import('../../src/core/ai/recipes/index.ts');
|
||||
let hint = '';
|
||||
try {
|
||||
getProviderCapabilities('voyage:voyage-3');
|
||||
throw new Error('expected AIConfigError for embedding-only provider');
|
||||
} catch (e) {
|
||||
hint = (e as { fix?: string }).fix ?? String(e);
|
||||
}
|
||||
const listed = hint.match(/chat: ([^.]+)\./)?.[1]?.split(', ') ?? [];
|
||||
expect(listed.length).toBeGreaterThan(0);
|
||||
const withChat = new Set(listRecipes().filter(r => r.touchpoints.chat).map(r => r.id));
|
||||
for (const id of listed) expect(withChat.has(id)).toBe(true);
|
||||
expect(listed).toContain('zhipu');
|
||||
});
|
||||
|
||||
test('dimsProviderOptions threads dimensions for embedding-3 (Matryoshka)', async () => {
|
||||
// Codex finding #1: Zhipu embedding-3 is Matryoshka 256-2048. Without
|
||||
// `dimensions` on the wire, user-selected non-default dims are
|
||||
|
||||
@@ -322,6 +322,28 @@ describe('gbrain-context engine', () => {
|
||||
expect(result.systemPromptAddition).not.toContain('Something later');
|
||||
});
|
||||
|
||||
it('injects documented "## P1 — Today" plain tasks from ops/tasks.md (#2186)', async () => {
|
||||
tmpDir = makeWorkspace({
|
||||
heartbeat: { garryAwake: true },
|
||||
tasks: `# Tasks\n\n## P0 — Urgent\n- [ ] **Escalate outage**\n\n## P1 — Today\n- [ ] Call Alice about launch plan\n- [ ] **Review Bob contract** — due Friday\n- [x] Completed item\n\n## P2 — This Week\n- [ ] Should not surface`,
|
||||
});
|
||||
const engine = createGBrainContextEngine({ workspaceDir: tmpDir });
|
||||
|
||||
const result = await engine.assemble({
|
||||
sessionId: 'test-session',
|
||||
messages: [],
|
||||
});
|
||||
|
||||
expect(result.systemPromptAddition).toContain('Open tasks');
|
||||
expect(result.systemPromptAddition).toContain('Call Alice about launch plan');
|
||||
// Bold form still extracts just the task name, not trailing metadata.
|
||||
expect(result.systemPromptAddition).toContain('Review Bob contract');
|
||||
expect(result.systemPromptAddition).not.toContain('due Friday');
|
||||
expect(result.systemPromptAddition).not.toContain('Escalate outage');
|
||||
expect(result.systemPromptAddition).not.toContain('Completed item');
|
||||
expect(result.systemPromptAddition).not.toContain('Should not surface');
|
||||
});
|
||||
|
||||
it('no activity section when calendar is empty and no tasks', async () => {
|
||||
tmpDir = makeWorkspace({
|
||||
heartbeat: { garryAwake: true },
|
||||
|
||||
Reference in New Issue
Block a user