dsh-engramory 1.0.1 → 1.0.3
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/README.en.md +221 -213
- package/README.md +135 -135
- package/index.js +241 -51
- package/package.json +79 -79
package/index.js
CHANGED
|
@@ -28,7 +28,7 @@ import {
|
|
|
28
28
|
realpathSync, statSync,
|
|
29
29
|
} from 'node:fs'
|
|
30
30
|
import * as fsp from 'node:fs/promises'
|
|
31
|
-
import { homedir } from 'node:os'
|
|
31
|
+
import { homedir, hostname, networkInterfaces } from 'node:os'
|
|
32
32
|
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path'
|
|
33
33
|
import { isDeepStrictEqual, promisify } from 'node:util'
|
|
34
34
|
|
|
@@ -214,7 +214,8 @@ export function apply(ctx, config = {}) {
|
|
|
214
214
|
if (typeof dispose === 'function') dispose()
|
|
215
215
|
dispose = inner.skills.register({
|
|
216
216
|
name: 'engramory',
|
|
217
|
-
description
|
|
217
|
+
// the description names the index the user configured, not always MEMORY.md
|
|
218
|
+
description: settings.text.description.replace('MEMORY.md', () => storesOf(settings).indexName) +
|
|
218
219
|
(settings.companion ? settings.text.descriptionCompanion : ''),
|
|
219
220
|
whenToUse: settings.text.whenToUse +
|
|
220
221
|
(settings.companion ? settings.text.whenToUseCompanion : ''),
|
|
@@ -1042,7 +1043,9 @@ const INERT_PRODUCERS = new Set([
|
|
|
1042
1043
|
* web's API, `dsh headless`, an editor or terminal client, a bridge writing that
|
|
1043
1044
|
* kind), any kind dsh's own producers do not use (`plugin:<name>`, as chat
|
|
1044
1045
|
* bridges write, or any other), `speaker: { role: 'guest' }`, and a source that
|
|
1045
|
-
* cannot be read
|
|
1046
|
+
* cannot be read. Anyone in a group, the owner included: a `speaker` whose
|
|
1047
|
+
* `chat` is set to anything but 'private' ('group' is the standard) — the whole
|
|
1048
|
+
* group reads the reply, even before anyone else there has spoken;
|
|
1046
1049
|
* undefined nobody: dsh's own producers (INERT_PRODUCERS) and a plugin's own message
|
|
1047
1050
|
* declared `speaker: { role: 'none' }` — a report or a reminder no outsider
|
|
1048
1051
|
* wrote. These decide nothing. (SPEAKERS also lets through two bare `user`
|
|
@@ -1050,10 +1053,11 @@ const INERT_PRODUCERS = new Set([
|
|
|
1050
1053
|
*/
|
|
1051
1054
|
function speakerOf(source) {
|
|
1052
1055
|
if (source === null || typeof source !== 'object') return 'other'
|
|
1053
|
-
const speaker = source.speaker !== null && typeof source.speaker === 'object' ? source.speaker
|
|
1054
|
-
if (speaker === '
|
|
1055
|
-
if (speaker
|
|
1056
|
-
if (speaker === '
|
|
1056
|
+
const speaker = source.speaker !== null && typeof source.speaker === 'object' ? source.speaker : undefined
|
|
1057
|
+
if (speaker?.role === 'none') return undefined
|
|
1058
|
+
if (speaker?.chat !== undefined && speaker.chat !== 'private') return 'other'
|
|
1059
|
+
if (speaker?.role === 'owner') return 'owner'
|
|
1060
|
+
if (speaker?.role === 'guest') return 'other'
|
|
1057
1061
|
const kind = source.kind
|
|
1058
1062
|
if (kind === 'user') {
|
|
1059
1063
|
return typeof source.rpcId === 'string' && typeof source.clientTimeZone === 'string' &&
|
|
@@ -1136,8 +1140,9 @@ function commandsAfter(state, event) {
|
|
|
1136
1140
|
const SPEAKERS = {
|
|
1137
1141
|
key: SPEAKERS_KEY,
|
|
1138
1142
|
// Bumped whenever the state's fields or the fold change, so dsh refolds a session from its
|
|
1139
|
-
// log rather than seed it from a checkpoint the fold no longer means (2: pre-release shapes
|
|
1140
|
-
|
|
1143
|
+
// log rather than seed it from a checkpoint the fold no longer means (2: pre-release shapes;
|
|
1144
|
+
// 3: a message in a group chat is someone else's, the owner's included).
|
|
1145
|
+
stateVersion: 3,
|
|
1141
1146
|
// dsh only calls `parse`, on a checkpoint before folding on from it; no zod needed.
|
|
1142
1147
|
stateSchema: {
|
|
1143
1148
|
parse(value) {
|
|
@@ -1355,6 +1360,14 @@ function osKey(p) {
|
|
|
1355
1360
|
function storeTargets(cwd, settings) {
|
|
1356
1361
|
const start = checkedRoot(cwd ?? process.cwd())
|
|
1357
1362
|
const dirs = [checkedRoot(join(dshHome(), STORE_DIR))]
|
|
1363
|
+
if (settings.indexPath === undefined) {
|
|
1364
|
+
// The global index may itself be a link, and recall reads through it: the directory
|
|
1365
|
+
// it points to holds the user's index under a name no store has.
|
|
1366
|
+
const index = join(dirs[0], settings.indexName)
|
|
1367
|
+
dirs.push(dirname(realpathOr(index)))
|
|
1368
|
+
const pointed = linkTarget(index)
|
|
1369
|
+
if (pointed !== undefined) dirs.push(dirname(pointed))
|
|
1370
|
+
}
|
|
1358
1371
|
for (let dir = start; ; dir = dirname(dir)) {
|
|
1359
1372
|
const store = join(dir, STORE_DIR)
|
|
1360
1373
|
if (present(store)) dirs.push(store)
|
|
@@ -1437,9 +1450,16 @@ function indexRecall(settings, sessionCwd) {
|
|
|
1437
1450
|
return (context) => {
|
|
1438
1451
|
const cwd = sessionCwd(context) ?? process.cwd()
|
|
1439
1452
|
const { labels } = settings.text
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1453
|
+
// A session directory on another machine is not looked into (remotePath), as the
|
|
1454
|
+
// memory page does not: neither its project store nor a pin that lands under it. A
|
|
1455
|
+
// store the user placed there by name — an absolute pin, $DSH_HOME — still is.
|
|
1456
|
+
const remote = remotePath(cwd)
|
|
1457
|
+
const pinned = settings.indexPath === undefined ? undefined : hostPath(cwd, settings.indexPath)
|
|
1458
|
+
const candidates = pinned !== undefined
|
|
1459
|
+
? (remote && !qualified(settings.indexPath) && remotePath(pinned)
|
|
1460
|
+
? []
|
|
1461
|
+
: [{ label: labels.pinned, path: pinned }])
|
|
1462
|
+
: [remote ? undefined : projectStore(cwd, settings.indexName, projects, labels.project),
|
|
1443
1463
|
{ label: labels.user, path: join(dshHome(), STORE_DIR, settings.indexName) }]
|
|
1444
1464
|
const seen = new Set()
|
|
1445
1465
|
const parts = []
|
|
@@ -1632,19 +1652,12 @@ function withinCap(text, settings, used = 0) {
|
|
|
1632
1652
|
*
|
|
1633
1653
|
* Guards are synchronous by contract, so this stays cheap: every tool that cannot
|
|
1634
1654
|
* write leaves on string compares; a write pays a path resolution (two with an index
|
|
1635
|
-
* pinned), and a write to the index one bounded
|
|
1655
|
+
* pinned; none for a path on another machine), and a write to the index one bounded
|
|
1656
|
+
* read of it.
|
|
1636
1657
|
*/
|
|
1637
1658
|
function refuseOversizedIndex(exec, settings, sessionCwd) {
|
|
1638
1659
|
const args = exec?.arguments
|
|
1639
1660
|
if (!args || typeof args !== 'object') return undefined
|
|
1640
|
-
|
|
1641
|
-
// dsh's file tools carry the target as `file_path`; `str_replace_editor` calls it
|
|
1642
|
-
// `path`.
|
|
1643
|
-
const filePath = typeof args.file_path === 'string' ? args.file_path
|
|
1644
|
-
: typeof args.path === 'string' ? args.path
|
|
1645
|
-
: undefined
|
|
1646
|
-
if (filePath === undefined) return undefined
|
|
1647
|
-
|
|
1648
1661
|
const tool = typeof exec.name === 'string' ? exec.name : ''
|
|
1649
1662
|
|
|
1650
1663
|
// Nothing below can refuse a read, a view, or an unknown tool, so leave before
|
|
@@ -1656,6 +1669,21 @@ function refuseOversizedIndex(exec, settings, sessionCwd) {
|
|
|
1656
1669
|
&& (args.command === 'create' || args.command === 'str_replace'
|
|
1657
1670
|
|| args.command === 'insert'))
|
|
1658
1671
|
if (!gated) return undefined
|
|
1672
|
+
|
|
1673
|
+
// Every path the call names is judged: dsh's `write` / `edit` take `file_path`,
|
|
1674
|
+
// `str_replace_editor` takes `path`, another plugin's `write` may take `path`, and dsh
|
|
1675
|
+
// ignores a field a tool does not declare — so reading one name only let a decoy in
|
|
1676
|
+
// the other hide a write to the index (it passed as one to README.md). A call naming
|
|
1677
|
+
// the index in a field its tool ignores may be refused; that costs nothing.
|
|
1678
|
+
for (const filePath of new Set([args.file_path, args.path].filter((p) => typeof p === 'string'))) {
|
|
1679
|
+
const reason = judgeWrite(exec, args, tool, filePath, settings, sessionCwd)
|
|
1680
|
+
if (reason !== undefined) return reason
|
|
1681
|
+
}
|
|
1682
|
+
return undefined
|
|
1683
|
+
}
|
|
1684
|
+
|
|
1685
|
+
/** refuseOversizedIndex() for one path a gated call may write. */
|
|
1686
|
+
function judgeWrite(exec, args, tool, filePath, settings, sessionCwd) {
|
|
1659
1687
|
// Every read and identity check below uses the file the host will actually touch.
|
|
1660
1688
|
let target
|
|
1661
1689
|
try {
|
|
@@ -1698,22 +1726,21 @@ function refuseOversizedIndex(exec, settings, sessionCwd) {
|
|
|
1698
1726
|
const currentBuf = readIndex(target, settings.readLimit)
|
|
1699
1727
|
if (currentBuf === undefined || !Buffer.isBuffer(currentBuf)) return undefined
|
|
1700
1728
|
const current = currentBuf.toString('utf8')
|
|
1701
|
-
const
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
const
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
over.push(`at least ${simulated.bytes} bytes > ${settings.maxBytes}`)
|
|
1729
|
+
const insert = insertOf(tool, args)
|
|
1730
|
+
const edits = insert === undefined ? editsOf(tool, args) : []
|
|
1731
|
+
if (insert !== undefined || edits.length > 0) {
|
|
1732
|
+
// A tool whose schema this guard does not know may be judged on more than one
|
|
1733
|
+
// reading of its arguments: the refusal stands if any reading would refuse.
|
|
1734
|
+
const results = insert !== undefined
|
|
1735
|
+
? [simulateInsert(current, insert, settings.readLimit)]
|
|
1736
|
+
: edits.map((edit) => simulateEdit(current, edit, settings.readLimit))
|
|
1737
|
+
for (const simulated of results) {
|
|
1738
|
+
const reason = typeof simulated === 'string'
|
|
1739
|
+
? verdict(simulated, currentBuf, filePath, settings)
|
|
1740
|
+
: bounded(simulated, current, currentBuf, filePath, settings)
|
|
1741
|
+
if (reason !== undefined) return reason
|
|
1715
1742
|
}
|
|
1716
|
-
return
|
|
1743
|
+
return undefined
|
|
1717
1744
|
}
|
|
1718
1745
|
|
|
1719
1746
|
// The edit's result genuinely cannot be reconstructed from its arguments. Honest,
|
|
@@ -1818,13 +1845,86 @@ function notMyIndexHint(settings) {
|
|
|
1818
1845
|
}
|
|
1819
1846
|
|
|
1820
1847
|
/**
|
|
1821
|
-
*
|
|
1822
|
-
*
|
|
1823
|
-
*
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1848
|
+
* A result too long to build, judged on lower bounds of its size by the same
|
|
1849
|
+
* grow-past-the-cap rule as verdict(). A bound that clears both tests refuses only what
|
|
1850
|
+
* the full result would; one that does not lets the edit through unmeasured.
|
|
1851
|
+
*/
|
|
1852
|
+
function bounded(simulated, current, currentBuf, filePath, settings) {
|
|
1853
|
+
const over = []
|
|
1854
|
+
if (simulated.newlines > settings.maxLines && simulated.newlines > countLines(current)) {
|
|
1855
|
+
over.push(`at least ${simulated.newlines} lines > ${settings.maxLines}`)
|
|
1856
|
+
}
|
|
1857
|
+
if (simulated.bytes > settings.maxBytes && simulated.bytes > currentBuf.length) {
|
|
1858
|
+
over.push(`at least ${simulated.bytes} bytes > ${settings.maxBytes}`)
|
|
1859
|
+
}
|
|
1860
|
+
return over.length ? capRefusal(over, filePath, settings) : undefined
|
|
1861
|
+
}
|
|
1862
|
+
|
|
1863
|
+
/**
|
|
1864
|
+
* The replacements a call asks for, read in the argument names its tool reads. dsh's
|
|
1865
|
+
* `edit` reads `old_string` / `new_string` / `replace_all` and ignores any other field,
|
|
1866
|
+
* so a call carrying `old_str` as well must be judged on what dsh applies: reading a
|
|
1867
|
+
* decoy `old_str` first predicted "not found, no change" and let dsh write past the cap.
|
|
1868
|
+
* `str_replace_editor` reads `old_str` / `new_str` and has no replace-all. A tool whose
|
|
1869
|
+
* schema is not known here is read both ways. A reading with no non-empty old string
|
|
1870
|
+
* is dropped (the real tool errors on it); none left means the call is unsimulable.
|
|
1871
|
+
*/
|
|
1872
|
+
function editsOf(tool, args) {
|
|
1873
|
+
// `lf`: dsh's edit matches on LF-normalised text and writes back the file's own line
|
|
1874
|
+
// endings. `exact`: dsh's str_replace_editor matches the text as read (BOM dropped) and
|
|
1875
|
+
// writes the result as is — normalising for it saw two matches in a file mixing CRLF
|
|
1876
|
+
// and LF where the editor saw one, predicted "ambiguous, no change", and passed.
|
|
1877
|
+
const claude = { old: args.old_string, neu: args.new_string, all: args.replace_all === true }
|
|
1878
|
+
const anthropic = { old: args.old_str, neu: args.new_str, all: false }
|
|
1879
|
+
const any = args.replace_all === true || args.replaceAll === true
|
|
1880
|
+
const readings = tool === 'edit' ? [{ ...claude, mode: 'lf' }]
|
|
1881
|
+
: tool === 'str_replace_editor' ? [{ ...anthropic, mode: 'exact' }]
|
|
1882
|
+
: [claude, anthropic].flatMap((r) => ['lf', 'exact'].map((mode) => ({ ...r, all: any, mode })))
|
|
1883
|
+
return readings
|
|
1884
|
+
.filter((r) => typeof r.old === 'string' && r.old !== '')
|
|
1885
|
+
.map((r) => ({ old: r.old, neu: typeof r.neu === 'string' ? r.neu : '', all: r.all, mode: r.mode }))
|
|
1886
|
+
}
|
|
1887
|
+
|
|
1888
|
+
/**
|
|
1889
|
+
* An insert's line and text (`str_replace_editor`'s `insert` command, or a tool named
|
|
1890
|
+
* `insert` taking the same arguments), or undefined when the call is not one. Treating it
|
|
1891
|
+
* as unsimulable let one large insert carry an index from under the cap to far past it.
|
|
1892
|
+
*/
|
|
1893
|
+
function insertOf(tool, args) {
|
|
1894
|
+
const isInsert = tool === 'insert' || (tool === 'str_replace_editor' && args.command === 'insert')
|
|
1895
|
+
if (!isInsert || !Number.isSafeInteger(args.insert_line) || typeof args.new_str !== 'string') {
|
|
1896
|
+
return undefined
|
|
1897
|
+
}
|
|
1898
|
+
return { line: args.insert_line, text: args.new_str }
|
|
1899
|
+
}
|
|
1900
|
+
|
|
1901
|
+
/**
|
|
1902
|
+
* An insert's result, as `str_replace_editor` builds it: the text's lines placed after
|
|
1903
|
+
* line `line` (0 = before the first), the whole joined on `\n`. A line out of range is an
|
|
1904
|
+
* error in the real tool, so nothing changes. `{ bytes, newlines }` when too long to build.
|
|
1905
|
+
*/
|
|
1906
|
+
function simulateInsert(current, { line, text }, limit) {
|
|
1907
|
+
// the editor reads through TextDecoder, which drops a leading BOM, and writes without it
|
|
1908
|
+
const decoded = current.startsWith('\ufeff') ? current.slice(1) : current
|
|
1909
|
+
const segments = occurrences(decoded, '\n') + 1
|
|
1910
|
+
if (line < 0 || line > segments) return current
|
|
1911
|
+
if (decoded.length + text.length + 1 > limit) {
|
|
1912
|
+
return {
|
|
1913
|
+
bytes: Buffer.byteLength(decoded) + Buffer.byteLength(text) + 1,
|
|
1914
|
+
newlines: occurrences(decoded, '\n') + occurrences(text, '\n') + 1,
|
|
1915
|
+
}
|
|
1916
|
+
}
|
|
1917
|
+
const lines = decoded.split('\n')
|
|
1918
|
+
return [...lines.slice(0, line), text, ...lines.slice(line)].join('\n')
|
|
1919
|
+
}
|
|
1920
|
+
|
|
1921
|
+
/**
|
|
1922
|
+
* Reconstruct a partial edit's post-write text from one reading of its arguments
|
|
1923
|
+
* (editsOf). Mirrors the Python guard's Edit simulation: replace the unique occurrence,
|
|
1924
|
+
* or all of them under a replace-all flag; an absent or ambiguous old-string means the
|
|
1925
|
+
* real tool errors and changes nothing, so the current text is the honest prediction.
|
|
1926
|
+
* Returns `{ bytes, newlines }` — lower bounds of the result's size — when it is too
|
|
1927
|
+
* long to build.
|
|
1828
1928
|
*
|
|
1829
1929
|
* Matching happens on LF-normalised text and the result goes back in the file's own
|
|
1830
1930
|
* line endings, as dsh's local backend does it (`applyLiteralEdit` /
|
|
@@ -1832,13 +1932,11 @@ function notMyIndexHint(settings) {
|
|
|
1832
1932
|
* index — common on Windows — read every LF `old_string` as "not found", predict no
|
|
1833
1933
|
* change, and pass an edit dsh then applied.
|
|
1834
1934
|
*/
|
|
1835
|
-
function simulateEdit(current,
|
|
1836
|
-
const oldRaw = firstString(args.old_str, args.old_string)
|
|
1837
|
-
if (oldRaw === undefined || oldRaw === '') return undefined
|
|
1838
|
-
const newRaw = firstString(args.new_str, args.new_string) ?? ''
|
|
1935
|
+
function simulateEdit(current, { old: oldRaw, neu: newRaw, all, mode }, limit) {
|
|
1839
1936
|
// dsh decodes with TextDecoder, which drops a leading BOM — from the text it
|
|
1840
1937
|
// matches, from the sample it detects line endings on, and from what it writes back.
|
|
1841
1938
|
const decoded = current.startsWith('\uFEFF') ? current.slice(1) : current
|
|
1939
|
+
if (mode === 'exact') return simulateExact(current, decoded, oldRaw, newRaw, all, limit)
|
|
1842
1940
|
// Normalising CRLF at most halves a string, so an old_string over twice the text's
|
|
1843
1941
|
// length cannot be in it: the real tool errors, nothing changes. Checked before it
|
|
1844
1942
|
// is normalised, so an argument the size of the heap is never copied (#21).
|
|
@@ -1847,7 +1945,6 @@ function simulateEdit(current, args, limit) {
|
|
|
1847
1945
|
const oldStr = lf(oldRaw)
|
|
1848
1946
|
const first = text.indexOf(oldStr)
|
|
1849
1947
|
if (first === -1) return current // the real tool errors: nothing changes
|
|
1850
|
-
const all = args.replace_all === true || args.replaceAll === true
|
|
1851
1948
|
if (!all && text.indexOf(oldStr, first + oldStr.length) !== -1) {
|
|
1852
1949
|
return current // ambiguous: the real tool errors, nothing changes
|
|
1853
1950
|
}
|
|
@@ -1885,6 +1982,32 @@ function simulateEdit(current, args, limit) {
|
|
|
1885
1982
|
return crlfDominates(decoded) ? lf(edited).replaceAll('\n', '\r\n') : edited
|
|
1886
1983
|
}
|
|
1887
1984
|
|
|
1985
|
+
/**
|
|
1986
|
+
* simulateEdit() for a tool that matches the text as read (BOM dropped) and writes the
|
|
1987
|
+
* result as is, as dsh's str_replace_editor does: no line endings normalised or restored.
|
|
1988
|
+
*/
|
|
1989
|
+
function simulateExact(current, decoded, oldStr, newStr, all, limit) {
|
|
1990
|
+
if (oldStr.length > decoded.length) return current // cannot be in it: nothing changes
|
|
1991
|
+
const first = decoded.indexOf(oldStr)
|
|
1992
|
+
if (first === -1) return current
|
|
1993
|
+
if (!all && decoded.indexOf(oldStr, first + oldStr.length) !== -1) return current
|
|
1994
|
+
const matches = all ? occurrences(decoded, oldStr) : 1
|
|
1995
|
+
const length = decoded.length + matches * (newStr.length - oldStr.length)
|
|
1996
|
+
if (length > limit) {
|
|
1997
|
+
const wellFormed = !LONE_SURROGATE.test(decoded) && !LONE_SURROGATE.test(newStr)
|
|
1998
|
+
&& !LONE_SURROGATE.test(oldStr)
|
|
1999
|
+
return {
|
|
2000
|
+
bytes: wellFormed
|
|
2001
|
+
? Buffer.byteLength(decoded) + matches * (Buffer.byteLength(newStr) - Buffer.byteLength(oldStr))
|
|
2002
|
+
: length,
|
|
2003
|
+
newlines: occurrences(decoded, '\n') + matches * (occurrences(newStr, '\n') - occurrences(oldStr, '\n')),
|
|
2004
|
+
}
|
|
2005
|
+
}
|
|
2006
|
+
return all
|
|
2007
|
+
? decoded.replaceAll(oldStr, () => newStr)
|
|
2008
|
+
: decoded.slice(0, first) + newStr + decoded.slice(first + oldStr.length)
|
|
2009
|
+
}
|
|
2010
|
+
|
|
1888
2011
|
/** A high surrogate with no low after it, or a low with no high before it. */
|
|
1889
2012
|
const LONE_SURROGATE = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/
|
|
1890
2013
|
|
|
@@ -2021,10 +2144,17 @@ function hostPath(cwd, p) {
|
|
|
2021
2144
|
* anyway, as dsh does there, so the path is resolve()d first; the OS then expands an 8.3
|
|
2022
2145
|
* short name (`PROGRA~1`, `MEMORY~1.MD`), which Node's JS realpath keeps — the same file
|
|
2023
2146
|
* written through its short name was not the guarded index.
|
|
2147
|
+
*
|
|
2148
|
+
* A path on another machine is keyed as written, `\\?\UNC\host\` as `\\host\`, and not
|
|
2149
|
+
* looked up (remotePath) — unless it holds a `~`: a short name there (`MEMORY~1.MD`) is
|
|
2150
|
+
* worth the wait. (A link on a share is not followed by Windows by default.)
|
|
2024
2151
|
*/
|
|
2025
2152
|
function pathKey(p) {
|
|
2026
2153
|
const posix = process.platform !== 'win32'
|
|
2027
2154
|
let head = posix && isAbsolute(p) ? p : resolve(p)
|
|
2155
|
+
if (remotePath(head) && !head.includes('~')) {
|
|
2156
|
+
return head.replace(/^[\\/]{2}[?.][\\/]UNC[\\/]/i, '\\\\').toLowerCase()
|
|
2157
|
+
}
|
|
2028
2158
|
const tail = []
|
|
2029
2159
|
for (;;) {
|
|
2030
2160
|
try {
|
|
@@ -2041,6 +2171,48 @@ function pathKey(p) {
|
|
|
2041
2171
|
return process.platform === 'win32' ? out.toLowerCase() : out
|
|
2042
2172
|
}
|
|
2043
2173
|
|
|
2174
|
+
/**
|
|
2175
|
+
* Is `p` on another machine: on Windows, a UNC path to a host that is not this one? A
|
|
2176
|
+
* synchronous call on such a path waits while the host does not answer — 21 s measured
|
|
2177
|
+
* for an address nobody holds — and the guard and recall run on dsh's main thread, so
|
|
2178
|
+
* the whole of dsh would wait. `\\?\C:\…` and `\\.\…` name this machine's own drives and
|
|
2179
|
+
* devices, and a host that is this machine (localHost) the machine itself: those answer
|
|
2180
|
+
* at once, so they are looked up as any path is — a link or a short name there resolves.
|
|
2181
|
+
* (A mapped drive letter, or a local link to a share, cannot be told by its spelling.
|
|
2182
|
+
* Nor is one host under another name the same file: Windows resolves neither
|
|
2183
|
+
* `\\127.0.0.1\c$\x` to `C:\x` nor one server's names to each other, so those were
|
|
2184
|
+
* two keys before this shortcut too.)
|
|
2185
|
+
*/
|
|
2186
|
+
function remotePath(p) {
|
|
2187
|
+
if (process.platform !== 'win32') return false
|
|
2188
|
+
const host = /^[\\/]{2}(?:[?.][\\/]UNC[\\/])?([^\\/]+)/i.exec(p)?.[1]
|
|
2189
|
+
if (host === undefined || host === '?' || host === '.') return false
|
|
2190
|
+
return !localHost(host)
|
|
2191
|
+
}
|
|
2192
|
+
|
|
2193
|
+
/**
|
|
2194
|
+
* Does a UNC host name this machine? Its name, also with a domain or a trailing dot; a
|
|
2195
|
+
* loopback address or one of its interfaces', in any spelling a URL takes (`127.1`,
|
|
2196
|
+
* `[::1]`) or as an `ipv6-literal.net` name; a WebDAV `@SSL` / `@port` suffix aside.
|
|
2197
|
+
*/
|
|
2198
|
+
function localHost(host) {
|
|
2199
|
+
const canonical = (name) => {
|
|
2200
|
+
try {
|
|
2201
|
+
return new URL(`http://${name}/`).hostname
|
|
2202
|
+
} catch {
|
|
2203
|
+
return name
|
|
2204
|
+
}
|
|
2205
|
+
}
|
|
2206
|
+
const name = host.toLowerCase().replace(/@.*$/, '').replace(/\.$/, '')
|
|
2207
|
+
const literal = /^(.+)\.ipv6-literal\.net$/.exec(name)
|
|
2208
|
+
const key = canonical(literal ? `[${literal[1].replace(/s.*$/, '').replace(/-/g, ':')}]` : name)
|
|
2209
|
+
if (key === 'localhost' || key === '[::1]' || /^127\./.test(key)) return true
|
|
2210
|
+
const self = canonical(hostname().toLowerCase())
|
|
2211
|
+
if (key === self || key.split('.')[0] === self.split('.')[0]) return true
|
|
2212
|
+
return Object.values(networkInterfaces()).flat().some((face) => face !== undefined &&
|
|
2213
|
+
canonical(face.address.includes(':') ? `[${face.address.replace(/%.*$/, '')}]` : face.address) === key)
|
|
2214
|
+
}
|
|
2215
|
+
|
|
2044
2216
|
|
|
2045
2217
|
/**
|
|
2046
2218
|
* An empty or non-string indexName must fall back, not silently disable the cap:
|
|
@@ -2226,12 +2398,24 @@ const TEXT = {
|
|
|
2226
2398
|
* directory, where neither recall nor the memory page looks, after searching the disk.
|
|
2227
2399
|
*/
|
|
2228
2400
|
function storesOf(settings) {
|
|
2229
|
-
const how = {
|
|
2401
|
+
const how = {
|
|
2402
|
+
injected: settings.injectIndex !== false,
|
|
2403
|
+
social: settings.social === true,
|
|
2404
|
+
maxLines: settings.maxLines ?? DEFAULT_MAX_LINES,
|
|
2405
|
+
maxBytes: settings.maxBytes ?? DEFAULT_MAX_BYTES,
|
|
2406
|
+
}
|
|
2230
2407
|
return settings.indexPath !== undefined
|
|
2231
2408
|
? { ...how, pinned: settings.indexPath, indexName: basename(settings.indexPath) }
|
|
2232
2409
|
: { ...how, global: join(dshHome(), STORE_DIR), indexName: settings.indexName }
|
|
2233
2410
|
}
|
|
2234
2411
|
|
|
2412
|
+
/** The configured caps as the skill states them: `200 lines / 25 KB` by default. */
|
|
2413
|
+
function capsOf(stores, zh = false) {
|
|
2414
|
+
const size = stores.maxBytes % 1024 === 0 ? `${stores.maxBytes / 1024} KB`
|
|
2415
|
+
: zh ? `${stores.maxBytes} 字节` : `${stores.maxBytes} bytes`
|
|
2416
|
+
return zh ? `${stores.maxLines} 行 / ${size}` : `${stores.maxLines} lines / ${size}`
|
|
2417
|
+
}
|
|
2418
|
+
|
|
2235
2419
|
/** The store's own folder: the pinned index's, or the global store. */
|
|
2236
2420
|
const storeDir = (stores) => (stores.pinned !== undefined ? dirname(stores.pinned) : stores.global)
|
|
2237
2421
|
|
|
@@ -2435,9 +2619,12 @@ function skillEn(companion = false, stores = storesOf({ indexName: DEFAULT_INDEX
|
|
|
2435
2619
|
'refresh project state, promote only reusable feedback, retire completed transient',
|
|
2436
2620
|
'state, then report what was added, updated, archived, and skipped.',
|
|
2437
2621
|
'',
|
|
2622
|
+
'After any memory write or sync, report what was added, updated, archived (deletions',
|
|
2623
|
+
'included) and skipped, with a reason for each skip; when nothing was written, say so.',
|
|
2624
|
+
'',
|
|
2438
2625
|
'## The cap is enforced here',
|
|
2439
2626
|
'',
|
|
2440
|
-
|
|
2627
|
+
`This host denies a write that would GROW the index past ${capsOf(stores)}. That is`,
|
|
2441
2628
|
'a real refusal, not a warning — but a write that shrinks the index always passes,',
|
|
2442
2629
|
'so compact first, step by step if needed: the index is loaded every session, and',
|
|
2443
2630
|
'anything past the cap stops being recalled.',
|
|
@@ -2552,9 +2739,12 @@ function skillZh(companion = false, stores = storesOf({ indexName: DEFAULT_INDEX
|
|
|
2552
2739
|
'在主动压缩、清空或开新线程之前:扫一遍任务,去重并更新,刷新项目状态,只提炼可复用',
|
|
2553
2740
|
'的反馈,退休已完成的临时状态,然后汇报新增、更新、归档、跳过了什么。',
|
|
2554
2741
|
'',
|
|
2742
|
+
'每次写记忆或同步之后,都汇报新增、更新、归档(含删除)、跳过了什么,每条跳过写明原因;',
|
|
2743
|
+
'什么都没写,也要说一声。',
|
|
2744
|
+
'',
|
|
2555
2745
|
'## 上限由这里强制',
|
|
2556
2746
|
'',
|
|
2557
|
-
|
|
2747
|
+
`本宿主会拒绝让索引**增长**到超过 ${capsOf(stores, true)} 的写入。这是真拒绝,不是警告——但`,
|
|
2558
2748
|
'让索引变小的写入总能通过,所以先压缩,必要时分几步:索引每次会话都会加载,超过上限',
|
|
2559
2749
|
'的部分就不会再被回忆。',
|
|
2560
2750
|
'',
|
package/package.json
CHANGED
|
@@ -1,79 +1,79 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "dsh-engramory",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "DeepSeek Harness 的长期记忆插件:AI 记住的东西存成普通 markdown 文件,每轮自动带上记忆索引,索引有大小上限。",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"dsh-plugin",
|
|
7
|
-
"deepseek-harness",
|
|
8
|
-
"dsh",
|
|
9
|
-
"memory",
|
|
10
|
-
"agent-memory",
|
|
11
|
-
"long-term-memory",
|
|
12
|
-
"engramory",
|
|
13
|
-
"markdown"
|
|
14
|
-
],
|
|
15
|
-
"type": "module",
|
|
16
|
-
"main": "index.js",
|
|
17
|
-
"dsh": {
|
|
18
|
-
"bundle": {
|
|
19
|
-
"patch": "./cordis.patch.yml"
|
|
20
|
-
},
|
|
21
|
-
"client": {
|
|
22
|
-
"platform": "web",
|
|
23
|
-
"inject": [
|
|
24
|
-
"@deepseek-ai/dsh-client-locale",
|
|
25
|
-
"@deepseek-ai/dsh-client-ui-plugin-manager"
|
|
26
|
-
]
|
|
27
|
-
},
|
|
28
|
-
"compatibility": {
|
|
29
|
-
"dsh": ">=0.1.0-rc.7 <0.3.0-0",
|
|
30
|
-
"dshReleases": {
|
|
31
|
-
"0.1.5-rc.3": "compatible",
|
|
32
|
-
"0.1.7-alpha.1": "compatible",
|
|
33
|
-
"0.1.7-alpha.2": "compatible",
|
|
34
|
-
"0.1.7-rc.1": "compatible",
|
|
35
|
-
"0.1.7-rc.2": "compatible",
|
|
36
|
-
"0.2.1-alpha.5": "compatible",
|
|
37
|
-
"0.2.1-rc.1": "compatible",
|
|
38
|
-
"0.2.1-rc.2": "compatible",
|
|
39
|
-
"0.2.1-rc.3": "compatible",
|
|
40
|
-
"0.2.1-rc.4": "compatible",
|
|
41
|
-
"0.2.1-rc.5": "compatible",
|
|
42
|
-
"0.2.2-alpha.2": "compatible"
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
"exports": {
|
|
47
|
-
".": "./index.js",
|
|
48
|
-
"./client": "./client.js",
|
|
49
|
-
"./locale/*.json": "./locale/*.json",
|
|
50
|
-
"./icon": "./icon.svg",
|
|
51
|
-
"./package.json": "./package.json"
|
|
52
|
-
},
|
|
53
|
-
"files": [
|
|
54
|
-
"index.js",
|
|
55
|
-
"client.js",
|
|
56
|
-
"cordis.patch.yml",
|
|
57
|
-
"locale/*.json",
|
|
58
|
-
"icon.svg",
|
|
59
|
-
"README.md",
|
|
60
|
-
"LICENSE"
|
|
61
|
-
],
|
|
62
|
-
"author": "tinqiao-oss",
|
|
63
|
-
"license": "MIT",
|
|
64
|
-
"repository": {
|
|
65
|
-
"type": "git",
|
|
66
|
-
"url": "git+https://github.com/tinqiao-oss/engramory.git",
|
|
67
|
-
"directory": "adapters/dsh/plugin"
|
|
68
|
-
},
|
|
69
|
-
"homepage": "https://github.com/tinqiao-oss/engramory/tree/master/adapters/dsh/plugin#readme",
|
|
70
|
-
"bugs": {
|
|
71
|
-
"url": "https://github.com/tinqiao-oss/engramory/issues"
|
|
72
|
-
},
|
|
73
|
-
"engines": {
|
|
74
|
-
"node": ">=18"
|
|
75
|
-
},
|
|
76
|
-
"publishConfig": {
|
|
77
|
-
"access": "public"
|
|
78
|
-
}
|
|
79
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "dsh-engramory",
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "DeepSeek Harness 的长期记忆插件:AI 记住的东西存成普通 markdown 文件,每轮自动带上记忆索引,索引有大小上限。",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"dsh-plugin",
|
|
7
|
+
"deepseek-harness",
|
|
8
|
+
"dsh",
|
|
9
|
+
"memory",
|
|
10
|
+
"agent-memory",
|
|
11
|
+
"long-term-memory",
|
|
12
|
+
"engramory",
|
|
13
|
+
"markdown"
|
|
14
|
+
],
|
|
15
|
+
"type": "module",
|
|
16
|
+
"main": "index.js",
|
|
17
|
+
"dsh": {
|
|
18
|
+
"bundle": {
|
|
19
|
+
"patch": "./cordis.patch.yml"
|
|
20
|
+
},
|
|
21
|
+
"client": {
|
|
22
|
+
"platform": "web",
|
|
23
|
+
"inject": [
|
|
24
|
+
"@deepseek-ai/dsh-client-locale",
|
|
25
|
+
"@deepseek-ai/dsh-client-ui-plugin-manager"
|
|
26
|
+
]
|
|
27
|
+
},
|
|
28
|
+
"compatibility": {
|
|
29
|
+
"dsh": ">=0.1.0-rc.7 <0.3.0-0",
|
|
30
|
+
"dshReleases": {
|
|
31
|
+
"0.1.5-rc.3": "compatible",
|
|
32
|
+
"0.1.7-alpha.1": "compatible",
|
|
33
|
+
"0.1.7-alpha.2": "compatible",
|
|
34
|
+
"0.1.7-rc.1": "compatible",
|
|
35
|
+
"0.1.7-rc.2": "compatible",
|
|
36
|
+
"0.2.1-alpha.5": "compatible",
|
|
37
|
+
"0.2.1-rc.1": "compatible",
|
|
38
|
+
"0.2.1-rc.2": "compatible",
|
|
39
|
+
"0.2.1-rc.3": "compatible",
|
|
40
|
+
"0.2.1-rc.4": "compatible",
|
|
41
|
+
"0.2.1-rc.5": "compatible",
|
|
42
|
+
"0.2.2-alpha.2": "compatible"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"exports": {
|
|
47
|
+
".": "./index.js",
|
|
48
|
+
"./client": "./client.js",
|
|
49
|
+
"./locale/*.json": "./locale/*.json",
|
|
50
|
+
"./icon": "./icon.svg",
|
|
51
|
+
"./package.json": "./package.json"
|
|
52
|
+
},
|
|
53
|
+
"files": [
|
|
54
|
+
"index.js",
|
|
55
|
+
"client.js",
|
|
56
|
+
"cordis.patch.yml",
|
|
57
|
+
"locale/*.json",
|
|
58
|
+
"icon.svg",
|
|
59
|
+
"README.md",
|
|
60
|
+
"LICENSE"
|
|
61
|
+
],
|
|
62
|
+
"author": "tinqiao-oss",
|
|
63
|
+
"license": "MIT",
|
|
64
|
+
"repository": {
|
|
65
|
+
"type": "git",
|
|
66
|
+
"url": "git+https://github.com/tinqiao-oss/engramory.git",
|
|
67
|
+
"directory": "adapters/dsh/plugin"
|
|
68
|
+
},
|
|
69
|
+
"homepage": "https://github.com/tinqiao-oss/engramory/tree/master/adapters/dsh/plugin#readme",
|
|
70
|
+
"bugs": {
|
|
71
|
+
"url": "https://github.com/tinqiao-oss/engramory/issues"
|
|
72
|
+
},
|
|
73
|
+
"engines": {
|
|
74
|
+
"node": ">=18"
|
|
75
|
+
},
|
|
76
|
+
"publishConfig": {
|
|
77
|
+
"access": "public"
|
|
78
|
+
}
|
|
79
|
+
}
|