clearai-dsh 0.5.0 → 0.5.2

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.
@@ -1027,6 +1027,7 @@ export function describeDomainGraph(lexicon) {
1027
1027
  // 会话账本只活在一次会话里,而研究要跨会话攒下来。所以「攒下来的东西」住在工作区的文件里:
1028
1028
  // · `clear/knowledge/facts/<id>.json`:升格的事实,一条一个文件,只有系统写;
1029
1029
  // · `clear/knowledge/lessons/<id>.json`:结案时经独立评估核过的经验,一条一个文件,只有系统写;
1030
+ // · `clear/knowledge/negatives/<id>.json`:负向条目(已排除、未解、缺陷),系统随发生随写;
1030
1031
  // · `clear/ontology/{concepts,relations,entities}/**.json`:本体,模型用原生文件工具直接写。
1031
1032
  // 内核每一拍把这两处的变化折成一条 `workspace/synced` 变更,投影从文件内容派生词汇、实体与
1032
1033
  // 事实——折法仍然只吃账本,文件是账本之外唯一的输入,而且进账本时就是一条可重放的事实。
@@ -1035,6 +1036,8 @@ export function describeDomainGraph(lexicon) {
1035
1036
  export const FACTS_DIR = 'clear/knowledge/facts'
1036
1037
  /** 经验文件所在的目录(相对工作区)。 */
1037
1038
  export const LESSONS_DIR = 'clear/knowledge/lessons'
1039
+ /** 负向条目(已排除、未解、缺陷):内核随发生随写,一条一个文件。 */
1040
+ export const NEGATIVES_DIR = 'clear/knowledge/negatives'
1038
1041
  /** 经验的四类:坑、要核的读数、会骗人的捷径、先验。 */
1039
1042
  export const LESSON_KINDS = ['trap', 'check', 'shortcut', 'prior']
1040
1043
  /** 本体文件树的根(相对工作区)。 */
@@ -1064,7 +1067,7 @@ export function definitionFingerprint(entry) {
1064
1067
  /** 单位与形状只在写了时进指纹:没写这两格的旧词条,指纹与从前逐字相同。 */
1065
1068
  const meaning =
1066
1069
  'range' in entry || 'domain' in entry
1067
- ? { domain: text(entry.domain), range: isPlainObject(entry.range) ? { term: text(entry.range.term), form: text(entry.range.form), unit: text(entry.range.unit) } : null, functional: entry.functional === true, ...(text(entry.shape) === '' ? {} : { shape: text(entry.shape) }) }
1070
+ ? { domain: text(entry.domain), range: isPlainObject(entry.range) ? { term: text(entry.range.term), form: text(entry.range.form), unit: text(entry.range.unit) } : null, functional: entry.functional === true, gloss: text(entry.gloss), check: text(entry.check), ...(text(entry.shape) === '' ? {} : { shape: text(entry.shape) }) }
1068
1071
  : { gloss: text(entry.gloss), parent: text(entry.parent), ...(text(entry.unit) === '' ? {} : { unit: text(entry.unit) }) }
1069
1072
  return `fnv:${hashText(JSON.stringify(meaning))}`
1070
1073
  }
@@ -1125,6 +1128,8 @@ export function classifyWorkspacePath(path) {
1125
1128
  if (parts.length === facts.length + 1 && facts.every((part, index) => parts[index] === part)) return { kind: 'fact', id, dirs: [] }
1126
1129
  const lessons = LESSONS_DIR.split('/')
1127
1130
  if (parts.length === lessons.length + 1 && lessons.every((part, index) => parts[index] === part)) return { kind: 'lesson', id, dirs: [] }
1131
+ const negatives = NEGATIVES_DIR.split('/')
1132
+ if (parts.length === negatives.length + 1 && negatives.every((part, index) => parts[index] === part)) return { kind: 'negative', id, dirs: [] }
1128
1133
  const root = ONTOLOGY_DIR.split('/')
1129
1134
  if (parts.length >= root.length + 2 && root.every((part, index) => parts[index] === part)) {
1130
1135
  const kind = ONTOLOGY_BRANCHES[parts[root.length]]
@@ -1145,7 +1150,16 @@ export function factFromFile(data, path) {
1145
1150
  goal: data.goal ?? null,
1146
1151
  hypothesis: data.hypothesis ?? null,
1147
1152
  text: String(data.text),
1148
- scope: data.scope ?? null,
1153
+ about: stringList(data.about),
1154
+ scope: data.scope_spec === undefined && data.refute_when === undefined ? null : data.scope ?? null,
1155
+ scope_spec: isPlainObject(data.scope_spec) ? clone(data.scope_spec) : null,
1156
+ use: typeof data.use === 'string' && data.use !== '' ? data.use : null,
1157
+ refute_when: typeof data.refute_when === 'string' ? data.refute_when : data.scope_spec === undefined && typeof data.scope === 'string' ? data.scope : null,
1158
+ boundaries: Array.isArray(data.boundaries) ? clone(data.boundaries) : [],
1159
+ challenges: Array.isArray(data.challenges) ? clone(data.challenges) : [],
1160
+ calculation: isPlainObject(data.calculation) ? clone(data.calculation) : null,
1161
+ rechecks: Array.isArray(data.rechecks) ? clone(data.rechecks) : [],
1162
+ evidence_records: Array.isArray(data.evidence_records) ? clone(data.evidence_records) : [],
1149
1163
  level: data.level ?? null,
1150
1164
  evidence: Array.isArray(data.evidence) ? data.evidence : [],
1151
1165
  assertions: Array.isArray(data.assertions) ? clone(data.assertions) : null,
@@ -1167,7 +1181,8 @@ export function lessonFromFile(data, path) {
1167
1181
  goal: data.goal ?? null,
1168
1182
  text: String(data.text),
1169
1183
  kind: LESSON_KINDS.includes(data.kind) ? data.kind : 'trap',
1170
- about: Array.isArray(data.about) ? data.about.map(String).filter((item) => item.trim() !== '').slice(0, 6) : [],
1184
+ about: stringList(data.about),
1185
+ scope_spec: isPlainObject(data.scope_spec) ? clone(data.scope_spec) : null,
1171
1186
  evidence: typeof data.evidence === 'string' ? data.evidence : null,
1172
1187
  boundary: typeof data.boundary === 'string' ? data.boundary : null,
1173
1188
  status: data.status === 'retracted' ? 'retracted' : 'active',
@@ -1176,6 +1191,38 @@ export function lessonFromFile(data, path) {
1176
1191
  }
1177
1192
  }
1178
1193
 
1194
+ /** 负向条目的种类与状态(与内核 `knowledge-items.js` 同值)。 */
1195
+ export const NEGATIVE_KINDS = ['excluded', 'unresolved', 'defect']
1196
+ export const NEGATIVE_STATUS = ['excluded', 'preliminary_excluded', 'unresolved', 'explained', 'ruled_out', 'escalated', 'defect']
1197
+
1198
+ /**
1199
+ * 负向条目文件 → 条目行。人可以在文件上写 `review`(如 `{"decision": "retracted"}`)撤回一条,撤回的不再列出。
1200
+ */
1201
+ export function negativeFromFile(data, path) {
1202
+ if (!isPlainObject(data) || text(data.id) === '' || text(data.statement) === '') return null
1203
+ const kind = NEGATIVE_KINDS.includes(data.kind) ? data.kind : 'unresolved'
1204
+ return {
1205
+ id: text(data.id),
1206
+ kind,
1207
+ status: NEGATIVE_STATUS.includes(data.status) ? data.status : kind,
1208
+ statement: String(data.statement),
1209
+ touches: stringList(data.touches),
1210
+ evidence: Array.isArray(data.evidence) ? clone(data.evidence) : [],
1211
+ about: stringList(data.about),
1212
+ scope_spec: isPlainObject(data.scope) ? clone(data.scope) : null,
1213
+ strength: isPlainObject(data.strength) ? clone(data.strength) : null,
1214
+ resolution: isPlainObject(data.resolution) ? clone(data.resolution) : null,
1215
+ source: isPlainObject(data.source) ? clone(data.source) : null,
1216
+ review: isPlainObject(data.review) ? clone(data.review) : null,
1217
+ path: path ?? null,
1218
+ at: typeof data.at === 'number' ? data.at : null,
1219
+ }
1220
+ }
1221
+
1222
+ function stringList(raw) {
1223
+ return Array.isArray(raw) ? raw.map(String).filter((item) => item.trim() !== '').slice(0, 12) : []
1224
+ }
1225
+
1179
1226
  // ═══ 本体文件树:字段、单文件校验、从文件折出词汇与实体 ═════════════════════════
1180
1227
  //
1181
1228
  // 本体由模型用原生文件工具直接写,住在 `clear/ontology/{concepts,relations,entities}/` 下:
@@ -1315,7 +1362,7 @@ function evidenceShape(value, at) {
1315
1362
  */
1316
1363
  export function checkOntologyFile(path, content) {
1317
1364
  const place = classifyWorkspacePath(path)
1318
- if (place === null || place.kind === 'fact' || place.kind === 'lesson') return [tr(`不是本体文件的位置:本体文件要放在 ${ONTOLOGY_DIR}/{concepts,relations,entities}/ 下,扩展名 .json`, `Not an ontology file location: ontology files go under ${ONTOLOGY_DIR}/{concepts,relations,entities}/ with a .json extension`)]
1365
+ if (place === null || place.kind === 'fact' || place.kind === 'lesson' || place.kind === 'negative') return [tr(`不是本体文件的位置:本体文件要放在 ${ONTOLOGY_DIR}/{concepts,relations,entities}/ 下,扩展名 .json`, `Not an ontology file location: ontology files go under ${ONTOLOGY_DIR}/{concepts,relations,entities}/ with a .json extension`)]
1319
1366
  let data = content
1320
1367
  if (typeof content === 'string') {
1321
1368
  try {
@@ -1423,7 +1470,7 @@ export function materializeOntology(files) {
1423
1470
  const flag = (path, id, code, detail, severity = 'warning') => problems.push({ path, id, code, detail, severity })
1424
1471
  const entries = Object.entries(isPlainObject(files) ? files : {})
1425
1472
  .map(([path, file]) => ({ path, file, place: classifyWorkspacePath(path) }))
1426
- .filter((item) => item.place !== null && item.place.kind !== 'fact' && item.place.kind !== 'lesson')
1473
+ .filter((item) => item.place !== null && item.place.kind !== 'fact' && item.place.kind !== 'lesson' && item.place.kind !== 'negative')
1427
1474
  .sort((a, b) => (a.path < b.path ? -1 : 1))
1428
1475
  const terms = []
1429
1476
  const predicates = []