@cortex-agent/server 2026.6.22 → 2026.6.24
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/defaults/config/thread-templates.json +12 -6
- package/defaults/context/user/CORTEX.md +2 -2
- package/defaults/hooks/ask-user-question-hook.mjs +1 -0
- package/defaults/hooks/exit-plan-mode-hook.mjs +1 -0
- package/defaults/hooks/memory-ref-tracker.mjs +1 -0
- package/defaults/hooks/new-session-hook.mjs +1 -0
- package/defaults/hooks/post-task-hook.mjs +1 -0
- package/defaults/hooks/rules-loader.mjs +1 -0
- package/defaults/hooks/sensitive-file-edit.mjs +1 -0
- package/defaults/hooks/session-activity-tracker.mjs +1 -0
- package/defaults/hooks/task-status-check.mjs +1 -0
- package/defaults/hooks/tasks-yaml-guard.mjs +1 -0
- package/defaults/plugins/cortex-feishu/.claude-plugin/plugin.json +5 -0
- package/defaults/plugins/cortex-feishu/skills/feishu-doc/SKILL.md +163 -0
- package/defaults/plugins/cortex-feishu/skills/feishu-doc/scripts/ensure-lark-cli.sh +53 -0
- package/defaults/prompts/directives/coder-reviewer.md +6 -6
- package/defaults/prompts/directives/coder.md +14 -15
- package/dist/agent-adapter/claude/adapter-tui.d.ts +12 -0
- package/dist/agent-adapter/claude/adapter-tui.js +15 -0
- package/dist/agent-adapter/claude/adapter.js +6 -2
- package/dist/agent-adapter/claude/bg-task-tracker.d.ts +8 -0
- package/dist/agent-adapter/claude/bg-task-tracker.js +18 -5
- package/dist/core/gateway-generator.js +10 -1
- package/dist/core/locales/en.d.ts +6 -0
- package/dist/core/locales/slices/interactions.d.ts +6 -0
- package/dist/core/locales/slices/interactions.js +14 -0
- package/dist/core/status-format.d.ts +14 -0
- package/dist/core/status-format.js +23 -1
- package/dist/core/types/thread-types.d.ts +3 -0
- package/dist/domain/agents/facade.d.ts +13 -0
- package/dist/domain/agents/facade.js +24 -1
- package/dist/domain/mcp/feishu/index.js +5 -51
- package/dist/domain/mcp/feishu-server.js +3 -2
- package/dist/domain/memory/user-context.d.ts +6 -5
- package/dist/domain/memory/user-context.js +12 -7
- package/dist/domain/remote/client-hot-reload.d.ts +9 -2
- package/dist/domain/remote/client-hot-reload.js +77 -6
- package/dist/domain/scheduling/jobs/task-dispatch.js +1 -0
- package/dist/domain/sessions/session-hooks.d.ts +31 -1
- package/dist/domain/sessions/session-hooks.js +69 -17
- package/dist/domain/system/doctor.d.ts +63 -0
- package/dist/domain/system/doctor.js +362 -0
- package/dist/domain/tasks/system/task-cli.js +7 -4
- package/dist/domain/tasks/system/task-state.d.ts +10 -1
- package/dist/domain/tasks/system/task-state.js +31 -1
- package/dist/domain/threads/prompt-builder.d.ts +7 -4
- package/dist/domain/threads/prompt-builder.js +9 -8
- package/dist/domain/threads/runner.js +30 -7
- package/dist/entry/app.js +38 -14
- package/dist/entry/cli.js +10 -0
- package/dist/entry/doctor-cli.d.ts +12 -0
- package/dist/entry/doctor-cli.js +76 -0
- package/dist/hooks/ask-user-question-hook.mjs +1 -0
- package/dist/hooks/exit-plan-mode-hook.mjs +1 -0
- package/dist/hooks/memory-ref-tracker.mjs +1 -0
- package/dist/hooks/new-session-hook.mjs +1 -0
- package/dist/hooks/post-task-hook.mjs +1 -0
- package/dist/hooks/rules-loader.mjs +1 -0
- package/dist/hooks/sensitive-file-edit.mjs +1 -0
- package/dist/hooks/session-activity-tracker.mjs +1 -0
- package/dist/hooks/task-status-check.mjs +1 -0
- package/dist/hooks/tasks-yaml-guard.mjs +1 -0
- package/dist/orchestration/agent-runner.js +3 -2
- package/dist/orchestration/conversation-runner.js +4 -1
- package/dist/orchestration/lifecycle.d.ts +2 -1
- package/dist/orchestration/lifecycle.js +15 -1
- package/dist/orchestration/manager-qa.d.ts +3 -2
- package/dist/orchestration/manager-qa.js +17 -12
- package/dist/orchestration/resume-dispatcher.d.ts +5 -0
- package/dist/orchestration/resume-dispatcher.js +38 -22
- package/dist/orchestration/thread-callback.d.ts +7 -3
- package/dist/orchestration/thread-callback.js +39 -35
- package/dist/store/plugin-sync.d.ts +21 -0
- package/dist/store/plugin-sync.js +119 -0
- package/dist/store/version-migrations.d.ts +9 -0
- package/dist/store/version-migrations.js +100 -0
- package/dist/tui/App.js +11 -7
- package/dist/tui/components/Dashboard.js +26 -11
- package/dist/tui/components/InputBox.js +43 -4
- package/dist/tui/components/SidePanel.js +1 -1
- package/package.json +1 -1
- package/dist/domain/mcp/feishu/bitable.d.ts +0 -3
- package/dist/domain/mcp/feishu/bitable.js +0 -168
- package/dist/domain/mcp/feishu/blocks-to-text.d.ts +0 -19
- package/dist/domain/mcp/feishu/blocks-to-text.js +0 -43
- package/dist/domain/mcp/feishu/docx.d.ts +0 -3
- package/dist/domain/mcp/feishu/docx.js +0 -163
- package/dist/domain/mcp/feishu/drive.d.ts +0 -23
- package/dist/domain/mcp/feishu/drive.js +0 -66
- package/dist/domain/mcp/feishu/markdown-to-blocks.d.ts +0 -40
- package/dist/domain/mcp/feishu/markdown-to-blocks.js +0 -191
- package/dist/domain/mcp/feishu/sheets.d.ts +0 -3
- package/dist/domain/mcp/feishu/sheets.js +0 -119
- package/dist/domain/mcp/feishu/wiki.d.ts +0 -3
- package/dist/domain/mcp/feishu/wiki.js +0 -77
|
@@ -167,6 +167,12 @@ export declare const en: {
|
|
|
167
167
|
'modal.planFeedbackTitle': "Plan Feedback";
|
|
168
168
|
'modal.feedbackLabel': "Your feedback (Cortex will revise the plan)";
|
|
169
169
|
'modal.feedbackPlaceholder': "What should be changed?";
|
|
170
|
+
'subtask.fromTask': "Subtask #${taskId}";
|
|
171
|
+
'subtask.fromUnknown': "a subtask";
|
|
172
|
+
'subtask.escalateHeader': "[Subtask question — escalated to you] ${from} hit something unclear/contradictory while executing and has no manager above it, so it is checking with you:";
|
|
173
|
+
'subtask.questionLabel': "Question: ${question}";
|
|
174
|
+
'subtask.escalateReply': "Just reply in this channel — your next message will be returned to that subtask as the answer.";
|
|
175
|
+
'subtask.replyDelivered': "Your reply has been delivered to the subtask that asked.";
|
|
170
176
|
'schedule.help.title': "*Schedule commands:*";
|
|
171
177
|
'schedule.help.addInterval': "`!schedule add interval <duration> [--profile <name>] <message>` — repeat every duration (e.g. `30m`, `2h`, `1d`)";
|
|
172
178
|
'schedule.help.addDaily': "`!schedule add daily <HH:MM> [--profile <name>] <message>` — run every day at a fixed time (24-hour)";
|
|
@@ -43,5 +43,11 @@ export declare const interactionsEn: {
|
|
|
43
43
|
readonly 'modal.planFeedbackTitle': "Plan Feedback";
|
|
44
44
|
readonly 'modal.feedbackLabel': "Your feedback (Cortex will revise the plan)";
|
|
45
45
|
readonly 'modal.feedbackPlaceholder': "What should be changed?";
|
|
46
|
+
readonly 'subtask.fromTask': "Subtask #${taskId}";
|
|
47
|
+
readonly 'subtask.fromUnknown': "a subtask";
|
|
48
|
+
readonly 'subtask.escalateHeader': "[Subtask question — escalated to you] ${from} hit something unclear/contradictory while executing and has no manager above it, so it is checking with you:";
|
|
49
|
+
readonly 'subtask.questionLabel': "Question: ${question}";
|
|
50
|
+
readonly 'subtask.escalateReply': "Just reply in this channel — your next message will be returned to that subtask as the answer.";
|
|
51
|
+
readonly 'subtask.replyDelivered': "Your reply has been delivered to the subtask that asked.";
|
|
46
52
|
};
|
|
47
53
|
export declare const interactionsZh: Record<keyof typeof interactionsEn, string>;
|
|
@@ -50,6 +50,13 @@ export const interactionsEn = {
|
|
|
50
50
|
'modal.planFeedbackTitle': 'Plan Feedback',
|
|
51
51
|
'modal.feedbackLabel': 'Your feedback (Cortex will revise the plan)',
|
|
52
52
|
'modal.feedbackPlaceholder': 'What should be changed?',
|
|
53
|
+
// --- manager-qa.ts (subtask escalated to a human at the top of the tree) ---
|
|
54
|
+
'subtask.fromTask': 'Subtask #${taskId}',
|
|
55
|
+
'subtask.fromUnknown': 'a subtask',
|
|
56
|
+
'subtask.escalateHeader': '[Subtask question — escalated to you] ${from} hit something unclear/contradictory while executing and has no manager above it, so it is checking with you:',
|
|
57
|
+
'subtask.questionLabel': 'Question: ${question}',
|
|
58
|
+
'subtask.escalateReply': 'Just reply in this channel — your next message will be returned to that subtask as the answer.',
|
|
59
|
+
'subtask.replyDelivered': 'Your reply has been delivered to the subtask that asked.',
|
|
53
60
|
};
|
|
54
61
|
export const interactionsZh = {
|
|
55
62
|
// --- interaction-handlers.ts ---
|
|
@@ -99,4 +106,11 @@ export const interactionsZh = {
|
|
|
99
106
|
'modal.planFeedbackTitle': '计划反馈',
|
|
100
107
|
'modal.feedbackLabel': '你的反馈(Cortex 将修订计划)',
|
|
101
108
|
'modal.feedbackPlaceholder': '应该修改什么?',
|
|
109
|
+
// --- manager-qa.ts (subtask escalated to a human at the top of the tree) ---
|
|
110
|
+
'subtask.fromTask': '子任务 #${taskId}',
|
|
111
|
+
'subtask.fromUnknown': '一个子任务',
|
|
112
|
+
'subtask.escalateHeader': '[子任务提问 — 已升级到你] ${from} 在执行中遇到不清楚/矛盾之处,没有上级 manager,转而向你确认:',
|
|
113
|
+
'subtask.questionLabel': '问题: ${question}',
|
|
114
|
+
'subtask.escalateReply': '直接在本频道回复即可——你的下一条消息会作为答复返回给该子任务。',
|
|
115
|
+
'subtask.replyDelivered': '已把你的回复作为答复返回给提问的子任务。',
|
|
102
116
|
};
|
|
@@ -16,3 +16,17 @@ export declare function buildUserProcessingMessage({ startTime, elapsed_s, num_t
|
|
|
16
16
|
sessionName?: string | null;
|
|
17
17
|
sessionId?: string | null;
|
|
18
18
|
}): string;
|
|
19
|
+
/** Build the multi-agent thread step status line. When task info is present (task-dispatch
|
|
20
|
+
* threads carry taskProject/taskId/taskText in metadata) the line leads with the task identity
|
|
21
|
+
* — "[proj] <text…> · `id`" — so a glance tells you what is running; the short thread id is kept
|
|
22
|
+
* at the tail for thread-op debugging. Without task info it falls back to the thread-only form. */
|
|
23
|
+
export declare function buildThreadStatusMessage({ threadId, stepNumber, label, elapsedS, numTurns, taskProject, taskId, taskText }: {
|
|
24
|
+
threadId: string;
|
|
25
|
+
stepNumber: number;
|
|
26
|
+
label: string;
|
|
27
|
+
elapsedS: number;
|
|
28
|
+
numTurns?: number | null;
|
|
29
|
+
taskProject?: string | null;
|
|
30
|
+
taskId?: string | null;
|
|
31
|
+
taskText?: string | null;
|
|
32
|
+
}): string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// input: formatDurationCompact (core/utils)
|
|
2
|
-
// output:
|
|
2
|
+
// output: 5 pure formatting functions: computeElapsed / formatMetricsSuffix / buildSessionTag / buildUserProcessingMessage / buildThreadStatusMessage
|
|
3
3
|
// pos: zero-dependency pure functions in the core layer; the subset imported by domain-layer status-helpers
|
|
4
4
|
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
5
|
import { formatDurationCompact } from './utils.js';
|
|
@@ -31,3 +31,25 @@ export function buildUserProcessingMessage({ startTime, elapsed_s = null, num_tu
|
|
|
31
31
|
const turnsStr = num_turns != null ? ` | ${Icons.repeat} ${num_turns} turns` : '';
|
|
32
32
|
return `${Icons.processing} ${t('status.processing')} | ${sessionTag}${profileName || 'default'} | ${Icons.stopwatch} ${formatDurationCompact(elapsed || 0)}${turnsStr}`;
|
|
33
33
|
}
|
|
34
|
+
const THREAD_STATUS_TASK_TEXT_MAX = 60;
|
|
35
|
+
const THREAD_STATUS_THREAD_ID_LEN = 12;
|
|
36
|
+
/** Build the multi-agent thread step status line. When task info is present (task-dispatch
|
|
37
|
+
* threads carry taskProject/taskId/taskText in metadata) the line leads with the task identity
|
|
38
|
+
* — "[proj] <text…> · `id`" — so a glance tells you what is running; the short thread id is kept
|
|
39
|
+
* at the tail for thread-op debugging. Without task info it falls back to the thread-only form. */
|
|
40
|
+
export function buildThreadStatusMessage({ threadId, stepNumber, label, elapsedS, numTurns = null, taskProject = null, taskId = null, taskText = null }) {
|
|
41
|
+
const shortId = threadId.substring(0, THREAD_STATUS_THREAD_ID_LEN);
|
|
42
|
+
const turnsPart = numTurns != null ? ` (${numTurns} turns)` : '';
|
|
43
|
+
const stepPart = `Step ${stepNumber}: *${label}*${turnsPart}`;
|
|
44
|
+
const timePart = `${Icons.stopwatch} ${formatDurationCompact(elapsedS)}`;
|
|
45
|
+
if (taskId) {
|
|
46
|
+
const projPart = taskProject ? `[${taskProject}] ` : '';
|
|
47
|
+
const raw = (taskText ?? '').trim();
|
|
48
|
+
const text = raw.length > THREAD_STATUS_TASK_TEXT_MAX
|
|
49
|
+
? raw.slice(0, THREAD_STATUS_TASK_TEXT_MAX).trimEnd() + '…'
|
|
50
|
+
: raw;
|
|
51
|
+
const textPart = text ? `${text} ` : '';
|
|
52
|
+
return `${Icons.processing} ${projPart}${textPart}· \`${taskId}\` | ${stepPart} | ${shortId} | ${timePart}`;
|
|
53
|
+
}
|
|
54
|
+
return `${Icons.processing} Thread ${shortId} | ${stepPart} | ${timePart}`;
|
|
55
|
+
}
|
|
@@ -264,6 +264,9 @@ export interface ThreadMetadata {
|
|
|
264
264
|
* onEnd task-status-check hook on re-entry (extraHooks are not persisted). */
|
|
265
265
|
taskId?: string | null;
|
|
266
266
|
taskProject?: string | null;
|
|
267
|
+
/** Task text (TASKS.yaml `text`) at dispatch time, for the thread step status line so a glance
|
|
268
|
+
* shows what is running. Persisted because status updates outlive the in-memory selected task. */
|
|
269
|
+
taskText?: string | null;
|
|
267
270
|
/** Set when the thread was paused (status==='rate_limited') by an API rate limit, so the
|
|
268
271
|
* resume path and startup recovery can tell a rate-limit pause apart from a real failure. */
|
|
269
272
|
interruptedByRateLimit?: boolean;
|
|
@@ -58,6 +58,18 @@ export interface RunAgentOptions {
|
|
|
58
58
|
* `mode` name; no gateway path string leaks into profiles.json.
|
|
59
59
|
*/
|
|
60
60
|
export declare function buildPiGatewaySubPath(mode: string | null, provider: string): string | undefined;
|
|
61
|
+
/** Plugins that load only for sessions originating from a specific platform channel.
|
|
62
|
+
* Mirrors the channel-gated MCP loading (loadFeishuMcp = channel.startsWith('feishu:')):
|
|
63
|
+
* the cortex-feishu skill bundle is only relevant when the user is working inside Feishu,
|
|
64
|
+
* so it is stripped from non-Feishu sessions even when listed in an agent's pluginDirs. */
|
|
65
|
+
export declare const CHANNEL_SCOPED_PLUGINS: ReadonlyArray<{
|
|
66
|
+
plugin: string;
|
|
67
|
+
channelPrefix: string;
|
|
68
|
+
}>;
|
|
69
|
+
/** Drop channel-scoped plugin dirs whose channel prefix the current session does not match.
|
|
70
|
+
* Non-scoped plugins always pass through. Matched by the plugin dir's final path segment
|
|
71
|
+
* (basename) so substrings like `cortex-feishu-x` are not affected. */
|
|
72
|
+
export declare function filterChannelScopedPlugins(dirs: string[] | undefined, channel: string | undefined): string[] | undefined;
|
|
61
73
|
declare function buildSpawnConfig(options: RunAgentOptions, config: AgentConfig, anthropicBaseUrl: string | undefined): AgentSpawnConfig;
|
|
62
74
|
export declare function runWithAdapter(adapter: AgentAdapter, message: string, options: RunAgentOptions, config: AgentConfig, anthropicBaseUrl: string | undefined): AgentHandle;
|
|
63
75
|
export declare function runAgentOnce(message: string, options: RunAgentOptions, config: AgentConfig): AgentHandle;
|
|
@@ -68,6 +80,7 @@ export declare function allConfigsRateLimited(profileName: string | null): boole
|
|
|
68
80
|
export declare const _test: {
|
|
69
81
|
runWithAdapter: typeof runWithAdapter;
|
|
70
82
|
buildSpawnConfig: typeof buildSpawnConfig;
|
|
83
|
+
filterChannelScopedPlugins: typeof filterChannelScopedPlugins;
|
|
71
84
|
};
|
|
72
85
|
export { closeSession, closeSessionsByPrefix, closeAllSessions, _test as claudeTest, } from '../../agent-adapter/claude/adapter.js';
|
|
73
86
|
export { shutdownCodex, buildMcpBlock } from '../../agent-adapter/codex/adapter.js';
|
|
@@ -29,6 +29,28 @@ export function buildPiGatewaySubPath(mode, provider) {
|
|
|
29
29
|
return undefined;
|
|
30
30
|
return `/m/${mode}/${provider}`;
|
|
31
31
|
}
|
|
32
|
+
// --- Channel-scoped plugin gating ---
|
|
33
|
+
/** Plugins that load only for sessions originating from a specific platform channel.
|
|
34
|
+
* Mirrors the channel-gated MCP loading (loadFeishuMcp = channel.startsWith('feishu:')):
|
|
35
|
+
* the cortex-feishu skill bundle is only relevant when the user is working inside Feishu,
|
|
36
|
+
* so it is stripped from non-Feishu sessions even when listed in an agent's pluginDirs. */
|
|
37
|
+
export const CHANNEL_SCOPED_PLUGINS = [
|
|
38
|
+
{ plugin: 'cortex-feishu', channelPrefix: 'feishu:' },
|
|
39
|
+
];
|
|
40
|
+
/** Drop channel-scoped plugin dirs whose channel prefix the current session does not match.
|
|
41
|
+
* Non-scoped plugins always pass through. Matched by the plugin dir's final path segment
|
|
42
|
+
* (basename) so substrings like `cortex-feishu-x` are not affected. */
|
|
43
|
+
export function filterChannelScopedPlugins(dirs, channel) {
|
|
44
|
+
if (!dirs)
|
|
45
|
+
return dirs;
|
|
46
|
+
return dirs.filter((dir) => {
|
|
47
|
+
const base = dir.split('/').filter(Boolean).pop();
|
|
48
|
+
const rule = CHANNEL_SCOPED_PLUGINS.find((r) => r.plugin === base);
|
|
49
|
+
if (!rule)
|
|
50
|
+
return true;
|
|
51
|
+
return !!channel && channel.startsWith(rule.channelPrefix);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
32
54
|
// --- Adapter execution ---
|
|
33
55
|
function buildSpawnConfig(options, config, anthropicBaseUrl) {
|
|
34
56
|
// Pack the Cortex execution context only if at least one field is set, so adapters can
|
|
@@ -58,7 +80,7 @@ function buildSpawnConfig(options, config, anthropicBaseUrl) {
|
|
|
58
80
|
model: config.model,
|
|
59
81
|
systemPrompt: typeof options.systemPrompt === 'string' ? options.systemPrompt : undefined,
|
|
60
82
|
outputStyle: typeof options.outputStyle === 'string' ? options.outputStyle : undefined,
|
|
61
|
-
pluginDirs: Array.isArray(options.pluginDirs) ? options.pluginDirs : undefined,
|
|
83
|
+
pluginDirs: filterChannelScopedPlugins(Array.isArray(options.pluginDirs) ? options.pluginDirs : undefined, options.channel),
|
|
62
84
|
env: config.extraEnv && Object.keys(config.extraEnv).length > 0 ? config.extraEnv : undefined,
|
|
63
85
|
extraOption: config.extraOption && Object.keys(config.extraOption).length > 0 ? config.extraOption : undefined,
|
|
64
86
|
claudeBackend: config.claudeBackend,
|
|
@@ -300,6 +322,7 @@ export function allConfigsRateLimited(profileName) {
|
|
|
300
322
|
export const _test = {
|
|
301
323
|
runWithAdapter,
|
|
302
324
|
buildSpawnConfig,
|
|
325
|
+
filterChannelScopedPlugins,
|
|
303
326
|
};
|
|
304
327
|
// --- Bridge helper re-exports (replacing claude-bridge.ts / codex-bridge.ts) ---
|
|
305
328
|
export { closeSession, closeSessionsByPrefix, closeAllSessions, _test as claudeTest, } from '../../agent-adapter/claude/adapter.js';
|
|
@@ -1,61 +1,15 @@
|
|
|
1
|
-
// input: MCP SDK,
|
|
2
|
-
// output: registerFeishuTools —
|
|
3
|
-
// pos: Single entry the cortex-feishu MCP server calls to wire all Feishu tools
|
|
1
|
+
// input: MCP SDK, registerFileTools, FeishuToolDeps
|
|
2
|
+
// output: registerFeishuTools — wire the feishu_send_file tool onto a server
|
|
3
|
+
// pos: Single entry the cortex-feishu MCP server calls to wire all Feishu tools.
|
|
4
|
+
// Document/table/wiki tooling was removed in favor of the official lark-cli
|
|
5
|
+
// (see the feishu-doc skill); this MCP now only exposes file sending.
|
|
4
6
|
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
|
-
import { registerDocxTools } from './docx.js';
|
|
6
|
-
import { registerWikiTools } from './wiki.js';
|
|
7
|
-
import { registerBitableTools } from './bitable.js';
|
|
8
|
-
import { registerSheetsTools } from './sheets.js';
|
|
9
|
-
import { registerDriveTools } from './drive.js';
|
|
10
7
|
import { registerFileTools } from './file.js';
|
|
11
8
|
/** Tool names exposed by the cortex-feishu MCP server (kept in sync for verification). */
|
|
12
9
|
export const FEISHU_TOOL_NAMES = [
|
|
13
10
|
// file — send files to chats
|
|
14
11
|
'feishu_send_file',
|
|
15
|
-
// docx — cloud documents
|
|
16
|
-
'feishu_docx_create',
|
|
17
|
-
'feishu_docx_get_content',
|
|
18
|
-
'feishu_docx_list_blocks',
|
|
19
|
-
'feishu_docx_append',
|
|
20
|
-
'feishu_docx_insert',
|
|
21
|
-
'feishu_docx_update_block',
|
|
22
|
-
'feishu_docx_delete_blocks',
|
|
23
|
-
'feishu_docx_delete',
|
|
24
|
-
// wiki — knowledge base
|
|
25
|
-
'feishu_wiki_list_spaces',
|
|
26
|
-
'feishu_wiki_list_nodes',
|
|
27
|
-
'feishu_wiki_get_node',
|
|
28
|
-
'feishu_wiki_create_node',
|
|
29
|
-
'feishu_wiki_update_node_title',
|
|
30
|
-
// bitable — 多维表格
|
|
31
|
-
'feishu_bitable_create_app',
|
|
32
|
-
'feishu_bitable_delete_app',
|
|
33
|
-
'feishu_bitable_list_tables',
|
|
34
|
-
'feishu_bitable_create_table',
|
|
35
|
-
'feishu_bitable_delete_table',
|
|
36
|
-
'feishu_bitable_list_fields',
|
|
37
|
-
'feishu_bitable_create_field',
|
|
38
|
-
'feishu_bitable_list_records',
|
|
39
|
-
'feishu_bitable_create_records',
|
|
40
|
-
'feishu_bitable_update_records',
|
|
41
|
-
'feishu_bitable_delete_records',
|
|
42
|
-
// sheets — 电子表格
|
|
43
|
-
'feishu_sheets_create',
|
|
44
|
-
'feishu_sheets_delete',
|
|
45
|
-
'feishu_sheets_get',
|
|
46
|
-
'feishu_sheets_read_range',
|
|
47
|
-
'feishu_sheets_write_range',
|
|
48
|
-
'feishu_sheets_append_rows',
|
|
49
|
-
'feishu_sheets_add_sheet',
|
|
50
|
-
'feishu_sheets_delete_sheet',
|
|
51
|
-
// drive — sharing & permissions
|
|
52
|
-
'feishu_drive_set_link_share',
|
|
53
12
|
];
|
|
54
13
|
export function registerFeishuTools(server, deps) {
|
|
55
14
|
registerFileTools(server, deps);
|
|
56
|
-
registerDocxTools(server, deps);
|
|
57
|
-
registerWikiTools(server, deps);
|
|
58
|
-
registerBitableTools(server, deps);
|
|
59
|
-
registerSheetsTools(server, deps);
|
|
60
|
-
registerDriveTools(server, deps);
|
|
61
15
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// input: MCP SDK, feishu/ tool registration, lark client builder
|
|
2
|
-
// output: cortex-feishu MCP stdio server — Feishu
|
|
2
|
+
// output: cortex-feishu MCP stdio server — Feishu file sending (feishu_send_file).
|
|
3
|
+
// Document/table/wiki tooling moved to the official lark-cli (see feishu-doc skill).
|
|
3
4
|
// pos: Standalone MCP server (peer of core-server.ts & server.ts); loaded only for Feishu-originated
|
|
4
5
|
// sessions (channel carries the `feishu:` prefix) — Claude via mcp-config-feishu.json layering,
|
|
5
6
|
// PI via the mcp-bridge feishu handle. Not loaded for thread/core sessions.
|
|
@@ -20,7 +21,7 @@ registerFeishuTools(server, { client });
|
|
|
20
21
|
export const TOOL_NAMES = FEISHU_TOOL_NAMES;
|
|
21
22
|
export async function startServer() {
|
|
22
23
|
if (!client) {
|
|
23
|
-
log.warn('FEISHU_APP_ID / FEISHU_APP_SECRET not set —
|
|
24
|
+
log.warn('FEISHU_APP_ID / FEISHU_APP_SECRET not set — feishu_send_file will return a not-configured error');
|
|
24
25
|
}
|
|
25
26
|
const transport = new StdioServerTransport();
|
|
26
27
|
await server.connect(transport);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
/**
|
|
2
|
+
* The user profile for plain, thread-free conversation turns. Injected by default;
|
|
3
|
+
* set CORTEX_DISABLE_USER_CONTEXT=1 to opt out. Multi-agent thread steps deliberately
|
|
4
|
+
* do NOT inject this — only the direct conversation path calls it.
|
|
5
|
+
*/
|
|
6
|
+
export declare function loadUserContext(): string | null;
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
// input:
|
|
1
|
+
// input: CONTEXT_DIR, fs
|
|
2
2
|
// output: loadUserContext()
|
|
3
|
-
// pos: user profile injection — reads USER.md and injects
|
|
3
|
+
// pos: user profile injection — reads USER.md and injects into thread-free conversation
|
|
4
|
+
// turns only (buildConversationPrompt), and only on a session's FIRST turn (the caller
|
|
5
|
+
// gates via includeUserContext; session resume keeps it in history thereafter).
|
|
6
|
+
// Thread steps never carry the user profile.
|
|
4
7
|
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
8
|
import { readFileSync, statSync } from 'fs';
|
|
6
9
|
import * as path from 'path';
|
|
7
10
|
import { CONTEXT_DIR } from '../../core/utils.js';
|
|
8
11
|
const USER_MD_PATH = path.join(CONTEXT_DIR, 'user', 'USER.md');
|
|
9
|
-
const DIRECT_TEMPLATES = new Set(['direct', 'direct-web', 'direct-review']);
|
|
10
12
|
let cachedContent = null;
|
|
11
13
|
let cachedMtimeMs = 0;
|
|
12
14
|
function readUserMd() {
|
|
@@ -22,10 +24,13 @@ function readUserMd() {
|
|
|
22
24
|
return null;
|
|
23
25
|
}
|
|
24
26
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
/**
|
|
28
|
+
* The user profile for plain, thread-free conversation turns. Injected by default;
|
|
29
|
+
* set CORTEX_DISABLE_USER_CONTEXT=1 to opt out. Multi-agent thread steps deliberately
|
|
30
|
+
* do NOT inject this — only the direct conversation path calls it.
|
|
31
|
+
*/
|
|
32
|
+
export function loadUserContext() {
|
|
33
|
+
if (process.env.CORTEX_DISABLE_USER_CONTEXT === '1')
|
|
29
34
|
return null;
|
|
30
35
|
const content = readUserMd();
|
|
31
36
|
if (!content)
|
|
@@ -13,7 +13,14 @@ interface ClientUpdateResult {
|
|
|
13
13
|
devices: DeviceResult[];
|
|
14
14
|
duration: number;
|
|
15
15
|
}
|
|
16
|
+
interface LocalUpdateDeps {
|
|
17
|
+
getInstalledVersion: () => string | null;
|
|
18
|
+
kill: () => Promise<boolean>;
|
|
19
|
+
npmUpdate: () => Promise<string>;
|
|
20
|
+
restart: () => Promise<boolean>;
|
|
21
|
+
}
|
|
22
|
+
declare function updateClientReleaseLocal(device: string, latestVersion: string, deps: LocalUpdateDeps): Promise<DeviceResult>;
|
|
16
23
|
declare function checkAndUpdateClients(): Promise<ClientUpdateResult | null>;
|
|
17
24
|
declare function formatUpdateSlackMessage(result: ClientUpdateResult): string;
|
|
18
|
-
export { checkAndUpdateClients, formatUpdateSlackMessage };
|
|
19
|
-
export type { ClientUpdateResult, DeviceResult };
|
|
25
|
+
export { checkAndUpdateClients, formatUpdateSlackMessage, updateClientReleaseLocal };
|
|
26
|
+
export type { ClientUpdateResult, DeviceResult, LocalUpdateDeps };
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
// Client hot-reload — two modes:
|
|
2
2
|
// Dev mode (CORTEX_REPO set): build client from source, check tgz mtime,
|
|
3
3
|
// SCP to remotes + npm install -g + restart.
|
|
4
|
-
// Release mode (CORTEX_REPO unset): check npm registry vs
|
|
5
|
-
//
|
|
4
|
+
// Release mode (CORTEX_REPO unset): check npm registry vs installed version,
|
|
5
|
+
// npm update -g + restart. Covers remote devices
|
|
6
|
+
// (over SSH) AND the local same-machine client
|
|
7
|
+
// (local npm + process.kill + detached respawn).
|
|
6
8
|
import * as fs from 'fs';
|
|
7
9
|
import * as path from 'path';
|
|
8
|
-
import { execSync, execFile } from 'child_process';
|
|
10
|
+
import { execSync, execFile, spawn } from 'child_process';
|
|
9
11
|
import { getMachineRegistry } from '../tasks/dispatch-utils.js';
|
|
10
12
|
import { sshExec, clientPids, buildRemoteSpawnCommand } from './client-manager.js';
|
|
11
13
|
import { STORE_DIR } from '../../core/utils.js';
|
|
@@ -140,6 +142,30 @@ function getNpmRegistryVersion() {
|
|
|
140
142
|
return null;
|
|
141
143
|
}
|
|
142
144
|
}
|
|
145
|
+
function getLocalInstalledVersion() {
|
|
146
|
+
try {
|
|
147
|
+
const result = execSync('npm ls -g @cortex-agent/client --json 2>/dev/null || true', {
|
|
148
|
+
encoding: 'utf8',
|
|
149
|
+
timeout: 15000,
|
|
150
|
+
stdio: 'pipe',
|
|
151
|
+
}).trim();
|
|
152
|
+
const parsed = JSON.parse(result);
|
|
153
|
+
return parsed?.dependencies?.['@cortex-agent/client']?.version || null;
|
|
154
|
+
}
|
|
155
|
+
catch {
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
function npmUpdateLocal() {
|
|
160
|
+
return new Promise((resolve, reject) => {
|
|
161
|
+
execFile('npm', ['update', '-g', '@cortex-agent/client'], { timeout: 120000 }, (err, stdout, stderr) => {
|
|
162
|
+
if (err)
|
|
163
|
+
reject(new Error(`npm update error: ${err.message}\n${stderr}`));
|
|
164
|
+
else
|
|
165
|
+
resolve(stdout.trim());
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
}
|
|
143
169
|
async function getRemoteInstalledVersion(host) {
|
|
144
170
|
try {
|
|
145
171
|
const cmd = 'npm ls -g @cortex-agent/client --json 2>/dev/null || true';
|
|
@@ -183,6 +209,22 @@ async function killClientOnDevice(device, reg) {
|
|
|
183
209
|
}
|
|
184
210
|
async function restartClientOnDevice(device, reg) {
|
|
185
211
|
try {
|
|
212
|
+
if (!reg.ssh) {
|
|
213
|
+
// Local device: spawn a detached cortex-client (mirrors client-manager
|
|
214
|
+
// startRemoteClient local branch). PATH now resolves to the just-updated
|
|
215
|
+
// global binary. Env (incl. CORTEX_CLIENT_TOKEN) is inherited from the server.
|
|
216
|
+
const child = spawn('cortex-client', [], { detached: true, stdio: 'ignore' });
|
|
217
|
+
child.on('error', (err) => {
|
|
218
|
+
log.warn(`Local client respawn error on ${device}: ${err.message}`);
|
|
219
|
+
});
|
|
220
|
+
child.unref();
|
|
221
|
+
if (child.pid) {
|
|
222
|
+
clientPids.set(device, child.pid);
|
|
223
|
+
log.info(`Restarted local client on ${device} (PID ${child.pid})`);
|
|
224
|
+
return true;
|
|
225
|
+
}
|
|
226
|
+
return false;
|
|
227
|
+
}
|
|
186
228
|
if (reg.win) {
|
|
187
229
|
const wmiArg = 'cmd.exe /c cortex-client';
|
|
188
230
|
await sshExec(reg.ssh, `powershell -Command "(Invoke-WmiMethod -Class Win32_Process -Name Create -ArgumentList '${wmiArg}').ProcessId"`, 30000);
|
|
@@ -230,12 +272,41 @@ async function updateClientDev(device, reg, tgzPath, tgzName) {
|
|
|
230
272
|
}
|
|
231
273
|
return res;
|
|
232
274
|
}
|
|
275
|
+
async function updateClientReleaseLocal(device, latestVersion, deps) {
|
|
276
|
+
const res = { device, updated: false, restarted: false, oldVersion: '?', newVersion: latestVersion };
|
|
277
|
+
try {
|
|
278
|
+
const localVer = deps.getInstalledVersion();
|
|
279
|
+
res.oldVersion = localVer || '?';
|
|
280
|
+
if (localVer === latestVersion) {
|
|
281
|
+
log.info(` ${device}: already at latest (${latestVersion})`);
|
|
282
|
+
return res;
|
|
283
|
+
}
|
|
284
|
+
// 1. Kill the running local client (frees the device name for reconnect)
|
|
285
|
+
await deps.kill();
|
|
286
|
+
// 2. npm update -g locally
|
|
287
|
+
const updateOutput = await deps.npmUpdate();
|
|
288
|
+
res.updated = true;
|
|
289
|
+
log.info(` ${device}: local npm update output: ${updateOutput.slice(0, 200)}`);
|
|
290
|
+
// 3. Respawn the local client on the new binary
|
|
291
|
+
res.restarted = await deps.restart();
|
|
292
|
+
}
|
|
293
|
+
catch (err) {
|
|
294
|
+
res.error = err.message;
|
|
295
|
+
log.warn(` ${device}: local release update failed — ${res.error}`);
|
|
296
|
+
}
|
|
297
|
+
return res;
|
|
298
|
+
}
|
|
233
299
|
// --- Release mode: full per-device update ---
|
|
234
300
|
async function updateClientRelease(device, reg, latestVersion) {
|
|
235
301
|
const res = { device, updated: false, restarted: false, oldVersion: '?', newVersion: latestVersion };
|
|
236
302
|
if (!reg.ssh) {
|
|
237
|
-
|
|
238
|
-
return
|
|
303
|
+
// Local same-machine client: update via local npm + process.kill + detached respawn.
|
|
304
|
+
return updateClientReleaseLocal(device, latestVersion, {
|
|
305
|
+
getInstalledVersion: getLocalInstalledVersion,
|
|
306
|
+
kill: () => killClientOnDevice(device, reg),
|
|
307
|
+
npmUpdate: npmUpdateLocal,
|
|
308
|
+
restart: () => restartClientOnDevice(device, reg),
|
|
309
|
+
});
|
|
239
310
|
}
|
|
240
311
|
try {
|
|
241
312
|
// 1. Check remote installed version
|
|
@@ -371,4 +442,4 @@ function formatUpdateSlackMessage(result) {
|
|
|
371
442
|
}
|
|
372
443
|
return lines.join('\n');
|
|
373
444
|
}
|
|
374
|
-
export { checkAndUpdateClients, formatUpdateSlackMessage };
|
|
445
|
+
export { checkAndUpdateClients, formatUpdateSlackMessage, updateClientReleaseLocal };
|
|
@@ -125,6 +125,7 @@ async function executeDispatchTask({ selected, selectedTask, channel, scheduleTa
|
|
|
125
125
|
// DR-0014: persisted so a suspended parent's re-entry can rebuild the
|
|
126
126
|
// task-status-check onEnd hook (extraHooks are not persisted on ThreadRecord).
|
|
127
127
|
taskId: selectedTask.id ?? null, taskProject: selectedTask.project ?? null,
|
|
128
|
+
taskText: selectedTask.text ?? null,
|
|
128
129
|
resumeDest: 'project-report',
|
|
129
130
|
},
|
|
130
131
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { PlatformAdapter, OutputStream } from '../../platform/index.js';
|
|
2
|
+
import { runAgent } from '../agents/index.js';
|
|
2
3
|
export interface SessionHookConfig {
|
|
3
4
|
command: string;
|
|
4
5
|
args?: string[];
|
|
@@ -38,9 +39,38 @@ export interface SessionHookFormat {
|
|
|
38
39
|
export interface SessionHookInject {
|
|
39
40
|
targetSessionId: string;
|
|
40
41
|
profileName: string | null;
|
|
42
|
+
/** Session-pool key for the injected turn.
|
|
43
|
+
* - onNew: an ISOLATED key (onNewInjectSessionKey(channel)) so resuming the old session for
|
|
44
|
+
* the pre-close turn never collides with the channel's live pool slot — see the race below.
|
|
45
|
+
* - onMessageEnd: the channel itself, because the injection continues the live conversation. */
|
|
46
|
+
sessionKey: string;
|
|
41
47
|
/** Forwarded to runAgent as `trigger`, useful for telemetry / cost grouping. */
|
|
42
48
|
trigger?: string;
|
|
43
49
|
}
|
|
50
|
+
/** Pool key for the onNew hook's injected "pre-close" turn.
|
|
51
|
+
*
|
|
52
|
+
* MUST be distinct from the channel's live session-pool slot (which is keyed by the channel
|
|
53
|
+
* itself, see ClaudeAdapter / facade `sessionKey: options.channel`). Race it guards against:
|
|
54
|
+
* `!new` fires this hook fire-and-forget, then synchronously closeSession(channel) +
|
|
55
|
+
* resetChannelSession(channel). The hook's memory-write subprocess finishes LATER and injects
|
|
56
|
+
* its stdout as a final turn that RESUMES the old session. If that turn used `channel` as its
|
|
57
|
+
* pool key it would re-create (resurrect) a live session under the channel slot AFTER the reset
|
|
58
|
+
* — so the next message of the brand-new conversation (also keyed by channel) would reuse the
|
|
59
|
+
* resurrected OLD session instead of starting fresh. Routing the pre-close turn to a dedicated
|
|
60
|
+
* key keeps it off the live slot; we close that key once the turn is done. */
|
|
61
|
+
export declare function onNewInjectSessionKey(channel: string): string;
|
|
62
|
+
/** Injected-turn dependencies — seam for unit tests (default binds the real runAgent + a
|
|
63
|
+
* backend-aware session close). */
|
|
64
|
+
export interface InjectDeps {
|
|
65
|
+
runAgent: typeof runAgent;
|
|
66
|
+
/** Close the pooled session created for the injected turn (by sessionKey). */
|
|
67
|
+
closeInjectedSession: (channel: string, sessionKey: string) => void | Promise<void>;
|
|
68
|
+
}
|
|
69
|
+
/** Inject hook stdout as a fresh agent turn against `inject.targetSessionId`, routed through
|
|
70
|
+
* `stream`. Runs on `inject.sessionKey`; for onNew that is an isolated key which we close
|
|
71
|
+
* afterwards (the resurrected old session must not linger on / collide with the channel slot).
|
|
72
|
+
* For onMessageEnd the key IS the channel (live conversation) and is left open. */
|
|
73
|
+
export declare function runHookInjection(output: string, spec: SessionHookSpec, stream: OutputStream, deps?: InjectDeps): Promise<void>;
|
|
44
74
|
export interface SessionHookSpec {
|
|
45
75
|
name: HookName;
|
|
46
76
|
ctx: SessionHookContext;
|
|
@@ -56,7 +86,7 @@ export interface SessionHookSpec {
|
|
|
56
86
|
* reply chain (no top-level leak).
|
|
57
87
|
* - onNew: pass a fresh stream anchored at the last assistant message's thread parent
|
|
58
88
|
* (resolved via resolveSessionThreadTs). */
|
|
59
|
-
export declare function runSessionHook(spec: SessionHookSpec, stream: OutputStream): Promise<void>;
|
|
89
|
+
export declare function runSessionHook(spec: SessionHookSpec, stream: OutputStream, deps?: InjectDeps): Promise<void>;
|
|
60
90
|
/** Resolve the profile name to use when injecting the onNew hook's stdout as a fresh
|
|
61
91
|
* agent turn. Priority order:
|
|
62
92
|
* 1. session-registry (per-session truth — correct for thread-spawned sessions whose
|