advisers 0.0.3 → 0.0.4

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-zh.md CHANGED
@@ -2,17 +2,30 @@
2
2
 
3
3
  **Advisers** 的 cordis-only 发行:一个连续对话 + 用户账 + 承诺账 + 可审阅的流程账。
4
4
 
5
- 本包处于启动阶段,runtime 核心在仓库:
5
+ ## 安装
6
6
 
7
- https://github.com/PerryLink/advisers
7
+ ```sh
8
+ npm i -g advisers@next
9
+ advisers soul init
10
+ advisers chat "周五前把报价发给王工"
11
+ advisers ls
12
+ advisers export
13
+ ```
14
+
15
+ CLI 目前是**context 预览**,不是聊天 UI:它记录消息、生成 FocusFrame,并打印将要发给模型的上下文。模型调用是下一个里程碑。
8
16
 
9
17
  ## 状态
10
18
 
11
- `0.0.1` 用于占位。首个可用版本将提供:
19
+ `0.1.0-preview.1` 是预览版:
20
+
21
+ - 内存/JSON 账本,位于 `~/.advisers/state.json`;
22
+ - soul 位于 `~/.advisers/soul.md`,人类独占;
23
+ - 命令:`soul`、`chat`、`ls`、`why`、`forget`、`export`;
24
+ - 不调模型、不用 SQLite、不接真实 IM、不含 DSH bundle。
12
25
 
13
- - `createAdvisers()` —— headless runtime;
14
- - `advisers` CLI —— 第一个 adapter;
15
- - Link SPI —— email / Satori / dsh-im / gateway provider。
26
+ 核心与架构:
27
+
28
+ https://github.com/PerryLink/advisers
16
29
 
17
30
  ## 许可
18
31
 
package/README.md CHANGED
@@ -4,17 +4,32 @@ The cordis-only distribution of **Advisers** — a staff of AI advisers with one
4
4
  continuous conversation, a user ledger, a commitment ledger, and reviewable
5
5
  routines.
6
6
 
7
- This package is bootstrapping. The runtime core lives in the repository:
7
+ ## Install
8
8
 
9
- https://github.com/PerryLink/advisers
9
+ ```sh
10
+ npm i -g advisers@next
11
+ advisers soul init
12
+ advisers chat "周五前把报价发给王工"
13
+ advisers ls
14
+ advisers export
15
+ ```
16
+
17
+ The CLI is a **context preview**, not a chat UI: it records the message, builds
18
+ the FocusFrame, and prints what would be sent to a model. The model call is the
19
+ next milestone.
10
20
 
11
21
  ## Status
12
22
 
13
- `0.0.1` reserves the name. The first functional release will expose:
23
+ `0.1.0-preview.1` is a preview:
24
+
25
+ - in-memory/JSON ledger at `~/.advisers/state.json`;
26
+ - soul at `~/.advisers/soul.md`, human-owned;
27
+ - `soul`, `chat`, `ls`, `why`, `forget`, `export` commands;
28
+ - no LLM call, no SQLite, no real IM Link, no DSH bundle.
14
29
 
15
- - `createAdvisers()` — headless runtime;
16
- - `advisers` CLI — the first adapter;
17
- - Link SPI — email / Satori / dsh-im / gateway providers.
30
+ Shared core and architecture:
31
+
32
+ https://github.com/PerryLink/advisers
18
33
 
19
34
  ## License
20
35
 
package/bin/advisers.js CHANGED
@@ -1,25 +1,237 @@
1
1
  #!/usr/bin/env node
2
- import { createAdvisers } from 'advisers-core'
3
-
4
- const text = process.argv.slice(2).join(' ').trim()
5
- if (!text) {
6
- console.error('usage: advisers <message>')
7
- process.exit(1)
8
- }
9
-
10
- const runtime = createAdvisers()
11
- const context = await runtime.handleInbound({
12
- linkId: 'cli',
13
- accountId: 'local',
14
- conversationId: 'cli',
15
- messageId: `cli_${Date.now()}`,
16
- sender: { id: 'local' },
17
- text,
18
- timestamp: new Date().toISOString(),
19
- })
20
-
21
- console.log(context.prompt)
22
- if (context.hints.length) {
23
- console.log('\nhints:')
24
- for (const hint of context.hints) console.log(`- ${hint.title}: ${hint.why}`)
2
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
3
+ import { homedir } from 'node:os'
4
+ import { join } from 'node:path'
5
+
6
+ let core
7
+ if (process.env.ADVISERS_CORE_LOCAL === '1') {
8
+ core = await import('../../core/dist/index.js')
9
+ } else {
10
+ try {
11
+ core = await import('advisers-core')
12
+ } catch {
13
+ // Local development before the core package is published.
14
+ core = await import('../../core/dist/index.js')
15
+ }
16
+ }
17
+ const { createAdvisers, Ledger, systemPorts } = core
18
+
19
+ const HOME = process.env.ADVISERS_HOME || join(homedir(), '.advisers')
20
+ const STATE = join(HOME, 'state.json')
21
+ const SOUL = join(HOME, 'soul.md')
22
+ const SOUL_META = join(HOME, 'soul.meta.json')
23
+
24
+ function ensureHome() {
25
+ mkdirSync(HOME, { recursive: true })
26
+ }
27
+
28
+ function loadLedger() {
29
+ if (!existsSync(STATE)) return new Ledger()
30
+ return Ledger.fromJSON(JSON.parse(readFileSync(STATE, 'utf8')))
31
+ }
32
+
33
+ function saveLedger(ledger) {
34
+ ensureHome()
35
+ writeFileSync(STATE, JSON.stringify(ledger.toJSON(), null, 2) + '\n')
36
+ }
37
+
38
+ function loadSoul() {
39
+ if (!existsSync(SOUL)) return undefined
40
+ const meta = existsSync(SOUL_META) ? JSON.parse(readFileSync(SOUL_META, 'utf8')) : {}
41
+ const content = readFileSync(SOUL, 'utf8')
42
+ return {
43
+ id: 'soul',
44
+ version: meta.version ?? 1,
45
+ content,
46
+ updatedAt: meta.updatedAt ?? new Date().toISOString(),
47
+ updatedBy: 'human',
48
+ }
49
+ }
50
+
51
+ function saveSoul(doc) {
52
+ ensureHome()
53
+ writeFileSync(SOUL, doc.content)
54
+ writeFileSync(SOUL_META, JSON.stringify({ version: doc.version, updatedAt: doc.updatedAt }, null, 2) + '\n')
55
+ }
56
+
57
+ const soulStore = { load: loadSoul, save: saveSoul }
58
+
59
+ function runtimeFor(ledger) {
60
+ const ports = { ...systemPorts(), soul: soulStore }
61
+ return createAdvisers({ ledger, ports })
62
+ }
63
+
64
+ function now() {
65
+ return new Date().toISOString()
66
+ }
67
+
68
+ const [command, ...args] = process.argv.slice(2)
69
+
70
+ function help() {
71
+ console.log(`advisers — a staff of AI advisers
72
+
73
+ Usage:
74
+ advisers chat <text> record a message and print the focus context
75
+ advisers ls list matters
76
+ advisers why <pref-id> explain a preference
77
+ advisers forget <pref-id> forget a preference (tombstone)
78
+ advisers export export the ledger as JSON
79
+ advisers soul show print soul.md
80
+ advisers soul set <file> set soul.md from a file (human action)
81
+ advisers soul init write a minimal starter soul.md
82
+ advisers help
83
+
84
+ Environment:
85
+ ADVISERS_HOME default ~/.advisers
86
+ `)
87
+ }
88
+
89
+ function chat(text) {
90
+ if (!text) {
91
+ console.error('usage: advisers chat <text>')
92
+ process.exitCode = 1
93
+ return
94
+ }
95
+ const ledger = loadLedger()
96
+ const runtime = runtimeFor(ledger)
97
+ const context = runtime.handleInbound({
98
+ linkId: 'cli',
99
+ accountId: 'local',
100
+ conversationId: 'cli',
101
+ messageId: `cli_${Date.now()}`,
102
+ sender: { id: 'local' },
103
+ text,
104
+ timestamp: now(),
105
+ })
106
+ saveLedger(ledger)
107
+ console.log(`[thread] ${context.threadId}`)
108
+ console.log(context.prompt)
109
+ if (context.hints.length) {
110
+ console.log('\nhints:')
111
+ for (const hint of context.hints) console.log(`- ${hint.title}: ${hint.why}`)
112
+ }
113
+ }
114
+
115
+ function ls() {
116
+ const matters = loadLedger().listMatters()
117
+ if (!matters.length) {
118
+ console.log('no matters yet')
119
+ return
120
+ }
121
+ for (const m of matters) {
122
+ console.log(`${m.id}\t${m.status}\tsecrecy=${m.secrecy}\t${m.title}`)
123
+ }
124
+ }
125
+
126
+ function why(id) {
127
+ if (!id) {
128
+ console.error('usage: advisers why <pref-id>')
129
+ process.exitCode = 1
130
+ return
131
+ }
132
+ const pref = loadLedger().findPreference(id)
133
+ if (!pref) {
134
+ console.error(`unknown preference: ${id}`)
135
+ process.exitCode = 1
136
+ return
137
+ }
138
+ console.log(`${pref.id} [${pref.kind}/${pref.priority}] ${pref.statement}`)
139
+ console.log(`scope: ${pref.scope.level}${pref.scope.value ? ':' + pref.scope.value : ''}`)
140
+ console.log(`source: ${pref.source.type}${pref.source.quote ? ' — ' + pref.source.quote : ''}`)
141
+ console.log(`confidence: ${pref.confidence}; status: ${pref.status}`)
142
+ }
143
+
144
+ function forget(id) {
145
+ if (!id) {
146
+ console.error('usage: advisers forget <pref-id>')
147
+ process.exitCode = 1
148
+ return
149
+ }
150
+ const ledger = loadLedger()
151
+ const ok = ledger.forget('preference', id)
152
+ saveLedger(ledger)
153
+ console.log(ok ? `forgotten: ${id}` : `unknown preference: ${id}`)
154
+ if (!ok) process.exitCode = 1
155
+ }
156
+
157
+ function exportLedger() {
158
+ console.log(JSON.stringify(loadLedger().toJSON(), null, 2))
159
+ }
160
+
161
+ function soul(sub, file) {
162
+ if (sub === 'show') {
163
+ const doc = loadSoul()
164
+ if (!doc) {
165
+ console.log('no soul.md; run `advisers soul init` or `advisers soul set <file>`')
166
+ return
167
+ }
168
+ console.log(`# soul v${doc.version} (${doc.updatedAt})`)
169
+ console.log(doc.content)
170
+ return
171
+ }
172
+ if (sub === 'set') {
173
+ if (!file) {
174
+ console.error('usage: advisers soul set <file>')
175
+ process.exitCode = 1
176
+ return
177
+ }
178
+ if (!existsSync(file)) {
179
+ console.error(`file not found: ${file}`)
180
+ process.exitCode = 1
181
+ return
182
+ }
183
+ const previous = loadSoul()
184
+ const content = readFileSync(file, 'utf8')
185
+ const doc = {
186
+ id: 'soul',
187
+ version: (previous?.version ?? 0) + 1,
188
+ content,
189
+ updatedAt: now(),
190
+ updatedBy: 'human',
191
+ }
192
+ saveSoul(doc)
193
+ console.log(`soul updated to v${doc.version}; tell the user what changed`)
194
+ return
195
+ }
196
+ if (sub === 'init') {
197
+ if (existsSync(SOUL)) {
198
+ console.log('soul.md already exists; use `advisers soul set <file>` to replace it')
199
+ return
200
+ }
201
+ const doc = {
202
+ id: 'soul',
203
+ version: 1,
204
+ content:
205
+ 'You are my adviser. Be direct, concise, and useful.\n' +
206
+ 'You are a guest in my life: private things stay private.\n' +
207
+ 'If you change this file, tell me.\n',
208
+ updatedAt: now(),
209
+ updatedBy: 'human',
210
+ }
211
+ saveSoul(doc)
212
+ console.log(`wrote ${SOUL}`)
213
+ return
214
+ }
215
+ help()
216
+ process.exitCode = 1
217
+ }
218
+
219
+ if (!command || command === 'help' || command === '--help') {
220
+ help()
221
+ } else if (command === 'chat') {
222
+ chat(args.join(' ').trim())
223
+ } else if (command === 'ls') {
224
+ ls()
225
+ } else if (command === 'why') {
226
+ why(args[0])
227
+ } else if (command === 'forget') {
228
+ forget(args[0])
229
+ } else if (command === 'export') {
230
+ exportLedger()
231
+ } else if (command === 'soul') {
232
+ soul(args[0], args[1])
233
+ } else {
234
+ console.error(`unknown command: ${command}`)
235
+ help()
236
+ process.exitCode = 1
25
237
  }
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from 'advisers-core'
2
2
 
3
- export const version = '0.0.3'
3
+ export const version = '0.0.4'
4
4
  export const distribution = 'cordis'
5
5
  export const status = 'bootstrapping'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "advisers",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "A staff of AI advisers: a cordis-native personal secretary runtime with scoped memory, commitments, and reviewable routines.",
5
5
  "keywords": [
6
6
  "cordis",
@@ -30,7 +30,7 @@
30
30
  "LICENSE"
31
31
  ],
32
32
  "dependencies": {
33
- "advisers-core": "0.0.3"
33
+ "advisers-core": "0.0.4"
34
34
  },
35
35
  "repository": {
36
36
  "type": "git",