@buildaharness/aielia 0.3.9 → 0.3.10

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 (78) hide show
  1. package/dist/_memory-core-generated.d.ts +6 -0
  2. package/dist/assistant.d.ts +11 -0
  3. package/dist/{bin-CCwDFxDe.js → bin-Cz3FY6Ew.js} +30 -11
  4. package/dist/bin-Cz3FY6Ew.js.map +1 -0
  5. package/dist/claude-cli-llm-client.d.ts +2 -0
  6. package/dist/claude-cli-prompt.d.ts +7 -0
  7. package/dist/cli.js +1 -1
  8. package/dist/fact-repository.contract.d.ts +2 -0
  9. package/dist/fact-repository.d.ts +44 -0
  10. package/dist/file-tools-mcp-server.mjs +29 -0
  11. package/dist/harness-bridge.d.ts +5 -5
  12. package/dist/html-to-markdown.d.ts +11 -0
  13. package/dist/index.d.ts +82 -2
  14. package/dist/index.js +4975 -173
  15. package/dist/index.js.map +1 -1
  16. package/dist/layer-settings.d.ts +16 -3
  17. package/dist/memory-events.d.ts +177 -0
  18. package/dist/memory-service.d.ts +15 -0
  19. package/dist/model-pricing.d.ts +3 -0
  20. package/dist/{provider-setup-Cy9dwqrd.js → provider-setup-DG8iYm_F.js} +5756 -4787
  21. package/dist/provider-setup-DG8iYm_F.js.map +1 -0
  22. package/dist/scripted-llm-client.d.ts +1 -1
  23. package/dist/{tui-app-Dt72u8vZ.js → tui-app-oWbIUcBW.js} +3 -3
  24. package/dist/{tui-app-Dt72u8vZ.js.map → tui-app-oWbIUcBW.js.map} +1 -1
  25. package/dist/turn-abort.d.ts +5 -0
  26. package/dist/version.d.ts +1 -1
  27. package/dist/web-fetch-core.d.ts +0 -14
  28. package/dist/writer/article-autosave.d.ts +12 -0
  29. package/dist/writer/article-change-summary.d.ts +28 -0
  30. package/dist/writer/article-claims.d.ts +49 -0
  31. package/dist/writer/article-comments.d.ts +20 -0
  32. package/dist/writer/article-consistency.d.ts +27 -0
  33. package/dist/writer/article-decorations.d.ts +23 -0
  34. package/dist/writer/article-dependencies.d.ts +44 -0
  35. package/dist/writer/article-draft.d.ts +23 -0
  36. package/dist/writer/article-edit-outline.d.ts +16 -0
  37. package/dist/writer/article-edit-suggest.d.ts +30 -0
  38. package/dist/writer/article-folder.d.ts +29 -0
  39. package/dist/writer/article-history.d.ts +73 -0
  40. package/dist/writer/article-ideas.d.ts +34 -0
  41. package/dist/writer/article-issues.d.ts +47 -0
  42. package/dist/writer/article-marks.d.ts +25 -0
  43. package/dist/writer/article-memory-store.d.ts +3 -0
  44. package/dist/writer/article-model.d.ts +1337 -0
  45. package/dist/writer/article-outline.d.ts +43 -0
  46. package/dist/writer/article-resolver.d.ts +55 -0
  47. package/dist/writer/article-revisions.d.ts +30 -0
  48. package/dist/writer/article-rules.d.ts +60 -0
  49. package/dist/writer/article-sections.d.ts +26 -0
  50. package/dist/writer/article-selection.d.ts +26 -0
  51. package/dist/writer/article-service.d.ts +542 -0
  52. package/dist/writer/article-source-links.d.ts +42 -0
  53. package/dist/writer/article-sources.d.ts +82 -0
  54. package/dist/writer/article-style-derive.d.ts +26 -0
  55. package/dist/writer/article-style.d.ts +31 -0
  56. package/dist/writer/article-suggestions.d.ts +33 -0
  57. package/dist/writer/article-support.d.ts +33 -0
  58. package/dist/writer/article-verify.d.ts +42 -0
  59. package/dist/writer/local-folder.d.ts +49 -0
  60. package/dist/writer/model-failure-hint.d.ts +7 -0
  61. package/dist/writer/repo-reader.d.ts +29 -0
  62. package/dist/writer/repo-search.d.ts +33 -0
  63. package/dist/writer/repo-verify-loop.d.ts +61 -0
  64. package/dist/writer/text-tool-calls.d.ts +11 -0
  65. package/dist/writer/work-progress.d.ts +51 -0
  66. package/dist/writer/write-activity.d.ts +61 -0
  67. package/dist/writer/write-models.d.ts +12 -0
  68. package/dist/writer/write-parameters.d.ts +31 -0
  69. package/dist/writer/write-permissions.d.ts +89 -0
  70. package/dist/writer/write-spend.d.ts +16 -0
  71. package/dist/writer/writer-chat-capture.d.ts +25 -0
  72. package/dist/writer/writer-chat-history.d.ts +17 -0
  73. package/dist/writer/writer-chat-state.d.ts +358 -0
  74. package/dist/writer/writer-chat-turn.d.ts +52 -0
  75. package/dist/writer/writer-intent.d.ts +20 -0
  76. package/package.json +3 -3
  77. package/dist/bin-CCwDFxDe.js.map +0 -1
  78. package/dist/provider-setup-Cy9dwqrd.js.map +0 -1
@@ -1762,3 +1762,9 @@ export declare const INV16: {
1762
1762
  readonly neverPromotable: readonly ["agent", "tool", "web"];
1763
1763
  readonly neverReturnedTiers: readonly ["procedural", "commitment"];
1764
1764
  };
1765
+ export declare const MEMORY_EVENT_STORE_KEY: "memory:events";
1766
+ export declare const MEMORY_EVENT_KEEP: 500;
1767
+ export declare const MEMORY_EVENT_KINDS: readonly ["promote", "decline", "correct", "contradict", "supersede", "retire", "forget", "expire", "restore", "recall"];
1768
+ export declare const MEMORY_REASON_CODES: readonly ["user_stated", "user_corrected", "user_confirmed", "user_rejected", "inferred_high_conf", "inferred_pending_confirmation", "inferred_low_conf_session_only", "conflicts_with_fact", "superseded_by_newer", "explicit_forget", "retention_expired", "gate_blocked_secret", "gate_blocked_instruction", "duplicate"];
1769
+ export declare const MEMORY_SOURCE_TYPES: readonly ["user_message", "assistant_message", "tool_result", "prior_fact", "user_command"];
1770
+ export declare const MEMORY_DECIDED_BY: readonly ["user", "classifier", "reviewer", "consolidation", "rule"];
@@ -6,9 +6,11 @@ import { WebToolsContext } from './web-tools.js';
6
6
  import { ShellToolsContext } from './shell-tools.js';
7
7
  import { ActionToolsContext } from './action-tools.js';
8
8
  import { SpendCapConfig, SpendState } from './spend-cap.js';
9
+ import { WriterChatPort } from './writer/writer-chat-turn.js';
9
10
  import { TraceEvent } from './trace-events.js';
10
11
  import { AssistantToolStep } from './tool-step.js';
11
12
  import { MemoryService, MemorySummary, MemoryExport, AuditEntry, MemoryStatus, MemoryInjection, ConsolidationOutcome } from './memory-service.js';
13
+ import { EventFilter, MemoryEvent } from './memory-events.js';
12
14
  import { MemoryWriteMode } from './memory-governance.js';
13
15
  import { ConsolidationProposal } from './memory-consolidation.js';
14
16
  import { UserFact } from './fact-extraction.js';
@@ -233,6 +235,12 @@ export interface PersonalAssistantOptions {
233
235
  * Off by default.
234
236
  */
235
237
  dangerouslySkipPermissions?: boolean;
238
+ /**
239
+ * Aielia Write (T13): when set, each writer message is read for reviewer comments, decisions and corrections to sources, the result is
240
+ * stored per article through this port (not per session), and the open items of the active article are added to the system prompt
241
+ * on every turn. Unset (every other caller) means none of this runs. See plans/aielia_write_article_model_plan.html, section 8.
242
+ */
243
+ writerChat?: WriterChatPort;
236
244
  /**
237
245
  * Opt-in session spend/turn-count ceilings — see spend-cap.ts. Undefined by default, same as
238
246
  * every other field here that changes behavior only when a caller sets it: no ceiling means
@@ -323,6 +331,7 @@ export declare class PersonalAssistant {
323
331
  private readonly onTrace?;
324
332
  private readonly onDebugLog?;
325
333
  private readonly dangerouslySkipPermissions;
334
+ private readonly writerChat;
326
335
  /** Whenever any of fileTools/webTools/shellTools is configured, `turn()` routes through AgentLoop instead of a single plain chat call — computed once here since it never changes for the lifetime of an instance. */
327
336
  private readonly toolLoopWillRun;
328
337
  /** R3 of the internal plan — mirrors the same flag HarnessBridge was given at construction, kept here too so runTurn can decide whether to defer the tool loop into a harness-driven proposer instead of precomputing draftReply. See PersonalAssistantOptions.oneLoopMode's doc comment. */
@@ -555,6 +564,8 @@ export declare class PersonalAssistant {
555
564
  forgetFact(selector: string, sessionId: string, erase?: boolean): Promise<MemoryPendingOutcome>;
556
565
  /** `/memory history` — the newest audit-log entries (M2). Empty unless `AUDIT_MEMORY_AUDIT_LOG` is on. */
557
566
  memoryHistory(limit?: number): Promise<AuditEntry[]>;
567
+ /** `/memory history events [fact]` — transition events with reason and sources (`AUDIT_MEMORY_EVENTS`, default on). */
568
+ memoryEvents(limit?: number, filter?: EventFilter): Promise<MemoryEvent[]>;
558
569
  /** `/memory undo <seq>` — restores the pre-image of one audit entry (M2). */
559
570
  undoMemoryChange(selector: string, sessionId: string): Promise<{
560
571
  ok: boolean;
@@ -8,7 +8,7 @@ import { rename, stat, realpath, readdir, mkdir, unlink, writeFile, readFile } f
8
8
  import { homedir, tmpdir } from "node:os";
9
9
  import { fileURLToPath, pathToFileURL } from "node:url";
10
10
  import { OPENROUTER_DEFAULT_MODEL, OPENAI_DEFAULT_MODEL, ANTHROPIC_DEFAULT_MODEL, InMemoryReminderStore, FileSystemAdapter, FileSystemExperienceStore } from "@buildaharness/runtime";
11
- import { af as buildClaudePrompt, co as stripJsonCodeFence, c2 as recallToolEnabled, bw as lexicalOffEnvValue, a as ALREADY_STAGED_ACTION_TOOL, cn as stagedActionInput, bT as parseClaudeCliOutput, cp as stripMcpToolPrefix, bE as memoryStatusChecks, bR as normalizePlanNodes, V as PROVIDER_SETUP, ao as cleanApiKey, ah as checkApiKeyFormat, aG as envOverridesFromProcessEnv, c6 as resolveConfig, cl as shouldLaunchTuiApp, t as DEFAULT_TUI_MODE, a8 as applyLayerSettings, cj as sanitizeLayerChoices, cu as testApiKey, cx as validateConfig, aW as findInvalidNumericSettings, f as ConfigValidationError, be as formatSpendCapStatus, br as isPlanGraphEnabled, X as PersonalAssistant, ae as buildAssistantOptions, cq as stripTerminalControls, bn as isGoalGraphEnabled, b$ as planToSnapshot, ar as createLlmClient, au as createSmtpSender, at as createResendSender, aZ as formatConfigListing, bm as isConfigKey, e as CONFIG_KEYS, x as ENV_VAR_FOR_CONFIG_KEY, bU as parseConfigValue, g as ConfigValueParseError, ai as checkProxyHealth, a$ as formatDoctorReport, a_ as formatCostSummary, bW as parseProjectCommand, b1 as formatGoalGraphState, bd as formatSearchResults, b6 as formatMemoryHistory, b9 as formatMemoryStatus, b8 as formatMemoryPendingOutcome, b4 as formatMemoryArchive, bY as parseUndoActionCommand, bh as formatUndoLogListing, c0 as planUndo, ax as defaultExportFilename, bg as formatTranscriptMarkdown, aj as classifyError, bf as formatStatus, b2 as formatHelp, aS as explainSteps, aR as explainSources, aP as explainLayers, b3 as formatLayerListing, cA as withLayerChoice, O as LayerSettingError, aT as explainWhy, bt as isQuitCommand, P as LiveSteeringChannel, ay as defaultMemoryExportFilename, b5 as formatMemoryExport, bD as memoryAuditLogEnabled, ba as formatMemorySummary, aa as approvalLabels, U as NO_TRACE, R as MISSING_PLAN_APPROVAL_ID_REASON, c1 as presentTurnResult, bb as formatNextSteps, aQ as explainPlan, bH as nodeToLayer, L as LAYER_DISPLAY_NAME, bG as nodeDisplayName, j as DEFAULT_CLARIFICATION_REASON, aE as emptyDraft, aC as draftToAnswer, bS as orderedOptions, cz as withCostEstimate, C as CLI_FEATURES, ad as braveSearch } from "./provider-setup-Cy9dwqrd.js";
11
+ import { ap as buildClaudePrompt, cU as stripJsonCodeFence, ct as recallToolEnabled, bT as lexicalOffEnvValue, a as ALREADY_STAGED_ACTION_TOOL, cR as stagedActionInput, az as claudeFailureMessage, ch as parseClaudeCliOutput, cV as stripMcpToolPrefix, c0 as memoryStatusChecks, cd as normalizePlanNodes, X as PROVIDER_SETUP, aA as cleanApiKey, as as checkApiKeyFormat, aV as envOverridesFromProcessEnv, cA as resolveConfig, cP as shouldLaunchTuiApp, t as DEFAULT_TUI_MODE, ag as applyLayerSettings, cN as sanitizeLayerChoices, c_ as testApiKey, d2 as validateConfig, bb as findInvalidNumericSettings, f as ConfigValidationError, by as formatSpendCapStatus, bN as isPlanGraphEnabled, Z as PersonalAssistant, ao as buildAssistantOptions, cW as stripTerminalControls, bJ as isGoalGraphEnabled, cp as planToSnapshot, aE as createLlmClient, aI as createSmtpSender, aH as createResendSender, bg as formatConfigListing, bI as isConfigKey, e as CONFIG_KEYS, x as ENV_VAR_FOR_CONFIG_KEY, ci as parseConfigValue, g as ConfigValueParseError, at as checkProxyHealth, bi as formatDoctorReport, bh as formatCostSummary, ck as parseProjectCommand, bk as formatGoalGraphState, bx as formatSearchResults, bo as formatMemoryEvents, bq as formatMemoryHistory, bt as formatMemoryStatus, bs as formatMemoryPendingOutcome, bn as formatMemoryArchive, cm as parseUndoActionCommand, bB as formatUndoLogListing, cq as planUndo, aL as defaultExportFilename, bA as formatTranscriptMarkdown, au as classifyError, bz as formatStatus, bl as formatHelp, b5 as explainSteps, b4 as explainSources, b2 as explainLayers, bm as formatLayerListing, d5 as withLayerChoice, P as LayerSettingError, bR as layerWarnings, b6 as explainWhy, bP as isQuitCommand, Q as LiveSteeringChannel, aM as defaultMemoryExportFilename, bp as formatMemoryExport, b$ as memoryAuditLogEnabled, bu as formatMemorySummary, ai as approvalLabels, W as NO_TRACE, S as MISSING_PLAN_APPROVAL_ID_REASON, cr as presentTurnResult, bv as formatNextSteps, b3 as explainPlan, c3 as nodeToLayer, L as LAYER_DISPLAY_NAME, c2 as nodeDisplayName, j as DEFAULT_CLARIFICATION_REASON, aS as emptyDraft, aQ as draftToAnswer, cg as orderedOptions, d4 as withCostEstimate, C as CLI_FEATURES, an as braveSearch } from "./provider-setup-DG8iYm_F.js";
12
12
  import { spawn } from "node:child_process";
13
13
  import { createServer, connect } from "node:net";
14
14
  import { createRequire } from "node:module";
@@ -129,7 +129,7 @@ function createNodeFsBackend() {
129
129
  }
130
130
  };
131
131
  }
132
- const CLI_VERSION = "0.3.9";
132
+ const CLI_VERSION = "0.3.10";
133
133
  function seaCacheDir(version, home = homedir()) {
134
134
  return join(home, ".buildaharness", "personal-assistant", "sea-cache", version);
135
135
  }
@@ -166,9 +166,15 @@ function resolveMcpServerPath(seaOverride, home) {
166
166
  return fileURLToPath(new URL(MCP_SERVER_FILE_NAME, import.meta.url));
167
167
  }
168
168
  const EMPTY_MCP_CONFIG = JSON.stringify({ mcpServers: {} });
169
- function invokeClaude(claudePath, args) {
169
+ function killOnAbort(proc, signal) {
170
+ if (!signal) return;
171
+ if (signal.aborted) proc.kill();
172
+ else signal.addEventListener("abort", () => proc.kill(), { once: true });
173
+ }
174
+ function invokeClaude(claudePath, args, signal) {
170
175
  return new Promise((resolvePromise, reject) => {
171
176
  const proc = spawn(claudePath, args, { cwd: tmpdir(), stdio: ["ignore", "pipe", "pipe"] });
177
+ killOnAbort(proc, signal);
172
178
  let stdout = "";
173
179
  let stderr = "";
174
180
  proc.stdout.on("data", (chunk) => {
@@ -180,16 +186,17 @@ function invokeClaude(claudePath, args) {
180
186
  proc.on("error", reject);
181
187
  proc.on("close", (code) => {
182
188
  if (code !== 0) {
183
- reject(new Error(stderr.trim() || `claude exited with code ${code}`));
189
+ reject(new Error(claudeFailureMessage(stdout, stderr, code)));
184
190
  return;
185
191
  }
186
192
  resolvePromise(parseClaudeCliOutput(stdout));
187
193
  });
188
194
  });
189
195
  }
190
- function invokeClaudeStreaming(claudePath, args, onToolStep) {
196
+ function invokeClaudeStreaming(claudePath, args, onToolStep, signal) {
191
197
  return new Promise((resolvePromise, reject) => {
192
198
  const proc = spawn(claudePath, args, { cwd: tmpdir(), stdio: ["ignore", "pipe", "pipe"] });
199
+ killOnAbort(proc, signal);
193
200
  let buffer = "";
194
201
  let stderr = "";
195
202
  let finalResultLine;
@@ -229,7 +236,7 @@ function invokeClaudeStreaming(claudePath, args, onToolStep) {
229
236
  proc.on("error", reject);
230
237
  proc.on("close", (code) => {
231
238
  if (code !== 0) {
232
- reject(new Error(stderr.trim() || `claude exited with code ${code}`));
239
+ reject(new Error(claudeFailureMessage(finalResultLine ?? "", stderr, code)));
233
240
  return;
234
241
  }
235
242
  handleLine(buffer);
@@ -312,6 +319,8 @@ function startToolGateServer(onToolProposal, onToolResult, onToolExecute) {
312
319
  }
313
320
  class ClaudeCliLLMClient {
314
321
  constructor(options = {}) {
322
+ /** Runs its own tool loop inside `claude -p`; it cannot return tool calls to a caller's loop, so those callers use text tool calls (see writer/text-tool-calls.ts). */
323
+ __publicField(this, "nativeToolCalls", false);
315
324
  __publicField(this, "claudePath");
316
325
  __publicField(this, "fileTools");
317
326
  __publicField(this, "remindersFile");
@@ -356,7 +365,7 @@ class ClaudeCliLLMClient {
356
365
  const model = options.model ?? this.model;
357
366
  if (model) args.push("--model", model);
358
367
  args.push("--", prompt);
359
- const { reply, usage, model: resolved } = await invokeClaude(this.claudePath, args);
368
+ const { reply, usage, model: resolved } = await invokeClaude(this.claudePath, args, options.signal);
360
369
  if (resolved) this.resolvedModelId = resolved;
361
370
  if (usage) (_a = options.onUsage) == null ? void 0 : _a.call(options, usage);
362
371
  return reply;
@@ -414,7 +423,9 @@ class ClaudeCliLLMClient {
414
423
  // M3: recall_memory is registered (gated, then served by the parent via onToolExecute) only under AUDIT_RECALL_TOOL.
415
424
  ...recallToolEnabled() ? { ENABLE_RECALL_TOOL: "1" } : {},
416
425
  // Always passed (even empty): the server reads an unset value as the default, every family off.
417
- ASSISTANT_LEXICAL_RESOLVED_OFF: lexicalOffEnvValue()
426
+ ASSISTANT_LEXICAL_RESOLVED_OFF: lexicalOffEnvValue(),
427
+ // Eval harness only: absent in the product, so the env block is unchanged.
428
+ ...process.env.BENCHMARK_TOOL_FAILURE ? { BENCHMARK_TOOL_FAILURE: process.env.BENCHMARK_TOOL_FAILURE } : {}
418
429
  }
419
430
  }
420
431
  }
@@ -443,7 +454,7 @@ class ClaudeCliLLMClient {
443
454
  if (model) args.push("--model", model);
444
455
  args.push("--", prompt);
445
456
  const callStartedAt = Date.now();
446
- const { reply, usage, model: resolved } = await invokeClaudeStreaming(this.claudePath, args, options.onToolStep);
457
+ const { reply, usage, model: resolved } = await invokeClaudeStreaming(this.claudePath, args, options.onToolStep, options.signal);
447
458
  if (resolved) this.resolvedModelId = resolved;
448
459
  if (usage) (_f = options.onUsage) == null ? void 0 : _f.call(options, usage);
449
460
  const staged = await this.findPendingActionStagedSince(workspaceRoot, callStartedAt);
@@ -3995,6 +4006,12 @@ Forgot ${removed} session digest${removed === 1 ? "" : "s"}.
3995
4006
  await handleMemoryForget(args.slice(1));
3996
4007
  return;
3997
4008
  }
4009
+ if (args[0] === "history" && args[1] === "events") {
4010
+ printSafe(`
4011
+ ${formatMemoryEvents(await assistant.memoryEvents(50, args[2] ? { fact: args[2] } : {}))}
4012
+ `);
4013
+ return;
4014
+ }
3998
4015
  if (args[0] === "history") {
3999
4016
  printSafe(`
4000
4017
  ${formatMemoryHistory(await assistant.memoryHistory())}
@@ -4662,6 +4679,8 @@ Usage: /layers ${sub} <id>
4662
4679
  ✗ Saved, but "${id}" is pinned by its AUDIT_* env flag, so the saved choice has no effect until that is unset.
4663
4680
  ` : `
4664
4681
  ✓ Layers updated (took effect immediately, no restart needed)
4682
+ `);
4683
+ for (const warning of layerWarnings(sanitizeLayerChoices(config.layers), layerPins, process.env)) printSafe(`⚠ ${warning}
4665
4684
  `);
4666
4685
  }
4667
4686
  async function handleModel(args) {
@@ -4843,7 +4862,7 @@ async function mainInner(argv) {
4843
4862
  });
4844
4863
  }
4845
4864
  if (shouldLaunchTuiApp(config.tuiMode ?? DEFAULT_TUI_MODE, Boolean(process.stdout.isTTY), Boolean(process.stdin.isTTY))) {
4846
- const { runTuiApp } = await import("./tui-app-Dt72u8vZ.js");
4865
+ const { runTuiApp } = await import("./tui-app-oWbIUcBW.js");
4847
4866
  await runTuiApp();
4848
4867
  return;
4849
4868
  }
@@ -4870,4 +4889,4 @@ export {
4870
4889
  sanitizeLabel as s,
4871
4890
  toLines as t
4872
4891
  };
4873
- //# sourceMappingURL=bin-CCwDFxDe.js.map
4892
+ //# sourceMappingURL=bin-Cz3FY6Ew.js.map