@useavalon/caelence-agent 0.5.0 → 0.6.0

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.
@@ -128,6 +128,33 @@ describe("desktop bridge", () => {
128
128
  expect(body.hasApiKey).toBe(true);
129
129
  expect(body.apiKeyHint).toBe("••••tkey");
130
130
  expect(JSON.stringify(body)).not.toContain("sk-or-v1-secretkey");
131
+
132
+ const settings = await fetch(`${ctx.ready.url}/settings`, { headers: ctx.headers });
133
+ const loaded = (await settings.json()) as { reasoningEffort: string };
134
+ expect(loaded.reasoningEffort).toBe("low");
135
+ const savedEffort = await fetch(`${ctx.ready.url}/settings`, {
136
+ method: "POST",
137
+ headers: ctx.headers,
138
+ body: JSON.stringify({ reasoningEffort: "high" }),
139
+ });
140
+ const after = (await savedEffort.json()) as {
141
+ reasoningEffort: string;
142
+ state: { reasoningEffort: string };
143
+ };
144
+ expect(after.reasoningEffort).toBe("high");
145
+ expect(after.state.reasoningEffort).toBe("high");
146
+
147
+ const combined = await fetch(`${ctx.ready.url}/settings`, {
148
+ method: "POST",
149
+ headers: ctx.headers,
150
+ body: JSON.stringify({ modelId: "x-ai/grok", reasoningEffort: "nope" }),
151
+ });
152
+ expect(combined.status).toBe(400);
153
+ const unchanged = (await (
154
+ await fetch(`${ctx.ready.url}/settings`, { headers: ctx.headers })
155
+ ).json()) as { modelId: string; reasoningEffort: string };
156
+ expect(unchanged.modelId).not.toBe("x-ai/grok");
157
+ expect(unchanged.reasoningEffort).toBe("high");
131
158
  } finally {
132
159
  await ctx.close();
133
160
  if (prevHome === undefined) delete process.env.HARNESS_HOME;
@@ -18,6 +18,7 @@ import type { ApprovalRequest } from "../core/approval.ts";
18
18
  import { errorMessage } from "../core/errors.ts";
19
19
  import type { AgentEvent } from "../core/events.ts";
20
20
  import { tryParseAgentMode } from "../core/mode.ts";
21
+ import { REASONING_EFFORT_USAGE, tryParseReasoningEffort } from "../core/reasoning.ts";
21
22
  import { normalizeSessionTitle, type Session, sessionTranscript } from "../core/session.ts";
22
23
  import { formatUsage } from "../core/usage.ts";
23
24
  import {
@@ -72,6 +73,7 @@ export interface DesktopState {
72
73
  name: string;
73
74
  cwd: string;
74
75
  mode: string;
76
+ reasoningEffort: string;
75
77
  modelId: string;
76
78
  modelLabel: string;
77
79
  modelTarget?: string;
@@ -144,6 +146,7 @@ function settingsPayload(harness: HarnessRuntime) {
144
146
  hasApiKey: harness.hasApiKey,
145
147
  apiKeyHint: harness.hasApiKey ? maskSecret(process.env.OPENROUTER_API_KEY ?? "") : "",
146
148
  mode: harness.mode,
149
+ reasoningEffort: harness.reasoningEffort,
147
150
  modelId: harness.modelId,
148
151
  modelLabel: modelLabel(harness.modelId),
149
152
  hasGoogleOAuth: Boolean(google?.clientId),
@@ -317,6 +320,7 @@ function snapshot(harness: HarnessRuntime, busy: boolean, title: string): Deskto
317
320
  name: harness.config.name,
318
321
  cwd: harness.cwd,
319
322
  mode: harness.mode,
323
+ reasoningEffort: harness.reasoningEffort,
320
324
  modelId: harness.modelId,
321
325
  modelLabel: label,
322
326
  ...(target && target.toLowerCase() !== label.toLowerCase() ? { modelTarget: target } : {}),
@@ -699,19 +703,27 @@ export async function startDesktopBridge(options: StartDesktopBridgeOptions): Pr
699
703
 
700
704
  const route_post_settings = async (req: Request, _url: URL): Promise<Response> => {
701
705
  const body = await readJson(req);
706
+ const nextMode = typeof body.mode === "string" ? tryParseAgentMode(body.mode) : undefined;
707
+ if (typeof body.mode === "string" && !nextMode) {
708
+ return json({ error: "Mode is ask, plan, or agent." }, 400);
709
+ }
710
+ const nextEffort =
711
+ typeof body.reasoningEffort === "string"
712
+ ? tryParseReasoningEffort(body.reasoningEffort)
713
+ : undefined;
714
+ if (typeof body.reasoningEffort === "string" && !nextEffort) {
715
+ return json({ error: REASONING_EFFORT_USAGE }, 400);
716
+ }
702
717
  if (typeof body.apiKey === "string") {
703
718
  writeOpenRouterKey(body.apiKey);
704
719
  harness.setApiKey(body.apiKey);
705
720
  refreshLiveNames();
706
721
  }
707
- if (typeof body.mode === "string") {
708
- const next = tryParseAgentMode(body.mode);
709
- if (!next) return json({ error: "Mode is ask, plan, or agent." }, 400);
710
- harness.setMode(next);
711
- }
722
+ if (nextMode) harness.setMode(nextMode);
712
723
  if (typeof body.modelId === "string" && body.modelId.trim()) {
713
724
  harness.setModel(body.modelId.trim());
714
725
  }
726
+ if (nextEffort) harness.setReasoningEffort(nextEffort);
715
727
  saveProviderOAuth(body, "google");
716
728
  saveProviderOAuth(body, "microsoft");
717
729
  if (typeof body.memoryEnabled === "boolean") {
package/src/index.ts CHANGED
@@ -75,6 +75,15 @@ export {
75
75
  toolsAllowedInMode,
76
76
  tryParseAgentMode,
77
77
  } from "./core/mode.ts";
78
+ export {
79
+ DEFAULT_REASONING_EFFORT,
80
+ parseReasoningEffort,
81
+ REASONING_EFFORT_USAGE,
82
+ REASONING_EFFORTS,
83
+ type ReasoningEffort,
84
+ resolveReasoningEffort,
85
+ tryParseReasoningEffort,
86
+ } from "./core/reasoning.ts";
78
87
  export {
79
88
  buildSystemPrompt,
80
89
  type RunTurnDeps,
@@ -102,8 +111,11 @@ export {
102
111
  type AgentTool,
103
112
  type ConstructAgent,
104
113
  type ConstructedAgent,
114
+ type ContextManagerStrategy,
115
+ type CreateConstructAgentOptions,
105
116
  constructOpenRouterProvider,
106
117
  createConstructAgent,
118
+ Offload,
107
119
  type StrandsBackedProvider,
108
120
  } from "./core/strands.ts";
109
121
  export { addUsage, formatUsage, parseTokenUsage, type TokenUsage } from "./core/usage.ts";
@@ -125,6 +125,33 @@ describe("createHarness modes", () => {
125
125
  }
126
126
  });
127
127
 
128
+ test("applies reasoning effort from config and setReasoningEffort", async () => {
129
+ const cwd = await mkdtemp(join(tmpdir(), "harness-effort-"));
130
+ const previous = process.env.HARNESS_REASONING_EFFORT;
131
+ delete process.env.HARNESS_REASONING_EFFORT;
132
+ try {
133
+ const harness = await createHarness({
134
+ cwd,
135
+ config: { ...DEFAULT_CONFIG, reasoningEffort: "high" },
136
+ provider: fakeProvider,
137
+ constructAgent: () => ({
138
+ async run() {
139
+ throw new Error("should not run");
140
+ },
141
+ }),
142
+ observability: noopObservability,
143
+ });
144
+ expect(harness.reasoningEffort).toBe("high");
145
+ harness.setReasoningEffort("medium");
146
+ expect(harness.reasoningEffort).toBe("medium");
147
+ harness.close();
148
+ } finally {
149
+ if (previous === undefined) delete process.env.HARNESS_REASONING_EFFORT;
150
+ else process.env.HARNESS_REASONING_EFFORT = previous;
151
+ await rm(cwd, { recursive: true, force: true });
152
+ }
153
+ });
154
+
128
155
  test("accumulates usage on the runtime", async () => {
129
156
  const cwd = await mkdtemp(join(tmpdir(), "harness-spend-"));
130
157
  try {
package/src/runtime.ts CHANGED
@@ -33,6 +33,11 @@ import {
33
33
  parseAgentMode,
34
34
  toolsAllowedInMode,
35
35
  } from "./core/mode.ts";
36
+ import {
37
+ parseReasoningEffort,
38
+ type ReasoningEffort,
39
+ resolveReasoningEffort,
40
+ } from "./core/reasoning.ts";
36
41
  import {
37
42
  buildSystemPrompt,
38
43
  defaultSummarizer,
@@ -159,6 +164,7 @@ export interface HarnessRuntime {
159
164
  systemPrompt: string;
160
165
  modelId: string;
161
166
  mode: AgentMode;
167
+ reasoningEffort: ReasoningEffort;
162
168
  activeSessionId?: string;
163
169
  /** True when the browser tools are on for the current chat, by `@browser`, a turn option, or config. */
164
170
  readonly browserActive: boolean;
@@ -172,6 +178,7 @@ export interface HarnessRuntime {
172
178
  ): Promise<Session | undefined>;
173
179
  setModel(modelId: string): void;
174
180
  setMode(mode: AgentMode): void;
181
+ setReasoningEffort(effort: ReasoningEffort): void;
175
182
  setSession(id: string | undefined): void;
176
183
  allowExecAlways(): void;
177
184
  allowRiskyAlways(toolName: string): void;
@@ -208,6 +215,7 @@ export interface CreateHarnessOptions {
208
215
  */
209
216
  memory?: MemoryStore;
210
217
  mode?: AgentMode;
218
+ reasoningEffort?: ReasoningEffort;
211
219
  /** Load one-click MCP connections from ~/.harness. Default on unless a test provider is passed. */
212
220
  loadIntegrations?: boolean;
213
221
  /** Replaces the stdio MCP loader for the browser server. Tests only. */
@@ -253,6 +261,10 @@ export async function createHarness(options: CreateHarnessOptions): Promise<Harn
253
261
  let skills = loadActiveSkills();
254
262
  const layers = loadInstructionLayers({ cwd, projectFile: config.instructionsFile });
255
263
  let mode = parseAgentMode(options.mode ?? config.mode);
264
+ let reasoningEffort = resolveReasoningEffort({
265
+ option: options.reasoningEffort,
266
+ config: config.reasoningEffort,
267
+ });
256
268
  const hostAppend = options.systemAppend?.trim();
257
269
  const composePrompt = (nextMode: AgentMode) => {
258
270
  const base = buildSystemPrompt({
@@ -400,6 +412,7 @@ export async function createHarness(options: CreateHarnessOptions): Promise<Harn
400
412
  apiKey,
401
413
  model: id,
402
414
  baseUrl: or.baseUrl,
415
+ reasoningEffort,
403
416
  sessionId: () => activeSessionId,
404
417
  ...(title ? { title } : {}),
405
418
  });
@@ -494,6 +507,9 @@ export async function createHarness(options: CreateHarnessOptions): Promise<Harn
494
507
  get mode() {
495
508
  return mode;
496
509
  },
510
+ get reasoningEffort() {
511
+ return reasoningEffort;
512
+ },
497
513
  spend: undefined,
498
514
  get activeSessionId() {
499
515
  return activeSessionId;
@@ -525,6 +541,10 @@ export async function createHarness(options: CreateHarnessOptions): Promise<Harn
525
541
  mode = parseAgentMode(next);
526
542
  systemPrompt = composePrompt(mode);
527
543
  },
544
+ setReasoningEffort(next) {
545
+ reasoningEffort = parseReasoningEffort(next);
546
+ if (!options.provider) provider = makeProvider(modelId);
547
+ },
528
548
  setSession(id) {
529
549
  if (id !== activeSessionId) resetBrowserChat();
530
550
  activeSessionId = id;