feat: 建立人格並補齊資料後產生圖示(SVG + PNG,零外部依賴)
`icon generate|show`:由**編號、Name、Emoji** 雜湊出配色與圖案,產出 512×512 的幾何徽章 icon.svg + icon.png,設為 Gitea 存取庫頭像並同步到 Wiki 區。 圖案(SVG 與 PNG 共用同一組單位座標與同一份 5×7 點陣字,**輸出的是同一張圖**): * 雙色對角漸層底 * 5×5 左右對稱點陣紋(identicon 式) * 中央兩個字母=編號前兩字(ASUNA-01 → AS),依背景亮度自動選黑/白 同一個人格永遠得到同一張圖(純函數,無隨機);ASUNA-01 與 ASUNA-02 明顯不同。 為什麼自己畫:這台機器(及多數伺服器)沒有 rsvg/inkscape/imagemagick, 沒有影像函式庫,也沒有 emoji 字型,而本專案禁止 npm 依賴。所以 scripts/persona-icon.mjs 自己柵格化(3× 超取樣 + 盒式縮減當反鋸齒), 再用內建 zlib 手工組出 IHDR/IDAT/IEND 與 CRC32。 emoji 無法柵格化,因此不作為圖形,但仍參與配色雜湊。 時機:**資料補齊之後才產生**——配色與字母綁在最終身分上,太早跑會對不上。 persona-create 第 7 步、persona-anime 第 8 步都補了這個步驟;改過身分用 --force 重畫。 selftest 128 項全綠(新增第 ⑭ 節:PNG chunk 合法性、決定性、不同人格不同圖、 圖示屬 Wiki 區、匯出用 base64 帶走二進位、guest 不得重畫)。 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -91,6 +91,8 @@ export const AREAS = {
|
||||
"SOUL.md",
|
||||
"AGENTS.md",
|
||||
"USER.md",
|
||||
"icon.svg",
|
||||
"icon.png",
|
||||
"memory/INDEX.md",
|
||||
"memory/long-term/",
|
||||
"mindmap/semantic.mmd",
|
||||
@@ -205,6 +207,14 @@ export async function ensureWikiHome(owner, code, content) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** 把人格圖示設成存取庫頭像(Gitea 各處的清單就會顯示這個人格的臉)。 */
|
||||
export async function setRepoAvatar(owner, code, pngBuffer) {
|
||||
const res = await api("POST", `/repos/${owner}/${encodeURIComponent(code)}/avatar`, {
|
||||
image: Buffer.from(pngBuffer).toString("base64"),
|
||||
});
|
||||
return res.ok;
|
||||
}
|
||||
|
||||
export const repoUrl = (host, owner, code, area) =>
|
||||
`${host}/${owner}/${encodeURIComponent(code)}${area === "wiki" ? ".wiki" : ""}.git`;
|
||||
|
||||
@@ -384,9 +394,11 @@ export function wikiHome(slug, code) {
|
||||
const ident = pl.identityFields(slug);
|
||||
const longTerm = pl.longTermEntries(slug);
|
||||
const relations = pl.loadRelations(slug);
|
||||
const hasIcon = fs.existsSync(path.join(pl.personaDir(slug), "icon.svg"));
|
||||
const lines = [
|
||||
`# ${ident.Emoji ? `${ident.Emoji} ` : ""}${ident.Name || slug} \`${code}\``,
|
||||
"",
|
||||
...(hasIcon ? [`<img src="icon.svg" alt="${code}" width="128" height="128">`, ""] : []),
|
||||
"> 由 jsc-persona 自動產生的人格設定百科。**低頻資料**(身分、長期記憶、心智圖、關係圖)放這裡;",
|
||||
"> 每輪都在變的活狀態(情緒、短期記憶、心裡話、逐字稿)在存取庫的檔案區。",
|
||||
"",
|
||||
|
||||
Reference in New Issue
Block a user