@steerable/agent-shell 0.12.8 → 0.13.1

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 (68) hide show
  1. package/dist/auth/credentials.d.ts +83 -0
  2. package/dist/auth/credentials.js +426 -0
  3. package/dist/auth/index.d.ts +33 -9
  4. package/dist/auth/index.js +85 -0
  5. package/dist/host/external-pack-loader.d.ts +40 -0
  6. package/dist/host/external-pack-loader.js +247 -0
  7. package/dist/host/http-routes.d.ts +6 -2
  8. package/dist/host/http-routes.js +5 -2
  9. package/dist/host/pack-assembly.d.ts +9 -1
  10. package/dist/host/runtime.js +54 -1
  11. package/dist/local-backend/coreloop-stream.d.ts +4 -0
  12. package/dist/local-backend/coreloop-stream.js +4 -0
  13. package/dist/local-backend/fact-chain.d.ts +38 -0
  14. package/dist/local-backend/fact-chain.js +145 -0
  15. package/dist/local-backend/router.d.ts +3 -1
  16. package/dist/local-backend/router.js +329 -35
  17. package/dist/local-backend/state-reconcile.d.ts +42 -0
  18. package/dist/local-backend/state-reconcile.js +81 -0
  19. package/dist/local-backend/title-refresh.d.ts +39 -0
  20. package/dist/local-backend/title-refresh.js +80 -0
  21. package/dist/local-backend/turn-security-context.d.ts +42 -0
  22. package/dist/local-backend/turn-security-context.js +62 -0
  23. package/dist/local-backend/ui-surface.d.ts +75 -0
  24. package/dist/local-backend/ui-surface.js +368 -0
  25. package/dist/local-executor.d.ts +3 -0
  26. package/dist/local-executor.js +40 -1
  27. package/dist/memory/authoring-candidates.d.ts +26 -0
  28. package/dist/memory/authoring-candidates.js +73 -0
  29. package/dist/memory/injector.d.ts +34 -0
  30. package/dist/memory/injector.js +111 -0
  31. package/dist/memory/routes.d.ts +16 -0
  32. package/dist/memory/routes.js +146 -0
  33. package/dist/memory/store.d.ts +176 -0
  34. package/dist/memory/store.js +623 -0
  35. package/dist/memory/tools.d.ts +83 -0
  36. package/dist/memory/tools.js +143 -0
  37. package/dist/present-files.d.ts +25 -1
  38. package/dist/present-files.js +170 -2
  39. package/dist/scenario/applications.d.ts +52 -0
  40. package/dist/scenario/applications.js +143 -0
  41. package/dist/scenario/pack.d.ts +1 -1
  42. package/dist/security/policy-digest.d.ts +28 -0
  43. package/dist/security/policy-digest.js +104 -0
  44. package/dist/server/http-server.js +23 -6
  45. package/dist/sidecar/boot.d.ts +1 -0
  46. package/dist/sidecar/boot.js +2 -0
  47. package/dist/sidecar/rejected-before-effect.d.ts +22 -0
  48. package/dist/sidecar/rejected-before-effect.js +63 -0
  49. package/dist/sidecar/reverse-approval.d.ts +2 -0
  50. package/dist/sidecar/reverse-approval.js +28 -5
  51. package/dist/sidecar/reverse-tools.d.ts +3 -0
  52. package/dist/sidecar/reverse-tools.js +129 -17
  53. package/dist/sidecar/types.d.ts +6 -0
  54. package/dist/storage/fde-fallback.d.ts +4 -0
  55. package/dist/storage/fde-fallback.js +354 -0
  56. package/dist/storage/fde-types.d.ts +215 -0
  57. package/dist/storage/fde-types.js +1 -0
  58. package/dist/storage/index.d.ts +113 -1
  59. package/dist/storage/index.js +797 -0
  60. package/dist/storage/insights-redact.d.ts +4 -1
  61. package/dist/storage/insights-redact.js +6 -1
  62. package/dist/storage/process-locks.d.ts +1 -1
  63. package/dist/storage/process-locks.js +1 -1
  64. package/dist/storage/scoped-store.d.ts +3 -1
  65. package/dist/tool-presentation.js +20 -0
  66. package/dist/tool-router.d.ts +20 -1
  67. package/dist/tool-router.js +76 -12
  68. package/package.json +5 -5
@@ -1,2 +1,5 @@
1
- export declare function redactInsightText(value: unknown, limit: number): string;
1
+ export declare function redactInsightText(value: unknown, limit: number, options?: {
2
+ readonly memoryContributed?: boolean;
3
+ readonly chatId?: string;
4
+ }): string;
2
5
  export declare function toolNamesOnly(raw: unknown): string[];
@@ -1,7 +1,12 @@
1
+ import { didChatContributeMemory } from '../memory/injector.js';
1
2
  const SECRET = /(sk-[A-Za-z0-9_\-]{8,}|api[_-]?key\s*[:=]\s*\S+|bearer\s+[A-Za-z0-9._\-]{8,})/gi;
2
3
  const WIN_HOME = /[A-Za-z]:\\(?:Users|home)\\[^\\\s]+/gi;
3
4
  const UNIX_HOME = /\/(?:Users|home)\/[^/\s]+/g;
4
- export function redactInsightText(value, limit) {
5
+ export function redactInsightText(value, limit, options) {
6
+ if (options?.memoryContributed === true ||
7
+ (options?.chatId && didChatContributeMemory(options.chatId))) {
8
+ return '';
9
+ }
5
10
  if (typeof value !== 'string' || !value)
6
11
  return '';
7
12
  let text = value.replace(/\u0000/g, '');
@@ -1,5 +1,5 @@
1
1
  import { type HeldWriteLease } from './write-lease.js';
2
- export declare const HOST_SCHEMA_VERSION = 1;
2
+ export declare const HOST_SCHEMA_VERSION = 2;
3
3
  /** How long a starting host waits for another host to finish migrating. */
4
4
  export declare const OPEN_LOCK_WAIT_MS = 15000;
5
5
  /**
@@ -7,7 +7,7 @@
7
7
  import { randomUUID } from 'node:crypto';
8
8
  import path from 'node:path';
9
9
  import { acquireWriteLease, StoreAlreadyOwnedError, } from './write-lease.js';
10
- export const HOST_SCHEMA_VERSION = 1;
10
+ export const HOST_SCHEMA_VERSION = 2;
11
11
  /** How long a starting host waits for another host to finish migrating. */
12
12
  export const OPEN_LOCK_WAIT_MS = 15_000;
13
13
  /**
@@ -6,8 +6,10 @@ import type { UsageSummary } from './usage-summary.js';
6
6
  import type { ReliabilitySummary } from './reliability-summary.js';
7
7
  import type { WebSearchSettings } from './web-search-settings.js';
8
8
  import type { TenantScope } from './driver.js';
9
+ import type { Phase9ScopedStore } from './fde-types.js';
10
+ export type { ChatDeliverableRecord, ChatUiReceiptRecord, ChatUiSurfaceRecord, CredentialOwnerScope, MemoryDocumentRecord, MemoryEntryRecord, MemoryRefinementMetaRecord, MemoryScopeKind, PackCredentialRecord, PendingReconciliationRecord, Phase9ScopedStore, } from './fde-types.js';
9
11
  /** Explicit asynchronous storage API bound to one tenant and user. */
10
- export interface ScopedStore {
12
+ export interface ScopedStore extends Partial<Phase9ScopedStore> {
11
13
  readonly scope: TenantScope;
12
14
  listChats(page?: number, limit?: number): Promise<{
13
15
  chats: ChatSessionRecord[];
@@ -239,6 +239,26 @@ const PRESENTERS = {
239
239
  },
240
240
  },
241
241
  present_files: { card: 'generic', kind: 'other', title: () => '交付文件' },
242
+ ui_surface_render: {
243
+ card: 'generic',
244
+ kind: 'other',
245
+ title: (args) => clip(str(args, 'title'), 48) || '结构化工作台',
246
+ },
247
+ memory_search: {
248
+ card: 'search',
249
+ kind: 'search',
250
+ title: (args) => clip(str(args, 'query'), 48) || '搜索记忆',
251
+ },
252
+ memory_read: {
253
+ card: 'read',
254
+ kind: 'read',
255
+ title: (args) => clip(str(args, 'topic') || str(args, 'scope'), 48) || '读取记忆',
256
+ },
257
+ memory_propose: {
258
+ card: 'generic',
259
+ kind: 'edit',
260
+ title: (args) => clip(str(args, 'content'), 48) || '保存记忆',
261
+ },
242
262
  local_open_path: {
243
263
  card: 'generic',
244
264
  kind: 'other',
@@ -4,9 +4,10 @@ import type { McpServerRegistry } from './mcp-server-registry.js';
4
4
  import type { ProjectRegistry } from './project-registry.js';
5
5
  import type { TaskService } from './local-backend/task-service.js';
6
6
  import type { WorktreeService } from './local-backend/worktree-service.js';
7
- import type { ToolApprovalSpec, ToolContribution, ToolMode, ToolExposure } from './scenario/pack.js';
7
+ import type { OriginChannel, PackCredentialClient, Principal, ToolApprovalSpec, ToolContribution, ToolMode, ToolExposure } from './scenario/pack.js';
8
8
  export type { ToolMode, ToolExposure } from './scenario/pack.js';
9
9
  import { type AgentToolPolicy } from './local-backend/agent-capability.js';
10
+ import type { ScopedStore } from './storage/scoped-store.js';
10
11
  import { GoalStore } from './goal-store.js';
11
12
  import type { LoopPtyMonitor } from './local-backend/loop-pty-monitor.js';
12
13
  /** 已注册 MCP 服务的动态工具名前缀:`mcp__<serverKey>__<toolName>`。 */
@@ -61,6 +62,18 @@ export interface ToolExecContext {
61
62
  * (广告层不出 + 分发层拒绝)。缺省 = 不限制。
62
63
  */
63
64
  toolPolicy?: AgentToolPolicy | null;
65
+ /** Authoritative authenticated principal injected by the host router. */
66
+ principal?: Principal;
67
+ /** Originating entry channel for channel-specific safety gates. */
68
+ originChannel?: OriginChannel;
69
+ /** Host-managed credential broker client scoped to `principal`. */
70
+ credentials?: PackCredentialClient;
71
+ /** Optional scoped store override for multi-tenant request contexts. */
72
+ store?: ScopedStore;
73
+ /** True when executing inside a delegated subagent. */
74
+ isSubagent?: boolean;
75
+ /** True when executing inside a forked conversation. */
76
+ isFork?: boolean;
64
77
  }
65
78
  export interface ToolSchema {
66
79
  name: string;
@@ -71,6 +84,10 @@ export interface ToolSchema {
71
84
  exposure?: ToolExposure;
72
85
  /** 审批分组。缺省时 sidecar 用工具名做类别。 */
73
86
  approval?: ToolApprovalSpec;
87
+ /** 非幂等写工具标记(false = 执行中异常落入 outcome_unknown)。 */
88
+ idempotent?: boolean;
89
+ /** 签批等级('outward' = 强制逐次人类确认)。 */
90
+ checkpoint?: 'standard' | 'outward';
74
91
  }
75
92
  /** 审批类别:小写开头,最长 64,且不占用内置类别。 */
76
93
  export declare const APPROVAL_CATEGORY_PATTERN: RegExp;
@@ -166,7 +183,9 @@ export declare class ToolRouter {
166
183
  stopMonitoredLoop(chatId: string, loopId: string): boolean;
167
184
  /** 会话目标的持久化。缺省写到用户数据目录;测试注入临时文件。 */
168
185
  private goalStore;
186
+ private phase9Store;
169
187
  setGoalStore(store: GoalStore | null): void;
188
+ setPhase9Store(store: ScopedStore | null): void;
170
189
  /** 目标工具使用的存储;LocalBackendRouter 的续跑与目标路由共用同一实例。 */
171
190
  goals(): GoalStore;
172
191
  setWebTools(delegate: WebToolDelegate | null, names?: readonly string[]): void;
@@ -3,11 +3,15 @@ import path from 'node:path';
3
3
  import { buildProjectRootViolation, canonicalFencePath, expandFencePath, resolveFencePath, isPathWithinRoot, writableFenceRoots, writableFenceViolation, } from './local-executor.js';
4
4
  import { writeShellStdin } from './shell-session.js';
5
5
  import { mcpExecutor } from './mcp-executor.js';
6
+ import { LOCAL_DEFAULT_PRINCIPAL } from './auth/index.js';
7
+ import { RejectedBeforeEffectError, validateArgsAgainstJsonSchema, } from './sidecar/rejected-before-effect.js';
6
8
  import { rankTools, resolveMaxResults, TOOL_SEARCH_DEFAULT_MAX_RESULTS, } from './tool-search-rank.js';
7
9
  import { maybeAutoInstallWrittenSkill } from './local-backend/skill-install.js';
8
10
  import { filterToolsByPolicy, isToolAllowed, } from './local-backend/agent-capability.js';
9
11
  import { processViewImage } from './image-attachment.js';
10
12
  import { PRESENT_FILES_SCHEMA, PRESENT_FILES_TOOL_NAME, executePresentFiles, } from './present-files.js';
13
+ import { UI_SURFACE_RENDER_SCHEMA, UI_SURFACE_RENDER_TOOL_NAME, renderAndPersistUiSurface, } from './local-backend/ui-surface.js';
14
+ import { MEMORY_PROPOSE_TOOL_NAME, MEMORY_READ_TOOL_NAME, MEMORY_SEARCH_TOOL_NAME, MEMORY_TOOL_SCHEMAS, executeMemoryTool, } from './memory/tools.js';
11
15
  import { isHostToolCapabilityEnabled } from './host-tools.js';
12
16
  import { getResolvedHostTools } from './host-tools-runtime.js';
13
17
  import { GoalStore, MODEL_GOAL_ACTIONS } from './goal-store.js';
@@ -135,9 +139,13 @@ export class ToolRouter {
135
139
  }
136
140
  /** 会话目标的持久化。缺省写到用户数据目录;测试注入临时文件。 */
137
141
  goalStore = null;
142
+ phase9Store = null;
138
143
  setGoalStore(store) {
139
144
  this.goalStore = store;
140
145
  }
146
+ setPhase9Store(store) {
147
+ this.phase9Store = store;
148
+ }
141
149
  /** 目标工具使用的存储;LocalBackendRouter 的续跑与目标路由共用同一实例。 */
142
150
  goals() {
143
151
  if (!this.goalStore)
@@ -361,6 +369,8 @@ export class ToolRouter {
361
369
  },
362
370
  },
363
371
  PRESENT_FILES_SCHEMA,
372
+ UI_SURFACE_RENDER_SCHEMA,
373
+ ...MEMORY_TOOL_SCHEMAS,
364
374
  {
365
375
  name: 'local_open_path',
366
376
  description: 'Open local path or URL',
@@ -504,14 +514,19 @@ export class ToolRouter {
504
514
  // 名字不带族前缀,按名归族会漏过 plugins 能力开关,这里显式判定。
505
515
  ...(this.pluginToolsEnabled() ? this.pluginToolSchemas.values() : []),
506
516
  // ─── 场景包贡献的工具(0.3a 开槽) ─────────────────
507
- ...[...this.contributedTools.values()].map((c) => ({
508
- name: c.name,
509
- description: c.description,
510
- inputSchema: c.inputSchema,
511
- mode: c.mode,
512
- ...(c.exposure ? { exposure: c.exposure } : {}),
513
- ...(c.approval ? { approval: c.approval } : {}),
514
- })),
517
+ ...[...this.contributedTools.values()].map((c) => {
518
+ const effectiveIdempotent = c.idempotent ?? (c.mode === 'read' ? undefined : false);
519
+ return {
520
+ name: c.name,
521
+ description: c.description,
522
+ inputSchema: c.inputSchema,
523
+ mode: c.mode,
524
+ ...(c.exposure ? { exposure: c.exposure } : {}),
525
+ ...(c.approval ? { approval: c.approval } : {}),
526
+ ...(effectiveIdempotent !== undefined ? { idempotent: effectiveIdempotent } : {}),
527
+ ...(c.checkpoint ? { checkpoint: c.checkpoint } : {}),
528
+ };
529
+ }),
515
530
  ];
516
531
  }
517
532
  /**
@@ -984,10 +999,10 @@ export class ToolRouter {
984
999
  // 已经把被拒的工具藏了,但模型可能从历史或幻觉里捞出名字直调。
985
1000
  const toolPolicy = context?.toolPolicy ?? null;
986
1001
  if (toolPolicy && !isToolAllowed(toolPolicy, call.name)) {
987
- throw new Error(`工具 ${call.name} 被当前智能体的工具策略拒绝(智能体管理 → 工具权限)`);
1002
+ throw RejectedBeforeEffectError.create('policy_denied', `工具 ${call.name} 被当前智能体的工具策略拒绝(智能体管理 → 工具权限)`, false);
988
1003
  }
989
1004
  if (!isHostToolCapabilityEnabled(call.name, getResolvedHostTools())) {
990
- throw new Error(`工具 ${call.name} 未在本产品引入`);
1005
+ throw RejectedBeforeEffectError.create('capability_disabled', `工具 ${call.name} 未在本产品引入`, false);
991
1006
  }
992
1007
  if (call.name.startsWith(MCP_DYNAMIC_TOOL_PREFIX)) {
993
1008
  return await this.executeRegisteredMcpTool(call.name, args);
@@ -1071,7 +1086,46 @@ export class ToolRouter {
1071
1086
  return edited;
1072
1087
  }
1073
1088
  case PRESENT_FILES_TOOL_NAME:
1074
- return await executePresentFiles(args, projectRoot);
1089
+ return await executePresentFiles(args, projectRoot, {
1090
+ store: context?.store ?? this.phase9Store ?? undefined,
1091
+ chatId: context?.chatId,
1092
+ principal: context?.principal,
1093
+ });
1094
+ case UI_SURFACE_RENDER_TOOL_NAME: {
1095
+ const activeStore = context?.store ?? this.phase9Store;
1096
+ if (!activeStore || !context?.chatId) {
1097
+ return {
1098
+ success: false,
1099
+ error: 'ui_surface_render requires an active chat context.',
1100
+ };
1101
+ }
1102
+ const surface = await renderAndPersistUiSurface({
1103
+ store: activeStore,
1104
+ chatId: context.chatId,
1105
+ principal: context.principal,
1106
+ raw: args,
1107
+ });
1108
+ return {
1109
+ success: true,
1110
+ surface,
1111
+ };
1112
+ }
1113
+ case MEMORY_SEARCH_TOOL_NAME:
1114
+ case MEMORY_READ_TOOL_NAME:
1115
+ case MEMORY_PROPOSE_TOOL_NAME: {
1116
+ const activeStore = context?.store ?? this.phase9Store;
1117
+ if (!activeStore) {
1118
+ return { success: false, error: 'memory tools require an active store.', effect: 'none' };
1119
+ }
1120
+ return await executeMemoryTool(call.name, args, {
1121
+ store: activeStore,
1122
+ chatId: context?.chatId,
1123
+ workspaceId: projectRoot ?? undefined,
1124
+ principal: context?.principal,
1125
+ isSubagent: context?.isSubagent,
1126
+ isFork: context?.isFork,
1127
+ });
1128
+ }
1075
1129
  case 'local_open_path':
1076
1130
  return await this.localExecutor.openLocalTarget({
1077
1131
  target: String(args.target || ''),
@@ -1228,7 +1282,17 @@ export class ToolRouter {
1228
1282
  // 场景包贡献的工具在 default 分发:内置工具优先(注册时已拒重名)。
1229
1283
  const contributed = this.contributedTools.get(call.name);
1230
1284
  if (contributed) {
1231
- return await contributed.handler(args, context ?? {});
1285
+ validateArgsAgainstJsonSchema(call.name, contributed.inputSchema, args);
1286
+ const safePrincipal = Object.freeze({
1287
+ ...(context?.principal ?? LOCAL_DEFAULT_PRINCIPAL),
1288
+ });
1289
+ return await contributed.handler(args, {
1290
+ projectRoot: context?.projectRoot,
1291
+ chatId: context?.chatId,
1292
+ principal: safePrincipal,
1293
+ originChannel: context?.originChannel ?? 'web',
1294
+ ...(context?.credentials ? { credentials: context.credentials } : {}),
1295
+ });
1232
1296
  }
1233
1297
  if (this.pluginToolSchemas.has(call.name) && this.pluginToolInvoke) {
1234
1298
  if (!this.pluginToolsEnabled()) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steerable/agent-shell",
3
- "version": "0.12.8",
3
+ "version": "0.13.1",
4
4
  "description": "Steerable framework — product-neutral Node HostRuntime and headless HTTP server shared by Tauri desktop and browser deployments; scenario packs extend it through @steerable/pack-sdk.",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://steerableframework.com/",
@@ -53,10 +53,10 @@
53
53
  "jpeg-js": "^0.4.4",
54
54
  "node-pty": "^1.1.0",
55
55
  "pngjs": "^7.0.0",
56
- "@steerable/agent-harness": "0.12.8",
57
- "@steerable/agent-protocol": "0.12.8",
58
- "@steerable/agent-runtime": "0.12.8",
59
- "@steerable/pack-sdk": "0.12.8"
56
+ "@steerable/agent-harness": "0.13.1",
57
+ "@steerable/agent-protocol": "0.13.1",
58
+ "@steerable/agent-runtime": "0.13.1",
59
+ "@steerable/pack-sdk": "0.13.1"
60
60
  },
61
61
  "devDependencies": {
62
62
  "@types/better-sqlite3": "^7.6.13",