@geminilight/mindos 0.6.25 → 0.6.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README.md +19 -3
  2. package/README_zh.md +19 -3
  3. package/app/app/api/a2a/discover/route.ts +23 -0
  4. package/app/components/CreateSpaceModal.tsx +1 -0
  5. package/app/components/ImportModal.tsx +3 -0
  6. package/app/components/OnboardingView.tsx +1 -0
  7. package/app/components/RightAskPanel.tsx +4 -2
  8. package/app/components/SidebarLayout.tsx +11 -2
  9. package/app/components/agents/DiscoverAgentModal.tsx +149 -0
  10. package/app/components/ask/AskContent.tsx +21 -9
  11. package/app/components/ask/SessionTabBar.tsx +70 -0
  12. package/app/components/echo/EchoInsightCollapsible.tsx +4 -0
  13. package/app/components/panels/AgentsPanel.tsx +25 -2
  14. package/app/components/renderers/workflow/WorkflowRenderer.tsx +5 -0
  15. package/app/components/settings/AiTab.tsx +1 -0
  16. package/app/components/settings/KnowledgeTab.tsx +2 -0
  17. package/app/components/settings/SyncTab.tsx +2 -0
  18. package/app/components/setup/StepDots.tsx +5 -1
  19. package/app/data/skills/mindos/SKILL.md +186 -0
  20. package/app/data/skills/mindos-zh/SKILL.md +185 -0
  21. package/app/hooks/useA2aRegistry.ts +53 -0
  22. package/app/hooks/useAskSession.ts +44 -25
  23. package/app/lib/a2a/a2a-tools.ts +212 -0
  24. package/app/lib/a2a/client.ts +207 -0
  25. package/app/lib/a2a/index.ts +8 -0
  26. package/app/lib/a2a/orchestrator.ts +255 -0
  27. package/app/lib/a2a/types.ts +54 -0
  28. package/app/lib/agent/tools.ts +6 -4
  29. package/app/lib/i18n-en.ts +52 -0
  30. package/app/lib/i18n-zh.ts +52 -0
  31. package/app/next-env.d.ts +1 -1
  32. package/bin/cli.js +180 -171
  33. package/bin/commands/agent.js +110 -18
  34. package/bin/commands/api.js +5 -3
  35. package/bin/commands/ask.js +3 -3
  36. package/bin/commands/file.js +13 -13
  37. package/bin/commands/search.js +2 -2
  38. package/bin/commands/space.js +64 -10
  39. package/bin/lib/command.js +10 -0
  40. package/package.json +1 -1
@@ -3,6 +3,7 @@
3
3
  import { useMemo, useState, useRef, useCallback } from 'react';
4
4
  import { Play, SkipForward, RotateCcw, CheckCircle2, Circle, Loader2, AlertCircle, ChevronDown, Sparkles } from 'lucide-react';
5
5
  import type { RendererContext } from '@/lib/renderers/registry';
6
+ import { useLocale } from '@/lib/LocaleContext';
6
7
 
7
8
  // ─── Types ────────────────────────────────────────────────────────────────────
8
9
 
@@ -171,6 +172,7 @@ function StepCard({
171
172
  onSkip: () => void;
172
173
  canRun: boolean;
173
174
  }) {
175
+ const { t } = useLocale();
174
176
  const [expanded, setExpanded] = useState(false);
175
177
  const hasBody = step.body.trim().length > 0;
176
178
  const hasOutput = step.output.length > 0;
@@ -201,6 +203,7 @@ function StepCard({
201
203
  <button
202
204
  onClick={onRun}
203
205
  disabled={!canRun}
206
+ title={!canRun ? t.hints.workflowStepRunning : undefined}
204
207
  style={{
205
208
  display: 'flex', alignItems: 'center', gap: 4,
206
209
  padding: '3px 10px', borderRadius: 6, fontSize: '0.72rem',
@@ -268,6 +271,7 @@ function StepCard({
268
271
  // ─── Main renderer ────────────────────────────────────────────────────────────
269
272
 
270
273
  export function WorkflowRenderer({ filePath, content }: RendererContext) {
274
+ const { t } = useLocale();
271
275
  const parsed = useMemo(() => parseWorkflow(content), [content]);
272
276
  const [steps, setSteps] = useState<WorkflowStep[]>(() => parsed.steps);
273
277
  const [running, setRunning] = useState(false);
@@ -357,6 +361,7 @@ export function WorkflowRenderer({ filePath, content }: RendererContext) {
357
361
  <button
358
362
  onClick={() => runStep(nextPendingIdx)}
359
363
  disabled={running}
364
+ title={running ? t.hints.workflowRunning : undefined}
360
365
  style={{
361
366
  display: 'flex', alignItems: 'center', gap: 5,
362
367
  padding: '4px 12px', borderRadius: 7, fontSize: '0.75rem',
@@ -125,6 +125,7 @@ export function AiTab({ data, updateAi, updateAgent, t }: AiTabProps) {
125
125
  <button
126
126
  type="button"
127
127
  disabled={disabled}
128
+ title={disabled ? t.hints.testInProgressOrNoKey : undefined}
128
129
  onClick={() => handleTestKey(providerName)}
129
130
  className="inline-flex items-center gap-1.5 px-2.5 py-1 text-xs rounded-lg border border-border text-muted-foreground hover:text-foreground hover:border-foreground/20 transition-colors disabled:opacity-40 disabled:cursor-not-allowed"
130
131
  >
@@ -173,6 +173,7 @@ export function KnowledgeTab({ data, setData, t }: KnowledgeTabProps) {
173
173
  <button
174
174
  onClick={() => setShowCleanupConfirm(true)}
175
175
  disabled={cleaningUp}
176
+ title={cleaningUp ? t.hints.cleanupInProgress : undefined}
176
177
  className="flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium rounded-lg border border-border text-muted-foreground hover:text-foreground hover:bg-muted transition-colors shrink-0 disabled:opacity-50"
177
178
  >
178
179
  {cleaningUp ? <Loader2 size={12} className="animate-spin" /> : <Trash2 size={12} />}
@@ -249,6 +250,7 @@ export function KnowledgeTab({ data, setData, t }: KnowledgeTabProps) {
249
250
  type="button"
250
251
  onClick={handleResetToken}
251
252
  disabled={resetting}
253
+ title={resetting ? t.hints.tokenResetInProgress : undefined}
252
254
  className="flex items-center gap-1.5 px-3 py-1.5 text-xs rounded-lg border border-border text-muted-foreground hover:text-foreground hover:bg-muted disabled:opacity-40 disabled:cursor-not-allowed transition-colors"
253
255
  >
254
256
  <RefreshCw size={12} className={resetting ? 'animate-spin' : ''} />
@@ -302,6 +302,7 @@ export function SyncTab({ t }: SyncTabProps) {
302
302
  type="button"
303
303
  onClick={handleSyncNow}
304
304
  disabled={syncing}
305
+ title={syncing ? t.hints.syncInProgress : undefined}
305
306
  className="flex items-center gap-1.5 px-3 py-1.5 text-xs rounded-lg border border-border text-muted-foreground hover:text-foreground hover:bg-muted disabled:opacity-40 disabled:cursor-not-allowed transition-colors"
306
307
  >
307
308
  <RefreshCw size={12} className={syncing ? 'animate-spin' : ''} />
@@ -311,6 +312,7 @@ export function SyncTab({ t }: SyncTabProps) {
311
312
  type="button"
312
313
  onClick={handleToggle}
313
314
  disabled={toggling}
315
+ title={toggling ? t.hints.toggleInProgress : undefined}
314
316
  className={`flex items-center gap-1.5 px-3 py-1.5 text-xs rounded-lg border transition-colors disabled:opacity-40 disabled:cursor-not-allowed ${
315
317
  status.enabled
316
318
  ? 'border-border text-muted-foreground hover:text-destructive hover:border-destructive/50'
@@ -1,5 +1,7 @@
1
1
  'use client';
2
2
 
3
+ import { useLocale } from '@/lib/LocaleContext';
4
+
3
5
  export interface StepDotsProps {
4
6
  step: number;
5
7
  setStep: (s: number) => void;
@@ -8,6 +10,7 @@ export interface StepDotsProps {
8
10
  }
9
11
 
10
12
  export default function StepDots({ step, setStep, stepTitles, disabled }: StepDotsProps) {
13
+ const { t } = useLocale();
11
14
  return (
12
15
  <div className="flex items-center gap-2 mb-8" role="navigation" aria-label="Setup steps">
13
16
  {stepTitles.map((title: string, i: number) => (
@@ -17,7 +20,8 @@ export default function StepDots({ step, setStep, stepTitles, disabled }: StepDo
17
20
  aria-current={i === step ? 'step' : undefined}
18
21
  aria-label={title}
19
22
  className="flex flex-col items-center gap-1 p-1 -m-1 disabled:cursor-not-allowed disabled:opacity-60"
20
- disabled={disabled || i >= step}>
23
+ disabled={disabled || i >= step}
24
+ title={(disabled || i >= step) ? t.hints.cannotJumpForward : undefined}>
21
25
  <div
22
26
  className="w-6 h-6 rounded-full text-xs font-medium flex items-center justify-center transition-colors"
23
27
  style={{
@@ -0,0 +1,186 @@
1
+ ---
2
+ name: mindos
3
+ description: >
4
+ Operate a MindOS knowledge base: update notes, search, organize files, execute SOPs/workflows,
5
+ retrospective, append CSV, cross-agent handoff, route unstructured input to the right files,
6
+ distill experience, sync related docs. 更新笔记, 搜索知识库, 整理, 执行SOP, 复盘, 追加CSV, 交接, 路由到文件, 提炼经验.
7
+ Use when the task targets files inside the user's MindOS KB (mindRoot).
8
+ NOT for editing app source, project docs, or paths outside the KB.
9
+ Core concepts: Space, Instruction (INSTRUCTION.md), Skill (SKILL.md); notes can embody both.
10
+ ---
11
+
12
+ # MindOS Skill
13
+
14
+ <!-- version: 1.3.0 -->
15
+
16
+ **Before every task, internalize these 5 rules:**
17
+
18
+ 1. The **bootstrap directory tree is the primary index** — reason from names and hierarchy before calling search. Most questions can be answered by reading what's already in context.
19
+ 2. **Default to read-only.** Only invoke write tools when the user explicitly asks to save, record, organize, or edit. Lookup / summarize / quote = no writes.
20
+ 3. **Rule precedence** (highest wins): user's current-turn instruction → `user-skill-rules.md` → nearest directory `INSTRUCTION.md` → root `INSTRUCTION.md` → this SKILL's defaults.
21
+ 4. **Multi-file edits require a plan first.** Present the full change list; execute only after approval.
22
+ 5. After create/delete/move/rename → **sync affected READMEs** automatically.
23
+
24
+ ---
25
+
26
+ ## NEVER do (hard-won pitfalls)
27
+
28
+ - **NEVER write to the KB root** unless the user explicitly says so. Root is for governance files only (`README.md`, `INSTRUCTION.md`, `CONFIG`). New content goes under the most semantically fitting subdirectory.
29
+ - **NEVER assume directory names.** Don't hardcode `Workflows/`, `Projects/`, `Contacts/` — always infer from the bootstrap tree you actually received. The user's KB may use Chinese names, flat layout, or unconventional hierarchy.
30
+ - **NEVER use `mindos_write_file` for a small edit.** Use `update_section`, `update_lines`, or `insert_after_heading` — full-file rewrites destroy git diffs and make changes unauditable.
31
+ - **NEVER search with a single keyword.** Always fire 2-4 parallel searches (synonyms, abbreviations, Chinese/English variants). One keyword misses too much.
32
+ - **NEVER modify `INSTRUCTION.md` or `README.md` without confirmation.** These are governance docs — treat as high-sensitivity even for trivial-looking typo fixes.
33
+ - **NEVER create a file without checking siblings first.** Read at least 1-2 files in the target directory to learn local naming, heading style, and CSV schema. Inventing a new convention is a common cause of inconsistency.
34
+ - **NEVER leave orphan references.** After any rename/move, run `get_backlinks` and update every referring file. Missing this is the #1 source of broken links in a KB.
35
+ - **NEVER skip the routing confirmation for multi-file writes.** Even when the destinations seem obvious — the user's mental model may differ from yours.
36
+
37
+ ---
38
+
39
+ ## MindOS concepts
40
+
41
+ - **Space** — Knowledge partitions organized the way you think. Agents follow the same structure.
42
+ - **Instruction** — A rules file all connected agents obey. Written once, enforced everywhere.
43
+ - **Skill** — Teaches agents how to read, write, and organize the KB. Agents execute installed Skills, not guesses.
44
+
45
+ **Notes as Instruction and Skill** — `INSTRUCTION.md` and `SKILL.md` are just Markdown files in the tree. A note can be free-form text, governance rules agents must follow, or a procedure package agents execute.
46
+
47
+ ---
48
+
49
+ ## Thinking framework
50
+
51
+ Before acting, ask yourself:
52
+
53
+ 1. **What is the user's intent category?** → read-only lookup | single-file edit | multi-file routing | structural change | SOP execution. This determines which path to take below.
54
+ 2. **Where does this content belong?** → Scan the directory tree. If you can't place it in <5 seconds of looking at names, the user probably needs to confirm.
55
+ 3. **What already exists nearby?** → Read 1-2 sibling files before writing. Match their style.
56
+ 4. **What will break if I change this?** → For renames/moves: `get_backlinks`. For content edits: think about who else cites this fact.
57
+ 5. **Am I being asked, or am I volunteering?** → If the user didn't ask you to write, don't write.
58
+
59
+ ---
60
+
61
+ ## Task routing decision tree
62
+
63
+ ```
64
+ User request
65
+
66
+ ├─ Only asks to look up / summarize / quote?
67
+ │ └─ YES → [Read-only path]: search + read + cite sources. No writes. Skip hooks.
68
+
69
+ ├─ Asks to save / record / update / organize specific content?
70
+ │ ├─ Single file target? → [Single-file edit]: startup → read → minimal edit → verify
71
+ │ └─ Multiple files or unclear target? → [Multi-file routing]: parse → plan → confirm → edit
72
+
73
+ ├─ Structural change (rename / move / delete / reorganize)?
74
+ │ └─ [Structural path]: get_backlinks → impact report → confirm → execute → update refs → sync READMEs
75
+
76
+ ├─ Procedural / repeatable task?
77
+ │ └─ [SOP path]: search for matching SOP (keywords + tree scan) → read → execute stepwise → propose SOP update if diverged
78
+
79
+ ├─ Retrospective / distill / handoff?
80
+ │ └─ [Retrospective path]: confirm scope → extract artifacts → route → summarize changes
81
+
82
+ └─ Ambiguous or too broad?
83
+ └─ ASK for clarification. Propose 2-3 specific options based on KB state. Do NOT start editing.
84
+ ```
85
+
86
+ ---
87
+
88
+ ## Startup protocol (write tasks only)
89
+
90
+ Skip for [read-only path](#task-routing-decision-tree). For all writes:
91
+
92
+ 1. **Bootstrap** — `mindos_bootstrap` (preferred) or manually read root `INSTRUCTION.md` + `README.md`.
93
+ 2. **Discover structure** — `mindos_list_spaces` (top-level zones + README blurbs) and/or `mindos_list_files` + targeted `mindos_search_notes`. Never assume top-level names.
94
+ 3. **Load local governance** — Read `README.md` / `INSTRUCTION.md` near the target path. Local conventions override global assumptions.
95
+ 4. **Match existing SOP** — If the task is procedural: scan tree for a procedure-holding directory (names like `Workflows/`, `SOPs/`, `流程/` are hints — don't assume). Search by keywords + `<!-- keywords: -->` metadata. If found, read and follow. If execution diverges, propose updating the SOP after.
96
+ 5. **Pre-write checks** — Confirm: target path exists or should be created; location is under a subdirectory (not root); current content is read; edit scope is minimal; backlink impact assessed for path changes.
97
+ 6. **Execute edits.**
98
+
99
+ If context is missing, continue with best effort and state assumptions.
100
+
101
+ ---
102
+
103
+ ## Tool selection
104
+
105
+ | Intent | Best tool | Avoid |
106
+ |--------|-----------|-------|
107
+ | Load context at start | `mindos_bootstrap` | Reading random files without bootstrap |
108
+ | List top-level Mind Spaces | `mindos_list_spaces` | Full `mindos_list_files` when you only need zone names and README blurbs |
109
+ | Find files | `mindos_search_notes` (2-4 parallel keyword variants) | Single-keyword search |
110
+ | Read content | `mindos_read_file` or `mindos_read_lines` (for large files) | Reading entire large file when you need 10 lines |
111
+ | Small text edit | `mindos_update_section` / `mindos_update_lines` / `mindos_insert_after_heading` | `mindos_write_file` for small changes |
112
+ | Append to end | `mindos_append_to_file` | Rewriting entire file to add a line |
113
+ | Full file replacement | `mindos_write_file` | Using this when a section edit suffices |
114
+ | New file | `mindos_create_file` | Creates parent dirs but does NOT scaffold Space files |
115
+ | New Mind Space (zone + README + INSTRUCTION) | `mindos_create_space` | The only way to create a Space. `create_file` creates plain folders |
116
+ | Rename a Space directory | `mindos_rename_space` | `rename_file` (files only; does not rename folders) |
117
+ | Add CSV row | `mindos_append_csv` (validates header) | Manual string append without header check |
118
+ | Check impact before rename | `mindos_get_backlinks` | Renaming without checking references |
119
+ | Inspect recent changes | `mindos_get_recent` | Guessing what changed recently |
120
+ | Recover old version | `mindos_get_file_at_version` | Asking user to recall what was there |
121
+
122
+ ### Fallbacks
123
+
124
+ - `mindos_bootstrap` unavailable → manual reads of root `INSTRUCTION.md` + `README.md`.
125
+ - Line/section tools unavailable → read + constrained `mindos_write_file` (simulate minimal edit).
126
+ - Search returns empty → don't give up: (1) scan tree in context, (2) read candidate files directly, (3) `mindos_list_files` on specific subdirectories, (4) try synonym/alternate-language keywords.
127
+
128
+ ---
129
+
130
+ ## Execution patterns
131
+
132
+ ### Single-file edit
133
+ Search → read target + local conventions → minimal edit → verify style match → summarize.
134
+
135
+ ### Context-aware Q&A (read-only)
136
+ Tree reasoning → search → read → answer with file citations → state gaps explicitly.
137
+
138
+ ### Multi-file routing
139
+ Parse unstructured input into semantic units → search candidates per unit → **present routing table** (what → file → position) → confirm → edit → summarize all changes.
140
+
141
+ ### Conversation retrospective
142
+ Confirm scope → extract decisions, rationale, pitfalls, next actions → route to best existing files → trace note of what changed.
143
+
144
+ ### SOP execution
145
+ Read SOP fully → execute step by step → update only stale sections → if diverged, propose SOP update.
146
+ **When creating a new SOP** → read [references/sop-template.md](./references/sop-template.md) first.
147
+
148
+ ### Structural changes
149
+ `get_backlinks` → report impact → confirm → execute → update all refs → sync READMEs.
150
+
151
+ ### Quick reference patterns
152
+
153
+ | Pattern | Key steps |
154
+ |---------|-----------|
155
+ | CSV append | Read header → validate fields → `mindos_append_csv` |
156
+ | TODO management | Find list → read format → minimal edit preserving conventions |
157
+ | Cross-agent handoff | Read task state + decisions → continue without re-discovery → write back progress |
158
+ | Knowledge conflict | Multi-keyword search → list affected files → present change plan → confirm → update |
159
+ | Periodic review | `get_recent` / `get_history` → read changed files → structured summary |
160
+ | Handoff doc | Read sources → synthesize (background, decisions, status, open items) → place in project dir |
161
+
162
+ ---
163
+
164
+ ## Interaction rules
165
+
166
+ - **Ambiguous request?** Ask first. Propose 2-3 options based on KB state (recent changes, directory structure). Never start reorganizing without understanding scope.
167
+ - **Cite sources.** Every fact from the KB gets a file path so the user can verify.
168
+ - **Brevity first.** Show the most likely match, not an exhaustive list.
169
+
170
+ ---
171
+
172
+ ## Post-task hooks
173
+
174
+ After **write tasks**, read [references/post-task-hooks.md](./references/post-task-hooks.md) for one-line follow-up proposals (experience capture, consistency sync, SOP drift, etc.).
175
+ **Read-only tasks: skip hooks.** If the user asked for quiet mode, skip all hooks for the session.
176
+ **Do NOT read** post-task-hooks for simple single-file edits or read-only lookups.
177
+
178
+ ## Preference capture
179
+
180
+ When the user expresses a standing preference ("don't do X", "always put Y in Z"), read [references/preference-capture.md](./references/preference-capture.md) and follow the confirm-then-write flow to `user-skill-rules.md`.
181
+ **Do NOT read** preference-capture unless the user actually expressed a preference to persist.
182
+
183
+ ## SOP authoring
184
+
185
+ When creating or rewriting a workflow SOP, **MANDATORY — read [references/sop-template.md](./references/sop-template.md)** for required structure (prerequisites, steps with branches, exit conditions, pitfall log).
186
+ **Do NOT read** sop-template for SOP execution (only for SOP creation/editing).
@@ -0,0 +1,185 @@
1
+ ---
2
+ name: mindos-zh
3
+ description: >
4
+ 操作 MindOS 知识库:更新笔记, 搜索知识库, 整理文件, 执行SOP/工作流, 复盘, 追加CSV, 跨Agent交接,
5
+ 路由非结构化输入到对应文件, 提炼经验, 同步关联文档.
6
+ update notes, search knowledge base, organize, SOP, retrospective, CSV, handoff, route notes, distill experience.
7
+ 仅 mindRoot 知识库内任务。不用于:改代码仓库/项目文档/KB 外路径。
8
+ 核心概念:空间、指令(INSTRUCTION.md)、技能(SKILL.md);笔记可承载指令与技能。
9
+ ---
10
+
11
+ # MindOS Skill
12
+
13
+ <!-- version: 1.3.0 -->
14
+
15
+ **每次任务前,内化这 5 条规则:**
16
+
17
+ 1. **bootstrap 目录树是首要索引** — 先从目录名和层级推断,再搜索。大多数定位不需要工具调用。
18
+ 2. **默认只读。** 只有用户明确要求保存、记录、整理、修改时才调写入工具。查阅/总结/引用 = 不写。
19
+ 3. **规则优先级**(越上越优先):用户当轮指令 → `user-skill-rules.md` → 就近目录 `INSTRUCTION.md` → 根 `INSTRUCTION.md` → 本 SKILL 默认。
20
+ 4. **多文件编辑必须先出计划。** 展示完整变更清单,确认后再执行。
21
+ 5. 增删/移动/重命名后 → **自动同步受影响 README**。
22
+
23
+ ---
24
+
25
+ ## 绝对不要(踩坑清单)
26
+
27
+ - **绝不写入 KB 根目录**,除非用户明确要求。根目录只放治理文件(`README.md`、`INSTRUCTION.md`、`CONFIG`)。新内容放语义最合适的子目录。
28
+ - **绝不假设目录名。** 不要写死 `Workflows/`、`Projects/`、`Contacts/` — 必须从实际收到的 bootstrap 目录树推断。用户可能用中文名、扁平结构或独特层级。
29
+ - **绝不用 `mindos_write_file` 做小修改。** 用 `update_section`、`update_lines` 或 `insert_after_heading` — 整文件覆写破坏 git diff,变更无法审计。
30
+ - **绝不单关键词搜索。** 必须并行 2-4 条搜索(同义词、缩写、中英文变体)。单条命中率太低。
31
+ - **绝不未经确认就改 `INSTRUCTION.md` 或 `README.md`。** 它们是治理文档,即使看起来只是修个错别字。
32
+ - **绝不在没看过邻居文件的情况下创建新文件。** 至少读 1-2 个同目录文件,学习本地命名/标题/CSV 格式。自创新规是不一致的常见根源。
33
+ - **绝不留孤链。** 重命名/移动后必须 `get_backlinks` 并更新每一个引用方。这是知识库断链的首因。
34
+ - **绝不跳过多文件写入的路由确认。** 即使目标看起来很明显——用户的心智模型可能和你不同。
35
+
36
+ ---
37
+
38
+ ## MindOS 核心概念
39
+
40
+ - **空间(Space)** — 按你的思维方式组织的知识分区。Agent 遵循同样的结构。
41
+ - **指令(Instruction)** — 所有接入 Agent 都遵守的规则文件。写一次,全局生效。
42
+ - **技能(Skill)** — 教 Agent 如何读写、整理知识库。Agent 按安装的 Skill 执行,不是瞎猜。
43
+
44
+ **笔记即指令 / 技能** — `INSTRUCTION.md` 和 `SKILL.md` 就是目录树里的 Markdown 文件。笔记可以是随笔,也可以是 Agent 必须遵守的治理规则,或 Agent 按步骤执行的程序包。
45
+
46
+ ---
47
+
48
+ ## 思维框架
49
+
50
+ 动手前,问自己:
51
+
52
+ 1. **用户意图属于哪类?** → 只读查阅 | 单文件编辑 | 多文件路由 | 结构变更 | SOP 执行。决定走下面哪条路径。
53
+ 2. **这个内容该放哪?** → 扫目录树。如果看名字 5 秒内定不下来,大概率要问用户确认。
54
+ 3. **附近有什么?** → 写之前读 1-2 个同级文件,照它们的风格。
55
+ 4. **改这里会打断什么?** → 重命名/移动:`get_backlinks`。内容修改:想想谁引用了这个事实。
56
+ 5. **用户让我写了吗,还是我自作主张?** → 没让你写就别写。
57
+
58
+ ---
59
+
60
+ ## 任务路由决策树
61
+
62
+ ```
63
+ 用户请求
64
+
65
+ ├─ 只是查找 / 总结 / 引用?
66
+ │ └─ 是 → [只读路径]:搜索 + 读取 + 标注来源。不写入。跳过 Hooks。
67
+
68
+ ├─ 要求保存 / 记录 / 更新 / 整理具体内容?
69
+ │ ├─ 单文件目标? → [单文件编辑]:启动协议 → 读取 → 最小化修改 → 验证
70
+ │ └─ 多文件或目标不明? → [多文件路由]:解析 → 出计划 → 确认 → 编辑
71
+
72
+ ├─ 结构变更(重命名 / 移动 / 删除 / 重组)?
73
+ │ └─ [结构路径]:get_backlinks → 影响报告 → 确认 → 执行 → 更新引用 → 同步 README
74
+
75
+ ├─ 流程性 / 可重复的任务?
76
+ │ └─ [SOP 路径]:搜索匹配 SOP(关键词 + 目录树扫描)→ 读取 → 逐步执行 → 偏差则提议更新 SOP
77
+
78
+ ├─ 复盘 / 提炼 / 交接?
79
+ │ └─ [复盘路径]:确认范围 → 抽取产物 → 路由 → 汇总变更
80
+
81
+ └─ 模糊或范围过大?
82
+ └─ 先问清楚。基于 KB 状态提出 2-3 个具体选项。不要开始编辑。
83
+ ```
84
+
85
+ ---
86
+
87
+ ## 启动协议(仅写入任务)
88
+
89
+ 只读路径跳过。所有写入任务:
90
+
91
+ 1. **Bootstrap** — `mindos_bootstrap`(首选),或手动读根 `INSTRUCTION.md` + `README.md`。
92
+ 2. **发现结构** — `mindos_list_spaces`(顶层分区与 README 摘要)和/或 `mindos_list_files` + 按需 `mindos_search_notes`。不假设一级目录名。
93
+ 3. **加载局部治理** — 读取目标路径附近的 `README.md` / `INSTRUCTION.md`。局部约定覆盖全局假设。
94
+ 4. **匹配已有 SOP** — 任务偏流程时:从树中识别存放流程的目录(`Workflows/`、`SOPs/`、`流程/` 等仅为常见名,不假设一定存在)。用关键词 + `<!-- keywords: -->` 元数据搜索。找到则读取并执行;偏差则任务后提议更新。
95
+ 5. **写前检查** — 确认:路径存在或应创建;位置在子目录下(非根);现有内容已读;修改范围最小;路径变更的反链影响已评估。
96
+ 6. **执行编辑。**
97
+
98
+ 上下文缺失时,按最佳努力继续并明确写出假设。
99
+
100
+ ---
101
+
102
+ ## 工具选型
103
+
104
+ | 意图 | 推荐工具 | 避免 |
105
+ |------|----------|------|
106
+ | 启动时加载上下文 | `mindos_bootstrap` | 不 bootstrap 就随机读文件 |
107
+ | 列出顶层心智空间 | `mindos_list_spaces` | 只需分区概览却拉整棵 `list_files` |
108
+ | 找文件 | `mindos_search_notes`(2-4 条并行关键词变体)| 单关键词搜索 |
109
+ | 读内容 | `mindos_read_file` 或 `mindos_read_lines`(大文件) | 只需 10 行却读整文件 |
110
+ | 小范围文字修改 | `mindos_update_section` / `update_lines` / `insert_after_heading` | 小修改用 `write_file` |
111
+ | 追加到末尾 | `mindos_append_to_file` | 为了加一行重写整文件 |
112
+ | 整文件替换 | `mindos_write_file` | 用它做章节级编辑 |
113
+ | 新建文件 | `mindos_create_file` | 自动创建父目录,但不会生成空间脚手架文件 |
114
+ | 新建心智空间(目录 + README + INSTRUCTION)| `mindos_create_space` | 创建空间的唯一方式。`create_file` 只创建普通目录 |
115
+ | 重命名空间目录 | `mindos_rename_space` | `rename_file`(仅文件,不能重命名文件夹)|
116
+ | 追加 CSV | `mindos_append_csv`(校验表头)| 手动拼字符串不校验 |
117
+ | 重命名前查影响 | `mindos_get_backlinks` | 不查引用就重命名 |
118
+ | 查看近期变动 | `mindos_get_recent` | 猜最近改了什么 |
119
+ | 恢复历史版本 | `mindos_get_file_at_version` | 让用户回忆之前内容 |
120
+
121
+ ### 回退
122
+
123
+ - `mindos_bootstrap` 不可用 → 手动读根 `INSTRUCTION.md` + `README.md`。
124
+ - 行级/章节级工具不可用 → 读 + 受限 `mindos_write_file`(模拟最小修改)。
125
+ - 搜索无结果 → 不放弃:(1) 扫上下文中的树;(2) 直接读候选文件;(3) `mindos_list_files` 细化子目录;(4) 用同义词/中英文变体重试。
126
+
127
+ ---
128
+
129
+ ## 执行模式
130
+
131
+ ### 单文件编辑
132
+ 搜索 → 读目标 + 局部约定 → 最小化修改 → 验证风格匹配 → 总结。
133
+
134
+ ### 基于上下文的问答(只读)
135
+ 目录树推断 → 搜索 → 读取 → 回答并标注来源 → 信息缺失时明确说。
136
+
137
+ ### 多文件路由
138
+ 解析非结构化输入为语义单元 → 为每个单元搜候选文件 → **展示路由表**(信息 → 文件 → 位置)→ 确认 → 编辑 → 汇总全部变更。
139
+
140
+ ### 对话复盘
141
+ 确认范围 → 抽取决策、理由、踩坑、下一步 → 路由到最合适的现有文件 → 补变更说明。
142
+
143
+ ### SOP 执行
144
+ 完整读取 SOP → 分步执行 → 仅更新过时章节 → 偏差则提议更新。
145
+ **创建新 SOP 时** → 必须先读 [references/sop-template.md](./references/sop-template.md)。
146
+
147
+ ### 结构变更
148
+ `get_backlinks` → 影响报告 → 确认 → 执行 → 更新所有引用 → 同步 README。
149
+
150
+ ### 速查模式表
151
+
152
+ | 模式 | 关键步骤 |
153
+ |------|----------|
154
+ | CSV 追加 | 读表头 → 校验字段 → `mindos_append_csv` |
155
+ | TODO 管理 | 定位列表 → 读格式 → 最小化编辑保持约定 |
156
+ | 跨 Agent 接力 | 读任务状态+决策 → 无需重复探索直接接续 → 回写进度 |
157
+ | 知识冲突联动 | 多关键词搜索 → 列受影响文件 → 展示计划 → 确认 → 更新 |
158
+ | 周期性回顾 | `get_recent`/`get_history` → 读变动文件 → 结构化总结 |
159
+ | 交接文档 | 读来源 → 合成(背景、决策、状态、待办)→ 放项目目录 |
160
+
161
+ ---
162
+
163
+ ## 交互规则
164
+
165
+ - **模糊请求?** 先问。基于 KB 现状提出 2-3 个选项。不要在没理解范围前开始编辑。
166
+ - **标注来源。** KB 中的事实附带文件路径,便于验证。
167
+ - **简洁优先。** 展示最可能的匹配,不列全部。
168
+
169
+ ---
170
+
171
+ ## 任务后 Hooks
172
+
173
+ **写入任务**完成后,读 [references/post-task-hooks.md](./references/post-task-hooks.md) 查看是否有一句话跟进提议(经验沉淀、一致性同步、SOP 偏差等)。
174
+ **只读任务:跳过。** 用户要求安静模式时,本会话跳过所有 Hooks。
175
+ **不要读** post-task-hooks 用于简单单文件修改或只读查阅。
176
+
177
+ ## 偏好捕获
178
+
179
+ 用户表达要长期记住的偏好(「以后不要…」「这个该放在…」)时,读 [references/preference-capture.md](./references/preference-capture.md) 并按确认后写入流程存入 `user-skill-rules.md`。
180
+ **不要读** preference-capture 除非用户真的表达了要持久化的偏好。
181
+
182
+ ## SOP 编写
183
+
184
+ 创建或改写工作流 SOP 时,**必须 — 读 [references/sop-template.md](./references/sop-template.md)**(前置条件、分支步骤、退出条件、踩坑记录)。
185
+ **不要读** sop-template 用于 SOP 执行(仅用于 SOP 创建/编辑)。
@@ -0,0 +1,53 @@
1
+ 'use client';
2
+
3
+ import { useState, useCallback } from 'react';
4
+ import type { RemoteAgent } from '@/lib/a2a/types';
5
+
6
+ interface A2aRegistry {
7
+ agents: RemoteAgent[];
8
+ discovering: boolean;
9
+ error: string | null;
10
+ discover: (url: string) => Promise<RemoteAgent | null>;
11
+ refresh: () => void;
12
+ }
13
+
14
+ export function useA2aRegistry(): A2aRegistry {
15
+ const [agents, setAgents] = useState<RemoteAgent[]>([]);
16
+ const [discovering, setDiscovering] = useState(false);
17
+ const [error, setError] = useState<string | null>(null);
18
+
19
+ const discover = useCallback(async (url: string): Promise<RemoteAgent | null> => {
20
+ setDiscovering(true);
21
+ setError(null);
22
+ try {
23
+ const res = await fetch('/api/a2a/discover', {
24
+ method: 'POST',
25
+ headers: { 'Content-Type': 'application/json' },
26
+ body: JSON.stringify({ url }),
27
+ });
28
+ const data = await res.json();
29
+ if (data.agent) {
30
+ setAgents(prev => {
31
+ const exists = prev.some(a => a.id === data.agent.id);
32
+ if (exists) return prev.map(a => a.id === data.agent.id ? data.agent : a);
33
+ return [...prev, data.agent];
34
+ });
35
+ return data.agent as RemoteAgent;
36
+ }
37
+ setError(data.error || 'Discovery failed');
38
+ return null;
39
+ } catch (err) {
40
+ setError((err as Error).message);
41
+ return null;
42
+ } finally {
43
+ setDiscovering(false);
44
+ }
45
+ }, []);
46
+
47
+ const refresh = useCallback(() => {
48
+ setAgents([]);
49
+ setError(null);
50
+ }, []);
51
+
52
+ return { agents, discovering, error, discover, refresh };
53
+ }