Compare commits

..

3 Commits

Author SHA1 Message Date
Zayden-Jung 87987f6cc6 Merge pull request '支持基于内部摘要的章节级文章编辑' (#30) from codex/document-sections into main
Verify and deploy Tabularium / verify-and-deploy (push) Successful in 8m39s
Reviewed-on: #30
2026-10-30 14:05:53 +00:00
Zayden-Jung 56b0ee60c0 Merge pull request '扩展中英文 AI 公司分类与收入核查' (#29) from codex/ai-research-source-lineage into main
Verify and deploy Tabularium / verify-and-deploy (push) Successful in 6m33s
Reviewed-on: #29
2026-10-30 13:05:46 +00:00
codex-bot 9ee2bd219a Add chapter editing API with internal summaries and revision control 2026-10-30 19:58:40 +08:00
14 changed files with 502 additions and 329 deletions
+1
View File
@@ -4,6 +4,7 @@
- Web 技术栈为 TypeScript、React、Tailwind CSS、Next.js Pages Router;不要切换到 App Router。 - Web 技术栈为 TypeScript、React、Tailwind CSS、Next.js Pages Router;不要切换到 App Router。
- 使用 pnpm 管理 JavaScript workspace,使用 uv 管理 `tools/figures` 的 Python 项目,保留两套锁文件。 - 使用 pnpm 管理 JavaScript workspace,使用 uv 管理 `tools/figures` 的 Python 项目,保留两套锁文件。
- 文档正文、目录元数据与修订记录以站点现有 SQLite 数据库为唯一权威源,使用文档 API 或 docs 管理工具直接更新;不得把新正文、目录 JSON、数据库文件或日常内容快照提交到仓库。历史 Git 文档只用于显式的一次性迁移,不作为运行时种子。Python 图形源码放在 `tools/figures/src/endor_figures`,可复现的 SVG 输出放在 `apps/docs/public/figures`。 - 文档正文、目录元数据与修订记录以站点现有 SQLite 数据库为唯一权威源,使用文档 API 或 docs 管理工具直接更新;不得把新正文、目录 JSON、数据库文件或日常内容快照提交到仓库。历史 Git 文档只用于显式的一次性迁移,不作为运行时种子。Python 图形源码放在 `tools/figures/src/endor_figures`,可复现的 SVG 输出放在 `apps/docs/public/figures`。
- 编辑已有文章时优先使用章节 API:先读取章节目录与内部摘要,据此选择需要读取正文的章节,再提交单章或多章操作。摘要缺失时先读对应正文并补充;修改观点前必须核对该章原文,检查读取版本与提交 revision 一致。摘要只写入内部章节数据,不放入网页正文、目录摘要或 Git;改写正文时同步更新摘要。完整操作与 Python 客户端用法见 README 的「先读摘要,再按章节编辑」。
- 未确认的架构提议明确标注为草案,不能表述为现有实现。 - 未确认的架构提议明确标注为草案,不能表述为现有实现。
- 本地开发与预览只监听 `127.0.0.1`。部署容器监听 `0.0.0.0:3000`,服务器入口默认 18135,可通过独立 production.env 配置。 - 本地开发与预览只监听 `127.0.0.1`。部署容器监听 `0.0.0.0:3000`,服务器入口默认 18135,可通过独立 production.env 配置。
- 对 gitea.entroia.com 仅使用 codex-bot,提交身份为 Codex Bot <codex-bot@gitea.entroia.local>。SSH 使用隔离配置:`ssh -F /dev/null -o IdentitiesOnly=yes -i /Users/zzyang/.codex/credentials/gitea-entroia/codex_entroia_ed25519 -p 22222`。 - 对 gitea.entroia.com 仅使用 codex-bot,提交身份为 Codex Bot <codex-bot@gitea.entroia.local>。SSH 使用隔离配置:`ssh -F /dev/null -o IdentitiesOnly=yes -i /Users/zzyang/.codex/credentials/gitea-entroia/codex_entroia_ed25519 -p 22222`。
+50
View File
@@ -75,6 +75,10 @@ sudo /opt/endorphin-tabularium-docs/docs save < "$doc_work_dir/document.json"
| `GET /api/documents/item/<slug>?revision=1` | 读取指定修订的完整正文 | | `GET /api/documents/item/<slug>?revision=1` | 读取指定修订的完整正文 |
| `POST /api/documents` | 保存一个完整文档 JSON;字段与 `docs save` 相同 | | `POST /api/documents` | 保存一个完整文档 JSON;字段与 `docs save` 相同 |
| `POST /api/documents/batch` | 保存 `{ "documents": [...] }`,每个请求 1—100 篇 | | `POST /api/documents/batch` | 保存 `{ "documents": [...] }`,每个请求 1—100 篇 |
| `GET /api/documents/sections/<slug>` | 读取章节 ID、标题和内部摘要,不返回正文 |
| `GET /api/documents/sections/<slug>?section=<id>` | 读取选中章节正文;重复 `section` 可选多章 |
| `GET /api/documents/sections/<slug>?revision=2` | 读取对应修订的章节目录;也可搭配 `section` |
| `POST /api/documents/sections/<slug>` | 原子执行章节新增、更新、删除和移动 |
写入使用 `Authorization: Bearer <文档 API Key>`。新建传 `revision: 0`;更新先读取当前全文,再使用读到的 revision。每篇正文最多 2,000,000 个 JavaScript 字符单位;每次请求最多 8 MiB。目录和修订分页的 `limit` 范围为 1—100,响应包含 `total` 和 `nextOffset`。 写入使用 `Authorization: Bearer <文档 API Key>`。新建传 `revision: 0`;更新先读取当前全文,再使用读到的 revision。每篇正文最多 2,000,000 个 JavaScript 字符单位;每次请求最多 8 MiB。目录和修订分页的 `limit` 范围为 1—100,响应包含 `total` 和 `nextOffset`。
@@ -82,6 +86,52 @@ sudo /opt/endorphin-tabularium-docs/docs save < "$doc_work_dir/document.json"
建议写入时提供 `Idempotency-Key`,由 1—128 个字母、数字或 `._:-` 组成。同一个 Key、相同请求 ID 和相同输入重试时,返回原回执并标记 `replayed: true`,不追加修订;相同 ID 改换输入会冲突。回执描述原请求,不代表之后没有其他修改;需要当前内容时重新读取文档。改过正文或 revision 后,应使用新的请求 ID。 建议写入时提供 `Idempotency-Key`,由 1—128 个字母、数字或 `._:-` 组成。同一个 Key、相同请求 ID 和相同输入重试时,返回原回执并标记 `replayed: true`,不追加修订;相同 ID 改换输入会冲突。回执描述原请求,不代表之后没有其他修改;需要当前内容时重新读取文档。改过正文或 revision 后,应使用新的请求 ID。
### 先读摘要,再按章节编辑
章节接口使用相同的文档 Key 和读写权限。编辑流程为:先读章节目录及摘要,选择需要深入的章节,再读取这些章节的正文,最后提交一组操作。不要只凭摘要修改未读正文;目录与正文响应的 `revision` 应一致,否则重新读取。接口不调用模型生成摘要:由编辑 Agent 阅读正文、撰写摘要,并在编辑请求中保存。
章节按行首 Markdown ATX 二级标题(`##`)划分,三级至六级标题随所属章节一起编辑;代码围栏内的标题不会切章。二级标题之前的文档标题及导言属于固定 ID `preamble`,可以修改但不能删除或移动。Setext 标题、带缩进或引用、列表标记的标题不作为章节边界。正文无行首二级标题时,全文作为导言处理。拆分及组合保持换行和未编辑内容原样,不自动格式化 Markdown。
目录中的每章包含 `id`、`title`、`position`、`summary`、`summaryStatus` 和 `contentHash`。摘要为编辑内部数据,单独保存在 SQLite 的 `document_sections` 和 `document_section_revisions` 中,不加入普通文档响应、网页 props、搜索索引或页面正文。完整数据库备份包含这些表;`docs export` 仍只导出当前文档,不包含内部摘要和修订。
旧文章无需重写,首次读取即可按原文返回目录,初始摘要为空,`summaryStatus` 为 `missing`。Agent 应按需读取这些章节,生成摘要并通过 `update` 保存;保存后状态为 `current`。这里的 `current` 仅表示摘要与该版正文一起保存,不保证模型的总结正确。全文接口仍兼容;未变化章节保留摘要与 ID,正文变化的章节清空摘要,等待更新。全文改名且改写章节时可能产生新 ID,因此全文保存后应重新读取目录。
章节编辑请求示例(示例 ID 需要替换为目录实际返回的值):
```json
{
"revision": 3,
"operations": [
{
"op": "update",
"id": "s_existing",
"content": "## 原有章节\n\n修改后的正文。\n\n",
"summary": "本章说明修改后的核心观点与边界。"
},
{
"op": "insert",
"after": "s_existing",
"content": "## 新章节\n\n新增论证。\n\n",
"summary": "补充上一章尚未覆盖的论证。"
}
]
}
```
`update` 可只改 `summary`,也可改正文;正文改变时若不提供新摘要,旧摘要会清空。`insert` 必须提供正文和非空摘要;摘要最多 8000 个 JavaScript 字符单位。`delete` 使用 `{ "op": "delete", "id": "s_existing" }`;`move` 使用 `{ "op": "move", "id": "s_existing", "after": "preamble" }`。按数组顺序执行,最多 100 个操作;新章 ID 由服务器生成,在回执目录中返回。章正文应从自己的 `##` 标题开始,只包含一个二级标题,并保留与下一章之间的换行;跨章代码围栏或章节边界改变会被拒绝,拆章请使用多个操作。
章节变更、内部摘要、组合后的全文和历史快照在同一事务内提交。每批操作只增加一次文章 `revision`;摘要单独更新也增加版本号。后续操作失败或全文版本过期时全部回滚。写入沿用幂等规则,回执包含新版本、章节目录和 `replayed`;章节接口与全文接口的幂等记录分开。修改章节不会改变其 ID,移动亦保留 ID;删除后的正文和摘要仍可从对应的旧修订读取。启用前的历史修订只有原文,摘要显示缺失。
Python 客户端对应命令:
```sh
python3 scripts/documents-client.py outline endor/endor-purpose-draft
python3 scripts/documents-client.py sections endor/endor-purpose-draft preamble s_existing
python3 scripts/documents-client.py edit-sections endor/endor-purpose-draft /private/path/edit.json --request-id chapter-edit-1
```
`outline` 和 `sections` 支持 `--revision`;请求文件只包含 `revision` 和 `operations`,不要把内部摘要文件提交到 Git。
### 创建、查看与撤销 Key ### 创建、查看与撤销 Key
管理员只需通过已验证的服务器连接进行 Key 管理: 管理员只需通过已验证的服务器连接进行 Key 管理:
+2 -2
View File
@@ -182,9 +182,9 @@ async function main() {
assert.equal(researchResponse.status, 200, "authenticated research API"); assert.equal(researchResponse.status, 200, "authenticated research API");
assert.ok(researchResponse.headers.get("cache-control")?.includes("no-store")); assert.ok(researchResponse.headers.get("cache-control")?.includes("no-store"));
const research = await researchResponse.json(); const research = await researchResponse.json();
assert.equal(research.companies.length, 1031); assert.equal(research.companies.length, 1029);
assert.equal(research.categories.length, 11); assert.equal(research.categories.length, 11);
assert.equal(research.evidence.length, 1424); assert.equal(research.evidence.length, 1412);
assert.equal(research.observations.length, 192); assert.equal(research.observations.length, 192);
assert.equal((await request("/api/research/ai-companies", { method: "POST", headers })).status, 405); assert.equal((await request("/api/research/ai-companies", { method: "POST", headers })).status, 405);
const researchPage = await request("/docs/other-research/ai-company-research/overview", { headers }); const researchPage = await request("/docs/other-research/ai-company-research/overview", { headers });
+75 -5
View File
@@ -1,5 +1,9 @@
import { randomUUID, createHash } from "node:crypto"; import { randomUUID, createHash } from "node:crypto";
import { openSiteDatabase } from "./site-database"; import { openSiteDatabase } from "./site-database";
import { DocumentValidationError, DocumentConflictError } from "./document-errors";
import { sectionSchema, loadSections, reconcileSections, persistSections, splitSections, outline,
applySectionOperations, parseSectionEdit, type DocumentSection } from "./document-sections";
export { DocumentValidationError, DocumentConflictError } from "./document-errors";
export type DocLink = { export type DocLink = {
slug: string; sourceSlug: string; category: string; title: string; searchText?: string; slug: string; sourceSlug: string; category: string; title: string; searchText?: string;
@@ -9,8 +13,6 @@ export type DocLink = {
export type Doc = DocLink & { content: string }; export type Doc = DocLink & { content: string };
export type DocInput = Omit<Doc, "revision" | "searchText">; export type DocInput = Omit<Doc, "revision" | "searchText">;
export type DocumentExport = { format: "tabularium-documents-v1"; documents: Doc[] }; export type DocumentExport = { format: "tabularium-documents-v1"; documents: Doc[] };
export class DocumentValidationError extends Error {}
export class DocumentConflictError extends Error {}
export type DocumentReceipt = Pick<Doc, "slug" | "sourceSlug" | "revision">; export type DocumentReceipt = Pick<Doc, "slug" | "sourceSlug" | "revision">;
export const validSlug = /^[a-z0-9]+(?:-[a-z0-9]+)*(?:\/[a-z0-9]+(?:-[a-z0-9]+)*)*$/; export const validSlug = /^[a-z0-9]+(?:-[a-z0-9]+)*(?:\/[a-z0-9]+(?:-[a-z0-9]+)*)*$/;
@@ -36,6 +38,7 @@ function database() {
digest TEXT PRIMARY KEY, document_count INTEGER NOT NULL, created_at TEXT NOT NULL digest TEXT PRIMARY KEY, document_count INTEGER NOT NULL, created_at TEXT NOT NULL
); );
`); `);
sectionSchema(db);
return db; return db;
} }
@@ -57,12 +60,13 @@ export function validateDocument(input: DocInput): void {
throw new DocumentValidationError("Use compressed WebP images instead of original rasters"); throw new DocumentValidationError("Use compressed WebP images instead of original rasters");
} }
function write(db: ReturnType<typeof database>, input: DocInput, expectedRevision: number): Doc { function write(db: ReturnType<typeof database>, input: DocInput, expectedRevision: number, editedSections?: DocumentSection[]): Doc {
validateDocument(input); validateDocument(input);
const existing = db.prepare("SELECT id, revision FROM documents WHERE source_slug=?") const existing = db.prepare("SELECT id, revision, payload FROM documents WHERE source_slug=?")
.get(input.sourceSlug) as { id: string; revision: number } | undefined; .get(input.sourceSlug) as { id: string; revision: number; payload: string } | undefined;
if ((existing?.revision ?? 0) !== expectedRevision) throw new DocumentConflictError("Document revision conflict"); if ((existing?.revision ?? 0) !== expectedRevision) throw new DocumentConflictError("Document revision conflict");
const id = existing?.id ?? randomUUID(); const id = existing?.id ?? randomUUID();
const previous = existing ? loadSections(db, id, (JSON.parse(existing.payload) as Doc).content) : [];
const doc: Doc = { slug: input.slug, sourceSlug: input.sourceSlug, category: input.category, const doc: Doc = { slug: input.slug, sourceSlug: input.sourceSlug, category: input.category,
title: input.title, group: input.group, collection: input.collection, description: input.description, title: input.title, group: input.group, collection: input.collection, description: input.description,
draft: input.draft, featured: input.featured, content: input.content, revision: expectedRevision + 1 }; draft: input.draft, featured: input.featured, content: input.content, revision: expectedRevision + 1 };
@@ -80,9 +84,75 @@ function write(db: ReturnType<typeof database>, input: DocInput, expectedRevisio
db.prepare("INSERT OR IGNORE INTO document_aliases VALUES (?,?)").run(alias, id); db.prepare("INSERT OR IGNORE INTO document_aliases VALUES (?,?)").run(alias, id);
db.prepare("INSERT INTO document_revisions VALUES (?,?,?,?)") db.prepare("INSERT INTO document_revisions VALUES (?,?,?,?)")
.run(id, doc.revision, payload, new Date().toISOString()); .run(id, doc.revision, payload, new Date().toISOString());
persistSections(db, id, doc.revision, editedSections ?? reconcileSections(doc.content, previous));
return doc; return doc;
} }
// Internal summaries never enter Doc, catalog, search or browser page props.
export function readDocumentSections(slug: string, revision?: number) {
if (!validSlug.test(slug)) throw new DocumentValidationError("Invalid document slug");
if (revision !== undefined && (!Number.isSafeInteger(revision) || revision < 1)) throw new DocumentValidationError("Invalid revision");
const db = database();
try {
db.exec("BEGIN");
const row = db.prepare(`SELECT d.id,d.payload FROM documents d JOIN document_aliases a
ON a.document_id=d.id WHERE a.alias=?`).get(slug) as { id: string; payload: string } | undefined;
if (!row) { db.exec("COMMIT"); return null; }
let doc = JSON.parse(row.payload) as Doc;
let sections: DocumentSection[];
if (revision === undefined || revision === doc.revision) sections = loadSections(db, row.id, doc.content);
else {
const prior = db.prepare("SELECT payload FROM document_revisions WHERE document_id=? AND revision=?")
.get(row.id, revision) as { payload: string } | undefined;
if (!prior) { db.exec("COMMIT"); return null; }
doc = JSON.parse(prior.payload) as Doc;
const snapshot = db.prepare("SELECT payload FROM document_section_revisions WHERE document_id=? AND revision=?")
.get(row.id, revision) as { payload: string } | undefined;
sections = snapshot ? JSON.parse(snapshot.payload) as DocumentSection[] : splitSections(doc.content);
}
db.exec("COMMIT");
return { slug: doc.slug, sourceSlug: doc.sourceSlug, title: doc.title, revision: doc.revision, sections };
} finally { db.close(); }
}
export function editDocumentSections(slug: string, value: unknown, request?: { namespace: string; id: string }) {
if (!validSlug.test(slug)) throw new DocumentValidationError("Invalid document slug");
const edit = parseSectionEdit(value);
if (request && (!request.namespace || !/^[A-Za-z0-9._:-]{1,128}$/.test(request.id))) throw new DocumentValidationError("Invalid Idempotency-Key");
const digest = createHash("sha256").update(JSON.stringify({ slug, edit })).digest("hex");
const namespace = request ? request.namespace + ":sections" : undefined;
const db = database();
try {
db.exec("BEGIN IMMEDIATE");
try {
if (request) {
const prior = db.prepare("SELECT digest,response FROM document_write_requests WHERE namespace=? AND request_id=?")
.get(namespace!, request.id) as { digest: string; response: string } | undefined;
if (prior) {
if (prior.digest !== digest) throw new DocumentConflictError("Idempotency-Key was used with different content");
db.exec("COMMIT");
return { ...JSON.parse(prior.response) as { slug: string; sourceSlug: string; revision: number; sections: ReturnType<typeof outline> }, replayed: true };
}
}
const row = db.prepare(`SELECT d.id,d.payload FROM documents d JOIN document_aliases a
ON a.document_id=d.id WHERE a.alias=?`).get(slug) as { id: string; payload: string } | undefined;
if (!row) { db.exec("COMMIT"); return null; }
const doc = JSON.parse(row.payload) as Doc;
if (doc.revision !== edit.revision) throw new DocumentConflictError("Document revision conflict");
const previous = loadSections(db, row.id, doc.content);
const sections = applySectionOperations(previous, edit.operations);
// Preserve the initial outline when upgrading an existing document for the first time.
db.prepare("INSERT OR IGNORE INTO document_section_revisions VALUES (?,?,?)").run(row.id, doc.revision, JSON.stringify(previous));
const saved = write(db, { ...doc, content: sections.map((s) => s.content).join("") }, doc.revision, sections);
const receipt = { slug: saved.slug, sourceSlug: saved.sourceSlug, revision: saved.revision, sections: outline(sections) };
if (request) db.prepare("INSERT INTO document_write_requests VALUES (?,?,?,?)")
.run(namespace!, request.id, digest, JSON.stringify(receipt));
db.exec("COMMIT");
return { ...receipt, replayed: false };
} catch (error) { db.exec("ROLLBACK"); throw error; }
} finally { db.close(); }
}
export function saveDocument(input: DocInput, expectedRevision: number): Doc { export function saveDocument(input: DocInput, expectedRevision: number): Doc {
if (!Number.isSafeInteger(expectedRevision) || expectedRevision < 0) throw new DocumentValidationError("Provide expected revision"); if (!Number.isSafeInteger(expectedRevision) || expectedRevision < 0) throw new DocumentValidationError("Provide expected revision");
const db = database(); const db = database();
+2
View File
@@ -0,0 +1,2 @@
export class DocumentValidationError extends Error {}
export class DocumentConflictError extends Error {}
+144
View File
@@ -0,0 +1,144 @@
import { createHash, randomUUID } from "node:crypto";
import type { DatabaseSync } from "node:sqlite";
import { DocumentValidationError } from "./document-errors";
export type DocumentSection = {
id: string; title: string; content: string; summary: string;
};
export type SectionOperation =
| { op: "update"; id: string; content?: string; summary?: string }
| { op: "insert"; after: string; content: string; summary: string }
| { op: "delete"; id: string }
| { op: "move"; id: string; after: string };
export type SectionEdit = { revision: number; operations: SectionOperation[] };
const hash = (text: string) => createHash("sha256").update(text).digest("hex");
// Preserve every byte, including CRLF and separators. H3-H6 belong to their H2 chapter.
export function splitSections(content: string): DocumentSection[] {
const starts: { offset: number; title: string }[] = [{ offset: 0, title: "导言" }];
let offset = 0;
let fence: { marker: string; length: number } | undefined;
for (const line of content.match(/[^\n]*\n|[^\n]+$/g) ?? []) {
const opening = line.match(/^ {0,3}(`{3,}|~{3,})(.*?)(?:\r?\n)?$/);
if (fence) {
if (new RegExp(`^ {0,3}${fence.marker}{${fence.length},}[ \\t]*\\r?\\n?$`).test(line)) fence = undefined;
} else if (opening && !(opening[1][0] === "`" && opening[2].includes("`"))) {
fence = { marker: opening[1][0], length: opening[1].length };
} else {
const heading = line.match(/^##(?:[ \t]+(.*?))?[ \t]*\r?\n?$/);
if (heading) starts.push({ offset, title: (heading[1] ?? "").replace(/[ \t]+#+[ \t]*$/, "").trim() });
}
offset += line.length;
}
const seen = new Map<string, number>();
return starts.map((start, index) => {
const occurrence = seen.get(start.title) ?? 0;
seen.set(start.title, occurrence + 1);
return { id: index === 0 ? "preamble" : "s_" + hash(`${start.title}\0${occurrence}`).slice(0, 24),
title: start.title, content: content.slice(start.offset, starts[index + 1]?.offset), summary: "" };
});
}
export function sectionSchema(db: DatabaseSync) {
db.exec(`CREATE TABLE IF NOT EXISTS document_sections (
document_id TEXT PRIMARY KEY REFERENCES documents(id), payload TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS document_section_revisions (
document_id TEXT NOT NULL REFERENCES documents(id), revision INTEGER NOT NULL,
payload TEXT NOT NULL, PRIMARY KEY(document_id, revision)
);`);
}
export function loadSections(db: DatabaseSync, documentId: string, content: string): DocumentSection[] {
const row = db.prepare("SELECT payload FROM document_sections WHERE document_id=?")
.get(documentId) as { payload: string } | undefined;
if (!row) return splitSections(content);
const sections = JSON.parse(row.payload) as DocumentSection[];
// A legacy writer must not leave an apparently current outline over different Markdown.
return sections.map((s) => s.content).join("") === content ? sections : reconcileSections(content, sections);
}
export function reconcileSections(content: string, previous: DocumentSection[]): DocumentSection[] {
const unused = new Set(previous);
return splitSections(content).map((section) => {
const prior = section.id === "preamble" ? previous.find((p) => p.id === "preamble") :
previous.find((p) => p.id !== "preamble" && unused.has(p) && p.content === section.content) ??
previous.find((p) => p.id !== "preamble" && unused.has(p) && p.title === section.title);
if (prior) unused.delete(prior);
return { ...section, id: prior?.id ?? (section.id === "preamble" ? "preamble" : "s_" + randomUUID()),
summary: prior?.content === section.content ? prior.summary : "" };
});
}
export function persistSections(db: DatabaseSync, documentId: string, revision: number, sections: DocumentSection[]) {
const payload = JSON.stringify(sections);
db.prepare(`INSERT INTO document_sections VALUES (?,?) ON CONFLICT(document_id)
DO UPDATE SET payload=excluded.payload`).run(documentId, payload);
db.prepare("INSERT INTO document_section_revisions VALUES (?,?,?)").run(documentId, revision, payload);
}
export function outline(sections: DocumentSection[]) {
return sections.map(({ content, ...section }, position) => ({ ...section, position,
contentHash: hash(content), summaryStatus: section.summary.trim() ? "current" : "missing" }));
}
export function parseSectionEdit(value: unknown): SectionEdit {
if (!value || typeof value !== "object" || Array.isArray(value)) throw new DocumentValidationError("Expected section edit object");
const row = value as Record<string, unknown>;
if (Object.keys(row).some((key) => !["revision", "operations"].includes(key)) ||
!Number.isSafeInteger(row.revision) || (row.revision as number) < 1 || !Array.isArray(row.operations) ||
!row.operations.length || row.operations.length > 100) throw new DocumentValidationError("Provide revision and 1 to 100 operations");
for (const raw of row.operations) {
if (!raw || typeof raw !== "object" || Array.isArray(raw)) throw new DocumentValidationError("Invalid operation");
const op = raw as Record<string, unknown>;
const fields: Record<string, string[]> = { update: ["op", "id", "content", "summary"],
insert: ["op", "after", "content", "summary"], delete: ["op", "id"], move: ["op", "id", "after"] };
if (typeof op.op !== "string" || !Object.hasOwn(fields, op.op) || Object.keys(op).some((key) => !fields[op.op as string].includes(key)))
throw new DocumentValidationError("Unknown operation or field");
for (const key of fields[op.op].filter((key) => !["content", "summary", "op"].includes(key)))
if (typeof op[key] !== "string" || !(op[key] as string).length) throw new DocumentValidationError("Missing section identifier");
for (const key of ["content", "summary"])
if (op[key] !== undefined && typeof op[key] !== "string") throw new DocumentValidationError(`Invalid ${key}`);
if (op.op === "update" && op.content === undefined && op.summary === undefined) throw new DocumentValidationError("Empty update");
if (op.op === "insert" && (typeof op.content !== "string" || typeof op.summary !== "string" || !op.summary.trim()))
throw new DocumentValidationError("Insert requires content and summary");
if (typeof op.summary === "string" && (!op.summary.trim() || op.summary.length > 8000))
throw new DocumentValidationError("Summary must contain 1 to 8000 characters");
}
return { revision: row.revision as number, operations: row.operations as SectionOperation[] };
}
export function applySectionOperations(previous: DocumentSection[], operations: SectionOperation[]) {
const sections = previous.map((section) => ({ ...section }));
function index(id: string) {
const result = sections.findIndex((s) => s.id === id);
if (result < 0) throw new DocumentValidationError("Unknown section id");
return result;
}
for (const op of operations) {
if (op.op === "insert") {
sections.splice(index(op.after) + 1, 0, { id: "s_" + randomUUID(), title: "", content: op.content, summary: op.summary });
} else {
const at = index(op.id);
if (op.op === "update") {
if (op.content !== undefined && op.content !== sections[at].content) sections[at].summary = "";
if (op.content !== undefined) sections[at].content = op.content;
if (op.summary !== undefined) sections[at].summary = op.summary;
} else {
if (op.id === "preamble") throw new DocumentValidationError("Cannot delete or move the preamble");
if (op.op === "delete") sections.splice(at, 1);
else {
if (op.id === op.after) throw new DocumentValidationError("Cannot move section after itself");
index(op.after);
const [section] = sections.splice(at, 1);
sections.splice(index(op.after) + 1, 0, section);
}
}
}
}
const content = sections.map((s) => s.content).join("");
const parsed = splitSections(content);
if (parsed.length !== sections.length || parsed.some((s, i) => s.content !== sections[i].content))
throw new DocumentValidationError("Each chapter must start with one H2 heading; preserve newline boundaries and balanced fences");
return sections.map((s, i) => ({ ...s, title: parsed[i].title }));
}
@@ -0,0 +1,37 @@
import type { NextApiRequest, NextApiResponse } from "next";
import { DocumentValidationError, readDocumentSections, editDocumentSections } from "@/lib/docs";
import { outline } from "@/lib/document-sections";
import { authorizeDocuments, documentApiError, idempotency } from "@/lib/documents-api";
export const config = { api: { bodyParser: { sizeLimit: "8mb" } } };
export default function handler(request: NextApiRequest, response: NextApiResponse) {
try {
const key = authorizeDocuments(request, response, request.method === "POST");
if (!key) return;
if (request.method !== "GET" && request.method !== "POST") {
response.setHeader("Allow", "GET, POST");
return response.status(405).end();
}
if (!Array.isArray(request.query.slug)) throw new DocumentValidationError("Invalid document slug");
const slug = request.query.slug.join("/");
if (Object.keys(request.query).some((k) => !["slug", "section", "revision"].includes(k)))
throw new DocumentValidationError("Unknown section query");
if (request.method === "POST") {
if (request.query.section !== undefined || request.query.revision !== undefined)
throw new DocumentValidationError("POST uses revision and operations in the body");
const saved = editDocumentSections(slug, request.body, idempotency(request, key.id));
return saved ? response.status(200).json(saved) : response.status(404).json({ code: "not_found" });
}
const revision = request.query.revision;
if (revision !== undefined && (typeof revision !== "string" || !/^[1-9]\d*$/.test(revision)))
throw new DocumentValidationError("Invalid revision");
const doc = readDocumentSections(slug, revision === undefined ? undefined : Number(revision));
if (!doc) return response.status(404).json({ code: "not_found" });
const selected = request.query.section;
if (selected === undefined) return response.status(200).json({ ...doc, sections: outline(doc.sections) });
const ids = typeof selected === "string" ? [selected] : selected;
if (!ids.length || ids.length > 100 || ids.some((id) => !id)) throw new DocumentValidationError("Select 1 to 100 sections");
if (ids.some((id) => !doc.sections.some((s) => s.id === id))) return response.status(404).json({ code: "not_found" });
return response.status(200).json({ ...doc, sections: doc.sections.filter((s) => ids.includes(s.id)) });
} catch (error) { return documentApiError(response, error); }
}
+123 -1
View File
@@ -7,8 +7,11 @@ import type { NextApiRequest, NextApiResponse } from "next";
import documents from "../src/pages/api/documents/index"; import documents from "../src/pages/api/documents/index";
import batch from "../src/pages/api/documents/batch"; import batch from "../src/pages/api/documents/batch";
import item from "../src/pages/api/documents/item/[...slug]"; import item from "../src/pages/api/documents/item/[...slug]";
import sections from "../src/pages/api/documents/sections/[...slug]";
import { splitSections } from "../src/lib/document-sections";
import { openSiteDatabase } from "../src/lib/site-database";
import { createDocumentKey, authenticateDocumentKey, revokeDocumentKey, listDocumentKeys } from "../src/lib/document-keys"; import { createDocumentKey, authenticateDocumentKey, revokeDocumentKey, listDocumentKeys } from "../src/lib/document-keys";
import { allDocuments, documentHistory, readDocument, saveDocument, type Doc } from "../src/lib/docs"; import { allDocuments, documentHistory, readDocument, saveDocument, readDocumentSections, type Doc } from "../src/lib/docs";
import { newAuthConfig, signSession } from "../src/lib/auth"; import { newAuthConfig, signSession } from "../src/lib/auth";
const input: Doc = { slug: "endor/example", sourceSlug: "00-example", title: "Example", category: "Endor", const input: Doc = { slug: "endor/example", sourceSlug: "00-example", title: "Example", category: "Endor",
@@ -134,3 +137,122 @@ test("invalid batch members, duplicate identifiers, raw images and malformed fie
assert.equal(call(documents, { method: "DELETE", headers }).status, 405); assert.equal(call(documents, { method: "DELETE", headers }).status, 405);
assert.equal(call(item, { headers, query: { slug: ["missing"] } }).status, 404); assert.equal(call(item, { headers, query: { slug: ["missing"] } }).status, 404);
})); }));
const chapterContent = "# Example\n\nIntroduction.\n\n## First\n\nFirst body.\n\n### Detail\n\nChild stays in chapter.\n\n## Second\n\nSecond body.\n";
type SectionResponse = { revision: number; replayed?: boolean;
sections: { id: string; title: string; summary: string; summaryStatus?: string; content?: string }[] };
const chapterQuery = { slug: input.slug.split("/") };
test("chapter parser preserves bytes, fences, duplicate headings and CRLF", () => {
const content = "# Title\r\n\r\n## Repeated\r\n~~~text\r\n## Inside fence\r\n~~~\r\n### Nested\r\n```js\r\n## Also inside\r\n````\r\n\r\n## Repeated\r\nTail";
const parts = splitSections(content);
assert.equal(parts.length, 3);
assert.notEqual(parts[1].id, parts[2].id);
assert.equal(parts.map((p) => p.content).join(""), content);
assert.equal(parts[1].title, "Repeated");
assert.ok(parts[1].content.includes("### Nested"));
assert.equal(splitSections("").length, 1);
assert.equal(splitSections("# Title\n\n- Item\n ## List detail\n\n> ## Quoted\n").length, 1);
});
test("outline reads existing Markdown without changing it and returns only selected bodies", () => isolated(({ headers }) => {
saveDocument({ ...input, content: chapterContent }, 0);
const db = openSiteDatabase();
db.exec("DELETE FROM document_sections; DELETE FROM document_section_revisions;"); db.close();
const result = call(sections, { headers, query: chapterQuery });
assert.equal(result.status, 200);
const outline = result.body as SectionResponse;
assert.equal(outline.revision, 1); assert.equal(outline.sections.length, 3);
assert.deepEqual(outline.sections.map((s) => s.title), ["导言", "First", "Second"]);
assert.ok(outline.sections.every((s) => s.content === undefined && s.summaryStatus === "missing"));
const selected = call(sections, { headers, query: { ...chapterQuery, section: outline.sections[1].id } }).body as SectionResponse;
assert.equal(selected.sections.length, 1);
assert.ok(selected.sections[0].content!.includes("### Detail"));
assert.equal(readDocument(input.slug)!.content, chapterContent);
assert.equal(call(sections, { headers, query: { ...chapterQuery, section: "missing" } }).status, 404);
assert.equal(call(sections, { headers, query: { ...chapterQuery, revision: "0" } }).status, 400);
}));
test("internal summaries persist separately and chapter updates leave other bytes untouched", () => isolated(({ headers }) => {
saveDocument({ ...input, content: chapterContent }, 0);
const before = readDocumentSections(input.slug)!;
const first = before.sections[1]; const second = before.sections[2];
const changed = first.content.replace("First body.", "Revised body.");
const edited = call(sections, { method: "POST", headers, query: chapterQuery, body: { revision: 1, operations: [
{ op: "update", id: first.id, content: changed, summary: "INTERNAL_SUMMARY_FIRST" },
{ op: "update", id: second.id, summary: "INTERNAL_SUMMARY_SECOND" },
] } });
assert.equal(edited.status, 200);
const after = readDocumentSections(input.slug)!;
assert.equal(after.revision, 2); assert.equal(after.sections[1].id, first.id);
assert.equal(after.sections[0].content, before.sections[0].content);
assert.equal(after.sections[2].content, before.sections[2].content);
assert.equal(after.sections[1].summary, "INTERNAL_SUMMARY_FIRST");
assert.equal(readDocument(input.slug)!.content, chapterContent.replace("First body.", "Revised body."));
assert.ok(!JSON.stringify(allDocuments()).includes("INTERNAL_SUMMARY"));
assert.ok(!JSON.stringify(call(item, { headers, query: chapterQuery }).body).includes("INTERNAL_SUMMARY"));
assert.ok(!JSON.stringify(call(documents, { headers }).body).includes("INTERNAL_SUMMARY"));
const history = readDocumentSections(input.slug, 1)!;
assert.equal(history.sections[1].content, first.content); assert.equal(history.sections[1].summary, "");
assert.equal(readDocumentSections(input.slug, 2)!.sections[1].summary, "INTERNAL_SUMMARY_FIRST");
}));
test("insert, move and delete chapters commit together with replay and conflict protection", () => isolated(({ headers }) => {
saveDocument({ ...input, content: chapterContent }, 0);
const before = readDocumentSections(input.slug)!;
const first = before.sections[1]; const second = before.sections[2];
const body = { revision: 1, operations: [
{ op: "move", id: second.id, after: "preamble" },
{ op: "delete", id: first.id },
{ op: "insert", after: second.id, content: "## New chapter\n\nNew body.\n", summary: "New material" },
] };
const options = { method: "POST", headers: { ...headers, "idempotency-key": "chapters-1" }, query: chapterQuery, body };
assert.equal(call(sections, options).status, 200);
const repeated = call(sections, options);
assert.equal(repeated.status, 200); assert.equal((repeated.body as SectionResponse).replayed, true);
const after = readDocumentSections(input.slug)!;
assert.deepEqual(after.sections.map((s) => s.title), ["导言", "Second", "New chapter"]);
assert.equal(after.sections[1].content, second.content);
assert.equal(after.revision, 2); assert.equal(documentHistory(input.sourceSlug).length, 2);
assert.equal(call(sections, { ...options, body: { ...body, revision: 2 } }).status, 409);
assert.equal(call(sections, { ...options, headers }).status, 409);
assert.equal(saveDocument({ ...readDocument(input.slug)!, description: "Changed metadata" }, 2).revision, 3);
assert.equal(readDocumentSections(input.slug)!.sections[2].summary, "New material");
}));
test("invalid late operation rolls back content, summary and history; read-only keys cannot edit", () => isolated(({ headers }) => {
saveDocument({ ...input, content: chapterContent }, 0);
const before = readDocumentSections(input.slug)!;
const invalid = [
[{ op: "update", id: before.sections[1].id, summary: "Should roll back" }, { op: "delete", id: "missing" }],
[{ op: "delete", id: "preamble" }],
[{ op: "move", id: before.sections[1].id, after: before.sections[1].id }],
[{ op: "update", id: before.sections[1].id, content: "## First\n\n## Extra\n" }],
[{ op: "update", id: before.sections[1].id, content: "## First\n![raw](/figures/raw.png)\n" }],
[{ op: "insert", after: "preamble", content: "## Missing summary\n" }],
[{ op: "delete", id: before.sections[1].id, unexpected: true }],
];
for (const operations of invalid) {
assert.equal(call(sections, { method: "POST", headers, query: chapterQuery, body: { revision: 1, operations } }).status, 400);
assert.deepEqual(readDocumentSections(input.slug), before);
assert.equal(documentHistory(input.sourceSlug).length, 1);
}
assert.equal(call(sections, { query: chapterQuery }).status, 401);
const reader = createDocumentKey("chapter reader", "read");
const readHeaders = { authorization: "Bearer " + reader.token };
assert.equal(call(sections, { headers: readHeaders, query: chapterQuery }).status, 200);
assert.equal(call(sections, { method: "POST", headers: readHeaders, query: chapterQuery, body: { revision: 1, operations: [] } }).status, 403);
}));
test("full-document saves invalidate changed chapter summaries and preserve unaffected summaries and ids", () => isolated(({ headers }) => {
saveDocument({ ...input, content: chapterContent }, 0);
const before = readDocumentSections(input.slug)!;
assert.equal(call(sections, { method: "POST", headers, query: chapterQuery, body: { revision: 1, operations:
before.sections.map((s) => ({ op: "update", id: s.id, summary: "Summary of " + s.title })) } }).status, 200);
saveDocument({ ...readDocument(input.slug)!, content: chapterContent.replace("First body.", "Changed externally.") }, 2);
const after = readDocumentSections(input.slug)!;
assert.equal(after.sections[1].id, before.sections[1].id);
assert.equal(after.sections[1].summary, "");
assert.equal(after.sections[2].summary, "Summary of Second");
assert.equal(readDocumentSections(input.slug, 2)!.sections[1].summary, "Summary of First");
}));
+8 -8
View File
@@ -23,8 +23,8 @@ test("research revisions share the authentication database and preserve replay l
for (let i = 0; i < 20; i++) consumeCode(config, "invalid"); for (let i = 0; i < 20; i++) consumeCode(config, "invalid");
assert.equal(consumeCode(config, "invalid"), "limited"); assert.equal(consumeCode(config, "invalid"), "limited");
const initial = readResearchSnapshot(); const initial = readResearchSnapshot();
assert.equal(initial.companies.length, 1031); assert.equal(initial.companies.length, 1029);
assert.equal(initial.evidence.length, 1424); assert.equal(initial.evidence.length, 1412);
assert.equal(initial.observations.length, 192); assert.equal(initial.observations.length, 192);
assert.deepEqual(initial.candidateBatches, seed.candidateBatches, "candidate gaps persist in the same database metadata"); assert.deepEqual(initial.candidateBatches, seed.candidateBatches, "candidate gaps persist in the same database metadata");
assert.deepEqual(initial.directoryRechecks, seed.directoryRechecks, "follow-up classifications persist without rewriting the discovery audit"); assert.deepEqual(initial.directoryRechecks, seed.directoryRechecks, "follow-up classifications persist without rewriting the discovery audit");
@@ -64,9 +64,9 @@ test("research validation rejects broken evidence and unsafe source links", () =
test("reviews link explicit companies without turning global or excluded cases into companies", () => { test("reviews link explicit companies without turning global or excluded cases into companies", () => {
const snapshot = structuredClone(seed) as ResearchSnapshot; const snapshot = structuredClone(seed) as ResearchSnapshot;
assert.equal(snapshot.reviews.filter((r) => r.scope === "companies").length, 76); assert.equal(snapshot.reviews.filter((r) => r.scope === "companies").length, 74);
assert.equal(snapshot.reviews.filter((r) => r.scope === "dataset").length, 10); assert.equal(snapshot.reviews.filter((r) => r.scope === "dataset").length, 10);
assert.equal(snapshot.reviews.filter((r) => r.scope === "excluded-candidate").length, 38); assert.equal(snapshot.reviews.filter((r) => r.scope === "excluded-candidate").length, 37);
const review = snapshot.reviews.find((r) => r.id === "R4")!; const review = snapshot.reviews.find((r) => r.id === "R4")!;
assert.deepEqual(reviewCompanyIds(snapshot, review), ["AI007", "AI013", "AI021", "AI034"]); assert.deepEqual(reviewCompanyIds(snapshot, review), ["AI007", "AI013", "AI021", "AI034"]);
assert.deepEqual(reviewCompanyIds(snapshot, snapshot.reviews.find((r) => r.id === "CN-R-PSI")!), []); assert.deepEqual(reviewCompanyIds(snapshot, snapshot.reviews.find((r) => r.id === "CN-R-PSI")!), []);
@@ -85,11 +85,11 @@ test("reviews link explicit companies without turning global or excluded cases i
test("disclosure counts exclude client income, biographies, targets and duplicate milestones", () => { test("disclosure counts exclude client income, biographies, targets and duplicate milestones", () => {
const snapshot = seed as ResearchSnapshot; const snapshot = seed as ResearchSnapshot;
const summary = categorySummary(snapshot); const summary = categorySummary(snapshot);
assert.equal(summary.reduce((n, c) => n + c.count, 0), 1031); assert.equal(summary.reduce((n, c) => n + c.count, 0), 1029);
assert.equal(summary.reduce((n, c) => n + c.self, 0), 28); assert.equal(summary.reduce((n, c) => n + c.self, 0), 28);
assert.equal(summary.reduce((n, c) => n + c.estimate, 0), 2); assert.equal(summary.reduce((n, c) => n + c.estimate, 0), 2);
assert.equal(summary.reduce((n, c) => n + c.platform, 0), 16); assert.equal(summary.reduce((n, c) => n + c.platform, 0), 16);
assert.equal(summary.reduce((n, c) => n + c.unknown, 0), 985); assert.equal(summary.reduce((n, c) => n + c.unknown, 0), 983);
assert.equal(snapshot.companies.find((c) => c.name === "Rork")?.revenueStatus, "unknown"); assert.equal(snapshot.companies.find((c) => c.name === "Rork")?.revenueStatus, "unknown");
assert.equal(snapshot.companies.find((c) => c.name === "Result")?.revenueStatus, "unknown"); assert.equal(snapshot.companies.find((c) => c.name === "Result")?.revenueStatus, "unknown");
assert.ok(snapshot.observations.filter((o) => o.selection === "signal").every((o) => o.scope === "公司整体")); assert.ok(snapshot.observations.filter((o) => o.selection === "signal").every((o) => o.scope === "公司整体"));
@@ -97,7 +97,7 @@ test("disclosure counts exclude client income, biographies, targets and duplicat
test("technical reviews keep accessible materials separate from tested capabilities", () => { test("technical reviews keep accessible materials separate from tested capabilities", () => {
const snapshot = structuredClone(seed) as ResearchSnapshot; const snapshot = structuredClone(seed) as ResearchSnapshot;
assert.equal(snapshot.companies.filter((c) => c.technicalReview).length, 30); assert.equal(snapshot.companies.filter((c) => c.technicalReview).length, 28);
assert.equal(snapshot.companies.filter((c) => c.technicalReview?.level === "public-artifact").length, 7); assert.equal(snapshot.companies.filter((c) => c.technicalReview?.level === "public-artifact").length, 7);
assert.equal(snapshot.companies.filter((c) => c.technicalReview?.level === "independent-test").length, 1); assert.equal(snapshot.companies.filter((c) => c.technicalReview?.level === "independent-test").length, 1);
assert.equal(snapshot.companies.find((c) => c.id === "AI051")?.revenueStatus, "unknown"); assert.equal(snapshot.companies.find((c) => c.id === "AI051")?.revenueStatus, "unknown");
@@ -307,7 +307,7 @@ test("unreconciled directory financials remain source reviews instead of income
assert.ok(review.evidenceIds.includes("PH-TANA-DR")); assert.ok(review.evidenceIds.includes("PH-TANA-DR"));
assert.equal(reviewCompanyIds(snapshot, review).length, 0); assert.equal(reviewCompanyIds(snapshot, review).length, 0);
assert.ok(!snapshot.observations.some((o) => o.evidence === "PH-TANA-DR")); assert.ok(!snapshot.observations.some((o) => o.evidence === "PH-TANA-DR"));
assert.equal(snapshot.candidateBatches!.flatMap((b) => b.records).filter((r) => r.status === "pending-year").length, 13); assert.equal(snapshot.candidateBatches!.flatMap((b) => b.records).filter((r) => r.status === "pending-year").length, 10);
}); });
test("product pivots and founder histories do not become new company years or current revenue", () => { test("product pivots and founder histories do not become new company years or current revenue", () => {
+1 -308
View File
@@ -1,5 +1,5 @@
{ {
"version": "2026-10-30-cn-sme-1", "version": "2026-10-30-tc-p56-1",
"asOf": "2026-10-30", "asOf": "2026-10-30",
"scope": "全球公开资料研究:保留首批个案,并扩展核查2025—2026八个YC批次候选池;成立年份以官方公司页面字段为依据。", "scope": "全球公开资料研究:保留首批个案,并扩展核查2025—2026八个YC批次候选池;成立年份以官方公司页面字段为依据。",
"limitations": [ "limitations": [
@@ -29279,82 +29279,6 @@
"AIMOGA-WRC" "AIMOGA-WRC"
] ]
} }
},
{
"id": "AI086",
"name": "企智芯",
"url": "https://vipqzx.com/",
"cat": "C05",
"year": 2025,
"team": null,
"location": "中国北京(公司官网自述)",
"business": "面向企业将AI文案、SCRM、人事、财务与项目工作流集成到管理软件。",
"buyer": "企业管理、运营及业务团队;具体付费客户未核",
"delivery": "公开模块说明和流程演示;本轮未登录或实际运行。",
"cohort": "官网自述2025年成立,精确注册未独立核验",
"teamBasis": "本轮未取得完整员工数,不以官网团队背景、案例或服务客户数字代替",
"price": "本轮未取得明确收费标准或签约价格",
"stage": "官网公开产品/服务,成立与能力为公司自述,未核实际履约及收入",
"sourceType": "公司官网定向检索及公开原始自述",
"revenueStatus": "unknown",
"evidenceIds": [
"QZX-ABOUT",
"QZX-HOME"
],
"notes": "采用和效率宣传缺少底表;流程演示中的合同、收款、利润与客户经营数据不作企智芯收入。",
"businessModel": "企业管理软件及AI功能;收费、部署与实施合同未核,不能先定为已实现订阅ARR",
"entityBasis": "官网关于页及页脚列企智芯(北京)科技有限公司;未独立核验注册代码及域名归属链。",
"classificationBasis": "按企业经营与通用工作流交付归C05;面向业务用户的落地服务不按技术术语归为模型基础设施。",
"technicalReview": {
"level": "description",
"reviewedAt": "2026-10-30",
"summary": "已读官网模块与AI功能自述;未核独立测试、实际客户验收或源代码。",
"evidenceIds": [
"QZX-ABOUT",
"QZX-HOME"
]
}
},
{
"id": "AI087",
"name": "九昇智能(NineRise Intelligence)",
"url": "https://www.9shengai.com/",
"cat": "C05",
"year": 2025,
"team": null,
"location": "中国杭州(官网自述南湖未来科学园)",
"business": "以诊断咨询、企业培训、智能体定制与持续陪跑帮助中小企业部署AI业务流程。",
"buyer": "中小企业经营团队,另承接政企与私有化场景;付费客户清单未核",
"delivery": "公开套餐、技术说明及案例;交付形式混合专业服务、工具建设和运营。",
"cohort": "官网自述2025年6月成立,精确注册未独立核验",
"teamBasis": "本轮未取得完整员工数,不以官网团队背景、案例或服务客户数字代替",
"price": "公开诊断/培训/定制/陪跑分档标价;例如年度顾问¥59800,币种未另确认,均不是收入",
"stage": "官网公开产品/服务,成立与能力为公司自述,未核实际履约及收入",
"sourceType": "公司官网定向检索及公开原始自述",
"revenueStatus": "unknown",
"evidenceIds": [
"NR-ABOUT",
"NR-SERVICES",
"NR-TECH",
"NR-CASES",
"NR-PARTNER"
],
"notes": "官网注明案例经营数据未经第三方审计;案例成果、包价及年度服务不作已确认ARR,未核收入数值。",
"businessModel": "咨询培训、定制实施与30/90天及年度陪跑服务;经常性软件许可、顾问与项目费须分开核",
"entityBasis": "官网列杭州九昇智能科技有限公司与英文品牌;原始登记代码、当前股权及法律沿革未核。",
"classificationBasis": "按企业经营与通用工作流交付归C05;面向业务用户的落地服务不按技术术语归为模型基础设施。",
"technicalReview": {
"level": "description",
"reviewedAt": "2026-10-30",
"summary": "已读RAG、模型适配、编排、评测等技术自述及官网案例;没有独立运行或评测记录。",
"evidenceIds": [
"NR-ABOUT",
"NR-SERVICES",
"NR-TECH",
"NR-CASES",
"NR-PARTNER"
]
}
} }
], ],
"observations": [ "observations": [
@@ -48001,138 +47925,6 @@
"kind": "媒体栏目发现入口", "kind": "媒体栏目发现入口",
"summary": "已读取栏目卡片入口,定向登记本批候选。", "summary": "已读取栏目卡片入口,定向登记本批候选。",
"limitation": "动态分页;只登记本批4项,不代表全部卡片、全部参赛者或两年档案已核。" "limitation": "动态分页;只登记本批4项,不代表全部卡片、全部参赛者或两年档案已核。"
},
{
"id": "QZX-ABOUT",
"companyId": "AI086",
"title": "企智芯官网成立与运营名称",
"url": "https://vipqzx.com/about.html",
"publishedAt": null,
"accessedAt": "2026-10-30",
"kind": "公司官方自述",
"summary": "官网列企智芯(北京)科技有限公司成立于2025年,定位企业数字化管理系统。",
"limitation": "未取得精确登记或独立主体核验;采用规模、效率与投入占比均未给可复算底表,不由此反推收入或团队人数。"
},
{
"id": "QZX-HOME",
"companyId": "AI086",
"title": "企智芯官网模块和流程展示",
"url": "https://vipqzx.com/",
"publishedAt": null,
"accessedAt": "2026-10-30",
"kind": "公司官方产品自述",
"summary": "展示获客、SCRM、人事、财务、工单、审批等模块及AI文案/汇报功能。",
"limitation": "仅读公开页面,未进入登录、执行交易或测试功能。流程中的50000元合同/收款及利润是演示路径,非公司自身收入;不能把产品功能当实际客户财务或合规认证。"
},
{
"id": "NR-ABOUT",
"companyId": "AI087",
"title": "九昇智能官网成立与主体",
"url": "https://www.9shengai.com/about/",
"publishedAt": null,
"accessedAt": "2026-10-30",
"kind": "公司官方自述",
"summary": "官网列杭州九昇智能科技有限公司、NineRise Intelligence及2025年6月成立,面向中小企业AI落地。",
"limitation": "原始登记未独立查询;创始背景、官网经营定位和总部自述不证明员工规模或财务业绩。"
},
{
"id": "NR-SERVICES",
"companyId": "AI087",
"title": "九昇智能产品服务与公开标价",
"url": "https://www.9shengai.com/services/index.html",
"publishedAt": null,
"accessedAt": "2026-10-30",
"kind": "公司官方定价资料",
"summary": "公开诊断、培训、智能体定制和陪跑方案;页面分别标价,企业/私有化定制标128000起。",
"limitation": "原文¥未另确认币种;标价不是成交、回款或已确认收入,实施、培训、订阅和持续顾问服务需拆分,不以价目表反推ARR。"
},
{
"id": "NR-TECH",
"companyId": "AI087",
"title": "九昇智能技术架构自述",
"url": "https://www.9shengai.com/technology/index.html",
"publishedAt": null,
"accessedAt": "2026-10-30",
"kind": "公司官方技术自述",
"summary": "公开RAG、模型适配、流程编排和权限/评测/日志等能力说明。",
"limitation": "本轮未运行智能体、查看源代码/模型权重或独立复现评测;术语和案例速度不转为技术强弱排名。"
},
{
"id": "NR-CASES",
"companyId": "AI087",
"title": "九昇智能案例及证据边界",
"url": "https://www.9shengai.com/cases/index.html",
"publishedAt": null,
"accessedAt": "2026-10-30",
"kind": "公司官方案例自述",
"summary": "页面列政府和企业场景,并注明经营数据未经第三方审计、效果受项目条件影响。",
"limitation": "案例主体多为匿名或行业描述,未取合同/验收/付款或客户独立确认;客户经营成效不是供应商公司收入,案例条数不作独立付费客户数。"
},
{
"id": "NR-PARTNER",
"companyId": "AI087",
"title": "九昇智能持续陪跑服务",
"url": "https://www.9shengai.com/services/partner/index.html",
"publishedAt": null,
"accessedAt": "2026-10-30",
"kind": "公司官方定价与交付自述",
"summary": "陪跑按30天、90天和年度顾问提供,年度顾问页面标¥59800,以项目推进和复盘为交付。",
"limitation": "期限一年不证明自动续订或软件ARR;未核实际订单、服务工时、续约及收入分摊,未把包价新增为收入观测。"
},
{
"id": "KR-HEMU",
"companyId": null,
"title": "合木智能:硬氪发现线索",
"url": "https://eu.36kr.com/zh/p/3963006194728324",
"publishedAt": "2026-09-02",
"accessedAt": "2026-10-30",
"kind": "中文媒体报道相关段落",
"summary": "报道列2026年5月成立,定位模具制造语义计算,提供陪跑服务和智能体软硬件。",
"limitation": "仅核相关成立与业务段落,未取得公司/孵化方原始成立资料;不把融资或创始人旧团队、论文和模型成绩当新公司收入或独立能力验证。"
},
{
"id": "KR-QUANTUM",
"companyId": null,
"title": "昆腾动力:硬氪发现线索",
"url": "https://www.36kr.com/p/3917874427555457",
"publishedAt": "2026-07-31",
"accessedAt": "2026-10-30",
"kind": "中文媒体报道相关段落",
"summary": "报道列2026年上半年成立,从物流仓储任务切入具身智能平台。",
"limitation": "仅核相关成立与业务段落,未取得公司/孵化方原始成立资料;不把融资或创始人旧团队、论文和模型成绩当新公司收入或独立能力验证。"
},
{
"id": "KR-WORLDMIND",
"companyId": null,
"title": "寰宇心生(WorldMind):硬氪发现线索",
"url": "https://www.36kr.com/p/3973553316081920",
"publishedAt": "2026-09-08",
"accessedAt": "2026-10-30",
"kind": "中文媒体报道相关段落",
"summary": "报道列2026年9月成立,描述具身智能与神经认知世界模型。",
"limitation": "仅核相关成立与业务段落,未取得公司/孵化方原始成立资料;不把融资或创始人旧团队、论文和模型成绩当新公司收入或独立能力验证。"
},
{
"id": "HEMU-REG-LEAD",
"companyId": null,
"title": "合木智能:第三方工商字段",
"url": "https://vc.pedaily.cn/company/902387.html",
"publishedAt": null,
"accessedAt": "2026-10-30",
"kind": "第三方公开企业目录",
"summary": "公开页列2026-05-18成立和91510100MAKDFXM749;概览与工商区字段完整度不同。",
"limitation": "本轮只取得检索返回相关内容,未独立核验登记原件或确认当前字段。两日相邻融资记录可能重复,不相加,不当收入。"
},
{
"id": "QUANTUM-REG-LEAD",
"companyId": null,
"title": "昆腾动力:第三方主体线索",
"url": "https://www.gasgoo.com/robot/data/6113-%E6%9D%AD%E5%B7%9E%E6%98%86%E8%85%BE%E5%8A%A8%E5%8A%9B%E6%99%BA%E8%83%BD%E6%9C%89%E9%99%90%E5%85%AC%E5%8F%B8/",
"publishedAt": null,
"accessedAt": "2026-10-30",
"kind": "第三方公开企业目录",
"summary": "公开检索列杭州昆腾动力智能有限公司、2026-03-17及91330110MAK9DCMB56。",
"limitation": "未直接核对注册原件或公司原始沿革;与quantum.com存储业务及同名新能源企业分开,不把投资或母体财务归新公司。"
} }
], ],
"reviews": [ "reviews": [
@@ -49948,54 +49740,6 @@
"DH-COMPANY" "DH-COMPANY"
], ],
"handling": "两项继续成立待核。客户交易示例、客户企业价值、融资、创始人旧业务和建设项目总价均不新增公司收入观测;Dream发布稿检索/直达差异留缺。" "handling": "两项继续成立待核。客户交易示例、客户企业价值、融资、创始人旧业务和建设项目总价均不新增公司收入观测;Dream发布稿检索/直达差异留缺。"
},
{
"id": "AI086-R-MODEL",
"type": "企业AI软件与专业服务收入边界核查",
"company": "企智芯",
"scope": "companies",
"companyIds": [
"AI086"
],
"summary": "企业管理软件及AI功能;收费、部署与实施合同未核,不能先定为已实现订阅ARR",
"evidenceIds": [
"QZX-ABOUT",
"QZX-HOME"
],
"handling": "采用和效率宣传缺少底表;流程演示中的合同、收款、利润与客户经营数据不作企智芯收入。 成立仅据公司官网自述,未独立注册核查;不新增收入观测,不把缺项当零收入。"
},
{
"id": "AI087-R-MODEL",
"type": "企业AI软件与专业服务收入边界核查",
"company": "九昇智能(NineRise Intelligence)",
"scope": "companies",
"companyIds": [
"AI087"
],
"summary": "咨询培训、定制实施与30/90天及年度陪跑服务;经常性软件许可、顾问与项目费须分开核",
"evidenceIds": [
"NR-ABOUT",
"NR-SERVICES",
"NR-TECH",
"NR-CASES",
"NR-PARTNER"
],
"handling": "官网注明案例经营数据未经第三方审计;案例成果、包价及年度服务不作已确认ARR,未核收入数值。 成立仅据公司官网自述,未独立注册核查;不新增收入观测,不把缺项当零收入。"
},
{
"id": "KR-R-PHYSICAL-PENDING",
"type": "中文行业AI候选原始成立缺项",
"company": "合木智能、昆腾动力、寰宇心生",
"scope": "excluded-candidate",
"summary": "三项媒体发现的主营初分类与成立线索已登记,原始主体核验仍缺。",
"evidenceIds": [
"KR-HEMU",
"HEMU-REG-LEAD",
"KR-QUANTUM",
"QUANTUM-REG-LEAD",
"KR-WORLDMIND"
],
"handling": "不把媒体/目录重复发布当多项独立确认;研究院早期积累、创始人履历、融资、客户产出和公司实际收入分别保留,不新增财务观测。"
} }
], ],
"coverage": { "coverage": {
@@ -51478,57 +51222,6 @@
"note": "检索公司主页有2025字段,但直达429、官网不可读,原始成立和创始人更早建筑业务主体边界未核;保留候选,不把媒体价格或旧业务转为新公司收入。" "note": "检索公司主页有2025字段,但直达429、官网不可读,原始成立和创始人更早建筑业务主体边界未核;保留候选,不把媒体价格或旧业务转为新公司收入。"
} }
] ]
},
{
"id": "KR-2026-targeted-2",
"sourceId": "S11",
"url": "https://www.36kr.com/p/3973553316081920",
"accessedAt": "2026-10-30",
"scope": "三项硬氪报道相关段落定向补查,媒体及目录有2026线索但原始成立/主体仍待核,不新增主公司表。不是全部文章、榜单或两年档案。",
"complete": false,
"records": [
{
"id": "KR26B-01",
"name": "合木智能",
"url": "https://eu.36kr.com/zh/p/3963006194728324",
"categoryId": "C07",
"kind": "company",
"profileStatus": "readable",
"status": "pending-year",
"evidenceIds": [
"KR-HEMU",
"HEMU-REG-LEAD"
],
"note": "报道和第三方目录有2026年5月线索,仍缺公司/孵化方原始成立与旧研究项目主体边界;模具服务、硬件和软件须拆分,融资不当收入。"
},
{
"id": "KR26B-02",
"name": "昆腾动力(Quantum Dynamics)",
"url": "https://www.36kr.com/p/3917874427555457",
"categoryId": "C10",
"kind": "company",
"profileStatus": "readable",
"status": "pending-year",
"evidenceIds": [
"KR-QUANTUM",
"QUANTUM-REG-LEAD"
],
"note": "报道与第三方目录有2026年线索,未取得公司或投资人原始成立资料;不与同名存储/新能源企业合并,旧任职团队及交易业务不继承。"
},
{
"id": "KR26B-03",
"name": "寰宇心生(WorldMind)",
"url": "https://www.36kr.com/p/3973553316081920",
"categoryId": "C10",
"kind": "company",
"profileStatus": "readable",
"status": "pending-year",
"evidenceIds": [
"KR-WORLDMIND"
],
"note": "报道列2026年9月,原始登记和公司官网未取得;创始人论文、实验室成果、模型竞赛及融资须分别归属。"
}
]
} }
], ],
"directoryRechecks": [ "directoryRechecks": [
+4 -4
View File
@@ -1,5 +1,5 @@
{ {
"version": "2026-10-30-30", "version": "2026-10-30-29",
"scopeConfirmedAt": "2026-10-30", "scopeConfirmedAt": "2026-10-30",
"acceptance": "以确认的公开来源清单为边界,逐条核对并标明缺项。", "acceptance": "以确认的公开来源清单为边界,逐条核对并标明缺项。",
"provenance": "S01—S12恢复自已提交用户的《AI公司研究_来源与分类模板》来源清单;S13—S16单列后续已使用的补充证据渠道,不将使用次数当作全量覆盖。", "provenance": "S01—S12恢复自已提交用户的《AI公司研究_来源与分类模板》来源清单;S13—S16单列后续已使用的补充证据渠道,不将使用次数当作全量覆盖。",
@@ -221,8 +221,8 @@
"eu.36kr.com" "eu.36kr.com"
], ],
"initialAccess": "安全检测,内容未核验", "initialAccess": "安全检测,内容未核验",
"boundary": "此前首页安全检测仍保留;本轮4项定向检索及相关段落补查,3项据政府/公司/交易当事方资料关联、1项按原始登记归范围外。清析检索与直达正文不一致未确认关联,其他文章为平台发布/授权转载,不代表两年全量。 另登记合木、昆腾动力、寰宇心生3项报道相关段落,原始成立/主体留缺,未新增主公司表;不是全量。", "boundary": "此前首页安全检测仍保留;本轮4项定向检索及相关段落补查,3项据政府/公司/交易当事方资料关联、1项按原始登记归范围外。清析检索与直达正文不一致未确认关联,其他文章为平台发布/授权转载,不代表两年全量。",
"nextCheck": "墨甲已由交易当事方原始公告补足2025成立及历史期间收入,母公司项目沿革和当前财务仍待核;继续补清析发现文章关联及未读正文,建两年公开文章台账,不绕过访问保护。 补本组三项公司/孵化/投资原始资料,避免融资与研究院、母体业绩归属混淆。", "nextCheck": "墨甲已由交易当事方原始公告补足2025成立及历史期间收入,母公司项目沿革和当前财务仍待核;继续补清析发现文章关联及未读正文,建两年公开文章台账,不绕过访问保护。",
"limitation": "仅核具体相关段落,检索和直达差异、转载与原始披露分别记录。", "limitation": "仅核具体相关段落,检索和直达差异、转载与原始披露分别记录。",
"accessRecheckedAt": "2026-10-30" "accessRecheckedAt": "2026-10-30"
}, },
@@ -234,7 +234,7 @@
"status": "per-company", "status": "per-company",
"hosts": [], "hosts": [],
"initialAccess": "按公司逐一核验", "initialAccess": "按公司逐一核验",
"boundary": "公司官网和官方材料逐条绑定证据;不是可预先列尽的全站候选池。 定向新增企智芯与九昇智能的2025成立自述及交付资料,精确注册、实际客户与收入未核;两个官网不代表中文公司全集。", "boundary": "公司官网和官方材料逐条绑定证据;不是可预先列尽的全站候选池。",
"nextCheck": "核定价、主体、交付与收入定义,自述与独立验证分开。", "nextCheck": "核定价、主体、交付与收入定义,自述与独立验证分开。",
"limitation": "自述不等于独立审计" "limitation": "自述不等于独立审计"
}, },
+1 -1
View File
@@ -1,5 +1,5 @@
{ {
"sourceVersion": "2026-10-30-cn-sme-1", "sourceVersion": "2026-10-30-tc-p56-1",
"asOf": "2026-10-30", "asOf": "2026-10-30",
"metric": "platform-mrr-usd", "metric": "platform-mrr-usd",
"sampleUnit": "product-or-business", "sampleUnit": "product-or-business",
+29
View File
@@ -116,6 +116,17 @@ def main():
mode.add_argument('--revision', type=int) mode.add_argument('--revision', type=int)
reading.add_argument('--limit', type=int, default=50) reading.add_argument('--limit', type=int, default=50)
reading.add_argument('--offset', type=int, default=0) reading.add_argument('--offset', type=int, default=0)
sections = sub.add_parser('outline', help='Read chapter titles and internal summaries without bodies')
sections.add_argument('slug')
sections.add_argument('--revision', type=int)
section = sub.add_parser('sections', help='Read selected chapter bodies')
section.add_argument('slug')
section.add_argument('ids', nargs='+')
section.add_argument('--revision', type=int)
editing = sub.add_parser('edit-sections', help='Atomically apply chapter operations from private JSON')
editing.add_argument('slug')
editing.add_argument('file')
editing.add_argument('--request-id')
saving = sub.add_parser('save') saving = sub.add_parser('save')
saving.add_argument('file', help='Private JSON file or - for stdin; one document or {documents: [...]}') saving.add_argument('file', help='Private JSON file or - for stdin; one document or {documents: [...]}')
saving.add_argument('--request-id', help='Reuse this id only with the same input when retrying') saving.add_argument('--request-id', help='Reuse this id only with the same input when retrying')
@@ -135,6 +146,24 @@ def main():
elif args.revision is not None: elif args.revision is not None:
path += '?' + urllib.parse.urlencode({'revision': args.revision}) path += '?' + urllib.parse.urlencode({'revision': args.revision})
result = request(base, token, 'GET', path) result = request(base, token, 'GET', path)
elif args.command in ('outline', 'sections', 'edit-sections'):
path = '/api/documents/sections/' + urllib.parse.quote(args.slug, safe='/')
if args.command == 'edit-sections':
payload = json.load(sys.stdin) if args.file == '-' else json.loads(Path(args.file).read_text())
request_id = args.request_id or str(uuid.uuid4())
if not request_id or len(request_id) > 100 or any(c not in 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789._:-' for c in request_id):
raise ValueError('Invalid request id')
print('Request id: ' + request_id, file=sys.stderr)
result = request(base, token, 'POST', path, payload, request_id)
else:
query = []
if args.revision is not None:
query.append(('revision', args.revision))
if args.command == 'sections':
query.extend(('section', section_id) for section_id in args.ids)
if query:
path += '?' + urllib.parse.urlencode(query)
result = request(base, token, 'GET', path)
else: else:
payload = json.load(sys.stdin) if args.file == '-' else json.loads(Path(args.file).read_text()) payload = json.load(sys.stdin) if args.file == '-' else json.loads(Path(args.file).read_text())
request_id = args.request_id or str(uuid.uuid4()) request_id = args.request_id or str(uuid.uuid4())
+25
View File
@@ -4,6 +4,7 @@ import io
import json import json
from pathlib import Path from pathlib import Path
import tempfile import tempfile
import sys
import unittest import unittest
from unittest.mock import patch from unittest.mock import patch
import urllib.error import urllib.error
@@ -15,6 +16,30 @@ spec.loader.exec_module(client)
class ClientTests(unittest.TestCase): class ClientTests(unittest.TestCase):
def test_section_reads_select_bodies_and_revision_without_full_document_fetch(self):
argv = ['client', '--url', 'https://docs.example', '--key-file', '/private/key',
'sections', 'endor/example', 'preamble', 's_one', '--revision', '3']
with patch.object(sys, 'argv', argv), patch.object(client, 'read_token', return_value='test-token'), \
patch.object(client, 'request', return_value={'revision': 3, 'sections': []}) as request, \
patch.object(sys, 'stdout', io.StringIO()):
client.main()
request.assert_called_once_with('https://docs.example', 'test-token', 'GET',
'/api/documents/sections/endor/example?revision=3&section=preamble&section=s_one')
def test_section_edit_keeps_payload_and_retry_id(self):
payload = {'revision': 3, 'operations': [{'op': 'update', 'id': 's_one', 'summary': 'Internal summary'}]}
with tempfile.TemporaryDirectory() as directory:
path = Path(directory) / 'edit.json'
path.write_text(json.dumps(payload))
argv = ['client', '--url', 'https://docs.example', '--key-file', '/private/key',
'edit-sections', 'endor/example', str(path), '--request-id', 'edit-1']
with patch.object(sys, 'argv', argv), patch.object(client, 'read_token', return_value='test-token'), \
patch.object(client, 'request', return_value={'revision': 4}) as request, \
patch.object(sys, 'stdout', io.StringIO()), patch.object(sys, 'stderr', io.StringIO()):
client.main()
request.assert_called_once_with('https://docs.example', 'test-token', 'POST',
'/api/documents/sections/endor/example', payload, 'edit-1')
def test_only_tls_or_loopback_origins_are_accepted(self): def test_only_tls_or_loopback_origins_are_accepted(self):
self.assertEqual(client.server_url('https://docs.example/'), 'https://docs.example') self.assertEqual(client.server_url('https://docs.example/'), 'https://docs.example')
self.assertEqual(client.server_url('http://127.0.0.1:18135'), 'http://127.0.0.1:18135') self.assertEqual(client.server_url('http://127.0.0.1:18135'), 'http://127.0.0.1:18135')