larkmate 0.1.9 → 0.1.11
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/README.md +7 -1
- package/bin/larkmate.js +96 -5
- package/bin/os-delegate-helper.js +31 -0
- package/docs/agent-broker.md +1 -1
- package/docs/ai-install.md +3 -1
- package/docs/os-delegation.example.json +21 -0
- package/docs/os-delegation.md +65 -0
- package/package.json +1 -1
- package/proto/lark.proto +41 -0
- package/proto/todo-schema.json +1 -0
- package/skills/larkmate/SKILL.md +5 -2
- package/skills/larkmate/references/chats.md +9 -1
- package/skills/larkmate/references/tasks.md +22 -0
- package/skills/larkmate/references/writes.md +1 -1
- package/src/agent-broker.js +9 -2
- package/src/feed-groups.js +82 -0
- package/src/gateway.js +12 -2
- package/src/os-delegate-client.js +94 -0
- package/src/os-delegate.js +172 -0
- package/src/sidebar-filters.js +80 -0
- package/src/tasks.js +112 -0
package/README.md
CHANGED
|
@@ -36,6 +36,8 @@ npx --registry=https://registry.npmjs.org/ skills add NWYLZW/larkmate --skill la
|
|
|
36
36
|
- [x] 查询、标记和取消标记会话
|
|
37
37
|
- [x] 标记已读或未读、设置免打扰
|
|
38
38
|
- [x] 移入或移出已完成、会话收纳
|
|
39
|
+
- [x] 按未读、免打扰、@我、单聊、群组等分组查询
|
|
40
|
+
- [x] 配置侧边栏分组的显示、隐藏、顺序和展示规则
|
|
39
41
|
- [x] 创建、重命名和删除标签,管理手动标签下的会话
|
|
40
42
|
- [ ] 修改自动规则标签的会话成员
|
|
41
43
|
- 消息
|
|
@@ -56,6 +58,10 @@ npx --registry=https://registry.npmjs.org/ skills add NWYLZW/larkmate --skill la
|
|
|
56
58
|
- [x] 邀请成员和机器人
|
|
57
59
|
- [x] 查询和设置机器人的移除限制
|
|
58
60
|
- [ ] 移除成员或退出群聊
|
|
61
|
+
- 飞书任务
|
|
62
|
+
- [x] 查询任务中心与任务视图,按关键词搜索任务
|
|
63
|
+
- [x] 新建、编辑、完成、重开和删除任务
|
|
64
|
+
- [x] 配置任务时间、负责人、关注人、重复规则及其他字段
|
|
59
65
|
- 录制妙记
|
|
60
66
|
- [x] 查询当前用户可访问的录制妙记
|
|
61
67
|
- [x] 导出文字记录,支持说话人和时间戳
|
|
@@ -66,4 +72,4 @@ npx --registry=https://registry.npmjs.org/ skills add NWYLZW/larkmate --skill la
|
|
|
66
72
|
|
|
67
73
|
具体用法和能力边界见 [LarkMate Skill](skills/larkmate/SKILL.md)。
|
|
68
74
|
|
|
69
|
-
如需将部分能力交给其他 Agent,可使用 [
|
|
75
|
+
如需将部分能力交给其他 Agent,可使用 [系统用户权限委托](docs/os-delegation.md)或 [本地代理](docs/agent-broker.md)。
|
package/bin/larkmate.js
CHANGED
|
@@ -5,16 +5,22 @@ import { Gateway } from '../src/gateway.js';
|
|
|
5
5
|
import { LarkMateClient } from '../src/client.js';
|
|
6
6
|
import { SessionControls } from '../src/session-controls.js';
|
|
7
7
|
import { Minutes, formatTranscript } from '../src/minutes.js';
|
|
8
|
-
import { writeFile } from 'node:fs/promises';
|
|
8
|
+
import { writeFile, readFile } from 'node:fs/promises';
|
|
9
9
|
import { FeishuError } from '../src/errors.js';
|
|
10
10
|
import { exportMessages } from '../src/export-messages.js';
|
|
11
11
|
import { brokerCall, brokerCommands, brokerProxy, createBrokerToken, loadBrokerToken, loadPolicy, startBroker } from '../src/agent-broker.js';
|
|
12
|
+
import { callOsDelegate, osDelegateProxy } from '../src/os-delegate-client.js';
|
|
13
|
+
import { SidebarFilters } from '../src/sidebar-filters.js';
|
|
14
|
+
import { FeedGroups } from '../src/feed-groups.js';
|
|
15
|
+
import { Tasks } from '../src/tasks.js';
|
|
12
16
|
|
|
13
17
|
const program = new Command();
|
|
14
|
-
program.name('larkmate').description('Operate Feishu as the logged-in user.').version('0.1.
|
|
18
|
+
program.name('larkmate').description('Operate Feishu as the logged-in user.').version('0.1.11');
|
|
15
19
|
program.option('--credentials-file <path>', 'read LarkMate credentials.json');
|
|
16
20
|
program.option('--broker <path>', 'use a restricted local broker socket (or LARKMATE_BROKER)');
|
|
17
21
|
program.option('--broker-token-file <path>', 'read the agent token (or LARKMATE_BROKER_TOKEN_FILE)');
|
|
22
|
+
program.option('--delegate-owner <user>', 'execute through a protected OS-user delegate (or LARKMATE_DELEGATE_OWNER)');
|
|
23
|
+
program.option('--delegate-launcher <path>', 'protected delegate launcher (or LARKMATE_DELEGATE_LAUNCHER)');
|
|
18
24
|
program.exitOverride();
|
|
19
25
|
let activeCommand;
|
|
20
26
|
program.hook('preAction', (_program, command) => { activeCommand = command.name(); });
|
|
@@ -24,7 +30,16 @@ const output = value => process.stdout.write(`${JSON.stringify({ ok: true, ...va
|
|
|
24
30
|
|
|
25
31
|
function configuredBroker() { return program.opts().broker || process.env.LARKMATE_BROKER || null; }
|
|
26
32
|
function configuredBrokerToken() { return program.opts().brokerTokenFile || process.env.LARKMATE_BROKER_TOKEN_FILE || null; }
|
|
33
|
+
function configuredDelegate() {
|
|
34
|
+
const owner = program.opts().delegateOwner || process.env.LARKMATE_DELEGATE_OWNER;
|
|
35
|
+
const launcher = program.opts().delegateLauncher || process.env.LARKMATE_DELEGATE_LAUNCHER;
|
|
36
|
+
if (!!owner !== !!launcher) throw new FeishuError('DELEGATE_CONFIG_INVALID', 'Both delegate owner and launcher are required.');
|
|
37
|
+
if (owner && (configuredBroker() || configuredBrokerToken() || program.opts().credentialsFile)) throw new FeishuError('DELEGATE_CONFIG_INVALID', 'Do not combine OS delegation with broker or credentials options.');
|
|
38
|
+
return owner ? { owner, launcher } : null;
|
|
39
|
+
}
|
|
27
40
|
function proxy(service) {
|
|
41
|
+
const delegate = configuredDelegate();
|
|
42
|
+
if (delegate) return osDelegateProxy(delegate.owner, delegate.launcher, service, () => activeCommand);
|
|
28
43
|
const path = configuredBroker();
|
|
29
44
|
if (!path && configuredBrokerToken()) throw new FeishuError('BROKER_CONFIGURATION_INVALID', 'A broker token file was configured without a broker socket.');
|
|
30
45
|
if (path && program.opts().credentialsFile) throw new FeishuError('INVALID_ARGUMENT', 'A broker client cannot select a credentials file.');
|
|
@@ -50,9 +65,34 @@ async function minutes() {
|
|
|
50
65
|
return new Minutes(new Gateway({ cookie: await loadCookie({ file: program.opts().credentialsFile }) }));
|
|
51
66
|
}
|
|
52
67
|
|
|
68
|
+
async function sidebar() {
|
|
69
|
+
const remote = proxy('sidebar');
|
|
70
|
+
if (remote) return remote;
|
|
71
|
+
return new SidebarFilters(new Gateway({ cookie: await loadCookie({ file: program.opts().credentialsFile }) }));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async function feeds() { const remote = proxy('feeds'); return remote || new FeedGroups(new Gateway({ cookie: await loadCookie({ file: program.opts().credentialsFile }) })); }
|
|
75
|
+
async function tasks() { const remote = proxy('tasks'); return remote || new Tasks(new Gateway({ cookie: await loadCookie({ file: program.opts().credentialsFile }) })); }
|
|
76
|
+
async function readJson(path, fallback) {
|
|
77
|
+
if (!path) return fallback;
|
|
78
|
+
let data; try { data = path === '-' ? await new Promise((resolve, reject) => { let text = ''; process.stdin.setEncoding('utf8'); process.stdin.on('data', x => { text += x; if (text.length > 1048576) reject(new Error()); }); process.stdin.on('end', () => resolve(text)); process.stdin.on('error', reject); }) : await readFile(path, 'utf8');
|
|
79
|
+
if (Buffer.byteLength(data) > 1048576) throw new Error(); return JSON.parse(data);
|
|
80
|
+
} catch { throw new FeishuError('INVALID_ARGUMENT', 'Cannot read JSON input (maximum 1 MiB).'); }
|
|
81
|
+
}
|
|
82
|
+
|
|
53
83
|
program.command('broker-commands').description('List operations supported by the agent broker and their scopes.')
|
|
54
84
|
.action(() => output({ items: brokerCommands() }));
|
|
55
85
|
|
|
86
|
+
program.command('delegate-commands').description('List operations supported by OS-user delegation and their scopes.')
|
|
87
|
+
.action(() => output({ items: brokerCommands() }));
|
|
88
|
+
|
|
89
|
+
program.command('delegate-info').description('Show the current OS-user delegation permissions.')
|
|
90
|
+
.action(async () => {
|
|
91
|
+
const delegate = configuredDelegate();
|
|
92
|
+
if (!delegate) throw new FeishuError('DELEGATE_CONFIG_INVALID', 'Configure the delegate owner and launcher.');
|
|
93
|
+
output(await callOsDelegate({ ...delegate, request: { command: 'delegate-info' } }));
|
|
94
|
+
});
|
|
95
|
+
|
|
56
96
|
program.command('broker-token-create').description('Create a private token for one agent broker.')
|
|
57
97
|
.requiredOption('--output <path>', 'absolute path for a new token file')
|
|
58
98
|
.action(async o => { await createBrokerToken(o.output); output({ status: 'created', output: o.output }); });
|
|
@@ -62,13 +102,13 @@ program.command('broker-serve').description('Start a restricted local agent brok
|
|
|
62
102
|
.requiredOption('--policy <path>', 'absolute JSON policy path')
|
|
63
103
|
.requiredOption('--token-file <path>', 'absolute owner-controlled agent token file')
|
|
64
104
|
.action(async o => {
|
|
65
|
-
if (configuredBroker()) throw new FeishuError('INVALID_ARGUMENT', 'Start the broker directly, without
|
|
105
|
+
if (configuredBroker() || configuredDelegate()) throw new FeishuError('INVALID_ARGUMENT', 'Start the broker directly, without a broker or OS delegate.');
|
|
66
106
|
const policy = await loadPolicy(o.policy);
|
|
67
107
|
const token = await loadBrokerToken(o.tokenFile, { owner: true });
|
|
68
108
|
let promise;
|
|
69
109
|
const getServices = () => promise ||= (async () => {
|
|
70
110
|
const gateway = new Gateway({ cookie: await loadCookie({ file: program.opts().credentialsFile }) });
|
|
71
|
-
return { client: new LarkMateClient(gateway), controls: new SessionControls(gateway), minutes: new Minutes(gateway) };
|
|
111
|
+
return { client: new LarkMateClient(gateway), controls: new SessionControls(gateway), minutes: new Minutes(gateway), sidebar: new SidebarFilters(gateway), feeds: new FeedGroups(gateway), tasks: new Tasks(gateway) };
|
|
72
112
|
})().catch(error => { promise = undefined; throw error; });
|
|
73
113
|
const broker = await startBroker({ socketPath: o.socket, policy, token, getServices });
|
|
74
114
|
output({ status: 'listening', socket: broker.socketPath });
|
|
@@ -114,8 +154,59 @@ program.command('chats').description('List a page of inbox chats without opening
|
|
|
114
154
|
output(page);
|
|
115
155
|
});
|
|
116
156
|
|
|
157
|
+
program.command('group-query').description('Find feed items by sidebar group across pages.')
|
|
158
|
+
.requiredOption('--group <name>', 'messages, unread, muted, at_me, p2p, group, topic_group, docs, threads or done')
|
|
159
|
+
.option('--query <text>', 'filter names') .option('--limit <number>', 'feed page size', '100').option('--pages <number>', 'maximum pages to scan', '20')
|
|
160
|
+
.option('--cursor <cursor>', 'continue from the previous result').option('--parent <id>', 'search inside a box')
|
|
161
|
+
.action(async o => output(await (await feeds()).query({ group: o.group, query: o.query, limit: Number(o.limit), pages: Number(o.pages), cursor: o.cursor, parent: o.parent })));
|
|
162
|
+
|
|
163
|
+
program.command('task-center').description('List task containers, views and sections.').action(async () => output(await (await tasks()).center()));
|
|
164
|
+
program.command('tasks-list').description('List tasks from a task center view.')
|
|
165
|
+
.option('--scope <name>', 'mine, followed, all, created, assigned or completed', 'mine').option('--container <id>', 'task center container ID')
|
|
166
|
+
.option('--limit <number>', 'tasks per page', '50').option('--cursor <cursor>', 'continue from previous page')
|
|
167
|
+
.action(async o => output(await (await tasks()).list({ scope: o.scope, container: o.container, limit: Number(o.limit), cursor: o.cursor })));
|
|
168
|
+
program.command('task-search').description('Search accessible tasks.').requiredOption('--query <text>').option('--limit <number>', 'page size', '20').option('--cursor <cursor>')
|
|
169
|
+
.action(async o => output(await (await tasks()).search({ query: o.query, limit: Number(o.limit), cursor: o.cursor })));
|
|
170
|
+
program.command('task-get').description('Read a task.').requiredOption('--id <id>').action(async o => output(await (await tasks()).get({ taskId: o.id })));
|
|
171
|
+
program.command('task-create').description('Create a task.').option('--title <text>').option('--description <text>').option('--start <time>', 'milliseconds or ISO date')
|
|
172
|
+
.option('--due <time>', 'milliseconds or ISO date').option('--all-day', 'all-day task').option('--assignee <id>', 'repeatable user ID', collect, [])
|
|
173
|
+
.option('--follower <id>', 'repeatable user ID', collect, []).option('--list <id>', 'repeatable task list ID', collect, [])
|
|
174
|
+
.option('--repeat <rrule>', 'recurrence rule').option('--points <value>').option('--json <path>', 'full InputTask JSON, or - for stdin')
|
|
175
|
+
.action(async o => output(await (await tasks()).create({ input: await readJson(o.json, {}), title: o.title, description: o.description, start: o.start, due: o.due, allDay: o.allDay, assignees: o.assignee, followers: o.follower, lists: o.list, repeat: o.repeat, points: o.points })));
|
|
176
|
+
program.command('task-update').description('Update task fields and members.').requiredOption('--id <id>').option('--title <text>').option('--description <text>')
|
|
177
|
+
.option('--start <time>', 'milliseconds or ISO date; 0 clears').option('--due <time>', 'milliseconds or ISO date; 0 clears')
|
|
178
|
+
.option('--all-day <bool>', 'true or false').option('--repeat <rrule>').option('--points <value>').option('--milestone <bool>', 'true or false')
|
|
179
|
+
.option('--add-assignee <id>', 'repeatable user ID', collect, []).option('--remove-assignee <id>', 'repeatable user ID', collect, [])
|
|
180
|
+
.option('--add-follower <id>', 'repeatable user ID', collect, []).option('--remove-follower <id>', 'repeatable user ID', collect, [])
|
|
181
|
+
.option('--commits-json <path>', 'advanced commit array JSON, or - for stdin')
|
|
182
|
+
.action(async o => { const patch = {}; for (const key of ['title','description','start','due','repeat','points']) if (o[key] != null) patch[key] = o[key];
|
|
183
|
+
for (const key of ['allDay','milestone']) if (o[key] != null) { if (!['true','false'].includes(o[key])) throw new FeishuError('INVALID_ARGUMENT', key + ' must be true or false.'); patch[key] = o[key] === 'true'; }
|
|
184
|
+
for (const key of ['addAssignee','removeAssignee','addFollower','removeFollower']) if (o[key].length) patch[key + 's'] = o[key];
|
|
185
|
+
output(await (await tasks()).update({ taskId: o.id, patch, commits: await readJson(o.commitsJson, []) })); });
|
|
186
|
+
for (const [command, completed] of [['task-complete', true], ['task-reopen', false]]) program.command(command).description('Change task completion status.').requiredOption('--id <id>')
|
|
187
|
+
.option('--assignee <id>', 'repeatable assignee ID', collect, []).action(async o => output(await (await tasks()).complete({ taskId: o.id, completed, assignees: o.assignee })));
|
|
188
|
+
program.command('task-delete').description('Delete a task.').requiredOption('--id <id>').action(async o => output(await (await tasks()).delete({ taskId: o.id })));
|
|
189
|
+
|
|
117
190
|
program.command('pinned').description('List pinned conversations.').action(async () => output(await (await controls()).pinned()));
|
|
118
191
|
program.command('marked').description('List conversations marked with a flag.').action(async () => output(await (await controls()).marked()));
|
|
192
|
+
program.command('sidebar-list').description('List sidebar groups and display settings.').action(async () => output(await (await sidebar()).list()));
|
|
193
|
+
program.command('sidebar-set').description('Change sidebar group visibility, order or display settings.')
|
|
194
|
+
.requiredOption('--filter <name-or-id>', 'filter name from sidebar-list or numeric ID')
|
|
195
|
+
.option('--visibility <mode>', 'show or hide')
|
|
196
|
+
.option('--position <number>', 'one-based position among visible groups')
|
|
197
|
+
.option('--display <mode>', 'always, new or never in the message group')
|
|
198
|
+
.option('--message-type <type>', 'all, at_me, at_all or star_contacts; repeatable', collect, [])
|
|
199
|
+
.option('--at-all <mode>', 'include @all in the @me group: true or false')
|
|
200
|
+
.option('--show-filter <bool>', 'show the group sidebar: true or false')
|
|
201
|
+
.option('--show-mute-filter <bool>', 'show muted filter: true or false')
|
|
202
|
+
.option('--flag-sorting-rule <number>', 'native numeric flag sorting rule')
|
|
203
|
+
.option('--commonly-used <filter>', 'repeatable common filter name or ID', collect, [])
|
|
204
|
+
.action(async o => {
|
|
205
|
+
if (o.atAll != null && !['true', 'false'].includes(o.atAll)) throw new FeishuError('INVALID_ARGUMENT', 'at-all must be true or false.');
|
|
206
|
+
for (const k of ['showFilter', 'showMuteFilter']) if (o[k] != null && !['true', 'false'].includes(o[k])) throw new FeishuError('INVALID_ARGUMENT', k + ' must be true or false.');
|
|
207
|
+
output(await (await sidebar()).set({ filter: o.filter, visibility: o.visibility, ...(o.position != null ? { position: Number(o.position) } : {}),
|
|
208
|
+
display: o.display, ...(o.messageType.length ? { messageTypes: o.messageType } : {}), ...(o.atAll != null ? { atAll: o.atAll === 'true' } : {}), ...(o.showFilter != null ? { showFilter: o.showFilter === 'true' } : {}), ...(o.showMuteFilter != null ? { showMuteFilter: o.showMuteFilter === 'true' } : {}), ...(o.flagSortingRule != null ? { flagSortingRule: Number(o.flagSortingRule) } : {}), ...(o.commonlyUsed.length ? { commonlyUsedFilters: o.commonlyUsed } : {}) }));
|
|
209
|
+
});
|
|
119
210
|
program.command('labels').description('List personal conversation labels.').action(async () => output(await (await controls()).labels()));
|
|
120
211
|
program.command('label-chats').description('List conversations in a label.')
|
|
121
212
|
.requiredOption('--label <id>', 'numeric label ID').action(async o => output(await (await controls()).labelChats(o.label)));
|
|
@@ -256,7 +347,7 @@ program.command('download-file').description('Download a message file or image t
|
|
|
256
347
|
.requiredOption('--chat <id>', 'numeric chat ID')
|
|
257
348
|
.requiredOption('--message <id>', 'numeric message ID')
|
|
258
349
|
.requiredOption('--key <key>', 'file or image key from history')
|
|
259
|
-
.option('--position <number>', 'message position from history (required by a
|
|
350
|
+
.option('--position <number>', 'message position from history (required by a broker or OS delegate)')
|
|
260
351
|
.requiredOption('--output <path>', 'new local output file')
|
|
261
352
|
.action(async o => output(await (await client()).downloadFile({ chatId: o.chat, messageId: o.message, key: o.key, output: o.output, ...(o.position != null ? { position: Number(o.position) } : {}) })));
|
|
262
353
|
program.command('message-link').description('Get the native link to a message.')
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// This helper is launched once by a protected, environment-clearing sudo wrapper.
|
|
2
|
+
// The policy location is fixed relative to this protected installation, never to caller input.
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { loadDelegateConfig, serveOne } from '../src/os-delegate.js';
|
|
5
|
+
import { loadCookie } from '../src/credentials.js';
|
|
6
|
+
import { Gateway } from '../src/gateway.js';
|
|
7
|
+
import { LarkMateClient } from '../src/client.js';
|
|
8
|
+
import { SessionControls } from '../src/session-controls.js';
|
|
9
|
+
import { Minutes } from '../src/minutes.js';
|
|
10
|
+
import { FeishuError } from '../src/errors.js';
|
|
11
|
+
import { SidebarFilters } from '../src/sidebar-filters.js';
|
|
12
|
+
import { FeedGroups } from '../src/feed-groups.js';
|
|
13
|
+
import { Tasks } from '../src/tasks.js';
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
const caller = process.env.SUDO_UID, owner = process.getuid?.();
|
|
17
|
+
if (!Number.isInteger(owner) || typeof caller !== 'string' || !/^[1-9]\d*$/.test(caller) || !Number.isSafeInteger(Number(caller)) || Number(caller) === owner) throw new FeishuError('POLICY_DENIED', 'The operating-system caller identity is unavailable.');
|
|
18
|
+
const config = await loadDelegateConfig(fileURLToPath(new URL('../delegate-policy.json', import.meta.url)), owner);
|
|
19
|
+
const profile = config.users[caller];
|
|
20
|
+
if (!profile) throw new FeishuError('POLICY_DENIED', 'This operating-system user has no delegation profile.');
|
|
21
|
+
let services;
|
|
22
|
+
const getServices = () => services ||= (async () => {
|
|
23
|
+
const gateway = new Gateway({ cookie: await loadCookie({ file: config.credentialsFile }) });
|
|
24
|
+
return { client: new LarkMateClient(gateway), controls: new SessionControls(gateway), minutes: new Minutes(gateway), sidebar: new SidebarFilters(gateway), feeds: new FeedGroups(gateway), tasks: new Tasks(gateway) };
|
|
25
|
+
})();
|
|
26
|
+
await serveOne({ input: process.stdin, output: process.stdout, uid: caller, profile, getServices });
|
|
27
|
+
} catch (error) {
|
|
28
|
+
const detail = error instanceof FeishuError ? { code: error.code, message: error.message } : { code: 'DELEGATE_ERROR', message: 'Cannot start the delegated operation.' };
|
|
29
|
+
process.stdout.write(JSON.stringify({ ok: false, error: detail }) + '\n');
|
|
30
|
+
process.exitCode = 1;
|
|
31
|
+
}
|
package/docs/agent-broker.md
CHANGED
|
@@ -51,7 +51,7 @@ LarkMate 可以由持有 Cookie 的账户启动本地代理,再让 Agent 使
|
|
|
51
51
|
|
|
52
52
|
`minutes-export`、`minutes-access-info` 和 `minutes-request-access` 按 `minuteTokens` 限制;申请权限会向妙记所有者提交请求。`minutes-list` 除须在 `allow` 中授权外,还必须同时开启 `allowGlobal` 和 `allowAllMinutes`。
|
|
53
53
|
|
|
54
|
-
`status`
|
|
54
|
+
`status`、用于搜索用户、机器人、群聊的 `search`、`sidebar-list` 以及任务命令需要开启 `allowGlobal`。任务命令分别授权,当前授权范围覆盖该用户可访问的任务,不能按单个任务限制。`group-query` 和 `sidebar-set` 同时需要 `allowGlobal` 与 `allowAllChats`。跨会话搜索、会话及收藏列表、标签管理,以及仅凭消息 ID 操作的链接、编辑、撤回、转发、收藏和表情命令,除须在 `allow` 中各自授权外,还必须同时开启 `allowGlobal` 和 `allowAllChats`——这是因为代理无法仅凭消息 ID 判断其是否属于受限会话。群创建、邀请成员和机器人保护设置同样需要同时开启这两个开关。开启这些权限会扩大 Agent 可访问的信息范围或可执行的操作范围,请按需选择。
|
|
55
55
|
|
|
56
56
|
`send-file`、`send-image` 与 `download-file` 均可单独加入 `allow` 列表,并受 `chatIds` 约束。发送时,由 Agent 进程读取本地文件并传输内容;下载时,由 Agent 进程创建输出文件。代理不接受 Agent 指定的代理端本地路径,而是在私有临时目录中处理中转文件,并在正常结束或失败时将其删除。若进程异常终止,可能会遗留临时文件,因此部署方应保护并按需清理代理账户的临时目录。
|
|
57
57
|
|
package/docs/ai-install.md
CHANGED
|
@@ -22,9 +22,11 @@
|
|
|
22
22
|
|
|
23
23
|
## 登录与使用
|
|
24
24
|
|
|
25
|
+
若环境中已配置 `LARKMATE_DELEGATE_OWNER` 和 `LARKMATE_DELEGATE_LAUNCHER`,请先运行 `larkmate delegate-info`,通过系统用户委托使用 LarkMate,无需读取或配置 Cookie。遇到权限不足时遵循审批结果,不尝试绕过;具体部署见 [系统用户权限委托](https://github.com/NWYLZW/larkmate/blob/main/docs/os-delegation.md)。
|
|
26
|
+
|
|
25
27
|
若运行环境中已配置 `LARKMATE_BROKER` 和 `LARKMATE_BROKER_TOKEN_FILE`,请先运行 `larkmate broker-info`,通过受限代理使用 LarkMate,无需读取或配置 Cookie。当代理权限不足时,应说明具体情况,由所有者决定是否调整权限;具体部署见 [Agent 权限委托指南](https://github.com/NWYLZW/larkmate/blob/main/docs/agent-broker.md)。
|
|
26
28
|
|
|
27
|
-
|
|
29
|
+
未使用系统用户委托或受限代理时,LarkMate 默认从 `~/.larkmate/credentials.json` 读取 Cookie,也支持 `LARKMATE_HOME`、`LARKMATE_COOKIE` 和 `--credentials-file`。先保留并检查已有登录态,可用 `larkmate status` 验证;不要读取或打印 Cookie 的值到对话、日志或命令参数中。
|
|
28
30
|
|
|
29
31
|
如果没有可用登录态,引导用户在本机安全配置,不要要求用户把 Cookie、密码或验证码发到对话中。配置格式和手动步骤见 [快速安装](https://github.com/NWYLZW/larkmate/blob/main/INSTALL.md)。不能自动完成登录时,如实说明,不声称已经登录。
|
|
30
32
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 1,
|
|
3
|
+
"ownerUid": 1000,
|
|
4
|
+
"credentialsFile": "/absolute/owner-only/credentials.json",
|
|
5
|
+
"users": {
|
|
6
|
+
"1001": {
|
|
7
|
+
"policy": {
|
|
8
|
+
"version": 1,
|
|
9
|
+
"allow": ["chat-info", "history"],
|
|
10
|
+
"chatIds": [],
|
|
11
|
+
"minuteTokens": [],
|
|
12
|
+
"allowAllChats": false,
|
|
13
|
+
"allowAllMinutes": false,
|
|
14
|
+
"allowGlobal": false,
|
|
15
|
+
"maxFileBytes": 104857600
|
|
16
|
+
},
|
|
17
|
+
"approvalScript": "/absolute/owner-controlled/approve",
|
|
18
|
+
"approvalTimeoutSeconds": 300
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# 按系统用户委托 LarkMate
|
|
2
|
+
|
|
3
|
+
系统用户委托无需常驻服务:Agent 每次通过 `sudo` 启动受保护的执行器,执行器依据调用者的系统 UID 读取对应授权。策略允许的操作直接执行;其余受支持的操作交由该用户配置的审批脚本处理。只有审批脚本明确批准当前请求后,执行器才会执行飞书操作;调用完成后进程退出。原有的[本地代理模式](agent-broker.md)仍可使用。
|
|
4
|
+
|
|
5
|
+
## 安全边界
|
|
6
|
+
|
|
7
|
+
部署方须将 Agent 与 Cookie 所有者配置为不同的系统用户,确保 Agent 无法读取 Cookie,也无法修改受保护安装、Node.js 可执行文件及其依赖、启动器、策略文件、审批脚本或这些文件的上级目录,同时禁止 Agent 通过其他 `sudo` 规则以所有者身份运行任意程序。Agent 对其他文件的访问范围由系统账户或容器权限限制;策略文件无法限制 Agent 已有的系统权限。
|
|
8
|
+
|
|
9
|
+
以下为部署示例,请由系统管理员按实际路径和账户配置;LarkMate 不自动修改系统账户、文件权限或 `sudoers`。若没有满足这些条件,不能仅靠策略文件防止绕过或 Cookie 泄露。
|
|
10
|
+
|
|
11
|
+
## 策略文件
|
|
12
|
+
|
|
13
|
+
将 [示例配置](os-delegation.example.json) 复制到受保护安装包根目录的 `delegate-policy.json`。这个位置相对于安装包固定,不接受调用方指定。文件必须是所有者或 root 拥有的普通文件,不得允许组用户或其他用户写入;还应保护上级目录和 ACL。`ownerUid` 填写执行器所有者的 UID,`credentialsFile` 指向仅所有者可读的 Cookie 配置文件;`users` 的键是 Agent 的数字 UID。调用者 UID 未配置时直接拒绝,不进入审批。不能把所有者自身配置为 Agent。
|
|
14
|
+
|
|
15
|
+
每个用户的 `policy` 与[代理策略](agent-broker.md#配置授权)使用相同字段;只允许 `allow` 和资源范围共同匹配的操作。可通过 `larkmate delegate-commands` 查看可委托的命令及范围。可选的 `approvalScript` 必须是绝对路径、由所有者或 root 拥有的可执行普通文件,且不得允许组用户或其他用户写入;不配置时未授权操作直接拒绝。`approvalTimeoutSeconds` 默认 300 秒,可设为 1 至 600 秒。
|
|
16
|
+
|
|
17
|
+
文件、图片发送及附件下载可分别授权;上传文件由 Agent 进程读取,下载文件由 Agent 进程写入。执行器不接受 Agent 提供的所有者本地路径。下载时须提供 `history` 返回的 `--position`,执行器会核验会话、消息和资源键。单个文件受 `maxFileBytes` 限制;执行器在所有者私有临时目录中处理中转数据,正常结束或失败时删除,异常退出可能留下临时文件。部署方应保护、按需清理临时目录,并根据实际需要配置系统资源限制。
|
|
18
|
+
|
|
19
|
+
## 启动器与 sudoers 示例
|
|
20
|
+
|
|
21
|
+
将 LarkMate 包及依赖安装在 Agent 无法修改的受保护位置,将以下启动器放在同样受保护的位置。示例路径均须替换为实际绝对路径;Node.js 可执行文件和其依赖也不能由 Agent 修改。固定工作目录并清空环境,避免调用者通过环境变量或当前目录影响执行器。
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
#!/bin/sh
|
|
25
|
+
case "${SUDO_UID-}" in ''|*[!0-9]*) exit 1 ;; esac
|
|
26
|
+
cd /opt/larkmate/node_modules/larkmate || exit 1
|
|
27
|
+
umask 077
|
|
28
|
+
exec /usr/bin/env -i \
|
|
29
|
+
SUDO_UID="$SUDO_UID" HOME=/absolute/owner/home PATH=/usr/bin:/bin \
|
|
30
|
+
/absolute/protected/node \
|
|
31
|
+
/opt/larkmate/node_modules/larkmate/bin/os-delegate-helper.js
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
例如,以下 sudoers 片段只允许 `agent` 以 `owner` 身份、不带额外参数运行这个启动器。必须先用 `visudo` 验证并由管理员安装,实际规则不能向 Agent 提供任意命令、`SETENV`、保留调用者环境或其他提权通道:
|
|
35
|
+
|
|
36
|
+
```sudoers
|
|
37
|
+
Cmnd_Alias LARKMATE_DELEGATE = /opt/larkmate/launch ""
|
|
38
|
+
Defaults!LARKMATE_DELEGATE env_reset
|
|
39
|
+
agent ALL=(owner) NOPASSWD: NOSETENV: LARKMATE_DELEGATE
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
执行器依赖 `sudo` 设置的 `SUDO_UID` 确定调用者;不要从 Agent 的环境、参数或文件中自行接收该 UID。启动器、策略、Node.js、依赖、审批脚本及上级目录的保护是部署前提,应检查 ACL 和已有的其他 sudo 规则。不要让 Agent 直接使用所有者账号。
|
|
43
|
+
|
|
44
|
+
在 Agent 环境中设置所有者名称和受保护启动器路径:
|
|
45
|
+
|
|
46
|
+
```sh
|
|
47
|
+
export LARKMATE_DELEGATE_OWNER=owner
|
|
48
|
+
export LARKMATE_DELEGATE_LAUNCHER=/opt/larkmate/launch
|
|
49
|
+
larkmate delegate-info
|
|
50
|
+
larkmate history --chat "$CHAT_ID" --limit 20
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
也可使用 `--delegate-owner` 和 `--delegate-launcher`。不可同时配置本地代理或指定 Cookie 文件。没有预设权限且配置了审批脚本时,调用会等待脚本结果。分页导出可能产生多次独立调用;若这些调用不在预设权限内,每次都会分别请求审批。
|
|
54
|
+
|
|
55
|
+
## 审批脚本协议
|
|
56
|
+
|
|
57
|
+
执行器不经 shell 直接启动脚本,通过标准输入发送一行 JSON;脚本通过标准输出返回一行 JSON,其他日志应写入标准错误。输入包含 `version`、随机 `requestId`、`callerUid` 和完整 `request`。发送文件或图片时还包含 `file.name`、`file.size` 和 `file.sha256`;摘要对应已收到的文件内容。脚本运行在所有者身份下,环境仅提供固定的 `PATH`、所有者 `HOME` 和 `LANG`。
|
|
58
|
+
|
|
59
|
+
脚本应把操作、目标及必要的内容呈现给所有者,可以自行发送卡片并等待确认。只有获得针对该 `requestId` 和对应请求的有效确认后,才以退出码 0 输出:
|
|
60
|
+
|
|
61
|
+
```json
|
|
62
|
+
{"decision":"allow","requestId":"输入中的 requestId"}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
脚本必须自行验证卡片确认人的身份,确保确认绑定当前请求且不可重放。拒绝、超时、异常、非零退出码、输出过大、格式错误或 `requestId` 不匹配均视为拒绝。一次批准只用于当前调用,不更改策略文件,也不会绕过文件大小上限、请求格式检查或附件归属校验。审批内容可能包含消息正文和文件名,请按数据敏感程度保护脚本、审批渠道和日志。
|
package/package.json
CHANGED
package/proto/lark.proto
CHANGED
|
@@ -499,7 +499,11 @@ message PullFeedCardsResponse {
|
|
|
499
499
|
map<string, Chat> chats = 1;
|
|
500
500
|
repeated InboxCard cards = 3;
|
|
501
501
|
optional int64 nextCursor = 4;
|
|
502
|
+
map<string, FeedDoc> docFeeds = 6;
|
|
503
|
+
map<string, FeedThread> threads = 8;
|
|
502
504
|
}
|
|
505
|
+
message FeedDoc { optional string id = 1; optional string title = 2; optional string url = 5; optional int32 newMessageCount = 10; }
|
|
506
|
+
message FeedThread { optional string id = 1; optional string channelId = 2; optional string topic = 4; optional int32 newMessageCount = 10; }
|
|
503
507
|
message CreateFileUploadRequest {
|
|
504
508
|
optional int32 fileType = 3;
|
|
505
509
|
optional string fileName = 5;
|
|
@@ -606,3 +610,40 @@ message BoxCardsRequest { map<string, int32> feedCards = 1; }
|
|
|
606
610
|
message PatchFeedCardsRequest { optional int32 type = 1; repeated string ids = 2; repeated InboxCard cards = 3; }
|
|
607
611
|
message PutReadMessagesRequest { optional string chatId = 1; repeated string messageIds = 2; optional int32 maxPosition = 3; }
|
|
608
612
|
message PutReadMessagesResponse { optional int32 lastMessagePosition = 1; optional int32 newMessageCount = 2; optional int32 readPosition = 6; }
|
|
613
|
+
|
|
614
|
+
// --- Conversation sidebar filters (cmd 7022/7023) ---
|
|
615
|
+
message SidebarFilter { optional int32 systemFilter = 1; }
|
|
616
|
+
message SidebarDisplayRule { optional int32 mainRule = 1; repeated int32 msgTypes = 2 [packed=false]; }
|
|
617
|
+
message SidebarFilterSetting {
|
|
618
|
+
optional bool showFilter = 1;
|
|
619
|
+
repeated SidebarFilter usedFilters = 2;
|
|
620
|
+
optional int64 version = 3;
|
|
621
|
+
optional bool showMuteFilter = 4;
|
|
622
|
+
repeated SidebarFilter unusedFilters = 5;
|
|
623
|
+
optional bool showAtAllInAtFilter = 6;
|
|
624
|
+
repeated SidebarFilter commonlyUsedFilters = 7;
|
|
625
|
+
map<int32, int32> commonlyUsedFilterRealAction = 8;
|
|
626
|
+
optional int32 flagSortingRule = 9;
|
|
627
|
+
map<int32, SidebarDisplayRule> filterDisplayFeedRule = 10;
|
|
628
|
+
map<int32, int32> filterDisplayFeedRuleChanged = 11;
|
|
629
|
+
}
|
|
630
|
+
message PullSidebarFilterSettingRequest { optional bool needAllFilters = 1; optional int64 clientSupportVersion = 2; optional int64 clientSupportVersionV2 = 3; }
|
|
631
|
+
message PullSidebarFilterSettingResponse { optional SidebarFilterSetting setting = 1; repeated SidebarFilter allFilters = 2; optional bool isDefaultSetting = 3; }
|
|
632
|
+
message PutSidebarFilterSettingRequest {
|
|
633
|
+
optional bool showFilter = 1;
|
|
634
|
+
repeated SidebarFilter usedFilters = 2;
|
|
635
|
+
optional bool showMuteFilter = 3;
|
|
636
|
+
optional int64 clientSupportVersion = 4;
|
|
637
|
+
optional bool showAtAllInAtFilter = 5;
|
|
638
|
+
repeated SidebarFilter commonlyUsedFilters = 6;
|
|
639
|
+
optional int32 flagSortingRule = 7;
|
|
640
|
+
map<int32, SidebarDisplayRule> filterDisplayFeedRule = 8;
|
|
641
|
+
map<int64, SidebarDisplayRule> feedGroupDisplayFeedRule = 9;
|
|
642
|
+
optional int64 clientSupportVersionV2 = 10;
|
|
643
|
+
repeated int32 updateFields = 31 [packed=false];
|
|
644
|
+
}
|
|
645
|
+
message PutSidebarFilterSettingResponse { optional SidebarFilterSetting setting = 1; }
|
|
646
|
+
message PullUnreadAtMessageIdsRequest { optional int32 version = 1; repeated int64 messageIds = 2 [packed=false]; }
|
|
647
|
+
message PullUnreadAtMessageIdsResponse { repeated string messageIds = 1; map<string, string> messageThreadIds = 2; }
|
|
648
|
+
message PullMessagesByIdsRequest { repeated string messageIds = 1; }
|
|
649
|
+
message PullMessagesByIdsResponse { map<string, MessageEntity> messages = 1; }
|