dsdb#
The ds command#
Live session on an empty program#
ds
ds with no argument opens the shell on a live session whose program is empty.
The program is built up with definitions.
(Source: tools/dsdb/lib/cli/main.js)
Shell#
ds [PROG.dsc | PROG.ds -L DIR...] [TRACE | FACTS...] [-f]
This form opens the shell on the program and what it is given.
A
.dsis compiled with its own directory and then each-Lon the search path.A trace that embeds its program needs no other.
A
.dsgiven with a.dscis checked against it, and is its source if the.dscembeds none.With a trace, the session replays it. Without one, the session is live, and its wall clock reads the Unix epoch at its clock’s
0.Fact files start a live session: each row is fed as in batch, deadline stops included. Each row and each deadline stop is a step of its own on the session’s timeline, and point opens at the end. Fact files and a trace together are a usage error.
(Source: tools/dsdb/lib/cli/main.js, tools/dsdb/lib/cli/open.js, tools/dsdb/lib/api/open.js, tools/dsdb/lib/core/engine-timeline.js, Spec: [LDEB.2.2], [LDEB.2.3])
Batch#
ds -b (PROG.dsc | PROG.ds -L DIR...) FACTS... [--out DIR --format csv|tsv|jsonl]
[--calls SOCK | --listen SOCK] [--pumps N] [--call-timeout SECONDS] [--until D]
This form runs the facts through the program with no shell, and reads nothing from stdin.
The engine runs on a mock clock from 0. Each merged row moves the clock forward to its @at, never back, then is asserted and pumped. Before the clock moves to a later row, it stops at each engine deadline earlier than that row, and the engine pumps there; a deadline a stop’s pump arms is read before the clock moves on, and a deadline at the row’s own @at takes no step of its own. The wall clock reads the Unix epoch at 0 and moves with the mock clock, so now(), and a ts a rule’s emit or publish fills, read a row’s @at.
With --until D, after the rows and the reply cycles, the clock moves to D through each engine deadline earlier than D, pumping at each, and the engine pumps once at D. A row past D is refused with exit 1, naming the file and line. Without it, the run ends at the last row’s time.
The output is what the rules publish, every schema keyed, each slot as it was when published. An emitted fact is not output. A run that emitted and published nothing says so on stderr.
Without
--out, the output is one JSON document on stdout, in the form of a.jsonfact file.With
--out DIR --format F, each schema is written toDIR/<own name>.F, in the form of that format’s fact file.DIRis created.--outand--formatgo together.
A call is reported on stderr, and is made only with --calls or --listen.
ds -b -q rules.dsc Reading.csv --out out --format jsonl --until 10_s
(Spec: [NLFC.2.5], Source: tools/dsdb/lib/cli/main.js, tools/dsdb/lib/core/batch.js, tools/dsdb/lib/core/facts.js, tools/dsdb/lib/core/facts-out.js)
Listing#
ds -b [PROG.dsc | PROG.ds -L DIR...] TRACE [-f] [--from SEQ]
This form lists a trace as text, its facts typed by the program it was recorded with.
A line starts with the atom’s
seqas 8 hex digits, blank for an atom with none, and its message name. AStreamHeadertakes one line per field.A program given types the facts. Without one, the program the trace embeds does. With neither, a fact’s line says its slots are not typed.
An atom whose body is not decoded is named with its length.
--from SEQomits atoms beforeSEQ, aseqin hex, as a listing prints it. Anything but hex digits is a usage error, exit2. An atom with noseqis always listed.-fkeeps reading as the file grows, until interrupted. A partial atom at the end is read when it is whole.Without
-f, a trace that ends in a partial atom lists every complete atom, names the partial atom’s offset on stderr, and exits0.
A program given is put to the binding check before any record is read. Bytes that cannot be read as an atom are named by offset on stderr, with exit 1.
The format is The fact stream.
(Source: tools/dsdb/lib/cli/main.js, tools/dsdb/lib/text/listing.js)
Binding check#
The shell and the listing check a trace against the program they pair it with, and refuse a mismatch with exit 3.
The trace’s |
Outcome |
|---|---|
|
refused with |
neither |
no check |
both, the program stating no |
no check |
both |
|
A dsc_hash that differs is DS_ERR_BND_DSC_MISMATCH. capabilities that differ, in membership or in order, or a dialect_def_sha256 that differs, is DS_ERR_BND_DIALECT_MISMATCH.
A refusal writes ds: the trace was not recorded with this program (<code>) to stderr, then a line naming the field that differs and each side’s value, a hash as its first 16 hex digits. Where no check is made, stderr says the trace’s program cannot be checked.
(Spec: [RFCS.4.5], [RBND.2.1], Source: tools/dsdb/lib/core/binding.js, tools/dsdb/lib/api/open.js, tools/dsdb/lib/cli/main.js)
Subcommands#
Form |
Page |
|---|---|
|
|
|
|
|
|
|
|
|
A word one edit or one swap from a subcommand, naming no file, is a usage error that names the subcommand.
(Source: tools/dsdb/lib/cli/main.js)
--version#
ds --version
--version prints the version of ds, then the libds and the compiler it runs on.
The libds line names the target, native or wasm. A libds or a compiler that is absent is stated on its line, with exit 0.
(Source: tools/dsdb/lib/cli/main.js)
Options#
Option |
Value |
Effect |
|---|---|---|
|
none |
the shell; the default |
|
none |
no shell |
|
none |
stream events on stderr; the default |
|
none |
with |
|
none |
take in what is appended to the trace |
|
a directory |
adds a library directory; accumulates |
|
a directory |
batch output directory |
|
|
batch output format |
|
a |
listing start |
|
a socket path |
calls socket to connect to |
|
a socket path |
calls socket to make |
|
a whole number from |
pump cycles; default |
|
seconds, |
how long a cycle waits for replies; default |
|
a duration from the start, such as |
batch end time |
|
none |
the usage on stdout, exit |
--out, --format, --from, --calls, --listen, --pumps, --call-timeout and --until are refused without -b, exit 2.
With -b, each form refuses the options it does not read, exit 2:
Form |
Refused |
|---|---|
|
|
batch with neither |
|
|
-q and -L are taken by every form with -b.
-q changes batch alone. ds -b with no -q writes each stream event to stderr. A rule’s log, a call and a reply reach stderr under -q too.
--pumps above 1 needs --calls or --listen. --calls and --listen exclude each other, and need a program and fact files. After a subcommand, -h prints that subcommand’s usage.
(Source: tools/dsdb/lib/cli/main.js)
File kinds#
ds recognises a file by its name.
Name |
Kind |
|---|---|
ends |
|
ends |
a program |
ends |
a program’s source |
anything else |
a trace |
(Source: tools/dsdb/lib/cli/main.js, tools/dsdb/lib/core/facts.js)
Exit statuses#
Status |
Meaning |
|---|---|
|
done, help or the version asked for, |
|
the input was refused: a fact file, the engine or the compiler; or a malformed trace |
|
a usage error, or a |
|
a trace the binding check refuses |
|
a file that cannot be read or is not a trace, |
(Source: tools/dsdb/lib/cli/main.js, tools/dsdb/lib/cli/open.js, tools/dsdb/lib/api/open.js)
Fact files#
File names#
<own name>.csv, <own name>.tsv, <own name>.jsonl, <name>.json
A .csv, .tsv or .jsonl file holds one schema’s rows, and its name is that schema’s own name. A .json file holds every schema it names.
A library schema’s file is named for its own name: board_model.Soc.csv. One schema has one source across the files given.
(Source: tools/dsdb/lib/core/facts.js)
@at#
@at
@at is a row’s time from the session’s start: a duration literal (12_s) or whole nanoseconds.
Absent or null, it is 0. A value past the longest Duration is refused. @at is the only column that is not a slot.
Rows merge by @at, then by the order the files were given, then by row.
A row of a schema that declares ts and gives none takes its @at as its ts, from the Unix epoch. A ts the row gives is kept as given, and a null one is refused.
(Spec: [LFAC.9.1], Source: tools/dsdb/lib/core/facts.js)
CSV#
<own name>.csv
RFC 4180, with the first record as the header.
A bare empty field is null, and in a String slot that is not nullable, the empty string. A quoted "" is the empty string.
(Source: tools/dsdb/lib/core/facts.js)
TSV#
<own name>.tsv
Tab-separated, one record per line, no quoting, with the first record as the header.
A field of exactly \N is null. \t, \n, \r and \\ are the escapes, and any other is refused. An empty field is the empty string.
(Source: tools/dsdb/lib/core/facts.js)
JSONL#
<own name>.jsonl
One JSON object per line, keyed by slot. A blank line is skipped.
(Source: tools/dsdb/lib/core/facts.js)
JSON#
<name>.json
One JSON object: each schema’s own name, then an array of its rows as JSONL’s objects.
{ "Reading": [ { "@at": "1_s", "id": "a", "level": 85.0 } ] }
(Source: tools/dsdb/lib/core/facts.js)
Cell types#
A cell is read as its slot’s type.
Slot type |
Cell |
|---|---|
|
an integer; in JSON, a number or a string of digits |
|
a number, or |
|
|
|
text; in JSON, a string |
|
JSON text; in JSONL and JSON, also the value itself |
|
base64 text |
A nan cell in a Float slot is refused with DS_ERR_NAN_REJECTED, exit 1, naming the file and line (NaN values). A reference to another fact is refused. A slot with no column or key is left to the engine. A column that names no slot is refused.
(Spec: [LEXP.4.2], Source: tools/dsdb/lib/core/facts.js, tools/dsdb/lib/cli/main.js)
Calls socket#
Connecting#
--calls SOCK, --listen SOCK
The calls socket is a Unix domain socket carrying one JSON object per line, each way.
--calls connects to a socket a responder listens on. --listen makes the socket, says so on stderr, takes the first peer that connects, and removes the file when done. Every file is read and the program compiled before either opens.
(Source: tools/dsdb/lib/cli/socket.js, tools/dsdb/lib/cli/main.js)
Call line#
{"call","service","corr","args","rule","at"}
A call line is one call, sent as it is issued.
call is its number from 1. corr is null for a call with no as. args holds each argument supplied, written as batch writes a slot of its kind, and a fact argument as {"schema","asserted_at","external"}, external in base64. at is the clock from the run’s start as a duration literal.
{"call":1,"service":"svc.op","corr":"q1","args":{"level":3},"rule":"ask","at":"2_s"}
(Source: tools/dsdb/lib/core/calls.js)
Pump cycles#
--pumps N
--pumps is the number of pump cycles batch runs; the facts are the first.
Each later cycle waits up to --call-timeout for a reply to every waiting call, delivers those that came, and pumps once. A cycle with no reply ends the run. Each call no reply reached is named on stderr.
(Source: tools/dsdb/lib/core/batch.js, tools/dsdb/lib/cli/main.js)
The shell#
Lines#
The shell reads one line at a time at a prompt, until quit, exit or the end of input.
A line ending in ( opens a block that a line of ) closes. A definition runs to two blank lines. The prompt shows the calls waiting at point and, on a hypothesis, its number, fork and changes.
(Source: tools/dsdb/lib/cli/shell.js, tools/dsdb/lib/core/session.js)
Point#
Point is the position on the current timeline that commands read.
A position is a record’s seq in hex. A trailing - is the unnamed point before it. A settled point is one where a pump has ended. A duration carries its _.
(Source: tools/dsdb/lib/core/grammar.js)
Timelines#
%0 is the real run, and %N is a hypothesis: a fork of a timeline that runs forward under changed inputs.
(Spec: [LDEB.6.3.1], Source: tools/dsdb/lib/core/session.js)
Help#
help
help lists the commands.
(Source: tools/dsdb/lib/text/session.js)
Quit#
quit, exit
These end the session, exit 0.
(Source: tools/dsdb/lib/core/session.js)
Queries and counts#
Query#
Q
A query is a rule’s left-hand side: Reading r where r.level > 80.0.
A last part -> a, b shows those values for each answer in place of the facts. A library schema is named by its own name: board_model.Soc s.
The compiler is the only parser of Q, and a query it refuses is an error at the prompt.
(Source: tools/dsdb/lib/text/session.js, tools/dsdb/lib/core/session.js, tools/dsdb/lib/core/program.js)
Population#
#. #: #@N
These give the facts per schema: at point, over time, at N.
(Source: tools/dsdb/lib/text/session.js)
Firings#
!. !: !@N
These list rule firings: that led to point, all of them, that led to N.
(Source: tools/dsdb/lib/text/session.js)
Firing counts#
^. ^: ^@N
These give the firings per rule, the same three ways.
(Source: tools/dsdb/lib/text/session.js)
Answers#
?.Q ?:Q ?@N Q
These give the answers to Q: at point, over time, at N.
(Source: tools/dsdb/lib/text/session.js)
Answer counts#
#.Q #:Q #@N Q
These give how many answers: at point, population over time, at N.
(Source: tools/dsdb/lib/text/session.js)
Join#
?.(
This opens a join: one pattern per line, then a line of ).
(Source: tools/dsdb/lib/text/session.js)
Filters#
/regex/, tumbling 1_s, min|max|mean
After #: or ^:, /regex/ filters names, and a trailing tumbling or min|max|mean shapes the histogram.
(Source: tools/dsdb/lib/text/session.js)
Comparison#
?.%0 %1 Q
This compares timelines: + is only in the others, - only in the first.
Within a hypothesis, one named timeline is compared with %0.
(Source: tools/dsdb/lib/text/session.js, tools/dsdb/lib/core/session.js)
Changes at point#
Where a change lands#
from here, from start, from @N
A change at the end of a live %0 applies to it, and anywhere else in %0 it opens a hypothesis.
from start and from @N move point first, and N is a position, <, > or a clock.
(Source: tools/dsdb/lib/text/session.js, tools/dsdb/lib/core/grammar.js)
emit#
from here emit Schema slot: value …
This asserts an input and runs to quiescence.
A library schema is named by its own name. The fact takes the session’s clock as its ts.
(Source: tools/dsdb/lib/text/session.js, tools/dsdb/lib/core/program.js, tools/dsdb/lib/core/changes.js)
withdraw#
from here withdraw #N
This retracts a live fact.
(Source: tools/dsdb/lib/text/session.js)
answer#
from here answer N JSON
This replies to call N.
(Source: tools/dsdb/lib/text/session.js)
fail#
from here fail N code: "…" message: "…"
This fails call N, as a CallError.
(Source: tools/dsdb/lib/text/session.js, tools/dsdb/lib/api/ops.js)
silence#
from here silence N
This drops call N’s recorded reply.
(Source: tools/dsdb/lib/text/session.js)
Advancing#
@+5_s n
At the end of a timeline, these advance the clock on a live session and feed reality on a hypothesis.
(Source: tools/dsdb/lib/text/session.js)
Timeline commands#
hyp#
hyp
This lists the timelines.
(Source: tools/dsdb/lib/text/session.js)
Current timeline#
%
This names the current timeline.
(Source: tools/dsdb/lib/text/session.js)
fg#
fg %N real
These switch timeline; real is fg %0.
(Source: tools/dsdb/lib/text/session.js)
bg and stop#
bg %N stop %N
With bg, %N follows %0’s point. With stop, it stays where it is.
(Source: tools/dsdb/lib/text/session.js)
fork#
fork
This opens a new hypothesis at point.
(Source: tools/dsdb/lib/text/session.js)
kill#
kill %N
This closes a hypothesis.
(Source: tools/dsdb/lib/text/session.js)
save trace#
save trace [%N] PATH
This writes a timeline as a trace.
(Source: tools/dsdb/lib/text/session.js)
changes#
changes
This lists the timeline’s changes at a point, each where it was made.
(Source: tools/dsdb/lib/text/session.js)
The program#
Definitions#
schema …, rule NAME: …, service …
A definition at the prompt, up to two blank lines, is added, or replaces the one of its kind and name.
This and del and mv apply for all time, and every timeline runs again under the edit.
(Source: tools/dsdb/lib/text/session.js, tools/dsdb/lib/cli/shell.js)
del#
del NAME, del KIND NAME, del use, del import MODULE
This removes a definition.
(Source: tools/dsdb/lib/text/session.js)
mv#
mv RULE N, mv RULE before|after OTHER
This moves a rule in the rule order.
(Source: tools/dsdb/lib/text/session.js)
show#
show rule NAME
This prints the rule’s text.
(Source: tools/dsdb/lib/text/session.js)
ls#
ls ls rules
These list the program’s definitions, and the rule order with firings.
(Source: tools/dsdb/lib/text/session.js)
save code#
save code PATH
This writes the program as one file.
(Source: tools/dsdb/lib/text/session.js)
Watching#
watch#
watch Q
This shows Q’s answers arriving (+) and leaving (-) on every move.
(Source: tools/dsdb/lib/text/session.js)
unwatch#
unwatch
This ends the watch.
(Source: tools/dsdb/lib/text/session.js)
next change#
next change, prev change
These move to where the watched answers change.
(Source: tools/dsdb/lib/text/session.js)
Inspecting#
Rows#
N
This drills into row N of the last listing.
(Source: tools/dsdb/lib/text/session.js)
Back and versions#
up < > @[ @]
These go back; to the prior or following version; and to where the fact began or ended.
(Source: tools/dsdb/lib/text/session.js)
match#
match
This runs the inspected fact through the network’s alpha tests.
(Source: tools/dsdb/lib/text/session.js)
why#
why, why #N, why !N, why RULE TT, depth D after any
This gives what led to the fact or firing shown.
(Source: tools/dsdb/lib/text/session.js)
calls#
calls calls all
These list the waiting calls, and every call.
(Source: tools/dsdb/lib/text/session.js)
list#
list [K]
This lists K records either side of point; K defaults to 10.
(Source: tools/dsdb/lib/text/session.js)
The matching network#
rete#
rete [@N] [/re/]
This gives each rule’s chain at point: facts, tokens, activations.
(Source: tools/dsdb/lib/text/session.js)
rete schemas#
rete schemas
This gives the alpha nodes by schema.
(Source: tools/dsdb/lib/text/session.js)
rete dot#
rete dot FILE
This writes the graph as Graphviz.
(Source: tools/dsdb/lib/text/session.js)
whynot#
whynot RULE
This gives how far the rule matches at point, and where it stops.
(Source: tools/dsdb/lib/text/session.js)
ds serve#
Command#
ds serve [--host 127.0.0.1] [--port 7373] [--origin URL]... [--token T] [-L DIR]...
[--root DIR]... [--out DIR] [--shell-lines]
ds serve is a WebSocket a web page drives dsdb’s API over, on this machine only.
It runs until SIGINT or SIGTERM, exit 0. It says where to connect on stderr, the token included. --root and --out confine it as they do ds mcp.
(Source: tools/dsdb/lib/cli/main.js, tools/dsdb/lib/serve/server.js)
Options#
Option |
Value |
Effect |
|---|---|---|
|
|
the address; any other is a usage error |
|
|
the port; default |
|
a URL |
a page origin let in; accumulates |
|
a token |
the token; default 24 random bytes in hex |
|
a directory |
a library directory for every load |
|
a directory |
a directory to read under |
|
a directory |
the directory to write under |
|
none |
turns on |
(Source: tools/dsdb/lib/cli/main.js, tools/dsdb/lib/serve/server.js)
Access#
ws://HOST:PORT/?token=TOKEN
A connection presents the token as ?token=, at path /.
Status |
Refused when |
|---|---|
|
an upgrade that is not to WebSocket, or carries no key |
|
the token is wrong or absent |
|
the |
|
the path is not |
|
the WebSocket version is not |
Without --origin, a page from a loopback address is let in. With it, only the origins named are. A client that sends no Origin is let in by its token alone.
(Source: tools/dsdb/lib/serve/server.js)
Protocol#
JSON-RPC 2.0, one session per connection, requests answered in order.
Method |
Params |
Result |
|---|---|---|
|
none |
|
|
none |
|
|
|
|
|
|
as |
|
none |
as |
|
none |
as |
|
|
as |
A call with a progress token gets progress notifications with token, progress, total and message. resources/list_changed follows a change in the resources listed.
(Source: tools/dsdb/lib/api/rpc.js, tools/dsdb/lib/serve/server.js)