@taopao/memoir 0.0.0-stage → 0.1.0

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 (84) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +8 -2
  3. package/assets/migrations-pg/0100_baseline.sql +1115 -0
  4. package/assets/migrations-pg/0101_functions.sql +93 -0
  5. package/assets/migrations-pg/0102_views.sql +2425 -0
  6. package/assets/migrations-pg/0103_constraints.sql +147 -0
  7. package/assets/migrations-pg/0104_protection.sql +33 -0
  8. package/assets/migrations-pg/0105_bocom_credit_card.sql +43 -0
  9. package/assets/migrations-pg/0106_psbc_debit_card.sql +87 -0
  10. package/assets/migrations-pg/0107_tailong_debit_card.sql +87 -0
  11. package/assets/migrations-pg/0108_ccb_debit_card.sql +87 -0
  12. package/assets/migrations-pg/0109_ccb_credit_card.sql +63 -0
  13. package/assets/migrations-pg/0110_icbc_debit_card.sql +87 -0
  14. package/assets/migrations-pg/0111_icbc_credit_card.sql +66 -0
  15. package/assets/migrations-pg/0112_boc_debit_card.sql +88 -0
  16. package/assets/migrations-pg/0113_jsb_debit_card.sql +88 -0
  17. package/assets/migrations-pg/0114_cmbc_debit_card.sql +88 -0
  18. package/assets/migrations-pg/0115_hzbank_debit_card.sql +88 -0
  19. package/assets/migrations-pg/0116_unified_bank_documents.sql +197 -0
  20. package/assets/migrations-pg/0117_agent_submissions.sql +50 -0
  21. package/assets/migrations-pg/0118_agent_reversions_analysis.sql +34 -0
  22. package/assets/migrations-pg/0119_agent_extension_registry.sql +72 -0
  23. package/assets/migrations-pg/0120_agent_record_sources.sql +22 -0
  24. package/assets/migrations-pg/0121_agent_extension_deprecation.sql +30 -0
  25. package/assets/migrations-pg/0122_agent_extension_controlled_revert.sql +107 -0
  26. package/assets/migrations-pg/0123_agent_extension_versions.sql +54 -0
  27. package/assets/migrations-pg/0124_agent_extension_retirement_groups.sql +26 -0
  28. package/assets/migrations-pg/0125_agent_candidate_reviews.sql +30 -0
  29. package/assets/migrations-pg/0126_agent_module_lifecycle.sql +93 -0
  30. package/assets/migrations-pg/0127_agent_tasks.sql +64 -0
  31. package/assets/migrations-pg/0128_agent_task_leases.sql +80 -0
  32. package/assets/migrations-pg/0129_agent_task_plans.sql +66 -0
  33. package/assets/migrations-pg/0130_agent_task_submissions.sql +72 -0
  34. package/assets/migrations-pg/0131_agent_task_completions.sql +93 -0
  35. package/assets/migrations-pg/0132_agent_task_changes.sql +113 -0
  36. package/assets/migrations-pg/0133_agent_imported_source_snapshots.sql +152 -0
  37. package/assets/migrations-pg/0134_agent_analysis_datasets.sql +6 -0
  38. package/assets/migrations-pg/0135_agent_maintenance_tasks.sql +139 -0
  39. package/assets/migrations-pg/0136_agent_task_structures.sql +66 -0
  40. package/assets/migrations-pg/0137_agent_personal_identity.sql +149 -0
  41. package/assets/migrations-pg/0138_agent_work_records.sql +24 -0
  42. package/assets/migrations-pg/0139_shared_files.sql +43 -0
  43. package/assets/migrations-pg/0140_shared_script_runs.sql +36 -0
  44. package/assets/migrations-pg/0141_payment_bank_links.sql +96 -0
  45. package/assets/migrations-pg/0142_consumption_order_types_and_places.sql +287 -0
  46. package/assets/migrations-pg/0143_skill_direct_write.sql +330 -0
  47. package/assets/migrations-pg/0144_skill_schema_archive.sql +73 -0
  48. package/assets/migrations-pg/0145_skill_ingest_wiki.sql +91 -0
  49. package/assets/migrations-pg/0146_skill_load.sql +17 -0
  50. package/assets/migrations-pg/0147_drop_agent_schema.sql +147 -0
  51. package/assets/migrations-pg/0148_ingest_lanes.sql +19 -0
  52. package/assets/migrations-pg/0149_account_ownership.sql +233 -0
  53. package/assets/migrations-pg/0150_bank_card_exact_link.sql +24 -0
  54. package/assets/migrations-pg/0151_account_ownership_enforce.sql +35 -0
  55. package/assets/migrations-pg/0152_account_ownership_views.sql +750 -0
  56. package/assets/migrations-pg/0153_web_frontend.sql +34 -0
  57. package/assets/migrations-pg/0154_audio_record_owners.sql +103 -0
  58. package/assets/migrations-pg/0155_ingest_knowledge_tables.sql +171 -0
  59. package/assets/migrations-pg/0156_batch_playbook_note.sql +17 -0
  60. package/assets/migrations-pg/0157_last_contact.sql +166 -0
  61. package/assets/migrations-pg/0158_refund_match_hash_join.sql +91 -0
  62. package/assets/migrations-pg/0159_fact_occurred_time.sql +88 -0
  63. package/assets/migrations-pg/0160_agent_notes.sql +118 -0
  64. package/assets/migrations-pg/0161_life_history.sql +314 -0
  65. package/assets/migrations-pg/0162_person_card.sql +427 -0
  66. package/assets/migrations-pg/0163_parking_drop_personal_defaults.sql +12 -0
  67. package/assets/native/darwin-arm64.node +0 -0
  68. package/assets/playbooks/audio.md +83 -0
  69. package/assets/playbooks/chat.md +37 -0
  70. package/assets/playbooks/common.md +66 -0
  71. package/assets/playbooks/intimate.md +19 -0
  72. package/assets/playbooks/journal.md +17 -0
  73. package/assets/playbooks/orders.md +15 -0
  74. package/assets/playbooks/payments.md +16 -0
  75. package/assets/playbooks/self.md +29 -0
  76. package/bin/install-codex-skill.mjs +77 -0
  77. package/bin/memoir.mjs +5 -0
  78. package/dist/cli.js +34062 -0
  79. package/package.json +40 -4
  80. package/release-manifest.json +432 -0
  81. package/skill/SKILL.md +120 -0
  82. package/skill/references//345/256/211/350/243/205/344/275/215/347/275/256.md +21 -0
  83. package/skill/references//346/225/260/346/215/256/345/217/243/345/276/204.md +36 -0
  84. package/skill/scripts/memoir.mjs +82 -0
@@ -0,0 +1,36 @@
1
+ # 数据口径
2
+
3
+ 字段以 `context <表名>` 的实际返回为准;本文只说明分析时最容易用错的含义。视图定义的主说明在 `packages/db/migrations-pg/0102_views.sql`。
4
+
5
+ ## 消费
6
+
7
+ | 对象 | 用途 | 关键字段 |
8
+ | --- | --- | --- |
9
+ | `v_spending` | 去重后的消费明细:电商订单按商品行分摊,加上没有可信订单关联的支付账单 | `source_type`(order/order_item/payment)、`source_key`、`platform`、`order_no`、`occurred_at`、`title`、`shop_name`、`category`、`sensitivity`、`amount_cents`、`amount_is_estimated`、`needs_match_review` |
10
+ | `v_me_spending_monthly` | 按月、平台、分类汇总 | `month`(YYYY-MM)、`platform`、`category`、`row_count`、`amount_cents`(已排除待确认)、`exact_cents`、`estimated_cents`、`unknown_amount_count`、`pending_match_count`、`pending_candidate_cents` |
11
+ | `public.orders` / `public.order_items` | 各电商平台的原始订单与商品 | 主键 `(platform, order_no)`;商品行另有 `line_no` |
12
+ | `public.payments` / `v_payments` | 支付宝、微信等支付账单 | 主键 `(platform, txn_id)`;`direction`、`is_refund`、`is_transfer` |
13
+
14
+ 要点:
15
+
16
+ - `v_spending` 已过滤:隐藏记录、火车票、退款、转账、金额为 0 或负数的行。
17
+ - 一个订单可能拆成多行 `order_item`,统计"订单笔数"时按 `platform || ':' || order_no` 去重;`payment` 行的 `order_no` 为空,用 `source_key` 计数。
18
+ - `occurred_at` 是 `YYYY-MM-DD HH:MM:SS` 文本,按日期范围筛选用 `occurred_at >= '2026-10-01' AND occurred_at < '2026-11-01'`。
19
+ - `v_me_spending_monthly.amount_cents` 只含已确认部分;待确认金额在 `pending_candidate_cents`。
20
+
21
+ ## 其他常用视图
22
+
23
+ 以下视图在 `context` 中可见,使用前先 `context <视图名>` 确认字段:
24
+
25
+ - 人物:`v_persons_current`
26
+ - 聊天与互动:`v_messages`、`v_utterances`、`v_us_interaction_daily`
27
+ - 时间线与日期:`v_timeline`、`v_us_timeline`、`v_upcoming_dates`
28
+ - 资金往来:`v_money_flow`、`v_us_money_flow`
29
+ - 按受益人统计消费:`v_us_spending_by_beneficiary`、`v_us_spending_unassigned`
30
+
31
+ Agent 自建的表与视图都在 `public`,`context` 中可见;破坏性结构变更不做备份,删了就找不回。
32
+
33
+ ## 限制
34
+
35
+ - `context` 的行数是统计估计,不是精确计数,也不代表覆盖的日期范围;需要时用有界查询核实。
36
+ - `query` 只接受单条 SELECT/WITH/VALUES/TABLE 只读语句,默认最多 200 行(上限 2000),默认超时 30 秒(上限 120 秒)。
@@ -0,0 +1,82 @@
1
+ import { spawn } from 'node:child_process'
2
+ import { existsSync, readFileSync } from 'node:fs'
3
+ import { isAbsolute, join } from 'node:path'
4
+ import { fileURLToPath } from 'node:url'
5
+
6
+ /**
7
+ * memoir Skill 入口:把参数原样转发给本机 CLI 的 `memoir skill <命令>`。
8
+ *
9
+ * CLI 定位顺序:环境变量 MEMOIR_CLI(兼容旧名 RELATION_VAULT_CLI)→ 本机 installation.json 的 entry → 源码仓库相对位置。
10
+ * 数据库连接由 CLI 读取数据目录 database.json 或环境变量,不经过本脚本、不进入聊天。
11
+ * 只启动这一次 CLI,不启动模型或后台进程。
12
+ */
13
+ try {
14
+ if (Number(process.versions.node.split('.')[0]) < 24) throw new Error('node')
15
+ const installation = fileURLToPath(
16
+ new URL('../installation.json', import.meta.url),
17
+ )
18
+ const config = existsSync(installation)
19
+ ? JSON.parse(readFileSync(installation, 'utf8'))
20
+ : {}
21
+ const runtime =
22
+ process.env.MEMOIR_RUNTIME ||
23
+ process.env.RELATION_VAULT_RUNTIME ||
24
+ config.runtime ||
25
+ fileURLToPath(new URL('../../../', import.meta.url))
26
+ const entry =
27
+ process.env.MEMOIR_CLI ||
28
+ process.env.RELATION_VAULT_CLI ||
29
+ config.entry ||
30
+ join(runtime, 'apps/cli/src/main.ts')
31
+ const node = config.node || process.execPath
32
+ const home = process.env.MEMOIR_HOME || process.env.VAULT_HOME || config.home
33
+ if (
34
+ ![entry, node, ...(home ? [home] : [])].every(
35
+ (path) => typeof path === 'string' && isAbsolute(path),
36
+ ) ||
37
+ !existsSync(entry)
38
+ )
39
+ throw new Error('path')
40
+ const args = process.argv.slice(2)
41
+ const child = spawn(
42
+ node,
43
+ [
44
+ entry,
45
+ 'skill',
46
+ ...args,
47
+ ...(home && !args.includes('--home') ? ['--home', home] : []),
48
+ ],
49
+ {
50
+ // 保持调用方当前目录:load/import/files 的相对路径按 Agent 所在目录解析(2026-11-05 评测发现
51
+ // 之前固定为 CLI 目录,Agent 写在工作目录的 CSV/JSONL 用相对路径会报找不到文件)。
52
+ cwd: process.cwd(),
53
+ env: process.env,
54
+ stdio: 'inherit',
55
+ shell: false,
56
+ },
57
+ )
58
+ const interrupt = () => child.kill('SIGINT')
59
+ const terminate = () => child.kill('SIGTERM')
60
+ process.on('SIGINT', interrupt)
61
+ process.on('SIGTERM', terminate)
62
+ child.on('error', () => {
63
+ process.exitCode = 1
64
+ })
65
+ child.on('close', (code) => {
66
+ process.off('SIGINT', interrupt)
67
+ process.off('SIGTERM', terminate)
68
+ process.exitCode = code ?? 1
69
+ })
70
+ } catch {
71
+ process.stdout.write(
72
+ `${JSON.stringify({
73
+ ok: false,
74
+ error: {
75
+ code: 'SKILL_INSTALLATION_INVALID',
76
+ message:
77
+ 'Skill 找不到 vault CLI:请确认 Node.js 24+,并按 references/安装位置.md 安装 CLI 或设置 MEMOIR_CLI',
78
+ },
79
+ })}\n`,
80
+ )
81
+ process.exitCode = 1
82
+ }