agent-things 0.0.0-stage → 1.2.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/LICENSE +21 -0
- package/NOTICE +5 -0
- package/README.md +221 -2
- package/README.zh-CN.md +222 -0
- package/bin/agent-things.cjs +8 -0
- package/bin/antigravity-session-status.cjs +96 -0
- package/bin/claude-session-status.cjs +55 -0
- package/bin/codex-session-status.cjs +287 -0
- package/mods/agent-things-ui/.claude-plugin/plugin.json +12 -0
- package/mods/agent-things-ui/SKILL.md +10 -0
- package/mods/agent-things-ui/hooks/controls.js +112 -0
- package/mods/agent-things-ui/hooks/foundation.js +431 -0
- package/mods/agent-things-ui/hooks/hooks.json +1 -0
- package/mods/agent-things-ui/hooks/presentation.js +223 -0
- package/mods/agent-things-ui/hooks/progress.js +1 -0
- package/mods/agent-things-ui/hooks/register.js +382 -0
- package/native/bin/bridge +0 -0
- package/native/bin/bridge.json +20 -0
- package/native/session-status-bridge.swift +280 -0
- package/outputs/antigravity-session-status.js +2476 -0
- package/outputs/codex-session-status.js +1761 -0
- package/package.json +75 -4
- package/scripts/build-antigravity-bundle.cjs +35 -0
- package/scripts/build-codex-bundle.cjs +31 -0
- package/scripts/build-native-bridge.cjs +55 -0
- package/scripts/build-shared-ui.cjs +16 -0
- package/scripts/setup-antigravity-service.cjs +71 -0
- package/scripts/setup-claude-service.cjs +21 -0
- package/skills/agent-things/SKILL.en.md +95 -0
- package/skills/agent-things/SKILL.md +99 -0
- package/skills/codex/things/SKILL.en.md +10 -0
- package/skills/codex/things/SKILL.md +10 -0
- package/skills/things/SKILL.en.md +10 -0
- package/skills/things/SKILL.md +10 -0
- package/skills/things/checklist.en.md +91 -0
- package/skills/things/checklist.md +95 -0
- package/src/analysis-app-server.cjs +74 -0
- package/src/analysis-assets/output.en.schema.json +93 -0
- package/src/analysis-assets/output.schema.json +93 -0
- package/src/analysis-assets/prompt.en.txt +17 -0
- package/src/analysis-assets/prompt.zh-CN.txt +18 -0
- package/src/analysis-budget.cjs +105 -0
- package/src/analysis-git.cjs +38 -0
- package/src/analysis-history.cjs +150 -0
- package/src/analysis-ledger.cjs +82 -0
- package/src/analysis-log.cjs +62 -0
- package/src/analysis-runner.cjs +203 -0
- package/src/analysis-service.cjs +197 -0
- package/src/analysis-source.cjs +72 -0
- package/src/antigravity-card.cjs +2063 -0
- package/src/antigravity-hook.cjs +138 -0
- package/src/antigravity-mcp-config.cjs +36 -0
- package/src/app-server.cjs +96 -0
- package/src/cdp.cjs +115 -0
- package/src/claude-inline-install.cjs +38 -0
- package/src/claude-mcp-config.cjs +29 -0
- package/src/cli/arguments.cjs +30 -0
- package/src/cli/environment-probe.cjs +130 -0
- package/src/cli/integration-state.cjs +15 -0
- package/src/cli/interactive-cli.cjs +236 -0
- package/src/cli/prompt-tui.cjs +420 -0
- package/src/cli/setup-orchestrator.cjs +449 -0
- package/src/codex-mcp-config.cjs +67 -0
- package/src/harnesses/antigravity/analysis-profile.cjs +41 -0
- package/src/harnesses/antigravity/antigravity-git.cjs +89 -0
- package/src/harnesses/antigravity/antigravity-harness.js +1477 -0
- package/src/harnesses/antigravity/antigravity-injector.cjs +104 -0
- package/src/harnesses/antigravity/antigravity-migration.cjs +235 -0
- package/src/harnesses/antigravity/antigravity-service.cjs +357 -0
- package/src/harnesses/antigravity/antigravity-title.cjs +155 -0
- package/src/harnesses/antigravity/gemini-runner.cjs +304 -0
- package/src/harnesses/antigravity/transcript-cleaner.cjs +129 -0
- package/src/harnesses/antigravity/transcript-source.cjs +100 -0
- package/src/harnesses/claude/claude-harness.js +93 -0
- package/src/harnesses/claude/claude-host-helper.cjs +176 -0
- package/src/harnesses/claude/claude-injector.cjs +95 -0
- package/src/harnesses/claude/claude-local-source.cjs +106 -0
- package/src/harnesses/claude/claude-navigation.cjs +99 -0
- package/src/harnesses/claude/claude-runner.cjs +74 -0
- package/src/harnesses/claude/claude-service.cjs +313 -0
- package/src/harnesses/claude/claude-source.cjs +70 -0
- package/src/harnesses/codex/codex-analysis.cjs +10 -0
- package/src/harnesses/codex/codex-card-bridge.js +123 -0
- package/src/harnesses/codex/codex-card-events.cjs +76 -0
- package/src/harnesses/codex/codex-card.cjs +169 -0
- package/src/harnesses/codex/codex-git.cjs +24 -0
- package/src/harnesses/codex/codex-harness.js +229 -0
- package/src/harnesses/codex/codex-local-card.js +97 -0
- package/src/harnesses/codex/codex-progress-context.cjs +84 -0
- package/src/harnesses/codex/codex-service.cjs +502 -0
- package/src/i18n.cjs +174 -0
- package/src/launchd.cjs +105 -0
- package/src/lifecycle-lock.cjs +13 -0
- package/src/local-progress-http.cjs +267 -0
- package/src/manual-status-agent.cjs +12 -0
- package/src/manual-status-startup.cjs +66 -0
- package/src/manual-status-store.cjs +466 -0
- package/src/mcp-stdio.cjs +67 -0
- package/src/model-router.cjs +63 -0
- package/src/native-bridge.cjs +17 -0
- package/src/npm-updates.cjs +228 -0
- package/src/plugins/things/assets/logo.svg +13 -0
- package/src/plugins/things/plugin.json +6 -0
- package/src/plugins/things/sidecars/things_board/app.js +447 -0
- package/src/plugins/things/sidecars/things_board/index.html +2141 -0
- package/src/plugins/things/sidecars/things_board/main.mjs +652 -0
- package/src/plugins/things/sidecars/things_board/package.json +6 -0
- package/src/plugins/things/sidecars/things_board/sidecar.json +21 -0
- package/src/plugins/things/sidecars/things_board/styles.css +560 -0
- package/src/plugins/things/sidecars/things_board/ui-i18n.mjs +434 -0
- package/src/progress-error.cjs +54 -0
- package/src/progress-tools.cjs +145 -0
- package/src/project-path.cjs +15 -0
- package/src/renderer-resource.cjs +17 -0
- package/src/request-budget.cjs +24 -0
- package/src/resolve.cjs +51 -0
- package/src/runtime-install.cjs +635 -0
- package/src/session-status-filter.cjs +136 -0
- package/src/session-status.js +992 -0
- package/src/session-view.cjs +34 -0
- package/src/startup/controller.cjs +354 -0
- package/src/startup/watch.cjs +126 -0
- package/src/state-file-lock.cjs +31 -0
- package/src/task-provenance.cjs +42 -0
- package/src/ui-foundation.cjs +435 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
const os = require('node:os');
|
|
6
|
+
const { ManualStatusStore } = require('./manual-status-store.cjs');
|
|
7
|
+
const { generateCardArtifact } = require('./antigravity-card.cjs');
|
|
8
|
+
const { resolveAntigravityTitle } = require('./harnesses/antigravity/antigravity-title.cjs');
|
|
9
|
+
const { readConfiguredLang, getUi, formatSessionMarkdownSummary } = require('./i18n.cjs');
|
|
10
|
+
|
|
11
|
+
function extractUserInput(raw) {
|
|
12
|
+
if (typeof raw !== 'string') return '';
|
|
13
|
+
const match = raw.match(/<USER_REQUEST>([\s\S]*?)<\/USER_REQUEST>/i);
|
|
14
|
+
return (match ? match[1] : raw).trim();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function isThingsCommand(input) {
|
|
18
|
+
const cleaned = extractUserInput(input);
|
|
19
|
+
return /^\s*\/things(?:\s|$)/i.test(cleaned);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function processHookInput(rawInput) {
|
|
23
|
+
let payload = {};
|
|
24
|
+
try {
|
|
25
|
+
payload = JSON.parse(rawInput);
|
|
26
|
+
} catch (_) {
|
|
27
|
+
return {};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const lastUserInput = payload.lastUserInput;
|
|
31
|
+
if (!isThingsCommand(lastUserInput)) {
|
|
32
|
+
return {};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const conversationId = payload.conversationId || 'default';
|
|
36
|
+
const artifactDir = payload.artifactDirectoryPath || path.join(os.homedir(), '.gemini/antigravity/brain', conversationId);
|
|
37
|
+
|
|
38
|
+
// 读取本地状态
|
|
39
|
+
const statePath = path.join(os.homedir(), '.gemini/antigravity/session-status/manual-state.json');
|
|
40
|
+
const lang = readConfiguredLang({ dataDir: path.dirname(statePath) });
|
|
41
|
+
const { t } = getUi(lang);
|
|
42
|
+
let progressData = null;
|
|
43
|
+
if (fs.existsSync(statePath)) {
|
|
44
|
+
try {
|
|
45
|
+
const store = new ManualStatusStore(statePath);
|
|
46
|
+
progressData = store.getProgress(conversationId);
|
|
47
|
+
} catch (_) {}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// 读取连接凭据
|
|
51
|
+
const credPath = path.join(os.homedir(), '.gemini/antigravity/session-status/manual-state.json.http.json');
|
|
52
|
+
let connection = null;
|
|
53
|
+
if (fs.existsSync(credPath)) {
|
|
54
|
+
try {
|
|
55
|
+
connection = JSON.parse(fs.readFileSync(credPath, 'utf8'));
|
|
56
|
+
} catch (_) {}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const isEmptySession = progressData == null;
|
|
60
|
+
const stateText = isEmptySession
|
|
61
|
+
? t('unrecordedSummary')
|
|
62
|
+
: (progressData?.state === 'completed' || progressData?.progress === 100
|
|
63
|
+
? t('mdStateDone')
|
|
64
|
+
: (progressData?.progress != null ? `${progressData.progress}%` : t('mdStateUnstarted')));
|
|
65
|
+
const total = progressData?.totalTasks || 0;
|
|
66
|
+
const done = progressData?.completedTasks || 0;
|
|
67
|
+
const tasksText = total > 0 ? t('totalsPattern', { done, total }) : t('mdTasksEmpty');
|
|
68
|
+
const noteText = progressData?.note ? `\n- **${t('mdNotesLabel')}**:${progressData.note}`.replace(':', lang === 'en' ? ': ' : ':') : '';
|
|
69
|
+
const summaryText = isEmptySession ? t('unrecordedSummary') : (progressData?.summary || '');
|
|
70
|
+
|
|
71
|
+
// 生成卡片工件(空会话时不分析、不建任务、不写账本)
|
|
72
|
+
const resolvedBrainDir = path.basename(artifactDir) === conversationId
|
|
73
|
+
? path.dirname(artifactDir)
|
|
74
|
+
: path.join(os.homedir(), '.gemini/antigravity/brain');
|
|
75
|
+
const sessionTitle = resolveAntigravityTitle(conversationId, {
|
|
76
|
+
brainDir: resolvedBrainDir,
|
|
77
|
+
fallback: t('defaultSessionTitle'),
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const cardResult = generateCardArtifact({
|
|
81
|
+
conversationId,
|
|
82
|
+
brainDir: artifactDir,
|
|
83
|
+
artifactDir,
|
|
84
|
+
record: isEmptySession ? null : {
|
|
85
|
+
state: progressData.state,
|
|
86
|
+
progress: progressData.progress,
|
|
87
|
+
note: progressData.note,
|
|
88
|
+
source: progressData.source,
|
|
89
|
+
updatedAt: progressData.updatedAt,
|
|
90
|
+
},
|
|
91
|
+
tasks: isEmptySession ? [] : (progressData?.tasks || []),
|
|
92
|
+
summary: summaryText,
|
|
93
|
+
revision: progressData?.revision || 0,
|
|
94
|
+
connection,
|
|
95
|
+
title: sessionTitle,
|
|
96
|
+
lang,
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const mdColon = lang === 'en' ? ': ' : ':';
|
|
100
|
+
const userMarkdown = `${cardResult.embedTag}\n\n**${t('mdProgressHeading')}${mdColon}${stateText}**\n- **${t('mdTasksOverview')}**${mdColon}${tasksText}${noteText}\n- **${t('mdQuickActionsLabel')}**${mdColon}${t('mdQuickActionsText')}`;
|
|
101
|
+
|
|
102
|
+
return {
|
|
103
|
+
injectSteps: [
|
|
104
|
+
{
|
|
105
|
+
systemMessage: {
|
|
106
|
+
systemMessage: t('hookPresentedMessage'),
|
|
107
|
+
metadata: {
|
|
108
|
+
user_markdown: userMarkdown,
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
terminationBehavior: 'terminate',
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function runCli() {
|
|
118
|
+
let buffer = '';
|
|
119
|
+
process.stdin.setEncoding('utf8');
|
|
120
|
+
process.stdin.on('data', chunk => {
|
|
121
|
+
buffer += chunk;
|
|
122
|
+
});
|
|
123
|
+
process.stdin.on('end', () => {
|
|
124
|
+
const output = processHookInput(buffer);
|
|
125
|
+
process.stdout.write(JSON.stringify(output));
|
|
126
|
+
process.exit(0);
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (require.main === module) {
|
|
131
|
+
runCli();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
module.exports = {
|
|
135
|
+
extractUserInput,
|
|
136
|
+
isThingsCommand,
|
|
137
|
+
processHookInput,
|
|
138
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const fs = require('node:fs');
|
|
3
|
+
const path = require('node:path');
|
|
4
|
+
const os = require('node:os');
|
|
5
|
+
const DEFAULT_FILE = path.join(os.homedir(), '.gemini/antigravity/mcp_config.json');
|
|
6
|
+
const owned = server => Array.isArray(server?.args) && server.args.some(arg => typeof arg === 'string' && path.basename(arg) === 'antigravity-session-status.cjs');
|
|
7
|
+
function updateConfig(file, change) {
|
|
8
|
+
const original = fs.existsSync(file) ? fs.readFileSync(file, 'utf8') : null;
|
|
9
|
+
const data = original === null ? {} : JSON.parse(original);
|
|
10
|
+
if (!data || typeof data !== 'object' || Array.isArray(data) ||
|
|
11
|
+
(data.mcpServers !== undefined && (!data.mcpServers || typeof data.mcpServers !== 'object' || Array.isArray(data.mcpServers)))) throw new Error('Antigravity MCP 配置格式无效');
|
|
12
|
+
data.mcpServers ||= {};
|
|
13
|
+
if (!change(data.mcpServers)) return;
|
|
14
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
15
|
+
if (original !== null) fs.writeFileSync(`${file}.agent-things.bak`, original, { mode: 0o600 });
|
|
16
|
+
const temporary = `${file}.${process.pid}.tmp`;
|
|
17
|
+
try { fs.writeFileSync(temporary, JSON.stringify(data, null, 2) + '\n', { mode: 0o600 }); fs.renameSync(temporary, file); }
|
|
18
|
+
finally { fs.rmSync(temporary, { force: true }); }
|
|
19
|
+
}
|
|
20
|
+
function installAntigravityMcp({ file = DEFAULT_FILE, scriptPath, nodeBin = process.execPath } = {}) {
|
|
21
|
+
updateConfig(file, servers => {
|
|
22
|
+
const key = Object.keys(servers).find(key => owned(servers[key])) || 'session_status';
|
|
23
|
+
if (servers[key] && !owned(servers[key])) throw new Error('Antigravity session_status 名称已被其他服务使用');
|
|
24
|
+
servers[key] = { command: nodeBin, args: [scriptPath] };
|
|
25
|
+
return true;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
function disableAntigravityMcp({ file = DEFAULT_FILE } = {}) {
|
|
29
|
+
if (!fs.existsSync(file)) return;
|
|
30
|
+
updateConfig(file, servers => {
|
|
31
|
+
const keys = Object.keys(servers).filter(key => owned(servers[key]));
|
|
32
|
+
for (const key of keys) delete servers[key];
|
|
33
|
+
return keys.length > 0;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
module.exports = { installAntigravityMcp, disableAntigravityMcp };
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const { EventEmitter } = require('node:events');
|
|
3
|
+
const { spawn } = require('node:child_process');
|
|
4
|
+
const readline = require('node:readline');
|
|
5
|
+
const { mergeResponse } = require('./limits.cjs');
|
|
6
|
+
|
|
7
|
+
// Minimal JSON-RPC client for `codex app-server` over stdio. Only ever asks for rate limits.
|
|
8
|
+
class AppServerClient extends EventEmitter {
|
|
9
|
+
constructor({ command, args = ['app-server'], version = '0', requestTimeoutMs = 15000 }) {
|
|
10
|
+
super();
|
|
11
|
+
Object.assign(this, { command, args, version, requestTimeoutMs });
|
|
12
|
+
this.child = null;
|
|
13
|
+
this.lines = null;
|
|
14
|
+
this.pending = new Map();
|
|
15
|
+
this.serial = 0;
|
|
16
|
+
this.rateLimits = null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async start() {
|
|
20
|
+
if (this.child) return;
|
|
21
|
+
const child = spawn(this.command, this.args, { stdio: ['pipe', 'pipe', 'pipe'], env: process.env });
|
|
22
|
+
this.child = child;
|
|
23
|
+
const fail = error => {
|
|
24
|
+
if (this.child !== child) return;
|
|
25
|
+
this.stop();
|
|
26
|
+
this.emit('server-exit', error);
|
|
27
|
+
};
|
|
28
|
+
child.once('error', fail);
|
|
29
|
+
child.once('exit', code => fail(new Error(`App Server exited (${code})`)));
|
|
30
|
+
child.stdin.on('error', fail);
|
|
31
|
+
child.stderr.resume(); // Drain it: the stream can carry account details, so it is never logged.
|
|
32
|
+
this.lines = readline.createInterface({ input: child.stdout });
|
|
33
|
+
this.lines.on('line', line => this.handleLine(line));
|
|
34
|
+
await this.request('initialize', {
|
|
35
|
+
clientInfo: { name: 'agent_things', title: 'Agent Things', version: this.version }
|
|
36
|
+
});
|
|
37
|
+
this.child?.stdin.write(`${JSON.stringify({ method: 'initialized', params: {} })}\n`);
|
|
38
|
+
await this.refresh();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
handleLine(line) {
|
|
42
|
+
let message;
|
|
43
|
+
try { message = JSON.parse(line); } catch { return; }
|
|
44
|
+
if (!message || typeof message !== 'object') return;
|
|
45
|
+
const request = this.pending.get(message.id);
|
|
46
|
+
if (request) {
|
|
47
|
+
this.pending.delete(message.id);
|
|
48
|
+
clearTimeout(request.timer);
|
|
49
|
+
if (message.error) request.reject(new Error(message.error.message || 'App Server request failed'));
|
|
50
|
+
else request.resolve(message.result);
|
|
51
|
+
} else if (message.method === 'account/rateLimits/updated') {
|
|
52
|
+
this.rateLimits = mergeResponse(this.rateLimits, message.params);
|
|
53
|
+
this.emit('rate-limits', this.rateLimits);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
request(method, params) {
|
|
58
|
+
if (!this.child?.stdin.writable) return Promise.reject(new Error('App Server is not running'));
|
|
59
|
+
const id = ++this.serial;
|
|
60
|
+
return new Promise((resolve, reject) => {
|
|
61
|
+
const timer = setTimeout(() => {
|
|
62
|
+
this.pending.delete(id);
|
|
63
|
+
reject(new Error(`${method} timed out`));
|
|
64
|
+
}, this.requestTimeoutMs);
|
|
65
|
+
this.pending.set(id, { resolve, reject, timer });
|
|
66
|
+
const body = JSON.stringify({ id, method, ...(params === undefined ? {} : { params }) });
|
|
67
|
+
this.child.stdin.write(`${body}\n`, error => {
|
|
68
|
+
if (error && this.pending.delete(id)) {
|
|
69
|
+
clearTimeout(timer);
|
|
70
|
+
reject(error);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async refresh() {
|
|
77
|
+
this.rateLimits = mergeResponse(null, await this.request('account/rateLimits/read'));
|
|
78
|
+
this.emit('rate-limits', this.rateLimits);
|
|
79
|
+
return this.rateLimits;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
stop() {
|
|
83
|
+
const child = this.child;
|
|
84
|
+
this.child = null;
|
|
85
|
+
this.lines?.close();
|
|
86
|
+
this.lines = null;
|
|
87
|
+
if (child && !child.killed) child.kill();
|
|
88
|
+
for (const item of this.pending.values()) {
|
|
89
|
+
clearTimeout(item.timer);
|
|
90
|
+
item.reject(new Error('App Server stopped'));
|
|
91
|
+
}
|
|
92
|
+
this.pending.clear();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
module.exports = { AppServerClient };
|
package/src/cdp.cjs
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const fs = require('node:fs');
|
|
3
|
+
const path = require('node:path');
|
|
4
|
+
|
|
5
|
+
const CDP_PORT = 39222;
|
|
6
|
+
const LOOPBACK_HOSTS = new Set(['127.0.0.1', 'localhost', '[::1]']);
|
|
7
|
+
|
|
8
|
+
// The endpoint can run code inside Codex, so never follow a target to anywhere but this machine.
|
|
9
|
+
function assertLoopback(url, port = CDP_PORT) {
|
|
10
|
+
const parsed = new URL(url);
|
|
11
|
+
if (parsed.protocol !== 'ws:' || !LOOPBACK_HOSTS.has(parsed.hostname) || Number(parsed.port) !== port) {
|
|
12
|
+
throw new Error(`CDP must use a loopback WebSocket on port ${port}`);
|
|
13
|
+
}
|
|
14
|
+
return parsed;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function isMainWindow(target) {
|
|
18
|
+
if (target?.type !== 'page' || typeof target.webSocketDebuggerUrl !== 'string') return false;
|
|
19
|
+
try {
|
|
20
|
+
const url = new URL(target.url || '');
|
|
21
|
+
return url.protocol === 'app:' && !/overlay|detached/i.test(decodeURIComponent(url.pathname + url.search + url.hash));
|
|
22
|
+
} catch {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function listTargets(port = CDP_PORT, timeoutMs = 3000) {
|
|
28
|
+
const response = await fetch(`http://127.0.0.1:${port}/json/list`, { signal: AbortSignal.timeout(timeoutMs) });
|
|
29
|
+
if (!response.ok) throw new Error('CDP unavailable');
|
|
30
|
+
return response.json();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
class CdpSession {
|
|
34
|
+
constructor(target, port = CDP_PORT) {
|
|
35
|
+
this.target = target;
|
|
36
|
+
this.port = port;
|
|
37
|
+
this.pending = new Map();
|
|
38
|
+
this.serial = 0;
|
|
39
|
+
this.socket = null;
|
|
40
|
+
this.onBinding = null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async connect() {
|
|
44
|
+
const ws = new WebSocket(assertLoopback(this.target.webSocketDebuggerUrl, this.port));
|
|
45
|
+
this.socket = ws;
|
|
46
|
+
ws.addEventListener('message', event => {
|
|
47
|
+
let message;
|
|
48
|
+
try { message = JSON.parse(event.data); } catch { return; }
|
|
49
|
+
if (message?.method === 'Runtime.bindingCalled') this.onBinding?.(message.params);
|
|
50
|
+
const request = this.pending.get(message?.id);
|
|
51
|
+
if (!request) return;
|
|
52
|
+
this.pending.delete(message.id);
|
|
53
|
+
clearTimeout(request.timer);
|
|
54
|
+
if (message.error || message.result?.exceptionDetails) request.reject(new Error(
|
|
55
|
+
message.error?.message || message.result.exceptionDetails.exception?.description || message.result.exceptionDetails.text
|
|
56
|
+
));
|
|
57
|
+
else request.resolve(message.result);
|
|
58
|
+
});
|
|
59
|
+
ws.addEventListener('close', () => this.rejectPending());
|
|
60
|
+
ws.addEventListener('error', () => this.rejectPending());
|
|
61
|
+
await new Promise((resolve, reject) => {
|
|
62
|
+
const timer = setTimeout(() => {
|
|
63
|
+
ws.close();
|
|
64
|
+
reject(new Error('CDP handshake timed out'));
|
|
65
|
+
}, 4000);
|
|
66
|
+
const finish = fn => {
|
|
67
|
+
clearTimeout(timer);
|
|
68
|
+
fn();
|
|
69
|
+
};
|
|
70
|
+
ws.addEventListener('open', () => finish(resolve), { once: true });
|
|
71
|
+
ws.addEventListener('error', () => finish(() => reject(new Error('CDP unavailable'))), { once: true });
|
|
72
|
+
ws.addEventListener('close', () => finish(() => reject(new Error('CDP closed'))), { once: true });
|
|
73
|
+
});
|
|
74
|
+
await this.request('Runtime.enable');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
request(method, params = {}, timeoutMs = 5000) {
|
|
78
|
+
if (this.socket?.readyState !== WebSocket.OPEN) return Promise.reject(new Error('CDP disconnected'));
|
|
79
|
+
const id = ++this.serial;
|
|
80
|
+
return new Promise((resolve, reject) => {
|
|
81
|
+
const timer = setTimeout(() => {
|
|
82
|
+
this.pending.delete(id);
|
|
83
|
+
reject(new Error('CDP request timed out'));
|
|
84
|
+
}, timeoutMs);
|
|
85
|
+
this.pending.set(id, { resolve, reject, timer });
|
|
86
|
+
try {
|
|
87
|
+
this.socket.send(JSON.stringify({ id, method, params }));
|
|
88
|
+
} catch (error) {
|
|
89
|
+
this.pending.delete(id);
|
|
90
|
+
clearTimeout(timer);
|
|
91
|
+
reject(error);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
evaluate(expression) {
|
|
97
|
+
return this.request('Runtime.evaluate', { expression, returnByValue: true, awaitPromise: true });
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
rejectPending() {
|
|
101
|
+
for (const request of this.pending.values()) {
|
|
102
|
+
clearTimeout(request.timer);
|
|
103
|
+
request.reject(new Error('CDP disconnected'));
|
|
104
|
+
}
|
|
105
|
+
this.pending.clear();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
close() {
|
|
109
|
+
this.rejectPending();
|
|
110
|
+
this.socket?.close();
|
|
111
|
+
this.socket = null;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
module.exports = { CDP_PORT, CdpSession, assertLoopback, isMainWindow, listTargets };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const fs = require('node:fs');
|
|
3
|
+
const path = require('node:path');
|
|
4
|
+
const os = require('node:os');
|
|
5
|
+
|
|
6
|
+
const { readConfiguredLang } = require('./i18n.cjs');
|
|
7
|
+
|
|
8
|
+
function syncClaudeInline(root, enabled, { home = (process.env.HOME || os.homedir()), lang } = {}) {
|
|
9
|
+
const en = (lang || readConfiguredLang()) === 'en';
|
|
10
|
+
const destination = path.join(home, '.claude/skills/agent-things-ui');
|
|
11
|
+
const source = path.join(root, 'mods/agent-things-ui');
|
|
12
|
+
const exists = fs.existsSync(destination);
|
|
13
|
+
if (!enabled && !exists) return null;
|
|
14
|
+
if (exists) {
|
|
15
|
+
const manifestFile = path.join(destination, '.claude-plugin/plugin.json');
|
|
16
|
+
const manifest = fs.existsSync(manifestFile) && JSON.parse(fs.readFileSync(manifestFile, 'utf8'));
|
|
17
|
+
if (manifest?.name !== 'agent-things-ui' || manifest?.author?.name !== 'Agent Things') {
|
|
18
|
+
if (!enabled) return null;
|
|
19
|
+
throw new Error(en ? "Claude's agent-things-ui directory is occupied by other content" : 'Claude 的 agent-things-ui 目录已被其他内容占用');
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
if (enabled && !fs.existsSync(source)) throw new Error(en ? 'Package is missing Claude session card' : '安装包缺少 Claude 会话卡片');
|
|
23
|
+
const backup = path.join(home, 'Library/Application Support/CodexSessionStatus/backups', `claude-inline-${Date.now()}-${process.pid}`);
|
|
24
|
+
fs.mkdirSync(backup, { recursive: true, mode: 0o700 });
|
|
25
|
+
if (enabled) fs.cpSync(source, path.join(backup, 'staged'), { recursive: true });
|
|
26
|
+
if (exists) fs.renameSync(destination, path.join(backup, 'previous'));
|
|
27
|
+
try {
|
|
28
|
+
if (enabled) { fs.mkdirSync(path.dirname(destination), { recursive: true }); fs.renameSync(path.join(backup, 'staged'), destination); }
|
|
29
|
+
} catch (error) {
|
|
30
|
+
if (exists) fs.renameSync(path.join(backup, 'previous'), destination);
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
return { backup, rollback() {
|
|
34
|
+
if (enabled && fs.existsSync(destination)) fs.renameSync(destination, path.join(backup, 'rolled-back-install'));
|
|
35
|
+
if (exists) fs.renameSync(path.join(backup, 'previous'), destination);
|
|
36
|
+
} };
|
|
37
|
+
}
|
|
38
|
+
module.exports = { syncClaudeInline };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const fs = require('node:fs');
|
|
3
|
+
const path = require('node:path');
|
|
4
|
+
const os = require('node:os');
|
|
5
|
+
const { resolveNode } = require('./resolve.cjs');
|
|
6
|
+
|
|
7
|
+
const owned = server => server?.args?.some(arg => typeof arg === 'string' && arg.endsWith('/claude-session-status.cjs'));
|
|
8
|
+
function updateClaudeMcp({ scriptPath, file = path.join(os.homedir(), '.claude.json'), enabled = true } = {}) {
|
|
9
|
+
const data = fs.existsSync(file) ? JSON.parse(fs.readFileSync(file, 'utf8')) : {};
|
|
10
|
+
const current = data.mcpServers?.session_status;
|
|
11
|
+
if (current && !owned(current)) {
|
|
12
|
+
if (enabled) throw new Error('Claude 已存在其他 session_status 服务,请先检查配置');
|
|
13
|
+
return { removed: false };
|
|
14
|
+
}
|
|
15
|
+
if (enabled) {
|
|
16
|
+
if (!scriptPath || !path.isAbsolute(scriptPath)) throw new Error('Claude MCP 入口路径无效');
|
|
17
|
+
data.mcpServers ||= {};
|
|
18
|
+
data.mcpServers.session_status = { type: 'stdio', command: resolveNode(), args: [scriptPath] };
|
|
19
|
+
} else {
|
|
20
|
+
if (!owned(current)) return { removed: false };
|
|
21
|
+
delete data.mcpServers.session_status;
|
|
22
|
+
}
|
|
23
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
24
|
+
if (fs.existsSync(file)) fs.copyFileSync(file, `${file}.agent-things-backup`);
|
|
25
|
+
const temporary = `${file}.${process.pid}.tmp`;
|
|
26
|
+
fs.writeFileSync(temporary, JSON.stringify(data, null, 2) + '\n', { mode: 0o600 }); fs.renameSync(temporary, file);
|
|
27
|
+
return { removed: !enabled };
|
|
28
|
+
}
|
|
29
|
+
module.exports = { installClaudeMcp: options => updateClaudeMcp(options), disableClaudeMcp: options => updateClaudeMcp({ ...options, enabled: false }) };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const path = require('node:path');
|
|
3
|
+
const { readConfiguredLang } = require('../i18n.cjs');
|
|
4
|
+
const commands = new Set(['setup', 'doctor', 'help', '--help', '-h', 'run', 'status', 'mcp', 'install-mcp', 'disable-mcp', 'update-renderer', 'install-autostart', 'disable-autostart']);
|
|
5
|
+
function parseArguments(raw) {
|
|
6
|
+
const en = readConfiguredLang() === 'en';
|
|
7
|
+
const args = [...raw];
|
|
8
|
+
const command = !args.length || ['--all', '-y', '--yes'].includes(args[0]) ? 'setup' : args.shift();
|
|
9
|
+
if (!commands.has(command)) throw new Error(en ? `Unknown command: ${command}` : `未知命令:${command}`);
|
|
10
|
+
const options = { command, port: 39222, watchStartup: false };
|
|
11
|
+
while (args.length) {
|
|
12
|
+
const flag = args.shift();
|
|
13
|
+
if (command === 'setup' && ['--all', '-y', '--yes'].includes(flag)) options.yes = true;
|
|
14
|
+
else if (command === 'setup' && flag === '--lang') {
|
|
15
|
+
options.lang = args.shift();
|
|
16
|
+
if (!['zh', 'en'].includes(options.lang)) throw new Error(en ? '--lang must be zh or en' : '--lang 应为 zh 或 en');
|
|
17
|
+
} else if (['--help', '-h'].includes(flag)) options.command = 'help';
|
|
18
|
+
else if (flag === '--port' && ['run', 'status', 'mcp'].includes(command)) {
|
|
19
|
+
options.port = Number(args.shift());
|
|
20
|
+
if (!Number.isInteger(options.port) || options.port < 1024 || options.port > 65535) throw new Error(en ? 'Invalid debug port' : '调试端口无效');
|
|
21
|
+
} else if (flag === '--watch-startup' && command === 'run') options.watchStartup = true;
|
|
22
|
+
else if (flag === '--data-dir' && ['run', 'status', 'mcp', 'update-renderer', 'install-autostart'].includes(command)) {
|
|
23
|
+
const value = args.shift();
|
|
24
|
+
if (!value || value.startsWith('--')) throw new Error(en ? '--data-dir requires a directory path' : '--data-dir 需要目录路径');
|
|
25
|
+
options.directory = path.resolve(value);
|
|
26
|
+
} else throw new Error(en ? `Option ${flag} is not supported for command ${command}` : `命令 ${command} 不支持选项:${flag}`);
|
|
27
|
+
}
|
|
28
|
+
return options;
|
|
29
|
+
}
|
|
30
|
+
module.exports = { parseArguments };
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const fs = require('node:fs');
|
|
3
|
+
const path = require('node:path');
|
|
4
|
+
const os = require('node:os');
|
|
5
|
+
const net = require('node:net');
|
|
6
|
+
const { execSync, execFileSync } = require('node:child_process');
|
|
7
|
+
const { listTargets, isMainWindow } = require('../cdp.cjs');
|
|
8
|
+
|
|
9
|
+
function checkPort(port, timeoutMs = 250) {
|
|
10
|
+
return new Promise(resolve => {
|
|
11
|
+
const socket = net.createConnection({ host: '127.0.0.1', port });
|
|
12
|
+
const done = value => {
|
|
13
|
+
socket.destroy();
|
|
14
|
+
resolve(value);
|
|
15
|
+
};
|
|
16
|
+
socket.once('connect', () => done(true));
|
|
17
|
+
socket.once('error', () => done(false));
|
|
18
|
+
socket.setTimeout(timeoutMs, () => done(false));
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function resolveBin(name) {
|
|
23
|
+
try {
|
|
24
|
+
const res = execSync(`which ${name} 2>/dev/null`, { encoding: 'utf8' }).trim();
|
|
25
|
+
if (res && fs.existsSync(res)) return res;
|
|
26
|
+
} catch {}
|
|
27
|
+
for (const dir of ['/usr/local/bin', '/opt/homebrew/bin', path.join(os.homedir(), '.local/bin')]) {
|
|
28
|
+
const full = path.join(dir, name);
|
|
29
|
+
if (fs.existsSync(full)) return full;
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function isAppRunning(executable) {
|
|
35
|
+
const output = execFileSync('/bin/ps', ['-axo', 'comm='], { encoding: 'utf8' });
|
|
36
|
+
return output.split('\n').some(line => line.trim() === executable);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function probeEnvironment() {
|
|
40
|
+
const home = os.homedir();
|
|
41
|
+
|
|
42
|
+
// 1. Codex (ChatGPT.app)
|
|
43
|
+
const codexAppPath = fs.existsSync('/Applications/ChatGPT.app') ? '/Applications/ChatGPT.app' : null;
|
|
44
|
+
const codexRunning = isAppRunning('/Applications/ChatGPT.app/Contents/MacOS/ChatGPT');
|
|
45
|
+
let codexPortActive = false;
|
|
46
|
+
try { codexPortActive = (await listTargets(39222, 500)).some(isMainWindow); } catch {}
|
|
47
|
+
|
|
48
|
+
// 2. Antigravity
|
|
49
|
+
const antigravityApp = fs.existsSync('/Applications/Antigravity.app');
|
|
50
|
+
const antigravityInstalled = antigravityApp;
|
|
51
|
+
let antigravityPort = null;
|
|
52
|
+
const devToolsFile = path.join(home, 'Library/Application Support/Antigravity/DevToolsActivePort');
|
|
53
|
+
if (fs.existsSync(devToolsFile)) {
|
|
54
|
+
try {
|
|
55
|
+
const line = fs.readFileSync(devToolsFile, 'utf8').trim().split('\n')[0];
|
|
56
|
+
const p = Number(line);
|
|
57
|
+
if (p > 0 && await checkPort(p)) antigravityPort = p;
|
|
58
|
+
} catch {}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// 3. agy CLI
|
|
62
|
+
const agyPath = resolveBin('agy');
|
|
63
|
+
|
|
64
|
+
// 4. Claude Desktop
|
|
65
|
+
const claudeApp = fs.existsSync('/Applications/Claude.app') ? '/Applications/Claude.app' : null;
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
codex: {
|
|
69
|
+
id: 'codex',
|
|
70
|
+
name: 'Codex (ChatGPT)',
|
|
71
|
+
installed: Boolean(codexAppPath),
|
|
72
|
+
path: codexAppPath,
|
|
73
|
+
running: codexRunning,
|
|
74
|
+
portActive: codexPortActive,
|
|
75
|
+
},
|
|
76
|
+
antigravity: {
|
|
77
|
+
id: 'antigravity',
|
|
78
|
+
name: 'Antigravity',
|
|
79
|
+
installed: antigravityInstalled,
|
|
80
|
+
path: antigravityApp ? '/Applications/Antigravity.app' : null,
|
|
81
|
+
running: isAppRunning('/Applications/Antigravity.app/Contents/MacOS/Antigravity'),
|
|
82
|
+
port: antigravityPort,
|
|
83
|
+
},
|
|
84
|
+
agy: {
|
|
85
|
+
id: 'agy',
|
|
86
|
+
name: 'agy CLI',
|
|
87
|
+
installed: Boolean(agyPath),
|
|
88
|
+
path: agyPath,
|
|
89
|
+
},
|
|
90
|
+
claude: {
|
|
91
|
+
id: 'claude',
|
|
92
|
+
name: 'Claude Desktop',
|
|
93
|
+
installed: Boolean(claudeApp),
|
|
94
|
+
path: claudeApp,
|
|
95
|
+
running: isAppRunning('/Applications/Claude.app/Contents/MacOS/Claude'),
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function formatProbeText(item, lang = 'zh') {
|
|
101
|
+
const isZh = lang === 'zh';
|
|
102
|
+
if (!item?.installed) {
|
|
103
|
+
return isZh ? '未检测到应用' : 'Not detected';
|
|
104
|
+
}
|
|
105
|
+
const displayPath = item.path ? item.path.replace(os.homedir(), '~') : '';
|
|
106
|
+
if (item.id === 'codex') {
|
|
107
|
+
if (item.portActive) return isZh ? `运行中 (CDP: 39222 可用)` : `Running (CDP: 39222 available)`;
|
|
108
|
+
if (item.running) return isZh ? `运行中 (无调试端口,需重启)` : `Running (No debug port, restart needed)`;
|
|
109
|
+
return isZh ? `已安装 (${displayPath})` : `Installed (${displayPath})`;
|
|
110
|
+
}
|
|
111
|
+
if (item.id === 'antigravity') {
|
|
112
|
+
if (item.port) return isZh ? `运行中 (调试端口: ${item.port} 可达)` : `Running (Debug port: ${item.port} reachable)`;
|
|
113
|
+
return isZh ? `已安装 (${displayPath})` : `Installed (${displayPath})`;
|
|
114
|
+
}
|
|
115
|
+
if (item.id === 'agy') {
|
|
116
|
+
return isZh ? `已就绪 (${displayPath})` : `Ready (${displayPath})`;
|
|
117
|
+
}
|
|
118
|
+
if (item.id === 'claude') {
|
|
119
|
+
return isZh ? `已安装 (${displayPath})` : `Installed (${displayPath})`;
|
|
120
|
+
}
|
|
121
|
+
return isZh ? `已就绪` : `Ready`;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
module.exports = {
|
|
125
|
+
probeEnvironment,
|
|
126
|
+
isAppRunning,
|
|
127
|
+
formatProbeText,
|
|
128
|
+
checkPort,
|
|
129
|
+
resolveBin,
|
|
130
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const fs = require('node:fs');
|
|
3
|
+
const os = require('node:os');
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
function assertIntegrationEnabled(app) {
|
|
6
|
+
const file = path.join(os.homedir(), 'Library/Application Support/CodexSessionStatus/config.json');
|
|
7
|
+
if (!fs.existsSync(file)) return; // Standalone MCP installation.
|
|
8
|
+
const config = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
9
|
+
const en = config?.lang === 'en';
|
|
10
|
+
if (!Array.isArray(config.enabledApps)) throw new Error(en ? 'Invalid plugin configuration' : '插件启用配置无效');
|
|
11
|
+
if (!config.enabledApps.includes(app)) {
|
|
12
|
+
throw Object.assign(new Error(en ? 'Integration for this application is disabled; please reload the host MCP configuration.' : '此应用的插件已停用,请重新加载宿主 MCP 配置。'), { code: 'INTEGRATION_DISABLED' });
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
module.exports = { assertIntegrationEnabled };
|