mirror of
https://github.com/bitbaum/causius.git
synced 2026-12-04 05:07:50 +01:00
feat(agent): read the law of all 26 cantons through LexFind
lib/law/lexfind.ts finds a cantonal act by abbreviation (StG), systematic number (631.1) or title through LexFind's public API (Institute of Federalism, University of Fribourg), reads the canton's official PDF with unpdf, drops repeated page headers, rejoins hyphenated words and cuts out one § or Art., stopping at the next heading but not at a reference to it. The source link is the canton's own page. read_law reads a non-federal act from the matter's canton, or from one named with the new canton field. Checked live: ZH StG § 140, BE StG Art. 187, VD LI Art. 1 (and LU, GE by hand). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018Lem7GyhyyjKhmwjG8G7Ud
This commit is contained in:
8 files changed
+325
-11
No files matched your search
+2
-1
@@ -13,7 +13,8 @@ brackets, it is the pull request to read for the detail.
|
||||
before it states the rule. The answer cites the article with its link. This
|
||||
needs no search engine and no paid service, so it works when web search does
|
||||
not. Liechtenstein law is read the same way, from gesetze.li, the
|
||||
Government's consolidated collection. {#read-law}
|
||||
Government's consolidated collection, and the law of all 26 cantons through
|
||||
LexFind, from each canton's own official text. {#read-law}
|
||||
|
||||
- **A quick check opens as a matter.** Under the deadline, one tap moves the
|
||||
check into a sealed matter. The deadline and its sentence, the letter, the
|
||||
|
||||
+14
-4
@@ -1,5 +1,6 @@
|
||||
import { srNumber } from "./acts";
|
||||
import { readFederalArticle, type LawLanguage, type ReadArticle } from "./fedlex";
|
||||
import { readCantonalProvision } from "./lexfind";
|
||||
import { liActId, readLiechtensteinProvision } from "./lilex";
|
||||
|
||||
/**
|
||||
@@ -17,18 +18,27 @@ export interface LawQuery {
|
||||
lang: LawLanguage;
|
||||
/** YYYY-MM-DD: the version in force that day, where the collection keeps versions. */
|
||||
day: string;
|
||||
/** A Swiss canton ("ZH") for cantonal law: the matter's, or one named. */
|
||||
canton?: string | null;
|
||||
fetchImpl?: typeof fetch;
|
||||
}
|
||||
|
||||
/** A reader returns null when the act is not one of its own. */
|
||||
const READERS: Record<string, { label: string; read: (q: LawQuery) => Promise<{ result: ReadArticle; cite: string } | null> }> = {
|
||||
CH: {
|
||||
label: "Fedlex",
|
||||
label: "Fedlex / LexFind",
|
||||
async read(q) {
|
||||
const sr = srNumber(q.act);
|
||||
if (!sr) return null;
|
||||
const result = await readFederalArticle({ sr, article: q.provision, lang: q.lang, day: q.day, fetchImpl: q.fetchImpl });
|
||||
return { result, cite: `${q.act} (SR ${sr})` };
|
||||
if (sr) {
|
||||
const result = await readFederalArticle({ sr, article: q.provision, lang: q.lang, day: q.day, fetchImpl: q.fetchImpl });
|
||||
return { result, cite: `${q.act} (SR ${sr})` };
|
||||
}
|
||||
// Not a federal act: the canton's own, through LexFind.
|
||||
if (!q.canton) return null;
|
||||
const found = await readCantonalProvision({ canton: q.canton, act: q.act, provision: q.provision, lang: q.lang, fetchImpl: q.fetchImpl });
|
||||
if (!found) return null;
|
||||
const { act, ...result } = found;
|
||||
return { result, cite: act ? `${act.abbreviation} ${q.canton} ${act.number} (${act.title})` : `${q.act} ${q.canton}` };
|
||||
},
|
||||
},
|
||||
LI: {
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { cleanPdfText, extractCantonalProvision, findCantonalAct } from "./lexfind";
|
||||
|
||||
// Zürich's StG as unpdf reads it: margin notes run into headings, a header and a page number per page.
|
||||
const header = "Steuergesetz (StG) 631.1";
|
||||
const ZH = [
|
||||
"Steuergesetz (StG)44",
|
||||
"I. Steuerarten§ 1. Der Kanton erhebt als Staatssteuern jährlich:",
|
||||
"a. Einkommens- und Vermögenssteuern von natürlichen Personen,",
|
||||
"II. Steuerfuss§ 2. 1 Die aufgrund der in diesem Gesetz festgelegten Steuersätze",
|
||||
...Array.from({ length: 9 }, (_, i) => [header, String(60 + i)]).flat(),
|
||||
"III. Einsprache § 140. 1 Gegen den Einschätzungsentscheid können der Steuer-",
|
||||
"pflichtige und die Gemeinde innert 30 Tagen nach Zustellung beim",
|
||||
"kantonalen Steueramt schriftlich Einsprache erheben. Vorbehalten bleibt § 141 Abs. 2.",
|
||||
"2 Eine Einschätzung nach pflichtgemässem Ermessen kann der Steuerpflichtige anfechten.",
|
||||
"2. Einsprache-",
|
||||
"verfahren",
|
||||
"§ 141. 1 Im Einspracheverfahren hat das kantonale Steueramt die gleichen Befugnisse.",
|
||||
"Übergangsbestimmungen § 1. 1 Die bisherigen Mitglieder bleiben im Amt.",
|
||||
].join("\n");
|
||||
|
||||
describe("cantonal text from a PDF", () => {
|
||||
const text = cleanPdfText(ZH);
|
||||
|
||||
it("drops page headers and numbers, and rejoins hyphenated words", () => {
|
||||
expect(text).not.toContain(header);
|
||||
expect(text).not.toMatch(/^6\d$/m);
|
||||
expect(text).toContain("Steuerpflichtige und die Gemeinde");
|
||||
expect(text).toContain("Einkommens- und Vermögenssteuern");
|
||||
});
|
||||
|
||||
it("cuts out one §, stopping at the next heading but not at a reference", () => {
|
||||
const p = extractCantonalProvision(text, "§ 140")!;
|
||||
expect(p).toMatch(/^§ 140\. 1 Gegen den Einschätzungsentscheid/);
|
||||
expect(p).toContain("Vorbehalten bleibt § 141 Abs. 2.");
|
||||
expect(p).toContain("2 Eine Einschätzung");
|
||||
expect(p).not.toContain("Im Einspracheverfahren");
|
||||
});
|
||||
|
||||
it("finds a heading a margin note runs into, and the first § 1, not the transitional one", () => {
|
||||
expect(extractCantonalProvision(text, "1")).toMatch(/^§ 1\. Der Kanton erhebt/);
|
||||
expect(extractCantonalProvision(text, "§ 999")).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("finding a cantonal act on LexFind", () => {
|
||||
const lexfind = (hits: unknown[]): typeof fetch =>
|
||||
(async (url: string | URL | Request, init?: RequestInit) => {
|
||||
const u = String(url);
|
||||
if (u.endsWith("/entities")) return Response.json([{ id: 26, abbreviation: "ZH" }]);
|
||||
if (init?.method === "POST") return Response.json({ id: 1, session_id: "s" });
|
||||
return Response.json({ texts_of_law_with_matches: hits });
|
||||
}) as typeof fetch;
|
||||
const hit = (id: number, title: string, keywords: string, number: string) => ({
|
||||
id,
|
||||
systematic_number: number,
|
||||
is_active: true,
|
||||
dta_urls: [{ language: "de", url: `/tol/${id}/de`, original_url: `https://www.zh.ch/${number}` }],
|
||||
matches: [{ title, keywords, is_active: true, version_active_since: "01.01.2026", category: { name: "Gesetz" } }],
|
||||
});
|
||||
|
||||
it("prefers the act whose abbreviation is the one asked for", async () => {
|
||||
const act = await findCantonalAct("ZH", "StG", "de", lexfind([hit(2, "Strassengesetz", "StrG", "722.1"), hit(1, "Steuergesetz", "StG", "631.1")]));
|
||||
expect(act).toMatchObject({ title: "Steuergesetz", number: "631.1", official: "https://www.zh.ch/631.1", pdf: "https://www.lexfind.ch/tol/1/de" });
|
||||
});
|
||||
|
||||
it("answers null for an act that is nobody's abbreviation, number or title", async () => {
|
||||
expect(await findCantonalAct("ZH", "Mietrecht", "de", lexfind([hit(3, "Gesetz über das Mietwesen", "MWG", "1.1")]))).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,219 @@
|
||||
/**
|
||||
* Cantonal law, all 26 cantons, through LexFind (lexfind.ch): the register of
|
||||
* Swiss cantonal and federal legislation run by the Institute of Federalism of
|
||||
* the University of Fribourg. It indexes each canton's own collection and
|
||||
* serves the text as the canton published it.
|
||||
*
|
||||
* Its public JSON API (the one its own site uses) finds an act by
|
||||
* abbreviation, title or systematic number; the text comes as the official
|
||||
* PDF, read here with unpdf, which Causius already uses for documents. A PDF
|
||||
* mixes page headers and margin notes into the text: repeated header lines
|
||||
* are removed, margin headings may remain, and the agent is told so.
|
||||
*/
|
||||
import { extractText, getDocumentProxy } from "unpdf";
|
||||
import type { LawLanguage, ReadArticle } from "./fedlex";
|
||||
|
||||
const BASE = "https://www.lexfind.ch";
|
||||
|
||||
export interface CantonalAct {
|
||||
tolId: number;
|
||||
title: string;
|
||||
abbreviation: string;
|
||||
/** The canton's systematic number, e.g. "631.1" (LS for Zürich). */
|
||||
number: string;
|
||||
pdf: string;
|
||||
/** The canton's own page for it, the link a person opens. */
|
||||
official: string;
|
||||
inForceSince: string;
|
||||
}
|
||||
|
||||
type Fetch = typeof fetch;
|
||||
|
||||
let entities: Promise<Record<string, number>> | null = null;
|
||||
|
||||
/** LexFind's id for a canton by its code ("ZH" → 26). */
|
||||
async function entityId(canton: string, doFetch: Fetch): Promise<number | null> {
|
||||
entities ??= doFetch(`${BASE}/api/fe/de/entities`, { signal: AbortSignal.timeout(30_000) })
|
||||
.then((r) => (r.ok ? r.json() : Promise.reject(new Error(String(r.status)))))
|
||||
.then((list: { id: number; abbreviation: string }[]) => Object.fromEntries(list.map((e) => [e.abbreviation.toUpperCase(), e.id])))
|
||||
.catch((e) => {
|
||||
entities = null;
|
||||
throw e;
|
||||
});
|
||||
return (await entities)[canton.toUpperCase()] ?? null;
|
||||
}
|
||||
|
||||
interface Match {
|
||||
title: string;
|
||||
keywords: string | null;
|
||||
is_active: boolean;
|
||||
version_active_since: string | null;
|
||||
category?: { name: string };
|
||||
}
|
||||
interface Hit {
|
||||
id: number;
|
||||
systematic_number: string;
|
||||
is_active: boolean;
|
||||
dta_urls: { language: string; url: string; original_url?: string }[];
|
||||
matches: Match[];
|
||||
}
|
||||
|
||||
const acts = new Map<string, CantonalAct | null>();
|
||||
|
||||
/** The act in force in `canton` that `act` names: its abbreviation (StG), systematic number (631.1) or title. */
|
||||
export async function findCantonalAct(canton: string, act: string, lang: LawLanguage, doFetch: Fetch = fetch): Promise<CantonalAct | null> {
|
||||
const key = `${canton}|${act}|${lang}`.toLowerCase();
|
||||
if (acts.has(key)) return acts.get(key)!;
|
||||
const entity = await entityId(canton, doFetch);
|
||||
if (entity === null) return null;
|
||||
const byNumber = /^\d+(\.\d+)*$/.test(act.trim());
|
||||
const created = await doFetch(`${BASE}/api/fe/${lang}/fulltext-search`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
search_text: act.trim(),
|
||||
entity_filter: [entity],
|
||||
active_only: true,
|
||||
search_in_systematic_number: byNumber,
|
||||
search_in_title: !byNumber,
|
||||
search_in_keywords: !byNumber,
|
||||
search_in_content: false,
|
||||
systematic_filter: [],
|
||||
category_filter: [],
|
||||
use_global_systematics: false,
|
||||
direct_search: false,
|
||||
}),
|
||||
signal: AbortSignal.timeout(30_000),
|
||||
});
|
||||
if (!created.ok) throw new Error(`lexfind search ${created.status}`);
|
||||
const { id, session_id } = (await created.json()) as { id: number; session_id: string };
|
||||
const res = await doFetch(
|
||||
`${BASE}/api/fe/${lang}/fulltext-search/${id}?session_id=${session_id}&page_no=1&results_per_page=20`,
|
||||
{ signal: AbortSignal.timeout(30_000) },
|
||||
);
|
||||
if (!res.ok) throw new Error(`lexfind results ${res.status}`);
|
||||
const hits = ((await res.json()) as { texts_of_law_with_matches?: Hit[] }).texts_of_law_with_matches ?? [];
|
||||
const wanted = act.trim().toLowerCase();
|
||||
const scored = hits
|
||||
.filter((h) => h.is_active)
|
||||
.map((h) => {
|
||||
const m = h.matches.find((x) => x.is_active) ?? h.matches[0];
|
||||
const keywords = (m?.keywords ?? "").toLowerCase().split(/[,;]\s*/);
|
||||
const named =
|
||||
(byNumber && h.systematic_number === act.trim() ? 4 : 0) +
|
||||
(keywords.includes(wanted) ? 4 : 0) +
|
||||
((m?.title ?? "").toLowerCase() === wanted ? 3 : 0);
|
||||
// The category only breaks a tie between acts that ARE named so.
|
||||
const score = named ? named + (m?.category?.name === "Gesetz" || m?.category?.name === "Loi" ? 1 : 0) : 0;
|
||||
return { h, m, score };
|
||||
})
|
||||
.filter((x) => x.m && x.score > 0)
|
||||
.sort((a, b) => b.score - a.score);
|
||||
const best = scored[0];
|
||||
const file = best?.h.dta_urls.find((u) => u.language === lang) ?? best?.h.dta_urls[0];
|
||||
const found =
|
||||
best && file
|
||||
? {
|
||||
tolId: best.h.id,
|
||||
title: best.m!.title,
|
||||
abbreviation: best.m!.keywords ?? act.trim(),
|
||||
number: best.h.systematic_number,
|
||||
pdf: `${BASE}${file.url}`,
|
||||
official: file.original_url ?? `${BASE}${file.url}`,
|
||||
inForceSince: best.m!.version_active_since ?? "",
|
||||
}
|
||||
: null;
|
||||
acts.set(key, found);
|
||||
return found;
|
||||
}
|
||||
|
||||
const texts = new Map<string, string>();
|
||||
const TEXTS_KEPT = 6;
|
||||
|
||||
/** The act's text as lines, without the header and footer lines repeated on every page. */
|
||||
export function cleanPdfText(raw: string): string {
|
||||
const lines = raw.split("\n").map((l) => l.replace(/\s+/g, " ").trim());
|
||||
const counts = new Map<string, number>();
|
||||
for (const l of lines) if (l) counts.set(l, (counts.get(l) ?? 0) + 1);
|
||||
return (
|
||||
lines
|
||||
.filter((l) => l && (counts.get(l) ?? 0) < 8 && !/^\d{1,4}$/.test(l) && !/^\d{1,2}\. ?\d{1,2}\. ?\d{2,4} - \d+$/.test(l))
|
||||
.join("\n")
|
||||
// A word hyphenated across a line break is one word ("Steuer-\npflichtige"),
|
||||
// unless the next is a conjunction ("Einkommens-\nund Vermögenssteuern").
|
||||
.replace(/(\p{L})-\n(?!(?:und|oder|bzw|et|ou|e|o)\b)(\p{Ll})/gu, "$1$2")
|
||||
);
|
||||
}
|
||||
|
||||
/** "§ 140", "140", "Art. 12a" → a pattern for the provision's own heading and one for the next heading. */
|
||||
function headings(provision: string): { start: RegExp; next: RegExp } | null {
|
||||
const m = /^\s*(§|art(?:\.|ikel|icle|icolo)?)?\s*(\d+)\s*([a-z]*)\s*$/i.exec(provision);
|
||||
if (!m) return null;
|
||||
const n = `${m[2]}${m[3] ? `\\s*${m[3]}` : ""}`;
|
||||
const sign = m[1] === "§" ? "§" : m[1] ? "Art\\." : "(?:§|Art\\.)";
|
||||
return {
|
||||
// A heading is the sign and number followed by a period or by the text,
|
||||
// never by "Abs." / "al." / "lit." / "cpv." as a reference to it is.
|
||||
// A margin note can run into a heading ("Steuerarten§ 1."), so anything
|
||||
// but a digit may come before it.
|
||||
start: new RegExp(`(?<![0-9])${sign}\\s*${n}(?![0-9a-z])\\.?\\s+(?!Abs\\.|al\\.|lit\\.|let\\.|cpv\\.|und\\b|et\\b|bis\\s+\\d|ff?\\.)`, "m"),
|
||||
next: new RegExp(
|
||||
`(?<![0-9])(?:§|Art\\.)\\s*\\d+\\s*[a-z]*\\.?\\s+(?!Abs\\.|al\\.|lit\\.|let\\.|cpv\\.|Ziff\\.|ch\\.)(?=\\d\\s+[A-ZÄÖÜÉÈ]|[A-ZÄÖÜÉÈ])`,
|
||||
"m",
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
/** One provision cut out of a cleaned act text, or null. */
|
||||
export function extractCantonalProvision(text: string, provision: string): string | null {
|
||||
const h = headings(provision);
|
||||
if (!h) return null;
|
||||
const start = h.start.exec(text);
|
||||
if (!start) return null;
|
||||
const rest = text.slice(start.index + start[0].length);
|
||||
const end = h.next.exec(rest);
|
||||
const body = rest.slice(0, end ? end.index : 4000).slice(0, 4000);
|
||||
return `${start[0].trim()} ${body.trim()}`.trim();
|
||||
}
|
||||
|
||||
async function actText(act: CantonalAct, doFetch: Fetch): Promise<string> {
|
||||
const kept = texts.get(act.pdf);
|
||||
if (kept) return kept;
|
||||
const res = await doFetch(act.pdf, { signal: AbortSignal.timeout(60_000) });
|
||||
if (!res.ok) throw new Error(`lexfind pdf ${res.status}`);
|
||||
const pdf = await getDocumentProxy(new Uint8Array(await res.arrayBuffer()));
|
||||
const text = cleanPdfText(String((await extractText(pdf, { mergePages: true })).text));
|
||||
if (texts.size >= TEXTS_KEPT) texts.delete(texts.keys().next().value!);
|
||||
texts.set(act.pdf, text);
|
||||
return text;
|
||||
}
|
||||
|
||||
/** One provision of a cantonal act in force today. */
|
||||
export async function readCantonalProvision(input: {
|
||||
canton: string;
|
||||
act: string;
|
||||
provision: string;
|
||||
lang: LawLanguage;
|
||||
fetchImpl?: Fetch;
|
||||
}): Promise<(ReadArticle & { act?: CantonalAct }) | null> {
|
||||
const doFetch = input.fetchImpl ?? fetch;
|
||||
let act: CantonalAct | null;
|
||||
try {
|
||||
act = await findCantonalAct(input.canton, input.act, input.lang, doFetch);
|
||||
} catch {
|
||||
return { ok: false, reason: "unreachable" };
|
||||
}
|
||||
if (!act) return null;
|
||||
try {
|
||||
const text = extractCantonalProvision(await actText(act, doFetch), input.provision);
|
||||
if (!text) return { ok: false, reason: "no_such_article" };
|
||||
const heading = text.split(/\s+/).slice(0, 2).join(" ").replace(/\.$/, "");
|
||||
return {
|
||||
ok: true,
|
||||
act,
|
||||
article: { heading, text: text.slice(heading.length).replace(/^\.?\s*/, ""), url: act.official, inForceSince: act.inForceSince },
|
||||
};
|
||||
} catch {
|
||||
return { ok: false, reason: "unreachable" };
|
||||
}
|
||||
}
|
||||
@@ -264,7 +264,7 @@ describe("the answer check", () => {
|
||||
expect(model.seen[0]).toContain('"name":"web_search"');
|
||||
expect(model.seen[1]).not.toContain('"name":"web_search"');
|
||||
expect(model.seen[1]).toContain("Search is not available for the rest of this turn");
|
||||
expect(model.seen[2]).toContain("read_law for a Swiss federal or Liechtenstein act");
|
||||
expect(model.seen[2]).toContain("read_law for a Swiss federal, cantonal or Liechtenstein act");
|
||||
expect(model.seen[3]).toContain("Fedlex could not be reached");
|
||||
const view = (await loadMatter(db, MASTER, id, OWNER))!;
|
||||
expect(view.events.some((e) => e.kind === "step" && e.tool === "unverified")).toBe(true);
|
||||
@@ -298,7 +298,7 @@ describe("reading the law", () => {
|
||||
text: "Can I contest my rent increase?",
|
||||
});
|
||||
expect(outcome).toMatchObject({ ok: true });
|
||||
expect(model.seen[1]).toContain("read_law for a Swiss federal or Liechtenstein act");
|
||||
expect(model.seen[1]).toContain("read_law for a Swiss federal, cantonal or Liechtenstein act");
|
||||
expect(model.seen[2]).toContain("official text from Fedlex, in force since 2026-10-01");
|
||||
const view = (await loadMatter(db, MASTER, id, OWNER))!;
|
||||
const answer = view.events.filter((e) => e.kind === "message" && e.role === "assistant").at(-1);
|
||||
|
||||
@@ -84,7 +84,7 @@ const SYSTEM = `You are Causius, a legal assistant working one matter for the pe
|
||||
|
||||
How you work:
|
||||
- Be concrete and practical. Say what the person should do, in what order, by when.
|
||||
- Ground statements of law in sources. For Swiss federal and Liechtenstein law, read the provision itself with read_law (act "OR", article "270b") before you state it: it returns the official text in force today with its [n]. Use web_search and read_page for cantonal law, decisions and official guidance, and cite them as [n] using the numbers given in the results. Every sentence that states a rule of law ends with its [n]; a rule you could not find a source for is marked as unverified. Prefer the official text (the statute, the authority's own page) over commentary. Never invent a statute, article, decision or deadline, and do not overstate how widely a rule applies. If you are unsure, say so and say how to find out.
|
||||
- Ground statements of law in sources. For Swiss federal, cantonal and Liechtenstein law, read the provision itself with read_law (act "OR", article "270b") before you state it: it returns the official text in force today with its [n]. Use web_search and read_page for cantonal law, decisions and official guidance, and cite them as [n] using the numbers given in the results. Every sentence that states a rule of law ends with its [n]; a rule you could not find a source for is marked as unverified. Prefer the official text (the statute, the authority's own page) over commentary. Never invent a statute, article, decision or deadline, and do not overstate how widely a rule applies. If you are unsure, say so and say how to find out.
|
||||
- Distinguish levels of law (national, and regional where regions make their own law). The notes on this matter's jurisdiction, if any, say what applies there.
|
||||
- Record every deadline you find or compute with record_deadline, quoting the text it comes from. If a deadline depends on a rule (e.g. "30 days from notification"), say which rule and what you assumed.
|
||||
- In your first turn on a new matter, call update_matter to give it a clear title, its area of law and its jurisdiction code. Record important facts with note_fact.
|
||||
@@ -138,13 +138,14 @@ const TOOLS = [
|
||||
function: {
|
||||
name: "read_law",
|
||||
description:
|
||||
"Read one provision of the law from its official collection: the text in force today and its link. Swiss federal acts (Fedlex): abbreviation (OR, ZGB, SchKG, ZPO, DBG, AIG, StGB, CO, CC, LP…) or SR number (220), and the article (270b). Liechtenstein (gesetze.li): LV, ABGB, PGR, SR, ZPO, StGB, StPO, LVG, AuG, SteG, ArG, and the article or § (\"Art. 12\", \"§ 1090\"; ABGB tenancy is \"Art. n\"). The matter's country is read first. Cite it by the [n] it returns.",
|
||||
"Read one provision of the law from its official collection: the text in force today and its link. Swiss federal acts (Fedlex): abbreviation (OR, ZGB, SchKG, ZPO, DBG, AIG, StGB, CO, CC, LP…) or SR number (220), and the article (270b). Cantonal acts of all 26 cantons (LexFind, the canton's official text): the canton's abbreviation (StG), systematic number (631.1) or title, and the § or Art. (\"§ 140\"). Liechtenstein (gesetze.li): LV, ABGB, PGR, SR, ZPO, StGB, StPO, LVG, AuG, SteG, ArG, and the article or § (\"Art. 12\", \"§ 1090\"; ABGB tenancy is \"Art. n\"). The matter's country is read first. Cite it by the [n] it returns.",
|
||||
parameters: {
|
||||
type: "object",
|
||||
properties: {
|
||||
act: { type: "string" },
|
||||
article: { type: "string" },
|
||||
language: { type: "string", enum: ["de", "fr", "it"] },
|
||||
canton: { type: "string", description: "Two letters (ZH, BE, GE…) for a cantonal act; defaults to the matter's canton." },
|
||||
},
|
||||
required: ["act", "article"],
|
||||
},
|
||||
@@ -318,6 +319,7 @@ const ARGS = {
|
||||
act: z.string().trim().min(1).max(40),
|
||||
article: z.string().trim().min(1).max(20),
|
||||
language: z.enum(["de", "fr", "it"]).optional(),
|
||||
canton: z.string().trim().regex(/^[A-Za-z]{2}$/).optional(),
|
||||
}),
|
||||
check_domain: z.object({
|
||||
names: z.array(z.string().trim().min(1).max(253)).min(1).max(10),
|
||||
@@ -804,9 +806,10 @@ async function runTurnLocked(input: {
|
||||
lang: (args.language as LawLanguage | undefined) ?? "de",
|
||||
day: swissToday(),
|
||||
country: jurisdiction?.split("-")[0],
|
||||
canton: args.canton?.toUpperCase() ?? (jurisdiction?.startsWith("CH-") ? jurisdiction.slice(3) : null),
|
||||
});
|
||||
if ("unknown" in found)
|
||||
return `"${args.act}" is not an act read_law knows. For a Swiss federal act give its SR number (every Fedlex page shows it); for cantonal, foreign or other law use web_search.`;
|
||||
return `"${args.act}" is not an act read_law found. For a Swiss federal act give its SR number; for a cantonal act give the canton (canton: "ZH") and its abbreviation, number or title; for foreign law use web_search.`;
|
||||
const { result, cite, collection } = found;
|
||||
if (!result.ok) {
|
||||
if (result.reason === "unreachable") canReadLaw = false;
|
||||
|
||||
@@ -68,7 +68,7 @@ export function repairPrompt(problems: readonly AnswerProblem[]): string {
|
||||
? "Your answer describes tool calls instead of making them. Nothing you described has happened. Call the tools now (natively, or with the TOOL/ARGS lines), then answer."
|
||||
: p === "unrecorded"
|
||||
? "Your answer gives a deadline, but none is recorded in the matter. Call record_deadline now for each deadline, quoting the text it comes from, then answer."
|
||||
: "Your answer states rules of law, but this turn consulted no source. Read each one now: read_law for a Swiss federal or Liechtenstein act (act and article), web_search and read_page for anything else. Cite each as [n], and drop or mark as unverified any rule you cannot source.",
|
||||
: "Your answer states rules of law, but this turn consulted no source. Read each one now: read_law for a Swiss federal, cantonal or Liechtenstein act (act and article), web_search and read_page for anything else. Cite each as [n], and drop or mark as unverified any rule you cannot source.",
|
||||
);
|
||||
return `${lines.join("\n")}\nDo not apologise or mention this message; just do it.`;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { FEDERAL_ACTS } from "../lib/law/acts";
|
||||
import { readFederalArticle } from "../lib/law/fedlex";
|
||||
import { readCantonalProvision } from "../lib/law/lexfind";
|
||||
import { LI_ACTS, readLiechtensteinProvision } from "../lib/law/lilex";
|
||||
|
||||
/**
|
||||
@@ -48,4 +49,14 @@ describe("Fedlex, live", () => {
|
||||
expect(r.ok || r.reason === "no_such_article", `${act}: ${r.ok ? "" : r.reason}`).toBe(true);
|
||||
}
|
||||
}, 600_000);
|
||||
|
||||
it.each([
|
||||
["ZH", "StG", "§ 140", "de", /innert 30 Tagen nach Zustellung/],
|
||||
["BE", "StG", "Art. 187", "de", /Quelle besteuerte Personen/],
|
||||
["VD", "LI", "Art. 1", "fr", /impôt sur le revenu/],
|
||||
] as const)("canton %s %s %s (LexFind)", async (canton, act, provision, lang, says) => {
|
||||
const r = await readCantonalProvision({ canton, act, provision, lang });
|
||||
expect(r && r.ok && r.article.text).toMatch(says);
|
||||
console.log(`[law] ${canton} ${act} ${provision} ${r && r.ok ? `${r.act?.title} ${r.article.url}` : JSON.stringify(r)}`);
|
||||
}, 120_000);
|
||||
});
|
||||
Reference in new issue
Block a user