watashi-db 0.0.13 → 0.0.15
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/CLAUDE.md +36 -0
- package/LICENSE +1 -1
- package/README.md +64 -2
- package/cowork-plugin/skills/groom/SKILL.md +51 -15
- package/cowork-plugin/skills/recall/SKILL.md +5 -6
- package/cowork-plugin/skills/reflect/SKILL.md +4 -4
- package/cowork-plugin/skills/remember/SKILL.md +3 -3
- package/cowork-plugin/skills/session-start/SKILL.md +3 -3
- package/dist/auth/token.d.ts +7 -0
- package/dist/auth/token.js +14 -0
- package/dist/auth/token.js.map +1 -0
- package/dist/config/schema.js +1 -1
- package/dist/constants.d.ts +9 -9
- package/dist/constants.js +29 -43
- package/dist/constants.js.map +1 -1
- package/dist/database/archive.js +6 -6
- package/dist/database/groom.js +5 -5
- package/dist/database/groom.js.map +1 -1
- package/dist/database/queries-core.d.ts +109 -5
- package/dist/database/queries-core.js +546 -186
- package/dist/database/queries-core.js.map +1 -1
- package/dist/database/queries.d.ts +85 -5
- package/dist/database/queries.js +33 -0
- package/dist/database/queries.js.map +1 -1
- package/dist/database/schema.d.ts +1 -0
- package/dist/database/schema.js +2299 -406
- package/dist/database/schema.js.map +1 -1
- package/dist/embedding/embed-on-write.d.ts +7 -1
- package/dist/embedding/embed-on-write.js +8 -3
- package/dist/embedding/embed-on-write.js.map +1 -1
- package/dist/hook.js +17 -9
- package/dist/hook.js.map +1 -1
- package/dist/http-server.d.ts +6 -0
- package/dist/http-server.js +235 -0
- package/dist/http-server.js.map +1 -0
- package/dist/index.js +14 -3
- package/dist/index.js.map +1 -1
- package/dist/resources/config-guide-content.d.ts +1 -1
- package/dist/resources/config-guide-content.js +2 -2
- package/dist/server-core.d.ts +15 -0
- package/dist/server-core.js +113 -0
- package/dist/server-core.js.map +1 -0
- package/dist/server-instructions.js +27 -24
- package/dist/server-instructions.js.map +1 -1
- package/dist/server.d.ts +4 -1
- package/dist/server.js +9 -103
- package/dist/server.js.map +1 -1
- package/dist/setup.js +5 -6
- package/dist/setup.js.map +1 -1
- package/dist/store/federation.d.ts +12 -1
- package/dist/store/federation.js +38 -0
- package/dist/store/federation.js.map +1 -1
- package/dist/store/sync-manager.d.ts +1 -1
- package/dist/store/sync-manager.js +9 -9
- package/dist/tools/claim-tools.d.ts +1 -1
- package/dist/tools/claim-tools.js +30 -17
- package/dist/tools/claim-tools.js.map +1 -1
- package/dist/tools/decision-tools.d.ts +1 -1
- package/dist/tools/decision-tools.js +23 -7
- package/dist/tools/decision-tools.js.map +1 -1
- package/dist/tools/episode-tools.d.ts +1 -1
- package/dist/tools/episode-tools.js +28 -7
- package/dist/tools/episode-tools.js.map +1 -1
- package/dist/tools/file-tools.d.ts +3 -0
- package/dist/tools/file-tools.js +350 -0
- package/dist/tools/file-tools.js.map +1 -0
- package/dist/tools/get-tools.d.ts +1 -1
- package/dist/tools/get-tools.js +39 -5
- package/dist/tools/get-tools.js.map +1 -1
- package/dist/tools/helpers.d.ts +40 -0
- package/dist/tools/helpers.js +69 -0
- package/dist/tools/helpers.js.map +1 -1
- package/dist/tools/knowledge-tools.d.ts +1 -1
- package/dist/tools/knowledge-tools.js +38 -6
- package/dist/tools/knowledge-tools.js.map +1 -1
- package/dist/tools/maintenance-tools.d.ts +1 -1
- package/dist/tools/maintenance-tools.js +95 -52
- package/dist/tools/maintenance-tools.js.map +1 -1
- package/dist/tools/memo-tools.d.ts +7 -11
- package/dist/tools/memo-tools.js +509 -309
- package/dist/tools/memo-tools.js.map +1 -1
- package/dist/tools/query-tools.d.ts +1 -1
- package/dist/tools/query-tools.js +266 -242
- package/dist/tools/query-tools.js.map +1 -1
- package/dist/types.d.ts +513 -76
- package/dist/types.js +185 -33
- package/dist/types.js.map +1 -1
- package/misc/20260316_110841_groom-recipe.md +483 -0
- package/misc/20260316_xaml-testing-library-recipe.md +817 -0
- package/misc/20260331_remote-transport-recipe.md +316 -0
- package/package.json +4 -2
- package/scripts/update-license-version.sh +7 -0
package/dist/tools/helpers.d.ts
CHANGED
|
@@ -13,5 +13,45 @@ export declare function withLintWarnings(obj: Record<string, unknown>, warnings:
|
|
|
13
13
|
* DB: l2_subject/l2_predicate/l2_object → API: subject/predicate/object
|
|
14
14
|
* l1_embedding は除外。
|
|
15
15
|
*/
|
|
16
|
+
/**
|
|
17
|
+
* 2026-03-25 追加: search_summary が未指定のとき、利用可能なフィールドから自動生成する。
|
|
18
|
+
* AI 生成ほど精度は高くないが、FTS 検索の最低限のカバレッジを確保する。
|
|
19
|
+
*/
|
|
20
|
+
export declare function generateSearchSummaryFallback(fields: {
|
|
21
|
+
title?: string | null;
|
|
22
|
+
description?: string | null;
|
|
23
|
+
l1_content?: string | null;
|
|
24
|
+
l2_reasoning?: string | null;
|
|
25
|
+
l2_context?: string | null;
|
|
26
|
+
l2_trigger?: string | null;
|
|
27
|
+
l2_problems?: string[];
|
|
28
|
+
l2_outcomes?: string[];
|
|
29
|
+
l2_principles?: string[];
|
|
30
|
+
l2_core_thesis?: string | null;
|
|
31
|
+
l2_alternatives?: string[];
|
|
32
|
+
user_input?: string | null;
|
|
33
|
+
}): string;
|
|
34
|
+
/**
|
|
35
|
+
* 2026-03-25 追加: l2_* フィールドから l1_content を自動生成する(Phase 2 代替)。
|
|
36
|
+
* AI 生成ほど自然な文章ではないが、embedding 入力として l2_* 連結より構造化されている。
|
|
37
|
+
*/
|
|
38
|
+
export declare function generateAutoL1ForEpisode(fields: {
|
|
39
|
+
title: string;
|
|
40
|
+
l2_context?: string | null;
|
|
41
|
+
l2_trigger?: string | null;
|
|
42
|
+
l2_problems?: string[];
|
|
43
|
+
l2_desires?: string[];
|
|
44
|
+
l2_decisions?: string[];
|
|
45
|
+
l2_outcomes?: string[];
|
|
46
|
+
l2_principles?: string[];
|
|
47
|
+
user_input?: string | null;
|
|
48
|
+
}): string;
|
|
49
|
+
export declare function generateAutoL1ForDecision(fields: {
|
|
50
|
+
title: string;
|
|
51
|
+
description: string;
|
|
52
|
+
l2_reasoning?: string | null;
|
|
53
|
+
l2_alternatives?: string[];
|
|
54
|
+
user_input?: string | null;
|
|
55
|
+
}): string;
|
|
16
56
|
export declare function serializeClaimForApi(claim: ClaimRow): Record<string, unknown>;
|
|
17
57
|
//# sourceMappingURL=helpers.d.ts.map
|
package/dist/tools/helpers.js
CHANGED
|
@@ -12,6 +12,75 @@ export function withLintWarnings(obj, warnings) {
|
|
|
12
12
|
* DB: l2_subject/l2_predicate/l2_object → API: subject/predicate/object
|
|
13
13
|
* l1_embedding は除外。
|
|
14
14
|
*/
|
|
15
|
+
/**
|
|
16
|
+
* 2026-03-25 追加: search_summary が未指定のとき、利用可能なフィールドから自動生成する。
|
|
17
|
+
* AI 生成ほど精度は高くないが、FTS 検索の最低限のカバレッジを確保する。
|
|
18
|
+
*/
|
|
19
|
+
export function generateSearchSummaryFallback(fields) {
|
|
20
|
+
const parts = [];
|
|
21
|
+
if (fields.title)
|
|
22
|
+
parts.push(fields.title);
|
|
23
|
+
if (fields.description)
|
|
24
|
+
parts.push(fields.description);
|
|
25
|
+
if (fields.l1_content)
|
|
26
|
+
parts.push(fields.l1_content);
|
|
27
|
+
if (fields.l2_reasoning)
|
|
28
|
+
parts.push(fields.l2_reasoning);
|
|
29
|
+
if (fields.l2_context)
|
|
30
|
+
parts.push(fields.l2_context);
|
|
31
|
+
if (fields.l2_trigger)
|
|
32
|
+
parts.push(fields.l2_trigger);
|
|
33
|
+
if (fields.l2_core_thesis)
|
|
34
|
+
parts.push(fields.l2_core_thesis);
|
|
35
|
+
if (fields.l2_problems?.length)
|
|
36
|
+
parts.push(fields.l2_problems.join(" "));
|
|
37
|
+
if (fields.l2_outcomes?.length)
|
|
38
|
+
parts.push(fields.l2_outcomes.join(" "));
|
|
39
|
+
if (fields.l2_principles?.length)
|
|
40
|
+
parts.push(fields.l2_principles.join(" "));
|
|
41
|
+
if (fields.l2_alternatives?.length)
|
|
42
|
+
parts.push(fields.l2_alternatives.join(" "));
|
|
43
|
+
// 300文字に切り詰め(FTS用キーワードとして十分)
|
|
44
|
+
return parts.join(" ").slice(0, 300);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* 2026-03-25 追加: l2_* フィールドから l1_content を自動生成する(Phase 2 代替)。
|
|
48
|
+
* AI 生成ほど自然な文章ではないが、embedding 入力として l2_* 連結より構造化されている。
|
|
49
|
+
*/
|
|
50
|
+
export function generateAutoL1ForEpisode(fields) {
|
|
51
|
+
// Issue #83: ラベル付き連結から自然文スタイルに変更(embedding精度向上)
|
|
52
|
+
const parts = [];
|
|
53
|
+
// 冒頭: タイトル + 背景
|
|
54
|
+
let opening = fields.title;
|
|
55
|
+
if (fields.l2_context)
|
|
56
|
+
opening += `(${fields.l2_context})`;
|
|
57
|
+
parts.push(opening + "。");
|
|
58
|
+
// 問題 → トリガー
|
|
59
|
+
if (fields.l2_trigger)
|
|
60
|
+
parts.push(`${fields.l2_trigger}がきっかけ。`);
|
|
61
|
+
if (fields.l2_problems?.length)
|
|
62
|
+
parts.push(`問題: ${fields.l2_problems.join("、")}。`);
|
|
63
|
+
if (fields.l2_desires?.length)
|
|
64
|
+
parts.push(`目的: ${fields.l2_desires.join("、")}。`);
|
|
65
|
+
// 判断 → 結果
|
|
66
|
+
if (fields.l2_decisions?.length)
|
|
67
|
+
parts.push(`${fields.l2_decisions.join("、")}と判断。`);
|
|
68
|
+
if (fields.l2_outcomes?.length)
|
|
69
|
+
parts.push(`結果: ${fields.l2_outcomes.join("、")}。`);
|
|
70
|
+
// 教訓
|
|
71
|
+
if (fields.l2_principles?.length)
|
|
72
|
+
parts.push(`教訓: ${fields.l2_principles.join("。")}。`);
|
|
73
|
+
return parts.join(" ");
|
|
74
|
+
}
|
|
75
|
+
export function generateAutoL1ForDecision(fields) {
|
|
76
|
+
// Issue #83: ラベル付き連結から自然文スタイルに変更(embedding精度向上)
|
|
77
|
+
const parts = [`${fields.title} — ${fields.description}。`];
|
|
78
|
+
if (fields.l2_reasoning)
|
|
79
|
+
parts.push(`理由: ${fields.l2_reasoning}。`);
|
|
80
|
+
if (fields.l2_alternatives?.length)
|
|
81
|
+
parts.push(`代替案として${fields.l2_alternatives.join("、")}を検討。`);
|
|
82
|
+
return parts.join(" ");
|
|
83
|
+
}
|
|
15
84
|
export function serializeClaimForApi(claim) {
|
|
16
85
|
const { l2_subject, l2_predicate, l2_object, l1_embedding, ...rest } = claim;
|
|
17
86
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/tools/helpers.ts"],"names":[],"mappings":"AAOA;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAA4B,EAAE,QAAuB;IACpF,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,OAAO,EAAE,GAAG,GAAG,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC;IAC7C,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAe;IAClD,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,GAAG,IAAI,EAAE,GAAG,KAA8C,CAAC;IACtH,OAAO;QACL,GAAG,IAAI;QACP,OAAO,EAAE,UAAU;QACnB,SAAS,EAAE,YAAY;QACvB,MAAM,EAAE,SAAS;KAClB,CAAC;AACJ,CAAC"}
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/tools/helpers.ts"],"names":[],"mappings":"AAOA;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAA4B,EAAE,QAAuB;IACpF,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,OAAO,EAAE,GAAG,GAAG,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC;IAC7C,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;;GAIG;AACH;;;GAGG;AACH,MAAM,UAAU,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aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACvF,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACzB,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAC,MAMzC;IACC,gDAAgD;IAChD,MAAM,KAAK,GAAa,CAAC,GAAG,MAAM,CAAC,KAAK,MAAM,MAAM,CAAC,WAAW,GAAG,CAAC,CAAC;IACrE,IAAI,MAAM,CAAC,YAAY;QAAE,KAAK,CAAC,IAAI,CAAC,OAAO,MAAM,CAAC,YAAY,GAAG,CAAC,CAAC;IACnE,IAAI,MAAM,CAAC,eAAe,EAAE,MAAM;QAAE,KAAK,CAAC,IAAI,CAAC,SAAS,MAAM,CAAC,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAChG,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACzB,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,KAAe;IAClD,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,GAAG,IAAI,EAAE,GAAG,KAA8C,CAAC;IACtH,OAAO;QACL,GAAG,IAAI;QACP,OAAO,EAAE,UAAU;QACnB,SAAS,EAAE,YAAY;QACvB,MAAM,EAAE,SAAS;KAClB,CAAC;AACJ,CAAC"}
|
|
@@ -3,5 +3,5 @@
|
|
|
3
3
|
* kind="theory"|"insight"|"model" — 全 kind で l1/l2 パラメータを共通使用
|
|
4
4
|
*/
|
|
5
5
|
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
6
|
-
export declare function registerKnowledgeTools(server: McpServer): void;
|
|
6
|
+
export declare function registerKnowledgeTools(server: McpServer, toolPrefix?: string): void;
|
|
7
7
|
//# sourceMappingURL=knowledge-tools.d.ts.map
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { StoreKnowledgeSchema } from "../types.js";
|
|
2
|
-
import { insertTheory, insertInsight, insertModel, insertAuditLog } from "../database/queries.js";
|
|
1
|
+
import { StoreKnowledgeSchema, UpdateKnowledgeSchema } from "../types.js";
|
|
2
|
+
import { insertTheory, insertInsight, insertModel, insertAuditLog, updateKnowledge } from "../database/queries.js";
|
|
3
3
|
import { buildProvenance } from "../provenance.js";
|
|
4
4
|
import { getDatabase } from "../database/connection.js";
|
|
5
5
|
import { getStoreManager, notifyWrite } from "../store/session-state.js";
|
|
6
6
|
import { getClientPolicy, checkScopeWritePolicy, buildPolicyErrorResponse } from "../policy.js";
|
|
7
7
|
import { applyLint, getLintMode, buildLintBlockResponse } from "../lint.js";
|
|
8
8
|
import { withLintWarnings } from "./helpers.js";
|
|
9
|
-
export function registerKnowledgeTools(server) {
|
|
10
|
-
server.tool(
|
|
9
|
+
export function registerKnowledgeTools(server, toolPrefix = "watashi_") {
|
|
10
|
+
server.tool(`${toolPrefix}store_knowledge`, "Store Theory/Insight/Model. Specify kind.", StoreKnowledgeSchema.shape, async (params, extra) => {
|
|
11
11
|
const lint = applyLint(params, getLintMode());
|
|
12
12
|
if (lint.blocked)
|
|
13
13
|
return buildLintBlockResponse(lint.warnings);
|
|
@@ -118,9 +118,41 @@ export function registerKnowledgeTools(server) {
|
|
|
118
118
|
return formatKnowledgeResult("model", record, lint.warnings);
|
|
119
119
|
}
|
|
120
120
|
});
|
|
121
|
+
// update_knowledge: Theory/Insight/Model 更新 (Issue #3 user_issue)
|
|
122
|
+
server.tool(`${toolPrefix}update_knowledge`, "Update a Theory/Insight/Model. Specify id and kind.", UpdateKnowledgeSchema.shape, async (params, extra) => {
|
|
123
|
+
const lint = applyLint(params, getLintMode());
|
|
124
|
+
if (lint.blocked)
|
|
125
|
+
return buildLintBlockResponse(lint.warnings);
|
|
126
|
+
const provenance = buildProvenance(extra.sessionId);
|
|
127
|
+
const { id, kind, reason, ...updates } = params;
|
|
128
|
+
const record = getDatabase().transaction(() => {
|
|
129
|
+
const r = updateKnowledge(kind, id, updates);
|
|
130
|
+
if (!r)
|
|
131
|
+
return null;
|
|
132
|
+
insertAuditLog({
|
|
133
|
+
operation: "update",
|
|
134
|
+
entity_type: kind,
|
|
135
|
+
entity_id: id,
|
|
136
|
+
summary: `Update ${kind}: ${reason}`,
|
|
137
|
+
provenance,
|
|
138
|
+
source_tool: params.source_tool,
|
|
139
|
+
});
|
|
140
|
+
return r;
|
|
141
|
+
})();
|
|
142
|
+
if (!record) {
|
|
143
|
+
return {
|
|
144
|
+
content: [{
|
|
145
|
+
type: "text",
|
|
146
|
+
text: JSON.stringify({ success: false, error: `${kind} ID '${id}' が見つかりません` }),
|
|
147
|
+
}],
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
notifyWrite();
|
|
151
|
+
return formatKnowledgeResult(kind, record, lint.warnings, `${kind.charAt(0).toUpperCase() + kind.slice(1)} を更新しました: ${record.title}`);
|
|
152
|
+
});
|
|
121
153
|
}
|
|
122
154
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
123
|
-
function formatKnowledgeResult(kind, record, lintWarnings) {
|
|
155
|
+
function formatKnowledgeResult(kind, record, lintWarnings, message) {
|
|
124
156
|
const parsed = {
|
|
125
157
|
...record,
|
|
126
158
|
l2_principles: JSON.parse(record.l2_principles),
|
|
@@ -142,7 +174,7 @@ function formatKnowledgeResult(kind, record, lintWarnings) {
|
|
|
142
174
|
text: JSON.stringify(withLintWarnings({
|
|
143
175
|
success: true,
|
|
144
176
|
kind,
|
|
145
|
-
message: `${kind.charAt(0).toUpperCase() + kind.slice(1)} を記録しました: ${record.title}`,
|
|
177
|
+
message: message ?? `${kind.charAt(0).toUpperCase() + kind.slice(1)} を記録しました: ${record.title}`,
|
|
146
178
|
record: parsed,
|
|
147
179
|
}, lintWarnings), null, 2),
|
|
148
180
|
}],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"knowledge-tools.js","sourceRoot":"","sources":["../../src/tools/knowledge-tools.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,oB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MAAM,CAAC,cAAc;QAAE,MAAM,CAAC,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;IAErF,OAAO;QACL,OAAO,EAAE,CAAC;gBACR,IAAI,EAAE,MAAe;gBACrB,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC;oBACpC,OAAO,EAAE,IAAI;oBACb,IAAI;oBACJ,OAAO,EAAE,OAAO,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,aAAa,MAAM,CAAC,KAAK,EAAE;oBAC9F,MAAM,EAAE,MAAM;iBACf,EAAE,YAAY,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;aAC3B,CAAC;KACH,CAAC;AACJ,CAAC"}
|
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
* update_search_summary, delete
|
|
9
9
|
*/
|
|
10
10
|
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
11
|
-
export declare function registerMaintenanceTools(server: McpServer): void;
|
|
11
|
+
export declare function registerMaintenanceTools(server: McpServer, toolPrefix?: string): void;
|
|
12
12
|
//# sourceMappingURL=maintenance-tools.d.ts.map
|
|
@@ -16,8 +16,8 @@ import * as core from "../database/queries-core.js";
|
|
|
16
16
|
import { getClientPolicy, checkClaimWritePolicy, checkScopeWritePolicy, buildPolicyErrorResponse } from "../policy.js";
|
|
17
17
|
import { backupDatabase } from "../store/sync-manager.js";
|
|
18
18
|
import { serializeClaimForApi } from "./helpers.js";
|
|
19
|
-
export function registerMaintenanceTools(server) {
|
|
20
|
-
server.tool(
|
|
19
|
+
export function registerMaintenanceTools(server, toolPrefix = "watashi_") {
|
|
20
|
+
server.tool(`${toolPrefix}maintain`, "Admin: stats/archive/backfill/backup/export/promote/list_stores/switch_context/sync/groom/archive_episodes/archive_decisions/update_search_summary/delete.", MaintainSchema.shape, async (params, extra) => {
|
|
21
21
|
if (params.action === "stats") {
|
|
22
22
|
const db = getDatabase();
|
|
23
23
|
const tableStats = getTableStats(db);
|
|
@@ -98,7 +98,7 @@ export function registerMaintenanceTools(server) {
|
|
|
98
98
|
const limit = params.limit ?? 100;
|
|
99
99
|
const entityTypes = params.entity_type
|
|
100
100
|
? [params.entity_type]
|
|
101
|
-
: ["claim", "decision", "episode", "theory", "insight", "model", "user_memo", "user_plan", "user_issue"];
|
|
101
|
+
: ["claim", "decision", "episode", "theory", "insight", "model", "user_memo", "user_plan", "user_issue", "user_topic"];
|
|
102
102
|
const results = {};
|
|
103
103
|
for (const entityType of entityTypes) {
|
|
104
104
|
let processed = 0;
|
|
@@ -349,8 +349,7 @@ export function registerMaintenanceTools(server) {
|
|
|
349
349
|
const rows = core.getUserIssuesWithoutL1Embedding(db, entityLimit);
|
|
350
350
|
for (let i = 0; i < rows.length; i += batchSize) {
|
|
351
351
|
const batch = rows.slice(i, i + batchSize);
|
|
352
|
-
|
|
353
|
-
const texts = batch.map(r => buildEmbeddingInput({ title: r.title, content: r.l1_content + " " + r.entries }));
|
|
352
|
+
const texts = batch.map(r => buildEmbeddingInput({ title: r.title, content: r.l1_content }));
|
|
354
353
|
try {
|
|
355
354
|
const embeddings = await provider.embedBatch(texts);
|
|
356
355
|
for (let j = 0; j < batch.length; j++) {
|
|
@@ -366,7 +365,7 @@ export function registerMaintenanceTools(server) {
|
|
|
366
365
|
catch {
|
|
367
366
|
for (const row of batch) {
|
|
368
367
|
try {
|
|
369
|
-
const text = buildEmbeddingInput({ title: row.title, content: row.l1_content
|
|
368
|
+
const text = buildEmbeddingInput({ title: row.title, content: row.l1_content });
|
|
370
369
|
const result = await provider.embed(text);
|
|
371
370
|
core.updateUserIssueL1Embedding(db, row.id, float32ToBuffer(result.vector));
|
|
372
371
|
succeeded++;
|
|
@@ -379,6 +378,39 @@ export function registerMaintenanceTools(server) {
|
|
|
379
378
|
processed += batch.length;
|
|
380
379
|
}
|
|
381
380
|
}
|
|
381
|
+
else if (entityType === "user_topic") {
|
|
382
|
+
const rows = core.getUserTopicsWithoutL1Embedding(db, entityLimit);
|
|
383
|
+
for (let i = 0; i < rows.length; i += batchSize) {
|
|
384
|
+
const batch = rows.slice(i, i + batchSize);
|
|
385
|
+
const texts = batch.map(r => buildEmbeddingInput({ title: r.title, content: r.summary }));
|
|
386
|
+
try {
|
|
387
|
+
const embeddings = await provider.embedBatch(texts);
|
|
388
|
+
for (let j = 0; j < batch.length; j++) {
|
|
389
|
+
try {
|
|
390
|
+
core.updateUserTopicL1Embedding(db, batch[j].id, float32ToBuffer(embeddings[j].vector));
|
|
391
|
+
succeeded++;
|
|
392
|
+
}
|
|
393
|
+
catch {
|
|
394
|
+
failed++;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
catch {
|
|
399
|
+
for (const row of batch) {
|
|
400
|
+
try {
|
|
401
|
+
const text = buildEmbeddingInput({ title: row.title, content: row.summary });
|
|
402
|
+
const result = await provider.embed(text);
|
|
403
|
+
core.updateUserTopicL1Embedding(db, row.id, float32ToBuffer(result.vector));
|
|
404
|
+
succeeded++;
|
|
405
|
+
}
|
|
406
|
+
catch {
|
|
407
|
+
failed++;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
processed += batch.length;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
382
414
|
results[entityType] = { processed, succeeded, failed };
|
|
383
415
|
}
|
|
384
416
|
if (Object.values(results).some(r => r.succeeded > 0))
|
|
@@ -450,6 +482,17 @@ export function registerMaintenanceTools(server) {
|
|
|
450
482
|
total_returned: episodes.length,
|
|
451
483
|
},
|
|
452
484
|
episodes: episodeList,
|
|
485
|
+
// Issue #1 user_issue: 蒸留時の探索軸ガイダンス
|
|
486
|
+
grooming_guide: {
|
|
487
|
+
instruction: "以下の探索軸でEpisode群を横断的に分析し、共通パターンをInsight/Theory/Modelとして蒸留してください。",
|
|
488
|
+
axes: [
|
|
489
|
+
{ name: "判断の型", description: "繰り返し現れる思考フレームワーク・意思決定パターン(例: 「収束先から逆算する」「診断が先、処方箋が後」)。次回同じ判断場面で適用すべき思考モードとして記録する。" },
|
|
490
|
+
{ name: "失敗→解決パターン", description: "同じ種類の失敗が複数回起きていないか。原因と解決策のペアをInsightにまとめ、次回の予防策として記録する。" },
|
|
491
|
+
{ name: "環境固有の罠", description: "OS・ツール・プラットフォーム固有の落とし穴(例: Windows + Git、CI環境の差異)。環境条件をtrigger_conditionsに明記する。" },
|
|
492
|
+
{ name: "ワークフロー改善", description: "作業手順の改善・効率化が複数回発見されていないか。手順をresolution_stepsに具体的に記録する。" },
|
|
493
|
+
{ name: "価値観・優先順位の表明", description: "ユーザーが判断基準や優先順位を明示した場面。Claimとして記録済みか確認し、未記録なら提案する。" },
|
|
494
|
+
],
|
|
495
|
+
},
|
|
453
496
|
});
|
|
454
497
|
}
|
|
455
498
|
// === mark_groomed ===
|
|
@@ -507,14 +550,14 @@ export function registerMaintenanceTools(server) {
|
|
|
507
550
|
}
|
|
508
551
|
const protectedIds = db.prepare(`
|
|
509
552
|
SELECT id FROM episodes
|
|
510
|
-
WHERE
|
|
553
|
+
WHERE validity_status = 'active' AND is_archived = 0${scopeFilter}
|
|
511
554
|
ORDER BY created_at DESC
|
|
512
555
|
LIMIT @keepLatest
|
|
513
556
|
`).all({ ...scopeValues, keepLatest });
|
|
514
557
|
const protectedSet = new Set(protectedIds.map(r => r.id));
|
|
515
558
|
const candidates = db.prepare(`
|
|
516
559
|
SELECT id, title FROM episodes
|
|
517
|
-
WHERE
|
|
560
|
+
WHERE validity_status = 'active' AND is_archived = 0 AND groomed_at IS NOT NULL${scopeFilter}
|
|
518
561
|
`).all(scopeValues);
|
|
519
562
|
const toArchive = candidates.filter(r => !protectedSet.has(r.id));
|
|
520
563
|
return ok({
|
|
@@ -562,14 +605,14 @@ export function registerMaintenanceTools(server) {
|
|
|
562
605
|
}
|
|
563
606
|
const protectedIds = db.prepare(`
|
|
564
607
|
SELECT id FROM decisions
|
|
565
|
-
WHERE
|
|
608
|
+
WHERE validity_status = 'active' AND is_archived = 0${scopeFilter}
|
|
566
609
|
ORDER BY created_at DESC
|
|
567
610
|
LIMIT @keepLatest
|
|
568
611
|
`).all({ ...scopeValues, keepLatest });
|
|
569
612
|
const protectedSet = new Set(protectedIds.map(r => r.id));
|
|
570
613
|
const candidates = db.prepare(`
|
|
571
614
|
SELECT id, title FROM decisions
|
|
572
|
-
WHERE
|
|
615
|
+
WHERE validity_status = 'active' AND is_archived = 0${scopeFilter}
|
|
573
616
|
`).all(scopeValues);
|
|
574
617
|
const toArchive = candidates.filter(r => !protectedSet.has(r.id));
|
|
575
618
|
return ok({
|
|
@@ -704,15 +747,15 @@ export function registerMaintenanceTools(server) {
|
|
|
704
747
|
const activeClaims = federatedGetAllActiveClaims(manager, context);
|
|
705
748
|
let allClaims = activeClaims;
|
|
706
749
|
if (params.include_retracted) {
|
|
707
|
-
const retracted = federatedSearchClaims(manager, context, { status: "
|
|
750
|
+
const retracted = federatedSearchClaims(manager, context, { status: "invalidated", limit: 10000 });
|
|
708
751
|
const superseded = federatedSearchClaims(manager, context, { status: "superseded", limit: 10000 });
|
|
709
752
|
allClaims = [...activeClaims, ...retracted, ...superseded];
|
|
710
753
|
}
|
|
711
754
|
const activeDecisions = federatedListDecisions(manager, context, { status: "active", limit: 10000 });
|
|
712
755
|
let allDecisions = activeDecisions;
|
|
713
756
|
if (params.include_retracted) {
|
|
714
|
-
const reversed = federatedListDecisions(manager, context, { status: "
|
|
715
|
-
const obsolete = federatedListDecisions(manager, context, { status: "
|
|
757
|
+
const reversed = federatedListDecisions(manager, context, { status: "invalidated", limit: 10000 });
|
|
758
|
+
const obsolete = federatedListDecisions(manager, context, { status: "superseded", limit: 10000 });
|
|
716
759
|
allDecisions = [...activeDecisions, ...reversed, ...obsolete];
|
|
717
760
|
}
|
|
718
761
|
const activeInsights = federatedListInsights(manager, context, { status: "active", limit: 10000 });
|
|
@@ -814,7 +857,7 @@ export function registerMaintenanceTools(server) {
|
|
|
814
857
|
const targetDb = manager.getStore(params.target_store);
|
|
815
858
|
try {
|
|
816
859
|
const purge = params.purge_source ?? false;
|
|
817
|
-
const result = promoteRecord(sourceDb, targetDb, entityType, params.promote_entity_id, params.source_store, purge);
|
|
860
|
+
const result = promoteRecord(sourceDb, targetDb, entityType, params.promote_entity_id, params.source_store, params.target_store, purge);
|
|
818
861
|
if (!result.success)
|
|
819
862
|
return errorResult(result.error);
|
|
820
863
|
insertAuditLog({
|
|
@@ -1005,23 +1048,23 @@ export function registerMaintenanceTools(server) {
|
|
|
1005
1048
|
return errorResult(`未知のaction: ${params.action}`);
|
|
1006
1049
|
});
|
|
1007
1050
|
}
|
|
1008
|
-
function promoteRecord(sourceDb, targetDb, entityType, entityId, sourceStore, purgeSource = false) {
|
|
1051
|
+
function promoteRecord(sourceDb, targetDb, entityType, entityId, sourceStore, targetStore, purgeSource = false) {
|
|
1009
1052
|
switch (entityType) {
|
|
1010
|
-
case "claim": return promoteClaim(sourceDb, targetDb, entityId, sourceStore, purgeSource);
|
|
1011
|
-
case "decision": return promoteDecision(sourceDb, targetDb, entityId, sourceStore, purgeSource);
|
|
1012
|
-
case "episode": return promoteEpisode(sourceDb, targetDb, entityId, sourceStore, purgeSource);
|
|
1013
|
-
case "theory": return promoteTheory(sourceDb, targetDb, entityId, sourceStore, purgeSource);
|
|
1014
|
-
case "insight": return promoteInsight(sourceDb, targetDb, entityId, sourceStore, purgeSource);
|
|
1015
|
-
case "model": return promoteModel(sourceDb, targetDb, entityId, sourceStore, purgeSource);
|
|
1053
|
+
case "claim": return promoteClaim(sourceDb, targetDb, entityId, sourceStore, targetStore, purgeSource);
|
|
1054
|
+
case "decision": return promoteDecision(sourceDb, targetDb, entityId, sourceStore, targetStore, purgeSource);
|
|
1055
|
+
case "episode": return promoteEpisode(sourceDb, targetDb, entityId, sourceStore, targetStore, purgeSource);
|
|
1056
|
+
case "theory": return promoteTheory(sourceDb, targetDb, entityId, sourceStore, targetStore, purgeSource);
|
|
1057
|
+
case "insight": return promoteInsight(sourceDb, targetDb, entityId, sourceStore, targetStore, purgeSource);
|
|
1058
|
+
case "model": return promoteModel(sourceDb, targetDb, entityId, sourceStore, targetStore, purgeSource);
|
|
1016
1059
|
default: return { success: false, error: `未対応のエンティティ種別: ${entityType}` };
|
|
1017
1060
|
}
|
|
1018
1061
|
}
|
|
1019
|
-
function promoteClaim(sourceDb, targetDb, entityId, sourceStore, purgeSource = false) {
|
|
1062
|
+
function promoteClaim(sourceDb, targetDb, entityId, sourceStore, targetStore, purgeSource = false) {
|
|
1020
1063
|
const source = sourceDb.prepare("SELECT * FROM claims WHERE id = ?").get(entityId);
|
|
1021
1064
|
if (!source)
|
|
1022
1065
|
return { success: false, error: `Claim ID '${entityId}' が見つかりません` };
|
|
1023
|
-
if (source.
|
|
1024
|
-
return { success: false, error: `Claim ID '${entityId}' はactive状態ではありません(現在: ${source.
|
|
1066
|
+
if (source.validity_status !== "active")
|
|
1067
|
+
return { success: false, error: `Claim ID '${entityId}' はactive状態ではありません(現在: ${source.validity_status})` };
|
|
1025
1068
|
// purge_source=true(移動)→ 元IDを保持、false(コピー)→ 新ID生成
|
|
1026
1069
|
const targetId = purgeSource ? entityId : ulid();
|
|
1027
1070
|
let wasExisting = false;
|
|
@@ -1032,25 +1075,25 @@ function promoteClaim(sourceDb, targetDb, entityId, sourceStore, purgeSource = f
|
|
|
1032
1075
|
else {
|
|
1033
1076
|
targetDb.prepare(`
|
|
1034
1077
|
INSERT INTO claims (id, l2_subject, l2_predicate, l2_object, category, scope, confidence, l2_evidence, l2_falsifier,
|
|
1035
|
-
source_tool,
|
|
1078
|
+
source_tool, session_id, validity_status, created_at, updated_at, client_name, client_version,
|
|
1036
1079
|
search_summary, promoted_from_store, promoted_from_id)
|
|
1037
1080
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'active', ?, ?, ?, ?, ?, ?, ?)
|
|
1038
|
-
`).run(targetId, source.l2_subject, source.l2_predicate, source.l2_object, source.category, source.scope, source.confidence, source.l2_evidence, source.l2_falsifier, source.source_tool, source.
|
|
1081
|
+
`).run(targetId, source.l2_subject, source.l2_predicate, source.l2_object, source.category, source.scope, source.confidence, source.l2_evidence, source.l2_falsifier, source.source_tool, source.session_id, source.created_at, source.updated_at, source.client_name, source.client_version, source.search_summary, sourceStore, entityId);
|
|
1039
1082
|
}
|
|
1040
1083
|
if (purgeSource) {
|
|
1041
1084
|
sourceDb.prepare("DELETE FROM claims WHERE id = ?").run(entityId);
|
|
1042
1085
|
}
|
|
1043
1086
|
else {
|
|
1044
|
-
sourceDb.prepare("UPDATE claims SET
|
|
1087
|
+
sourceDb.prepare("UPDATE claims SET promoted_to = ?, updated_at = ? WHERE id = ?").run(targetStore, new Date().toISOString(), entityId);
|
|
1045
1088
|
}
|
|
1046
1089
|
return { success: true, new_id: existing?.id ?? targetId, title: `${source.l2_subject} ${source.l2_predicate} ${source.l2_object}`, was_existing: wasExisting };
|
|
1047
1090
|
}
|
|
1048
|
-
function promoteDecision(sourceDb, targetDb, entityId, sourceStore, purgeSource = false) {
|
|
1091
|
+
function promoteDecision(sourceDb, targetDb, entityId, sourceStore, targetStore, purgeSource = false) {
|
|
1049
1092
|
const source = sourceDb.prepare("SELECT * FROM decisions WHERE id = ?").get(entityId);
|
|
1050
1093
|
if (!source)
|
|
1051
1094
|
return { success: false, error: `Decision ID '${entityId}' が見つかりません` };
|
|
1052
|
-
if (source.
|
|
1053
|
-
return { success: false, error: `Decision ID '${entityId}' はactive状態ではありません(現在: ${source.
|
|
1095
|
+
if (source.validity_status !== "active")
|
|
1096
|
+
return { success: false, error: `Decision ID '${entityId}' はactive状態ではありません(現在: ${source.validity_status})` };
|
|
1054
1097
|
const targetId = purgeSource ? entityId : ulid();
|
|
1055
1098
|
let wasExisting = false;
|
|
1056
1099
|
const existing = targetDb.prepare("SELECT id FROM decisions WHERE id = ? OR (promoted_from_store = ? AND promoted_from_id = ?)").get(targetId, sourceStore, entityId);
|
|
@@ -1060,7 +1103,7 @@ function promoteDecision(sourceDb, targetDb, entityId, sourceStore, purgeSource
|
|
|
1060
1103
|
else {
|
|
1061
1104
|
targetDb.prepare(`
|
|
1062
1105
|
INSERT INTO decisions (id, title, description, l1_content, l2_reasoning, l2_alternatives, related_claim_ids,
|
|
1063
|
-
|
|
1106
|
+
validity_status, source_tool, created_at, updated_at, client_name, client_version, scope,
|
|
1064
1107
|
search_summary, user_input, promoted_from_store, promoted_from_id)
|
|
1065
1108
|
VALUES (?, ?, ?, ?, ?, ?, ?, 'active', ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
1066
1109
|
`).run(targetId, source.title, source.description, source.l1_content, source.l2_reasoning, source.l2_alternatives, source.related_claim_ids, source.source_tool, source.created_at, source.updated_at, source.client_name, source.client_version, source.scope, source.search_summary, source.user_input, sourceStore, entityId);
|
|
@@ -1069,16 +1112,16 @@ function promoteDecision(sourceDb, targetDb, entityId, sourceStore, purgeSource
|
|
|
1069
1112
|
sourceDb.prepare("DELETE FROM decisions WHERE id = ?").run(entityId);
|
|
1070
1113
|
}
|
|
1071
1114
|
else {
|
|
1072
|
-
sourceDb.prepare("UPDATE decisions SET
|
|
1115
|
+
sourceDb.prepare("UPDATE decisions SET promoted_to = ?, updated_at = ? WHERE id = ?").run(targetStore, new Date().toISOString(), entityId);
|
|
1073
1116
|
}
|
|
1074
1117
|
return { success: true, new_id: existing?.id ?? targetId, title: source.title, was_existing: wasExisting };
|
|
1075
1118
|
}
|
|
1076
|
-
function promoteEpisode(sourceDb, targetDb, entityId, sourceStore, purgeSource = false) {
|
|
1119
|
+
function promoteEpisode(sourceDb, targetDb, entityId, sourceStore, targetStore, purgeSource = false) {
|
|
1077
1120
|
const source = sourceDb.prepare("SELECT * FROM episodes WHERE id = ?").get(entityId);
|
|
1078
1121
|
if (!source)
|
|
1079
1122
|
return { success: false, error: `Episode ID '${entityId}' が見つかりません` };
|
|
1080
|
-
if (source.
|
|
1081
|
-
return { success: false, error: `Episode ID '${entityId}' はactive状態ではありません(現在: ${source.
|
|
1123
|
+
if (source.validity_status !== "active")
|
|
1124
|
+
return { success: false, error: `Episode ID '${entityId}' はactive状態ではありません(現在: ${source.validity_status})` };
|
|
1082
1125
|
const targetId = purgeSource ? entityId : ulid();
|
|
1083
1126
|
let wasExisting = false;
|
|
1084
1127
|
const existing = targetDb.prepare("SELECT id FROM episodes WHERE id = ? OR (promoted_from_store = ? AND promoted_from_id = ?)").get(targetId, sourceStore, entityId);
|
|
@@ -1088,7 +1131,7 @@ function promoteEpisode(sourceDb, targetDb, entityId, sourceStore, purgeSource =
|
|
|
1088
1131
|
else {
|
|
1089
1132
|
targetDb.prepare(`
|
|
1090
1133
|
INSERT INTO episodes (id, title, l1_content, l2_context, l2_trigger, l2_problems, l2_desires, l2_decisions, l2_outcomes,
|
|
1091
|
-
l2_principles, evidence_refs, tags,
|
|
1134
|
+
l2_principles, evidence_refs, tags, validity_status, client_name, client_version, source_tool, session_id,
|
|
1092
1135
|
created_at, updated_at, scope, search_summary, user_input, promoted_from_store, promoted_from_id)
|
|
1093
1136
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'active', ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
1094
1137
|
`).run(targetId, source.title, source.l1_content, source.l2_context, source.l2_trigger, source.l2_problems, source.l2_desires, source.l2_decisions, source.l2_outcomes, source.l2_principles, source.evidence_refs, source.tags, source.client_name, source.client_version, source.source_tool, source.session_id, source.created_at, source.updated_at, source.scope, source.search_summary, source.user_input, sourceStore, entityId);
|
|
@@ -1097,16 +1140,16 @@ function promoteEpisode(sourceDb, targetDb, entityId, sourceStore, purgeSource =
|
|
|
1097
1140
|
sourceDb.prepare("DELETE FROM episodes WHERE id = ?").run(entityId);
|
|
1098
1141
|
}
|
|
1099
1142
|
else {
|
|
1100
|
-
sourceDb.prepare("UPDATE episodes SET
|
|
1143
|
+
sourceDb.prepare("UPDATE episodes SET promoted_to = ?, updated_at = ? WHERE id = ?").run(targetStore, new Date().toISOString(), entityId);
|
|
1101
1144
|
}
|
|
1102
1145
|
return { success: true, new_id: existing?.id ?? targetId, title: source.title, was_existing: wasExisting };
|
|
1103
1146
|
}
|
|
1104
|
-
function promoteTheory(sourceDb, targetDb, entityId, sourceStore, purgeSource = false) {
|
|
1147
|
+
function promoteTheory(sourceDb, targetDb, entityId, sourceStore, targetStore, purgeSource = false) {
|
|
1105
1148
|
const source = sourceDb.prepare("SELECT * FROM theories WHERE id = ?").get(entityId);
|
|
1106
1149
|
if (!source)
|
|
1107
1150
|
return { success: false, error: `Theory ID '${entityId}' が見つかりません` };
|
|
1108
|
-
if (source.
|
|
1109
|
-
return { success: false, error: `Theory ID '${entityId}' はactive状態ではありません(現在: ${source.
|
|
1151
|
+
if (source.validity_status !== "active")
|
|
1152
|
+
return { success: false, error: `Theory ID '${entityId}' はactive状態ではありません(現在: ${source.validity_status})` };
|
|
1110
1153
|
const targetId = purgeSource ? entityId : ulid();
|
|
1111
1154
|
let wasExisting = false;
|
|
1112
1155
|
const existing = targetDb.prepare("SELECT id FROM theories WHERE id = ? OR (promoted_from_store = ? AND promoted_from_id = ?)").get(targetId, sourceStore, entityId);
|
|
@@ -1118,7 +1161,7 @@ function promoteTheory(sourceDb, targetDb, entityId, sourceStore, purgeSource =
|
|
|
1118
1161
|
INSERT INTO theories (id, title, description, l1_content, l2_core_thesis, l2_applicable_context, l2_principles,
|
|
1119
1162
|
l2_trigger_conditions, l2_resolution_steps, non_goals, open_questions,
|
|
1120
1163
|
supporting_episode_ids, supporting_claim_ids, evidence_refs, tags, scope, confidence,
|
|
1121
|
-
|
|
1164
|
+
validity_status, search_summary, source_tool, session_id, client_name, client_version,
|
|
1122
1165
|
created_at, updated_at, promoted_from_store, promoted_from_id)
|
|
1123
1166
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'active', ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
1124
1167
|
`).run(targetId, source.title, source.description, source.l1_content, source.l2_core_thesis, source.l2_applicable_context, source.l2_principles, source.l2_trigger_conditions, source.l2_resolution_steps, source.non_goals, source.open_questions, source.supporting_episode_ids, source.supporting_claim_ids, source.evidence_refs, source.tags, source.scope, source.confidence, source.search_summary, source.source_tool, source.session_id, source.client_name, source.client_version, source.created_at, source.updated_at, sourceStore, entityId);
|
|
@@ -1127,16 +1170,16 @@ function promoteTheory(sourceDb, targetDb, entityId, sourceStore, purgeSource =
|
|
|
1127
1170
|
sourceDb.prepare("DELETE FROM theories WHERE id = ?").run(entityId);
|
|
1128
1171
|
}
|
|
1129
1172
|
else {
|
|
1130
|
-
sourceDb.prepare("UPDATE theories SET
|
|
1173
|
+
sourceDb.prepare("UPDATE theories SET promoted_to = ?, updated_at = ? WHERE id = ?").run(targetStore, new Date().toISOString(), entityId);
|
|
1131
1174
|
}
|
|
1132
1175
|
return { success: true, new_id: existing?.id ?? targetId, title: source.title, was_existing: wasExisting };
|
|
1133
1176
|
}
|
|
1134
|
-
function promoteInsight(sourceDb, targetDb, entityId, sourceStore, purgeSource = false) {
|
|
1177
|
+
function promoteInsight(sourceDb, targetDb, entityId, sourceStore, targetStore, purgeSource = false) {
|
|
1135
1178
|
const source = sourceDb.prepare("SELECT * FROM insights WHERE id = ?").get(entityId);
|
|
1136
1179
|
if (!source)
|
|
1137
1180
|
return { success: false, error: `Insight ID '${entityId}' が見つかりません` };
|
|
1138
|
-
if (source.
|
|
1139
|
-
return { success: false, error: `Insight ID '${entityId}' はactive状態ではありません(現在: ${source.
|
|
1181
|
+
if (source.validity_status !== "active")
|
|
1182
|
+
return { success: false, error: `Insight ID '${entityId}' はactive状態ではありません(現在: ${source.validity_status})` };
|
|
1140
1183
|
const targetId = purgeSource ? entityId : ulid();
|
|
1141
1184
|
let wasExisting = false;
|
|
1142
1185
|
const existing = targetDb.prepare("SELECT id FROM insights WHERE id = ? OR (promoted_from_store = ? AND promoted_from_id = ?)").get(targetId, sourceStore, entityId);
|
|
@@ -1148,7 +1191,7 @@ function promoteInsight(sourceDb, targetDb, entityId, sourceStore, purgeSource =
|
|
|
1148
1191
|
INSERT INTO insights (id, title, description, l1_content, l2_core_thesis, l2_applicable_context, l2_principles,
|
|
1149
1192
|
l2_trigger_conditions, l2_resolution_steps,
|
|
1150
1193
|
supporting_episode_ids, supporting_claim_ids, evidence_refs, tags, scope, confidence,
|
|
1151
|
-
|
|
1194
|
+
validity_status, search_summary, l1_embedding, source_tool, session_id, client_name, client_version,
|
|
1152
1195
|
created_at, updated_at, promoted_from_store, promoted_from_id)
|
|
1153
1196
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'active', ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
1154
1197
|
`).run(targetId, source.title, source.description, source.l1_content, source.l2_core_thesis, source.l2_applicable_context, source.l2_principles, source.l2_trigger_conditions, source.l2_resolution_steps, source.supporting_episode_ids, source.supporting_claim_ids, source.evidence_refs, source.tags, source.scope, source.confidence, source.search_summary, source.l1_embedding, source.source_tool, source.session_id, source.client_name, source.client_version, source.created_at, source.updated_at, sourceStore, entityId);
|
|
@@ -1157,16 +1200,16 @@ function promoteInsight(sourceDb, targetDb, entityId, sourceStore, purgeSource =
|
|
|
1157
1200
|
sourceDb.prepare("DELETE FROM insights WHERE id = ?").run(entityId);
|
|
1158
1201
|
}
|
|
1159
1202
|
else {
|
|
1160
|
-
sourceDb.prepare("UPDATE insights SET
|
|
1203
|
+
sourceDb.prepare("UPDATE insights SET promoted_to = ?, updated_at = ? WHERE id = ?").run(targetStore, new Date().toISOString(), entityId);
|
|
1161
1204
|
}
|
|
1162
1205
|
return { success: true, new_id: existing?.id ?? targetId, title: source.title, was_existing: wasExisting };
|
|
1163
1206
|
}
|
|
1164
|
-
function promoteModel(sourceDb, targetDb, entityId, sourceStore, purgeSource = false) {
|
|
1207
|
+
function promoteModel(sourceDb, targetDb, entityId, sourceStore, targetStore, purgeSource = false) {
|
|
1165
1208
|
const source = sourceDb.prepare("SELECT * FROM models WHERE id = ?").get(entityId);
|
|
1166
1209
|
if (!source)
|
|
1167
1210
|
return { success: false, error: `Model ID '${entityId}' が見つかりません` };
|
|
1168
|
-
if (source.
|
|
1169
|
-
return { success: false, error: `Model ID '${entityId}' はactive状態ではありません(現在: ${source.
|
|
1211
|
+
if (source.validity_status !== "active")
|
|
1212
|
+
return { success: false, error: `Model ID '${entityId}' はactive状態ではありません(現在: ${source.validity_status})` };
|
|
1170
1213
|
const targetId = purgeSource ? entityId : ulid();
|
|
1171
1214
|
let wasExisting = false;
|
|
1172
1215
|
const existing = targetDb.prepare("SELECT id FROM models WHERE id = ? OR (promoted_from_store = ? AND promoted_from_id = ?)").get(targetId, sourceStore, entityId);
|
|
@@ -1178,7 +1221,7 @@ function promoteModel(sourceDb, targetDb, entityId, sourceStore, purgeSource = f
|
|
|
1178
1221
|
INSERT INTO models (id, title, description, l1_content, l2_core_thesis, l2_applicable_context, l2_principles,
|
|
1179
1222
|
l2_trigger_conditions, l2_resolution_steps, non_goals, open_questions,
|
|
1180
1223
|
supporting_episode_ids, supporting_claim_ids, evidence_refs, tags, scope, confidence,
|
|
1181
|
-
|
|
1224
|
+
validity_status, search_summary, l1_embedding, source_tool, session_id, client_name, client_version,
|
|
1182
1225
|
created_at, updated_at, promoted_from_store, promoted_from_id)
|
|
1183
1226
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'active', ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
1184
1227
|
`).run(targetId, source.title, source.description, source.l1_content, source.l2_core_thesis, source.l2_applicable_context, source.l2_principles, source.l2_trigger_conditions, source.l2_resolution_steps, source.non_goals, source.open_questions, source.supporting_episode_ids, source.supporting_claim_ids, source.evidence_refs, source.tags, source.scope, source.confidence, source.search_summary, source.l1_embedding, source.source_tool, source.session_id, source.client_name, source.client_version, source.created_at, source.updated_at, sourceStore, entityId);
|
|
@@ -1187,7 +1230,7 @@ function promoteModel(sourceDb, targetDb, entityId, sourceStore, purgeSource = f
|
|
|
1187
1230
|
sourceDb.prepare("DELETE FROM models WHERE id = ?").run(entityId);
|
|
1188
1231
|
}
|
|
1189
1232
|
else {
|
|
1190
|
-
sourceDb.prepare("UPDATE models SET
|
|
1233
|
+
sourceDb.prepare("UPDATE models SET promoted_to = ?, updated_at = ? WHERE id = ?").run(targetStore, new Date().toISOString(), entityId);
|
|
1191
1234
|
}
|
|
1192
1235
|
return { success: true, new_id: existing?.id ?? targetId, title: source.title, was_existing: wasExisting };
|
|
1193
1236
|
}
|