@steerable/agent-shell 0.12.7 → 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.
- package/dist/auth/credentials.d.ts +83 -0
- package/dist/auth/credentials.js +426 -0
- package/dist/auth/index.d.ts +33 -9
- package/dist/auth/index.js +85 -0
- package/dist/host/external-pack-loader.d.ts +40 -0
- package/dist/host/external-pack-loader.js +247 -0
- package/dist/host/http-routes.d.ts +6 -2
- package/dist/host/http-routes.js +5 -2
- package/dist/host/pack-assembly.d.ts +9 -1
- package/dist/host/runtime.js +54 -1
- package/dist/local-backend/coreloop-stream.d.ts +4 -0
- package/dist/local-backend/coreloop-stream.js +4 -0
- package/dist/local-backend/fact-chain.d.ts +38 -0
- package/dist/local-backend/fact-chain.js +145 -0
- package/dist/local-backend/router.d.ts +3 -1
- package/dist/local-backend/router.js +329 -35
- package/dist/local-backend/state-reconcile.d.ts +42 -0
- package/dist/local-backend/state-reconcile.js +81 -0
- package/dist/local-backend/title-refresh.d.ts +39 -0
- package/dist/local-backend/title-refresh.js +80 -0
- package/dist/local-backend/turn-security-context.d.ts +42 -0
- package/dist/local-backend/turn-security-context.js +62 -0
- package/dist/local-backend/ui-surface.d.ts +75 -0
- package/dist/local-backend/ui-surface.js +368 -0
- package/dist/local-executor.d.ts +3 -0
- package/dist/local-executor.js +40 -1
- package/dist/memory/authoring-candidates.d.ts +26 -0
- package/dist/memory/authoring-candidates.js +73 -0
- package/dist/memory/injector.d.ts +34 -0
- package/dist/memory/injector.js +111 -0
- package/dist/memory/routes.d.ts +16 -0
- package/dist/memory/routes.js +146 -0
- package/dist/memory/store.d.ts +176 -0
- package/dist/memory/store.js +623 -0
- package/dist/memory/tools.d.ts +83 -0
- package/dist/memory/tools.js +143 -0
- package/dist/present-files.d.ts +25 -1
- package/dist/present-files.js +170 -2
- package/dist/scenario/applications.d.ts +52 -0
- package/dist/scenario/applications.js +143 -0
- package/dist/scenario/pack.d.ts +1 -1
- package/dist/security/policy-digest.d.ts +28 -0
- package/dist/security/policy-digest.js +104 -0
- package/dist/server/http-server.js +23 -6
- package/dist/sidecar/boot.d.ts +1 -0
- package/dist/sidecar/boot.js +2 -0
- package/dist/sidecar/rejected-before-effect.d.ts +22 -0
- package/dist/sidecar/rejected-before-effect.js +63 -0
- package/dist/sidecar/reverse-approval.d.ts +2 -0
- package/dist/sidecar/reverse-approval.js +28 -5
- package/dist/sidecar/reverse-tools.d.ts +3 -0
- package/dist/sidecar/reverse-tools.js +129 -17
- package/dist/sidecar/types.d.ts +6 -0
- package/dist/storage/fde-fallback.d.ts +4 -0
- package/dist/storage/fde-fallback.js +354 -0
- package/dist/storage/fde-types.d.ts +215 -0
- package/dist/storage/fde-types.js +1 -0
- package/dist/storage/index.d.ts +113 -1
- package/dist/storage/index.js +797 -0
- package/dist/storage/insights-redact.d.ts +4 -1
- package/dist/storage/insights-redact.js +6 -1
- package/dist/storage/process-locks.d.ts +1 -1
- package/dist/storage/process-locks.js +1 -1
- package/dist/storage/scoped-store.d.ts +3 -1
- package/dist/tool-presentation.js +20 -0
- package/dist/tool-router.d.ts +20 -1
- package/dist/tool-router.js +76 -12
- package/package.json +5 -5
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model-facing memory tools (`memory_search`, `memory_read`, `memory_propose`)
|
|
3
|
+
* with hard Subagent / Fork write prohibition (Phase 9 R8-2 & R8-3).
|
|
4
|
+
*/
|
|
5
|
+
import { type Principal } from '../auth/index.js';
|
|
6
|
+
import type { ScopedStore } from '../storage/scoped-store.js';
|
|
7
|
+
export declare const MEMORY_SEARCH_TOOL_NAME = "memory_search";
|
|
8
|
+
export declare const MEMORY_READ_TOOL_NAME = "memory_read";
|
|
9
|
+
export declare const MEMORY_PROPOSE_TOOL_NAME = "memory_propose";
|
|
10
|
+
export declare const MEMORY_TOOL_SCHEMAS: ({
|
|
11
|
+
name: string;
|
|
12
|
+
description: string;
|
|
13
|
+
mode: "read";
|
|
14
|
+
inputSchema: {
|
|
15
|
+
type: string;
|
|
16
|
+
required: string[];
|
|
17
|
+
properties: {
|
|
18
|
+
query: {
|
|
19
|
+
type: string;
|
|
20
|
+
};
|
|
21
|
+
scope?: undefined;
|
|
22
|
+
topic?: undefined;
|
|
23
|
+
content?: undefined;
|
|
24
|
+
turnId?: undefined;
|
|
25
|
+
toolCallId?: undefined;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
} | {
|
|
29
|
+
name: string;
|
|
30
|
+
description: string;
|
|
31
|
+
mode: "read";
|
|
32
|
+
inputSchema: {
|
|
33
|
+
type: string;
|
|
34
|
+
properties: {
|
|
35
|
+
scope: {
|
|
36
|
+
type: string;
|
|
37
|
+
enum: string[];
|
|
38
|
+
};
|
|
39
|
+
topic: {
|
|
40
|
+
type: string;
|
|
41
|
+
};
|
|
42
|
+
query?: undefined;
|
|
43
|
+
content?: undefined;
|
|
44
|
+
turnId?: undefined;
|
|
45
|
+
toolCallId?: undefined;
|
|
46
|
+
};
|
|
47
|
+
required?: undefined;
|
|
48
|
+
};
|
|
49
|
+
} | {
|
|
50
|
+
name: string;
|
|
51
|
+
description: string;
|
|
52
|
+
mode: "local";
|
|
53
|
+
inputSchema: {
|
|
54
|
+
type: string;
|
|
55
|
+
required: string[];
|
|
56
|
+
properties: {
|
|
57
|
+
scope: {
|
|
58
|
+
type: string;
|
|
59
|
+
enum: string[];
|
|
60
|
+
};
|
|
61
|
+
content: {
|
|
62
|
+
type: string;
|
|
63
|
+
};
|
|
64
|
+
turnId: {
|
|
65
|
+
type: string;
|
|
66
|
+
};
|
|
67
|
+
toolCallId: {
|
|
68
|
+
type: string;
|
|
69
|
+
};
|
|
70
|
+
query?: undefined;
|
|
71
|
+
topic?: undefined;
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
})[];
|
|
75
|
+
export interface MemoryToolExecContext {
|
|
76
|
+
readonly store: ScopedStore;
|
|
77
|
+
readonly chatId?: string;
|
|
78
|
+
readonly workspaceId?: string;
|
|
79
|
+
readonly principal?: Principal;
|
|
80
|
+
readonly isSubagent?: boolean;
|
|
81
|
+
readonly isFork?: boolean;
|
|
82
|
+
}
|
|
83
|
+
export declare function executeMemoryTool(toolName: string, args: Record<string, unknown>, ctx: MemoryToolExecContext): Promise<unknown>;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model-facing memory tools (`memory_search`, `memory_read`, `memory_propose`)
|
|
3
|
+
* with hard Subagent / Fork write prohibition (Phase 9 R8-2 & R8-3).
|
|
4
|
+
*/
|
|
5
|
+
import { LOCAL_DEFAULT_PRINCIPAL } from '../auth/index.js';
|
|
6
|
+
import { recordMidSessionMemoryDelta } from './injector.js';
|
|
7
|
+
import { MemoryStore } from './store.js';
|
|
8
|
+
export const MEMORY_SEARCH_TOOL_NAME = 'memory_search';
|
|
9
|
+
export const MEMORY_READ_TOOL_NAME = 'memory_read';
|
|
10
|
+
export const MEMORY_PROPOSE_TOOL_NAME = 'memory_propose';
|
|
11
|
+
export const MEMORY_TOOL_SCHEMAS = [
|
|
12
|
+
{
|
|
13
|
+
name: MEMORY_SEARCH_TOOL_NAME,
|
|
14
|
+
description: 'Search user, workspace, and tenant memory notes by keyword.',
|
|
15
|
+
mode: 'read',
|
|
16
|
+
inputSchema: {
|
|
17
|
+
type: 'object',
|
|
18
|
+
required: ['query'],
|
|
19
|
+
properties: {
|
|
20
|
+
query: { type: 'string' },
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: MEMORY_READ_TOOL_NAME,
|
|
26
|
+
description: 'Read MEMORY.md or a specific topic note (`topics/<name>.md`) from memory.',
|
|
27
|
+
mode: 'read',
|
|
28
|
+
inputSchema: {
|
|
29
|
+
type: 'object',
|
|
30
|
+
properties: {
|
|
31
|
+
scope: { type: 'string', enum: ['user', 'workspace', 'tenant'] },
|
|
32
|
+
topic: { type: 'string' },
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: MEMORY_PROPOSE_TOOL_NAME,
|
|
38
|
+
description: 'Propose saving a durable preference or refinement paragraph into memory.',
|
|
39
|
+
mode: 'local',
|
|
40
|
+
inputSchema: {
|
|
41
|
+
type: 'object',
|
|
42
|
+
required: ['content'],
|
|
43
|
+
properties: {
|
|
44
|
+
scope: { type: 'string', enum: ['user', 'workspace', 'tenant'] },
|
|
45
|
+
content: { type: 'string' },
|
|
46
|
+
turnId: { type: 'string' },
|
|
47
|
+
toolCallId: { type: 'string' },
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
];
|
|
52
|
+
export async function executeMemoryTool(toolName, args, ctx) {
|
|
53
|
+
const memoryStore = new MemoryStore(ctx.store);
|
|
54
|
+
const principal = ctx.principal ?? LOCAL_DEFAULT_PRINCIPAL;
|
|
55
|
+
if (toolName === MEMORY_SEARCH_TOOL_NAME) {
|
|
56
|
+
const hits = await memoryStore.search({
|
|
57
|
+
query: String(args.query ?? ''),
|
|
58
|
+
workspaceId: ctx.workspaceId,
|
|
59
|
+
principal,
|
|
60
|
+
});
|
|
61
|
+
return { success: true, hits };
|
|
62
|
+
}
|
|
63
|
+
if (toolName === MEMORY_READ_TOOL_NAME) {
|
|
64
|
+
const scope = args.scope === 'tenant' || args.scope === 'workspace' ? args.scope : 'user';
|
|
65
|
+
const scopeId = scope === 'workspace'
|
|
66
|
+
? ctx.workspaceId || 'default'
|
|
67
|
+
: scope === 'tenant'
|
|
68
|
+
? principal.tenantId
|
|
69
|
+
: principal.id;
|
|
70
|
+
if (typeof args.topic === 'string' && args.topic.trim()) {
|
|
71
|
+
const content = await memoryStore.readTopic({
|
|
72
|
+
scope,
|
|
73
|
+
scopeId,
|
|
74
|
+
principal,
|
|
75
|
+
topicName: args.topic.trim(),
|
|
76
|
+
});
|
|
77
|
+
return content !== null
|
|
78
|
+
? { success: true, scope, topic: args.topic.trim(), content }
|
|
79
|
+
: { success: false, error: `Topic "${args.topic.trim()}" not found.` };
|
|
80
|
+
}
|
|
81
|
+
const doc = await memoryStore.readDocument({ scope, scopeId, principal });
|
|
82
|
+
return {
|
|
83
|
+
success: true,
|
|
84
|
+
scope,
|
|
85
|
+
contentMarkdown: doc.contentMarkdown,
|
|
86
|
+
topics: doc.topics,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
if (toolName === MEMORY_PROPOSE_TOOL_NAME) {
|
|
90
|
+
// Hard invariant (T-MEM-08): subagents & forked chats may read inherited snapshots, never write!
|
|
91
|
+
if (ctx.isSubagent || ctx.isFork) {
|
|
92
|
+
return {
|
|
93
|
+
success: false,
|
|
94
|
+
error: 'subagent_memory_write_forbidden',
|
|
95
|
+
effect: 'none',
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
const mode = await memoryStore.getPermissionMode();
|
|
99
|
+
if (mode === 'off') {
|
|
100
|
+
return {
|
|
101
|
+
success: false,
|
|
102
|
+
error: 'memory_disabled',
|
|
103
|
+
effect: 'none',
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
const scope = args.scope === 'tenant' || args.scope === 'workspace' ? args.scope : 'user';
|
|
107
|
+
const scopeId = scope === 'workspace'
|
|
108
|
+
? ctx.workspaceId || 'default'
|
|
109
|
+
: scope === 'tenant'
|
|
110
|
+
? principal.tenantId
|
|
111
|
+
: principal.id;
|
|
112
|
+
const content = String(args.content ?? '').trim();
|
|
113
|
+
if (!content) {
|
|
114
|
+
return { success: false, error: 'content is required', effect: 'none' };
|
|
115
|
+
}
|
|
116
|
+
const res = await memoryStore.proposeRefinement({
|
|
117
|
+
scope,
|
|
118
|
+
scopeId,
|
|
119
|
+
principal,
|
|
120
|
+
content,
|
|
121
|
+
evidence: {
|
|
122
|
+
chatId: ctx.chatId || 'local',
|
|
123
|
+
turnId: typeof args.turnId === 'string' && args.turnId ? args.turnId : 'turn_current',
|
|
124
|
+
...(typeof args.toolCallId === 'string' ? { toolCallId: args.toolCallId } : {}),
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
if (!res.accepted) {
|
|
128
|
+
return {
|
|
129
|
+
success: false,
|
|
130
|
+
reason: res.reason,
|
|
131
|
+
effect: 'none',
|
|
132
|
+
...(res.conflictDraft ? { conflictDraft: res.conflictDraft } : {}),
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
recordMidSessionMemoryDelta(ctx.chatId, `saved ${scope} paragraph ${res.meta.id}`);
|
|
136
|
+
return {
|
|
137
|
+
success: true,
|
|
138
|
+
event: mode === 'ask' ? 'memory_approval_requested' : 'memory_saved',
|
|
139
|
+
refinement: res.meta,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
return { success: false, error: `Unknown memory tool: ${toolName}` };
|
|
143
|
+
}
|
package/dist/present-files.d.ts
CHANGED
|
@@ -6,8 +6,12 @@
|
|
|
6
6
|
* 导出副本,所以由模型显式声明。工具只 stat 元数据、不读内容,也不复制
|
|
7
7
|
* 文件——用户打开的是源文件当前版本。
|
|
8
8
|
*/
|
|
9
|
+
import type { Principal } from '@steerable/pack-sdk';
|
|
9
10
|
import type { ArtifactPurpose } from './local-backend/turn-file-selection.js';
|
|
11
|
+
import type { ChatDeliverableRecord } from './storage/fde-types.js';
|
|
12
|
+
import type { ScopedStore } from './storage/scoped-store.js';
|
|
10
13
|
export declare const PRESENT_FILES_TOOL_NAME = "present_files";
|
|
14
|
+
export declare const DELIVERABLE_VERIFIER_TIMEOUT_MS = 15000;
|
|
11
15
|
export declare const PRESENT_FILES_SCHEMA: {
|
|
12
16
|
name: string;
|
|
13
17
|
description: string;
|
|
@@ -58,14 +62,34 @@ export interface PresentedFile {
|
|
|
58
62
|
export declare function resolvePresentedPath(raw: string, projectRoot: string | null, homeDir?: string): string | null;
|
|
59
63
|
/** 从工具参数里取出声明的文件(不校验存在性);形状不符的条目跳过。 */
|
|
60
64
|
export declare function readPresentedArgs(args: unknown, projectRoot: string | null, homeDir?: string): PresentedFile[];
|
|
65
|
+
export interface PresentFilesVerifyContext {
|
|
66
|
+
readonly store?: ScopedStore;
|
|
67
|
+
readonly chatId?: string;
|
|
68
|
+
readonly principal?: Principal;
|
|
69
|
+
readonly messageId?: string | null;
|
|
70
|
+
readonly executedActions?: readonly {
|
|
71
|
+
readonly id?: string;
|
|
72
|
+
readonly tool: string;
|
|
73
|
+
readonly arguments: Record<string, unknown>;
|
|
74
|
+
readonly success: boolean;
|
|
75
|
+
}[];
|
|
76
|
+
readonly verifierTimeoutMs?: number;
|
|
77
|
+
}
|
|
61
78
|
/**
|
|
62
79
|
* 执行 `present_files`:每个路径必须是已存在的普通文件。任一路径不合格时
|
|
63
80
|
* 整次调用失败并逐个说明原因,模型可以修正后重试。
|
|
81
|
+
*
|
|
82
|
+
* 当 `purpose === 'output'` 时执行匹配的 `DeliverableVerifier`(15s 硬超时):
|
|
83
|
+
* - 存在 blocking 问题或校验器抛错/超时 → 返回 `{ success: false, needsFollowup: true, data: { blockers } }` 拦截未达标产物;
|
|
84
|
+
* - 通过后归档只读快照至 `<userDataDir>/deliverables/<chatId>/<sha256><ext>` 并记入 `chat_deliverables`。
|
|
64
85
|
*/
|
|
65
|
-
export declare function executePresentFiles(args: Record<string, unknown>, projectRoot: string | null): Promise<{
|
|
86
|
+
export declare function executePresentFiles(args: Record<string, unknown>, projectRoot: string | null, verifyContext?: PresentFilesVerifyContext): Promise<{
|
|
66
87
|
success: true;
|
|
67
88
|
presented: PresentedFile[];
|
|
89
|
+
deliverables?: ChatDeliverableRecord[];
|
|
68
90
|
} | {
|
|
69
91
|
success: false;
|
|
70
92
|
error: string;
|
|
93
|
+
needsFollowup?: boolean;
|
|
94
|
+
data?: Record<string, unknown>;
|
|
71
95
|
}>;
|
package/dist/present-files.js
CHANGED
|
@@ -6,10 +6,16 @@
|
|
|
6
6
|
* 导出副本,所以由模型显式声明。工具只 stat 元数据、不读内容,也不复制
|
|
7
7
|
* 文件——用户打开的是源文件当前版本。
|
|
8
8
|
*/
|
|
9
|
+
import { createHash } from 'node:crypto';
|
|
9
10
|
import fs from 'node:fs/promises';
|
|
10
11
|
import os from 'node:os';
|
|
11
12
|
import path from 'node:path';
|
|
13
|
+
import { LOCAL_DEFAULT_PRINCIPAL } from './auth/index.js';
|
|
14
|
+
import { getUserDataDir } from './runtime.js';
|
|
15
|
+
import { listDeliverableVerifiers } from './scenario/applications.js';
|
|
16
|
+
import { ensurePhase9Store } from './storage/fde-fallback.js';
|
|
12
17
|
export const PRESENT_FILES_TOOL_NAME = 'present_files';
|
|
18
|
+
export const DELIVERABLE_VERIFIER_TIMEOUT_MS = 15_000;
|
|
13
19
|
/** 单次调用最多声明的文件数;交付卡片过多就失去「最终结果」的意义。 */
|
|
14
20
|
const MAX_PRESENTED_FILES = 4;
|
|
15
21
|
export const PRESENT_FILES_SCHEMA = {
|
|
@@ -102,11 +108,53 @@ export function readPresentedArgs(args, projectRoot, homeDir) {
|
|
|
102
108
|
}
|
|
103
109
|
return out;
|
|
104
110
|
}
|
|
111
|
+
function guessMimeType(filePath) {
|
|
112
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
113
|
+
switch (ext) {
|
|
114
|
+
case '.pdf':
|
|
115
|
+
return 'application/pdf';
|
|
116
|
+
case '.docx':
|
|
117
|
+
return 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
|
|
118
|
+
case '.xlsx':
|
|
119
|
+
return 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
|
|
120
|
+
case '.md':
|
|
121
|
+
return 'text/markdown';
|
|
122
|
+
case '.json':
|
|
123
|
+
return 'application/json';
|
|
124
|
+
case '.csv':
|
|
125
|
+
return 'text/csv';
|
|
126
|
+
case '.txt':
|
|
127
|
+
return 'text/plain';
|
|
128
|
+
case '.png':
|
|
129
|
+
return 'image/png';
|
|
130
|
+
default:
|
|
131
|
+
return 'application/octet-stream';
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
async function runVerifierWithTimeout(promise, timeoutMs, verifierId) {
|
|
135
|
+
let timer;
|
|
136
|
+
try {
|
|
137
|
+
return await Promise.race([
|
|
138
|
+
promise,
|
|
139
|
+
new Promise((_, reject) => {
|
|
140
|
+
timer = setTimeout(() => reject(new Error(`DeliverableVerifier "${verifierId}" timed out after ${timeoutMs}ms`)), timeoutMs);
|
|
141
|
+
}),
|
|
142
|
+
]);
|
|
143
|
+
}
|
|
144
|
+
finally {
|
|
145
|
+
if (timer)
|
|
146
|
+
clearTimeout(timer);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
105
149
|
/**
|
|
106
150
|
* 执行 `present_files`:每个路径必须是已存在的普通文件。任一路径不合格时
|
|
107
151
|
* 整次调用失败并逐个说明原因,模型可以修正后重试。
|
|
152
|
+
*
|
|
153
|
+
* 当 `purpose === 'output'` 时执行匹配的 `DeliverableVerifier`(15s 硬超时):
|
|
154
|
+
* - 存在 blocking 问题或校验器抛错/超时 → 返回 `{ success: false, needsFollowup: true, data: { blockers } }` 拦截未达标产物;
|
|
155
|
+
* - 通过后归档只读快照至 `<userDataDir>/deliverables/<chatId>/<sha256><ext>` 并记入 `chat_deliverables`。
|
|
108
156
|
*/
|
|
109
|
-
export async function executePresentFiles(args, projectRoot) {
|
|
157
|
+
export async function executePresentFiles(args, projectRoot, verifyContext) {
|
|
110
158
|
const rawFiles = Array.isArray(args.files) ? args.files : [];
|
|
111
159
|
if (rawFiles.length === 0) {
|
|
112
160
|
return { success: false, error: 'files must list at least one file to present.' };
|
|
@@ -147,5 +195,125 @@ export async function executePresentFiles(args, projectRoot) {
|
|
|
147
195
|
if (problems.length > 0) {
|
|
148
196
|
return { success: false, error: `Cannot present: ${problems.join(' ')}` };
|
|
149
197
|
}
|
|
150
|
-
|
|
198
|
+
const verifiers = listDeliverableVerifiers();
|
|
199
|
+
const allBlockers = [];
|
|
200
|
+
const archivedDeliverables = [];
|
|
201
|
+
const timeoutMs = verifyContext?.verifierTimeoutMs ?? DELIVERABLE_VERIFIER_TIMEOUT_MS;
|
|
202
|
+
const principal = verifyContext?.principal ?? LOCAL_DEFAULT_PRINCIPAL;
|
|
203
|
+
const chatId = verifyContext?.chatId ?? 'local';
|
|
204
|
+
for (const file of presented) {
|
|
205
|
+
if (file.purpose !== 'output')
|
|
206
|
+
continue;
|
|
207
|
+
const ext = path.extname(file.path).toLowerCase();
|
|
208
|
+
const mimeType = guessMimeType(file.path);
|
|
209
|
+
const matching = verifiers.filter((v) => {
|
|
210
|
+
const extMatch = !v.matchExtensions ||
|
|
211
|
+
v.matchExtensions.length === 0 ||
|
|
212
|
+
v.matchExtensions.some((e) => e.toLowerCase() === ext);
|
|
213
|
+
const mimeMatch = !v.matchMimeTypes ||
|
|
214
|
+
v.matchMimeTypes.length === 0 ||
|
|
215
|
+
v.matchMimeTypes.includes(mimeType);
|
|
216
|
+
return extMatch && mimeMatch;
|
|
217
|
+
});
|
|
218
|
+
const collectedIssues = [];
|
|
219
|
+
const summaries = [];
|
|
220
|
+
let matchedVerifierId = null;
|
|
221
|
+
for (const verifier of matching) {
|
|
222
|
+
matchedVerifierId = verifier.id;
|
|
223
|
+
try {
|
|
224
|
+
const res = await runVerifierWithTimeout(verifier.verify({
|
|
225
|
+
filePath: file.path,
|
|
226
|
+
chatId,
|
|
227
|
+
principal,
|
|
228
|
+
executedActions: verifyContext?.executedActions ?? [],
|
|
229
|
+
}), timeoutMs, verifier.id);
|
|
230
|
+
if (res.summary)
|
|
231
|
+
summaries.push(res.summary);
|
|
232
|
+
for (const issue of res.issues) {
|
|
233
|
+
collectedIssues.push(issue);
|
|
234
|
+
if (issue.severity === 'blocking') {
|
|
235
|
+
allBlockers.push({ ...issue, filePath: file.path, verifierId: verifier.id });
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
if (res.status === 'failed' && !res.issues.some((i) => i.severity === 'blocking')) {
|
|
239
|
+
const synthetic = {
|
|
240
|
+
severity: 'blocking',
|
|
241
|
+
code: 'verification_failed',
|
|
242
|
+
message: res.summary || `Verifier "${verifier.id}" reported failed status`,
|
|
243
|
+
};
|
|
244
|
+
collectedIssues.push(synthetic);
|
|
245
|
+
allBlockers.push({ ...synthetic, filePath: file.path, verifierId: verifier.id });
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
catch (err) {
|
|
249
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
250
|
+
const blocker = {
|
|
251
|
+
severity: 'blocking',
|
|
252
|
+
code: 'verifier_exception',
|
|
253
|
+
message: msg,
|
|
254
|
+
};
|
|
255
|
+
collectedIssues.push(blocker);
|
|
256
|
+
allBlockers.push({ ...blocker, filePath: file.path, verifierId: verifier.id });
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
if (allBlockers.some((b) => b.filePath === file.path)) {
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
// Archive immutable snapshot when verifyContext.store is provided or verifiers ran
|
|
263
|
+
if (verifyContext?.store || matching.length > 0) {
|
|
264
|
+
const bytes = await fs.readFile(file.path);
|
|
265
|
+
const sha256 = createHash('sha256').update(bytes).digest('hex');
|
|
266
|
+
const archiveDir = path.join(getUserDataDir(), 'deliverables', chatId);
|
|
267
|
+
await fs.mkdir(archiveDir, { recursive: true });
|
|
268
|
+
const snapshotPath = path.join(archiveDir, `${sha256}${ext}`);
|
|
269
|
+
try {
|
|
270
|
+
await fs.stat(snapshotPath);
|
|
271
|
+
}
|
|
272
|
+
catch {
|
|
273
|
+
await fs.writeFile(snapshotPath, bytes, { mode: 0o444 });
|
|
274
|
+
}
|
|
275
|
+
if (verifyContext?.store) {
|
|
276
|
+
const hasWarnings = collectedIssues.some((i) => i.severity === 'warning');
|
|
277
|
+
const verificationStatus = matching.length === 0
|
|
278
|
+
? 'unverified'
|
|
279
|
+
: hasWarnings
|
|
280
|
+
? 'warnings'
|
|
281
|
+
: 'verified';
|
|
282
|
+
const saved = await ensurePhase9Store(verifyContext.store).saveChatDeliverable({
|
|
283
|
+
chatId,
|
|
284
|
+
messageId: verifyContext.messageId ?? null,
|
|
285
|
+
filePath: file.path,
|
|
286
|
+
fileName: path.basename(file.path),
|
|
287
|
+
mimeType,
|
|
288
|
+
sizeBytes: bytes.byteLength,
|
|
289
|
+
sha256,
|
|
290
|
+
verificationStatus,
|
|
291
|
+
verifierId: matchedVerifierId,
|
|
292
|
+
issues: collectedIssues,
|
|
293
|
+
summary: summaries.length > 0 ? summaries.join('; ') : null,
|
|
294
|
+
reportPath: snapshotPath,
|
|
295
|
+
});
|
|
296
|
+
archivedDeliverables.push(saved);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
if (allBlockers.length > 0) {
|
|
301
|
+
const summaryText = allBlockers
|
|
302
|
+
.map((b) => `[${b.code}] ${path.basename(b.filePath)}: ${b.message}`)
|
|
303
|
+
.join('; ');
|
|
304
|
+
return {
|
|
305
|
+
success: false,
|
|
306
|
+
error: `deliverable_verification_failed: ${summaryText}`,
|
|
307
|
+
needsFollowup: true,
|
|
308
|
+
data: {
|
|
309
|
+
blockers: allBlockers,
|
|
310
|
+
blockingCount: allBlockers.length,
|
|
311
|
+
},
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
return {
|
|
315
|
+
success: true,
|
|
316
|
+
presented,
|
|
317
|
+
...(archivedDeliverables.length > 0 ? { deliverables: archivedDeliverables } : {}),
|
|
318
|
+
};
|
|
151
319
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Three-layer capability decoupling registries (R3) & DeliverableVerifier /
|
|
3
|
+
* PackDataSource registries (R1, R5):
|
|
4
|
+
* Layer 1 (Capability Pack): tools, dataSources, deliverableVerifiers
|
|
5
|
+
* Layer 2 (Agent Profile): agentProfiles (role prompt, tool allowlist, skills)
|
|
6
|
+
* Layer 3 (Application): applications (default profile, workbench tabs, nav visibility)
|
|
7
|
+
*
|
|
8
|
+
* Includes Safe Recovery Mode (`safeMode: true` via `/?safe=1`) and one-step
|
|
9
|
+
* reset (`resetActiveApplication`) so a misconfigured ApplicationManifest can
|
|
10
|
+
* never brick the host UI.
|
|
11
|
+
*/
|
|
12
|
+
import type { AgentProfileSpec, ApplicationManifest, DeliverableVerifier, PackDataSource } from '@steerable/pack-sdk';
|
|
13
|
+
import type { ScopedStore } from '../storage/scoped-store.js';
|
|
14
|
+
export declare const ACTIVE_APPLICATION_SETTING_KEY = "active_application_id";
|
|
15
|
+
export declare const DEFAULT_APPLICATION_ID = "default";
|
|
16
|
+
export declare function registerPackDataSources(packId: string, items: readonly PackDataSource[]): void;
|
|
17
|
+
export declare function getRegisteredDataSource(sourceId: string): PackDataSource | null;
|
|
18
|
+
export declare function listRegisteredDataSources(): PackDataSource[];
|
|
19
|
+
export declare function registerAgentProfiles(packId: string, items: readonly AgentProfileSpec[]): void;
|
|
20
|
+
export declare function getRegisteredAgentProfile(profileId: string): AgentProfileSpec | null;
|
|
21
|
+
export declare function listRegisteredAgentProfiles(): AgentProfileSpec[];
|
|
22
|
+
export declare function registerApplications(packId: string, items: readonly ApplicationManifest[]): void;
|
|
23
|
+
export declare function getRegisteredApplication(appId: string): ApplicationManifest | null;
|
|
24
|
+
export declare function listRegisteredApplications(): ApplicationManifest[];
|
|
25
|
+
export declare function registerDeliverableVerifiers(packId: string, items: readonly DeliverableVerifier[]): void;
|
|
26
|
+
export declare function listDeliverableVerifiers(): DeliverableVerifier[];
|
|
27
|
+
export declare function resetPhase9PackRegistries(): void;
|
|
28
|
+
export interface ResolvedApplicationShell {
|
|
29
|
+
readonly id: string;
|
|
30
|
+
readonly title: Readonly<Record<string, string>>;
|
|
31
|
+
readonly defaultAgentProfileId: string;
|
|
32
|
+
readonly allowedPackIds: readonly string[];
|
|
33
|
+
readonly defaultWorkbenchTabs: readonly ('preview' | 'workbench' | 'terminal' | 'fact_chain')[];
|
|
34
|
+
readonly hiddenNavItems: readonly ('skills' | 'mcp' | 'agents' | 'terminal')[];
|
|
35
|
+
readonly safeMode: boolean;
|
|
36
|
+
readonly customApplicationBypassed: boolean;
|
|
37
|
+
}
|
|
38
|
+
export declare function buildDefaultApplicationShell(safeMode?: boolean): ResolvedApplicationShell;
|
|
39
|
+
/**
|
|
40
|
+
* Resolves the active application shell for the current user/tenant.
|
|
41
|
+
*
|
|
42
|
+
* When `safeMode === true` (triggered by `/?safe=1`), any custom
|
|
43
|
+
* ApplicationManifest navigation hiding or workbench restrictions are bypassed
|
|
44
|
+
* so operators can always recover settings, skills, MCP, and agent management.
|
|
45
|
+
*/
|
|
46
|
+
export declare function resolveActiveApplication(store: ScopedStore, options?: {
|
|
47
|
+
safeMode?: boolean;
|
|
48
|
+
}): Promise<ResolvedApplicationShell>;
|
|
49
|
+
/** Switches the active application id (or `'default'`). */
|
|
50
|
+
export declare function setActiveApplication(store: ScopedStore, applicationId: string): Promise<ResolvedApplicationShell>;
|
|
51
|
+
/** Resets the active application back to the built-in default shell (`steerable-cli app reset`). */
|
|
52
|
+
export declare function resetActiveApplication(store: ScopedStore): Promise<ResolvedApplicationShell>;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { getBrand } from '../brand.js';
|
|
2
|
+
import { ensurePhase9Store } from '../storage/fde-fallback.js';
|
|
3
|
+
export const ACTIVE_APPLICATION_SETTING_KEY = 'active_application_id';
|
|
4
|
+
export const DEFAULT_APPLICATION_ID = 'default';
|
|
5
|
+
const dataSources = new Map();
|
|
6
|
+
const agentProfiles = new Map();
|
|
7
|
+
const applications = new Map();
|
|
8
|
+
const deliverableVerifiers = new Map();
|
|
9
|
+
export function registerPackDataSources(packId, items) {
|
|
10
|
+
for (const item of items) {
|
|
11
|
+
if (!item.id.trim()) {
|
|
12
|
+
throw new Error(`[packs] dataSource in pack "${packId}" has empty id`);
|
|
13
|
+
}
|
|
14
|
+
if (dataSources.has(item.id)) {
|
|
15
|
+
throw new Error(`[packs] duplicate dataSource id "${item.id}" from pack "${packId}"`);
|
|
16
|
+
}
|
|
17
|
+
dataSources.set(item.id, item);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export function getRegisteredDataSource(sourceId) {
|
|
21
|
+
return dataSources.get(sourceId) ?? null;
|
|
22
|
+
}
|
|
23
|
+
export function listRegisteredDataSources() {
|
|
24
|
+
return [...dataSources.values()];
|
|
25
|
+
}
|
|
26
|
+
export function registerAgentProfiles(packId, items) {
|
|
27
|
+
for (const item of items) {
|
|
28
|
+
if (!item.id.trim()) {
|
|
29
|
+
throw new Error(`[packs] agentProfile in pack "${packId}" has empty id`);
|
|
30
|
+
}
|
|
31
|
+
if (agentProfiles.has(item.id)) {
|
|
32
|
+
throw new Error(`[packs] duplicate agentProfile id "${item.id}" from pack "${packId}"`);
|
|
33
|
+
}
|
|
34
|
+
agentProfiles.set(item.id, item);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export function getRegisteredAgentProfile(profileId) {
|
|
38
|
+
return agentProfiles.get(profileId) ?? null;
|
|
39
|
+
}
|
|
40
|
+
export function listRegisteredAgentProfiles() {
|
|
41
|
+
return [...agentProfiles.values()];
|
|
42
|
+
}
|
|
43
|
+
export function registerApplications(packId, items) {
|
|
44
|
+
for (const item of items) {
|
|
45
|
+
if (!item.id.trim() || item.id === DEFAULT_APPLICATION_ID) {
|
|
46
|
+
throw new Error(`[packs] invalid application id "${item.id}" in pack "${packId}" ("default" is reserved)`);
|
|
47
|
+
}
|
|
48
|
+
if (applications.has(item.id)) {
|
|
49
|
+
throw new Error(`[packs] duplicate application id "${item.id}" from pack "${packId}"`);
|
|
50
|
+
}
|
|
51
|
+
applications.set(item.id, item);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export function getRegisteredApplication(appId) {
|
|
55
|
+
return applications.get(appId) ?? null;
|
|
56
|
+
}
|
|
57
|
+
export function listRegisteredApplications() {
|
|
58
|
+
return [...applications.values()];
|
|
59
|
+
}
|
|
60
|
+
export function registerDeliverableVerifiers(packId, items) {
|
|
61
|
+
for (const item of items) {
|
|
62
|
+
if (!item.id.trim()) {
|
|
63
|
+
throw new Error(`[packs] deliverableVerifier in pack "${packId}" has empty id`);
|
|
64
|
+
}
|
|
65
|
+
if (deliverableVerifiers.has(item.id)) {
|
|
66
|
+
throw new Error(`[packs] duplicate deliverableVerifier id "${item.id}" from pack "${packId}"`);
|
|
67
|
+
}
|
|
68
|
+
deliverableVerifiers.set(item.id, item);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
export function listDeliverableVerifiers() {
|
|
72
|
+
return [...deliverableVerifiers.values()];
|
|
73
|
+
}
|
|
74
|
+
export function resetPhase9PackRegistries() {
|
|
75
|
+
dataSources.clear();
|
|
76
|
+
agentProfiles.clear();
|
|
77
|
+
applications.clear();
|
|
78
|
+
deliverableVerifiers.clear();
|
|
79
|
+
}
|
|
80
|
+
export function buildDefaultApplicationShell(safeMode = false) {
|
|
81
|
+
const brand = getBrand();
|
|
82
|
+
return {
|
|
83
|
+
id: DEFAULT_APPLICATION_ID,
|
|
84
|
+
title: { en: brand.displayName, zh: brand.displayName },
|
|
85
|
+
defaultAgentProfileId: brand.defaultAgentId,
|
|
86
|
+
allowedPackIds: [],
|
|
87
|
+
defaultWorkbenchTabs: ['preview', 'workbench', 'terminal', 'fact_chain'],
|
|
88
|
+
hiddenNavItems: [],
|
|
89
|
+
safeMode,
|
|
90
|
+
customApplicationBypassed: false,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Resolves the active application shell for the current user/tenant.
|
|
95
|
+
*
|
|
96
|
+
* When `safeMode === true` (triggered by `/?safe=1`), any custom
|
|
97
|
+
* ApplicationManifest navigation hiding or workbench restrictions are bypassed
|
|
98
|
+
* so operators can always recover settings, skills, MCP, and agent management.
|
|
99
|
+
*/
|
|
100
|
+
export async function resolveActiveApplication(store, options) {
|
|
101
|
+
const safeMode = Boolean(options?.safeMode);
|
|
102
|
+
const p9 = ensurePhase9Store(store);
|
|
103
|
+
const savedId = await p9.getCustomSetting(ACTIVE_APPLICATION_SETTING_KEY);
|
|
104
|
+
const envActiveId = process.env.STEERABLE_ACTIVE_APP?.trim() || null;
|
|
105
|
+
const effectiveId = savedId ?? envActiveId;
|
|
106
|
+
const selected = !effectiveId || effectiveId === DEFAULT_APPLICATION_ID
|
|
107
|
+
? null
|
|
108
|
+
: applications.get(effectiveId) ?? null;
|
|
109
|
+
if (!selected) {
|
|
110
|
+
return buildDefaultApplicationShell(safeMode);
|
|
111
|
+
}
|
|
112
|
+
if (safeMode) {
|
|
113
|
+
return {
|
|
114
|
+
...buildDefaultApplicationShell(true),
|
|
115
|
+
customApplicationBypassed: true,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
id: selected.id,
|
|
120
|
+
title: selected.title,
|
|
121
|
+
defaultAgentProfileId: selected.defaultAgentProfileId,
|
|
122
|
+
allowedPackIds: selected.allowedPackIds,
|
|
123
|
+
defaultWorkbenchTabs: selected.defaultWorkbenchTabs ?? ['preview', 'workbench', 'terminal'],
|
|
124
|
+
hiddenNavItems: selected.hiddenNavItems ?? [],
|
|
125
|
+
safeMode: false,
|
|
126
|
+
customApplicationBypassed: false,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
/** Switches the active application id (or `'default'`). */
|
|
130
|
+
export async function setActiveApplication(store, applicationId) {
|
|
131
|
+
if (applicationId !== DEFAULT_APPLICATION_ID && !applications.has(applicationId)) {
|
|
132
|
+
throw new Error(`Unknown application id: ${applicationId}`);
|
|
133
|
+
}
|
|
134
|
+
const p9 = ensurePhase9Store(store);
|
|
135
|
+
await p9.setCustomSetting(ACTIVE_APPLICATION_SETTING_KEY, applicationId);
|
|
136
|
+
return resolveActiveApplication(store);
|
|
137
|
+
}
|
|
138
|
+
/** Resets the active application back to the built-in default shell (`steerable-cli app reset`). */
|
|
139
|
+
export async function resetActiveApplication(store) {
|
|
140
|
+
const p9 = ensurePhase9Store(store);
|
|
141
|
+
await p9.setCustomSetting(ACTIVE_APPLICATION_SETTING_KEY, DEFAULT_APPLICATION_ID);
|
|
142
|
+
return buildDefaultApplicationShell(false);
|
|
143
|
+
}
|
package/dist/scenario/pack.d.ts
CHANGED
|
@@ -5,4 +5,4 @@
|
|
|
5
5
|
*
|
|
6
6
|
* 契约全文与设计约束见 packages/pack-sdk/types/index.d.ts 头注释。
|
|
7
7
|
*/
|
|
8
|
-
export type { ScenarioId, ToolMode, ToolExposure, PackToolContext, PackToolHandler, ToolApprovalSpec, ToolContribution, ServiceFactory, ServiceCreateContext, MigrationContribution, SkillContribution, AgentSeedIdentity, AgentSeed, HttpRouteContribution, HttpRouteRequest, MainContribution, ComponentRef, SettingsPanelContribution, RouteContribution, ChatSlotContribution, CardRendererContribution, RendererContribution, BrandSpec, PackagingSpec, CliCommandIO, CliCommandSpec, ScenarioPack, PackBackendAnyResponse, PackBackendBinaryBytesResponse, PackBackendBinaryFileResponse, PackBackendBinaryResponse, PackBackendRouteResponse, PackBackendRouteRequest, PackBackendRoute, PackTurnObserver, PackTurnHooks, } from '@steerable/pack-sdk';
|
|
8
|
+
export type { ScenarioId, OriginChannel, Principal, CredentialInjection, PackCredentialClient, PackDataSource, VerifierIssue, DeliverableVerificationResult, DeliverableVerifier, UiSurfaceSourceBinding, UiSurfaceActionSpec, UiSurfaceNodeSpec, UiSurfaceSpec, AgentProfileSpec, PublicAuthMethod, PublicBootstrapPayload, ApplicationManifest, ToolMode, ToolExposure, PackToolContext, PackToolHandler, ToolApprovalSpec, ToolContribution, ServiceFactory, ServiceCreateContext, MigrationContribution, SkillContribution, AgentSeedIdentity, AgentSeed, HttpRouteContribution, HttpRouteRequest, MainContribution, ComponentRef, SettingsPanelContribution, RouteContribution, ChatSlotContribution, CardRendererContribution, RendererContribution, BrandSpec, PackagingSpec, CliCommandIO, CliCommandSpec, ScenarioPack, PackBackendAnyResponse, PackBackendBinaryBytesResponse, PackBackendBinaryFileResponse, PackBackendBinaryResponse, PackBackendRouteResponse, PackBackendRouteRequest, PackBackendRoute, PackTurnObserver, PackTurnHooks, } from '@steerable/pack-sdk';
|