2 Commits
4 changed files with 50 additions and 12 deletions
+5
View File
@@ -11,6 +11,9 @@ jobs:
release: release:
runs-on: nixos runs-on: nixos
steps: steps:
- name: Note about the token
run: |
echo "Note: github.token / GITHUB_TOKEN is Gitea's own per-job token (GitHub-compatible name). It only works on this repo, expires when the job ends, and nothing is sent to GitHub."
- name: Checkout - name: Checkout
run: | run: |
set -euo pipefail set -euo pipefail
@@ -26,6 +29,8 @@ jobs:
cd dist && sha256sum sirmem-* > SHA256SUMS && cat SHA256SUMS cd dist && sha256sum sirmem-* > SHA256SUMS && cat SHA256SUMS
- name: Create release and upload assets - name: Create release and upload assets
env: env:
# Note: github.token / GITHUB_TOKEN is Gitea's own per-job token (GitHub-compatible name).
# It only works on this repo, expires when the job ends, and nothing is sent to GitHub.
TOKEN: ${{ github.token }} TOKEN: ${{ github.token }}
SERVER: ${{ github.server_url }} SERVER: ${{ github.server_url }}
REPO: ${{ github.repository }} REPO: ${{ github.repository }}
+2 -1
View File
@@ -27,7 +27,8 @@ delete an entity that tombstones point to, or one that is the only `applies-to`
silently become "everywhere"); the offending preferences/tombstones are listed. silently become "everywhere"); the offending preferences/tombstones are listed.
`sirmem lint --clean` applies structural fixes only and prints each change: removes unreferenced redirect `sirmem lint --clean` applies structural fixes only and prints each change: removes unreferenced redirect
tombstones, `relates-to` lines whose pair is also linked by a typed verb, and `part-of` lines implied by a tombstones, `relates-to` lines whose pair is also linked by a typed verb (a non-empty note is appended to the first typed
relation's note, separated by ` | `), and `part-of` lines implied by a
longer `part-of` chain. `sirmem lint --suggest` is read-only and prints numbered candidates (superseded, longer `part-of` chain. `sirmem lint --suggest` is read-only and prints numbered candidates (superseded,
contradicted, duplicate by normalised label/alias, orphan) with a suggested action for an LLM to review with the contradicted, duplicate by normalised label/alias, orphan) with a suggested action for an LLM to review with the
user. Both flags can be combined (clean first, then lint, then suggest). user. Both flags can be combined (clean first, then lint, then suggest).
+26 -11
View File
@@ -6,7 +6,7 @@ import std/[os, strutils, sequtils, algorithm, tables, times, osproc,
nativesockets, deques] nativesockets, deques]
const const
Version* = "0.1.3" Version* = "0.1.4"
CycleVerbs* = ["part-of", "supersedes"] CycleVerbs* = ["part-of", "supersedes"]
DefaultVerb* = "relates-to" DefaultVerb* = "relates-to"
@@ -755,7 +755,7 @@ proc cmdLint*(st: Store, errorCount: var int): string =
used.add r.s used.add r.s
used.add r.o used.add r.o
for id, e in st.entities: for id, e in st.entities:
if e.redirect == "" and id notin used: warns.add "orphan entity: " & id if e.redirect == "" and e.typ != "preference" and id notin used: warns.add "orphan entity: " & id
if e.fileId != id: warns.add "entity id " & id & " differs from filename " & e.fileId & ".md" if e.fileId != id: warns.add "entity id " & id & " differs from filename " & e.fileId & ".md"
if not st.schema.hasType(e.typ) and e.redirect == "": if not st.schema.hasType(e.typ) and e.redirect == "":
warns.add "entity " & id & " has type not in schema: " & e.typ warns.add "entity " & id & " has type not in schema: " & e.typ
@@ -772,15 +772,30 @@ proc cmdLintClean*(st: var Store): string =
var lines: seq[string] var lines: seq[string]
var rels = st.rels var rels = st.rels
# b. relates-to implied by any other verb on the same pair (either direction) # b. relates-to implied by any other verb on the same pair (either direction)
var keep: seq[Rel] var keep: seq[bool]
for r in rels: for r in rels:
if r.v == DefaultVerb and rels.anyIt(it.v != DefaultVerb and keep.add not (r.v == DefaultVerb and rels.anyIt(it.v != DefaultVerb and
((it.s == r.s and it.o == r.o) or (it.s == r.o and it.o == r.s))): ((it.s == r.s and it.o == r.o) or (it.s == r.o and it.o == r.s))))
lines.add "removed relation " & r.s & " " & r.v & " " & r.o & suffix(r.note) & for idx in 0 ..< rels.len:
" (pair already linked by a typed verb)" if keep[idx]: continue
else: let r = rels[idx]
keep.add r var target = -1
rels = keep for j in 0 ..< rels.len:
let t = rels[j]
if t.v != DefaultVerb and ((t.s == r.s and t.o == r.o) or (t.s == r.o and t.o == r.s)):
if target < 0 or (t.s, t.v, t.o) < (rels[target].s, rels[target].v, rels[target].o):
target = j
var msg = "removed relation " & r.s & " " & r.v & " " & r.o & suffix(r.note) &
" (pair already linked by a typed verb)"
if r.note != "" and target >= 0:
let t = rels[target]
rels[target].note = if t.note == "": r.note else: t.note & " | " & r.note
msg.add "; note appended to " & t.s & " " & t.v & " " & t.o
lines.add msg
var kept: seq[Rel]
for idx in 0 ..< rels.len:
if keep[idx]: kept.add rels[idx]
rels = kept
# c. transitively redundant part-of (sequential, so reachability is always preserved) # c. transitively redundant part-of (sequential, so reachability is always preserved)
var i = 0 var i = 0
while i < rels.len: while i < rels.len:
@@ -794,7 +809,7 @@ proc cmdLintClean*(st: var Store): string =
rels = others rels = others
continue continue
inc i inc i
if rels.len != st.rels.len: if rels != st.rels:
st.rels = rels st.rels = rels
st.saveRels st.saveRels
# a. unreferenced redirect tombstones, repeated until stable # a. unreferenced redirect tombstones, repeated until stable
+17
View File
@@ -349,6 +349,8 @@ suite "lint":
check "warning: domain/range" in out1 check "warning: domain/range" in out1
check "warning: orphan entity: d" in out1 check "warning: orphan entity: d" in out1
check run(d, "lint") == out1 and lastCode == 0 check run(d, "lint") == out1 and lastCode == 0
discard run(d, "new", "pref9", "preference")
check "orphan entity: pref9" notin run(d, "lint")
# break things by hand # break things by hand
writeFile(d / "relations.tsv", writeFile(d / "relations.tsv",
"a\tbogus\tb\n" & "a\tbogus\tb\n" &
@@ -405,6 +407,21 @@ suite "rm guards":
check fileExists(d / "entities" / "b.md") check fileExists(d / "entities" / "b.md")
suite "lint --clean / --suggest": suite "lint --clean / --suggest":
test "clean appends removed relates-to note to the first typed relation":
let d = freshDir()
seed(d)
discard run(d, "link", "a", "uses", "b", "first")
discard run(d, "link", "b", "part-of", "a", "second")
discard run(d, "link", "a", "relates-to", "b", "extra")
let o = run(d, "lint", "--clean")
check "note appended to a uses b" in o
check "a\tuses\tb\tfirst | extra" in relsText(d)
check "relates-to" notin relsText(d)
discard run(d, "link", "c", "uses", "d")
discard run(d, "link", "c", "relates-to", "d", "n2")
discard run(d, "lint", "--clean")
check "c\tuses\td\tn2" in relsText(d)
test "clean removes tombstones, redundant relates-to and part-of; prints changes": test "clean removes tombstones, redundant relates-to and part-of; prints changes":
let d = freshDir() let d = freshDir()
seed(d) seed(d)