@mebular/mcp 0.3.5 → 0.3.8

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/src/server.mjs CHANGED
@@ -15,6 +15,13 @@ import { createJoinServer } from './jointoken.mjs';
15
15
  import { clearApplyPending, readApplyPending, recoverPendingRollback, writeApplyResult, writeServeReady } from './config-apply.mjs';
16
16
  import { buildSettings } from './admin.mjs';
17
17
  import { isProvisionHome } from './provision.mjs';
18
+ import {
19
+ detectFreshHome,
20
+ FIRST_RUN_INIT_FAILED,
21
+ initializeFirstRunHome,
22
+ markFirstRunPending,
23
+ readFirstRunMarker,
24
+ } from './first-run.mjs';
18
25
  import { acquireActiveLock, profileIdForHome, resolveCloudRoot } from './profiles.mjs';
19
26
  import { advertiseHost, endpointHostname, isLoopbackHost } from './lan-host.mjs';
20
27
 
@@ -147,6 +154,16 @@ export async function startServeServer(options = {}) {
147
154
  // F-NET-1(C):**先取单实例锁,再初始化网络**——第二写者应在绑定监听端口前就得到
148
155
  // 可读的 MCP_STORAGE_LOCKED(此前 createMebular 先启网络 → 抢 4001 → 裸 EADDRINUSE)。
149
156
  let preConfig = provisionStart ? {} : await loadConfigFile(home).catch(() => ({}));
157
+ // 0.4.0 W1b:空 home 判定必须在取 `<home>/lock` 之前——锁文件本身会让目录看起来“非空”。
158
+ // 只写 pending marker,绝不启用;已有 home 不命中。
159
+ let firstRunWarning = null;
160
+ try {
161
+ if (await detectFreshHome({ home, env: process.env })) {
162
+ await markFirstRunPending({ home, env: process.env });
163
+ }
164
+ } catch (error) {
165
+ console.error(`FIRST_RUN_MARKER_FAILED ${error?.code ?? 'ERROR'}`);
166
+ }
150
167
  const { storagePathForHome } = await import('./home-identity.mjs');
151
168
  const preStoragePath = storagePathForHome(home, preConfig, process.env);
152
169
  const lock = await acquireLock(home, preStoragePath);
@@ -164,6 +181,24 @@ export async function startServeServer(options = {}) {
164
181
  provisionStart = isProvisionHome(home, { storagePath: process.env.MEBULAR_STORAGE_PATH });
165
182
  preConfig = provisionStart ? {} : await loadConfigFile(home).catch(() => ({}));
166
183
 
184
+ // 0.4.0 W1b:acked 的首启初始化在正常启动前重试;任一步失败只记录 warning,
185
+ // 不阻塞 serve,也不把失败当成 heuristic 默认启用。
186
+ if (!provisionStart) {
187
+ try {
188
+ const marker = await readFirstRunMarker({ home });
189
+ if (marker?.state === 'acked') {
190
+ const initialized = await initializeFirstRunHome({ home, env: process.env });
191
+ if (initialized.ok !== true) {
192
+ firstRunWarning = FIRST_RUN_INIT_FAILED;
193
+ console.error(`FIRST_RUN_INIT_FAILED ${initialized.reason ?? 'unknown'}`);
194
+ }
195
+ }
196
+ } catch (error) {
197
+ firstRunWarning = FIRST_RUN_INIT_FAILED;
198
+ console.error(`FIRST_RUN_INIT_FAILED ${error?.code ?? 'ERROR'}`);
199
+ }
200
+ }
201
+
167
202
  // 热初始化 / 正常启动共用:app、join 服务、运行时快照与生命周期资源。
168
203
  let current = null;
169
204
  let httpServer = null;
@@ -391,6 +426,7 @@ export async function startServeServer(options = {}) {
391
426
  writesEnabled: options.writesEnabled ?? process.env.MEBULAR_CONSOLE_WRITES !== '0',
392
427
  manageMemoryRuntime: true,
393
428
  provision: provisionStart,
429
+ firstRunWarning,
394
430
  initializeRuntime: async ({ action, result, server }) => {
395
431
  const next = await startRuntime({ action, result, serverContext: server, hot: true });
396
432
  current = next;
package/src/tools.mjs CHANGED
@@ -132,6 +132,8 @@ export const TOOL_SPECS = [
132
132
  limit: z.number().optional(),
133
133
  offset: z.number().optional(),
134
134
  includeHistory: z.boolean().optional(),
135
+ /** 评估 fact 有效性的时间点(Unix ms);缺省当前时间 */
136
+ asOf: z.number().optional(),
135
137
  /** G-ML-1:默认 false(归档不进入召回);显式 true 才可见已归档 */
136
138
  includeArchived: z.boolean().optional(),
137
139
  filters: z
@@ -153,6 +155,7 @@ export const TOOL_SPECS = [
153
155
  limit: clampLimit(args.limit),
154
156
  ...(args.offset !== undefined ? { offset: args.offset } : {}),
155
157
  ...(args.includeHistory !== undefined ? { includeHistory: args.includeHistory } : {}),
158
+ ...(args.asOf !== undefined ? { asOf: args.asOf } : {}),
156
159
  ...(args.includeArchived !== undefined ? { includeArchived: args.includeArchived } : {}),
157
160
  ...(args.filters ? { filters: args.filters } : {}),
158
161
  }));
@@ -170,6 +173,8 @@ export const TOOL_SPECS = [
170
173
  types: z.array(z.string()).optional(),
171
174
  limit: z.number().optional(),
172
175
  includeRelations: z.boolean().optional(),
176
+ /** 评估 fact 有效性的时间点(Unix ms);缺省当前时间 */
177
+ asOf: z.number().optional(),
173
178
  /** G-ML-1:默认 false(归档不进入召回) */
174
179
  includeArchived: z.boolean().optional(),
175
180
  filters: z
@@ -177,6 +182,8 @@ export const TOOL_SPECS = [
177
182
  tags: z.array(z.string()).optional(),
178
183
  createdAfter: z.number().optional(),
179
184
  createdBefore: z.number().optional(),
185
+ entity: z.string().optional(),
186
+ minConfidence: z.number().optional(),
180
187
  namespace: namespaceFilter,
181
188
  })
182
189
  .optional(),
@@ -188,6 +195,7 @@ export const TOOL_SPECS = [
188
195
  ...(args.types ? { types: args.types } : {}),
189
196
  limit: clampLimit(args.limit),
190
197
  ...(args.includeRelations !== undefined ? { includeRelations: args.includeRelations } : {}),
198
+ ...(args.asOf !== undefined ? { asOf: args.asOf } : {}),
191
199
  ...(args.includeArchived !== undefined ? { includeArchived: args.includeArchived } : {}),
192
200
  ...(args.filters ? { filters: args.filters } : {}),
193
201
  }));
package/src/version.mjs CHANGED
@@ -5,4 +5,4 @@
5
5
  // scripts/bump-version.mjs 只改这一处,scripts/verify-release-version.mjs
6
6
  // 校验它等于发布版本;不要在其它文件再写版本字面量。
7
7
 
8
- export const APP_VERSION = '0.3.5';
8
+ export const APP_VERSION = '0.3.8';