dsh-chief 1.4.0 → 1.5.0
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/CHANGELOG.md +42 -0
- package/README.en.md +66 -50
- package/README.md +67 -50
- package/api-routes.js +165 -3
- package/archive-core.js +136 -8
- package/archive-dossiers.js +450 -20
- package/archive-precipitated.js +115 -36
- package/auto-continue.js +13 -5
- package/board-actions.js +59 -4
- package/board-schema.js +1 -1
- package/chief-approvals.js +176 -11
- package/chief-archives.js +157 -30
- package/chief-commands.js +565 -101
- package/chief-models.js +158 -28
- package/chief-review.js +211 -70
- package/chief-state.js +362 -32
- package/chief-view.js +17 -14
- package/client.js +3744 -2207
- package/digest.js +18 -9
- package/model-tools.js +15 -5
- package/package.json +9 -4
- package/runtime-hooks.js +115 -12
- package/subagent-runtime.js +257 -1
package/archive-core.js
CHANGED
|
@@ -18,6 +18,10 @@ export const POINTS_CAP = 32
|
|
|
18
18
|
|
|
19
19
|
export const PRECIPITATED_CAP = 300
|
|
20
20
|
|
|
21
|
+
export const DESKTOP_TOKEN_BUDGET = 2400
|
|
22
|
+
|
|
23
|
+
export const DESKTOP_MAX_ITEMS = 6
|
|
24
|
+
|
|
21
25
|
export const SECRET_PATTERN = /(?:sk-[a-zA-Z0-9_-]{16,}|ghp_[a-zA-Z0-9]{20,}|AKIA[0-9A-Z]{16}|AIza[0-9A-Za-z_-]{30,}|Bearer\s+[A-Za-z0-9._~+/=-]{20,}|-----BEGIN [A-Z ]*PRIVATE KEY-----)/
|
|
22
26
|
|
|
23
27
|
export const DEFAULT_ARCHIVE_FOLDERS = [
|
|
@@ -612,6 +616,86 @@ export function normalizeTags(list) {
|
|
|
612
616
|
return out
|
|
613
617
|
}
|
|
614
618
|
|
|
619
|
+
export function normalizeSessionIdList(list, cap = 32) {
|
|
620
|
+
if (!Array.isArray(list)) return []
|
|
621
|
+
return [...new Set(list.map(s => String(s || '').trim()).filter(Boolean))].slice(0, cap)
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
export function normalizeDesktopMeta(raw) {
|
|
625
|
+
const out = {}
|
|
626
|
+
if (!raw || typeof raw !== 'object') return out
|
|
627
|
+
for (const [k, v] of Object.entries(raw)) {
|
|
628
|
+
const sid = String(k || '').trim()
|
|
629
|
+
if (!sid || !v || typeof v !== 'object') continue
|
|
630
|
+
out[sid] = {
|
|
631
|
+
pinnedAt: Number(v.pinnedAt) || Date.now(),
|
|
632
|
+
by: clamp(v.by || 'user', 30),
|
|
633
|
+
priority: Number.isFinite(Number(v.priority)) ? Number(v.priority) : 0,
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
return out
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
export function estimateArchiveTokens(item) {
|
|
640
|
+
if (!item || typeof item !== 'object') return 40
|
|
641
|
+
const pts = (Array.isArray(item.points) ? item.points : []).slice(0, 3)
|
|
642
|
+
const ptText = pts.map(p => `${p.title || ''} ${p.cue || p.detail || ''}`).join(' ')
|
|
643
|
+
const combined = `${item.title || ''}\n${item.summary || ''}\n${ptText || (item.body || '').slice(0, 480)}`
|
|
644
|
+
let cjkCount = 0
|
|
645
|
+
let asciiCount = 0
|
|
646
|
+
for (let i = 0; i < combined.length; i += 1) {
|
|
647
|
+
if (combined.charCodeAt(i) > 127) cjkCount += 1
|
|
648
|
+
else asciiCount += 1
|
|
649
|
+
}
|
|
650
|
+
const est = Math.ceil(cjkCount * 0.85 + asciiCount * 0.28) + 18
|
|
651
|
+
return Math.max(40, est)
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
export function deriveHookFromStructuredItem(raw, forceOrganized = false) {
|
|
655
|
+
const src = raw && typeof raw === 'object' ? raw : {}
|
|
656
|
+
const isOrganized = Boolean(forceOrganized || src.organizedBy === 'chief' || src.hasHook === true)
|
|
657
|
+
if (!isOrganized) {
|
|
658
|
+
return { hasHook: false, hookKeywords: [], hookCue: '' }
|
|
659
|
+
}
|
|
660
|
+
const candidates = []
|
|
661
|
+
if (Array.isArray(src.hookKeywords)) candidates.push(...src.hookKeywords)
|
|
662
|
+
if (Array.isArray(src.tags)) candidates.push(...src.tags)
|
|
663
|
+
if (Array.isArray(src.points)) {
|
|
664
|
+
for (const pt of src.points.slice(0, 4)) {
|
|
665
|
+
if (pt && pt.title) candidates.push(String(pt.title).split(/[::·—]/)[0])
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
if (!candidates.length && src.title) {
|
|
669
|
+
const words = String(src.title).split(/[\s/·::()()]+/).filter(w => w.length >= 2)
|
|
670
|
+
candidates.push(...words.slice(0, 3))
|
|
671
|
+
}
|
|
672
|
+
const seen = new Set()
|
|
673
|
+
const hookKeywords = []
|
|
674
|
+
for (const cand of candidates) {
|
|
675
|
+
const kw = clamp(String(cand || '').replace(/^#+/, '').trim(), 16)
|
|
676
|
+
if (!kw || kw === 'anchor') continue
|
|
677
|
+
const low = kw.toLowerCase()
|
|
678
|
+
if (seen.has(low)) continue
|
|
679
|
+
seen.add(low)
|
|
680
|
+
hookKeywords.push(kw)
|
|
681
|
+
if (hookKeywords.length >= 5) break
|
|
682
|
+
}
|
|
683
|
+
if (!hookKeywords.length && src.folder) {
|
|
684
|
+
hookKeywords.push(clamp(src.folder, 16))
|
|
685
|
+
}
|
|
686
|
+
const rawCue = str(src.hookCue, '').trim()
|
|
687
|
+
|| (Array.isArray(src.points) && src.points[0] && (src.points[0].cue || src.points[0].title))
|
|
688
|
+
|| src.summary
|
|
689
|
+
|| firstMeaningfulSentence(src.body || '')
|
|
690
|
+
|| src.title
|
|
691
|
+
const hookCue = clamp(rawCue, 40)
|
|
692
|
+
return {
|
|
693
|
+
hasHook: true,
|
|
694
|
+
hookKeywords,
|
|
695
|
+
hookCue,
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
|
|
615
699
|
export function normalizeArchiveItem(raw) {
|
|
616
700
|
if (!raw || typeof raw !== 'object') return null
|
|
617
701
|
const body = cleanMultiline(raw.body || '', 30000)
|
|
@@ -639,12 +723,23 @@ export function normalizeArchiveItem(raw) {
|
|
|
639
723
|
140,
|
|
640
724
|
)
|
|
641
725
|
|
|
642
|
-
const takenOutSessions =
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
const
|
|
646
|
-
|
|
647
|
-
|
|
726
|
+
const takenOutSessions = normalizeSessionIdList(raw.takenOutSessions)
|
|
727
|
+
const chiefMountedSessions = normalizeSessionIdList(raw.chiefMountedSessions)
|
|
728
|
+
const leadPulledSessions = normalizeSessionIdList(raw.leadPulledSessions)
|
|
729
|
+
const chiefPulledSessions = normalizeSessionIdList(raw.chiefPulledSessions)
|
|
730
|
+
const chiefDeliveredSessions = normalizeSessionIdList(raw.chiefDeliveredSessions)
|
|
731
|
+
const organizedBy = ['auto', 'chief', 'user'].includes(raw.organizedBy) ? raw.organizedBy : 'auto'
|
|
732
|
+
const tags = normalizeTags(Array.isArray(raw.tags) ? raw.tags : [])
|
|
733
|
+
const hook = deriveHookFromStructuredItem({
|
|
734
|
+
...raw,
|
|
735
|
+
title,
|
|
736
|
+
summary,
|
|
737
|
+
folder,
|
|
738
|
+
tags,
|
|
739
|
+
points,
|
|
740
|
+
body,
|
|
741
|
+
organizedBy,
|
|
742
|
+
}, organizedBy === 'chief' || raw.hasHook === true)
|
|
648
743
|
const contentHash = str(raw.contentHash, '').trim() || computeEntryContentHash({ title, summary, body })
|
|
649
744
|
|
|
650
745
|
return {
|
|
@@ -656,11 +751,18 @@ export function normalizeArchiveItem(raw) {
|
|
|
656
751
|
summary,
|
|
657
752
|
folder,
|
|
658
753
|
paperclip,
|
|
659
|
-
tags
|
|
754
|
+
tags,
|
|
660
755
|
cold: raw.cold !== false,
|
|
661
756
|
takenOutSessions,
|
|
662
757
|
chiefMountedSessions,
|
|
663
|
-
|
|
758
|
+
leadPulledSessions,
|
|
759
|
+
chiefPulledSessions,
|
|
760
|
+
chiefDeliveredSessions,
|
|
761
|
+
desktopMeta: normalizeDesktopMeta(raw.desktopMeta),
|
|
762
|
+
hasHook: hook.hasHook,
|
|
763
|
+
hookKeywords: hook.hookKeywords,
|
|
764
|
+
hookCue: hook.hookCue,
|
|
765
|
+
organizedBy,
|
|
664
766
|
points,
|
|
665
767
|
body,
|
|
666
768
|
contentHash,
|
|
@@ -686,6 +788,31 @@ export function normalizeGlobalVaultEntry(raw) {
|
|
|
686
788
|
}
|
|
687
789
|
}
|
|
688
790
|
|
|
791
|
+
function normalizeRecentlyUnpinnedWatch(raw) {
|
|
792
|
+
if (!Array.isArray(raw)) return []
|
|
793
|
+
const out = []
|
|
794
|
+
const seen = new Set()
|
|
795
|
+
for (const item of raw) {
|
|
796
|
+
if (!item || typeof item !== 'object') continue
|
|
797
|
+
const id = str(item.id, '').trim()
|
|
798
|
+
const vaultScope = item.vaultScope === 'global' ? 'global' : 'session'
|
|
799
|
+
if (!id) continue
|
|
800
|
+
const key = `${vaultScope}:${id}`
|
|
801
|
+
if (seen.has(key)) continue
|
|
802
|
+
seen.add(key)
|
|
803
|
+
out.push({
|
|
804
|
+
id,
|
|
805
|
+
vaultScope,
|
|
806
|
+
title: clamp(item.title || '未命名卷宗', 120),
|
|
807
|
+
folder: str(item.folder, 'inbox').trim() || 'inbox',
|
|
808
|
+
unpinnedAt: Number(item.unpinnedAt) || Date.now(),
|
|
809
|
+
by: clamp(item.by || 'user', 30),
|
|
810
|
+
})
|
|
811
|
+
if (out.length >= 12) break
|
|
812
|
+
}
|
|
813
|
+
return out
|
|
814
|
+
}
|
|
815
|
+
|
|
689
816
|
export function normalizeArchiveStore(raw) {
|
|
690
817
|
const src = raw && typeof raw === 'object' ? raw : {}
|
|
691
818
|
const folderMap = new Map()
|
|
@@ -733,6 +860,7 @@ export function normalizeArchiveStore(raw) {
|
|
|
733
860
|
updatedAt: Number(src.updatedAt) || Date.now(),
|
|
734
861
|
folders,
|
|
735
862
|
items,
|
|
863
|
+
recentlyUnpinnedWatch: src.isSystemGlobalVault ? [] : normalizeRecentlyUnpinnedWatch(src.recentlyUnpinnedWatch),
|
|
736
864
|
}
|
|
737
865
|
}
|
|
738
866
|
|