NAME
Skilletor::State - Instance state under ~/.claude/skilletor – trust, the sync lock and the records a sync keeps
VERSION
version 0.008000
SYNOPSIS
use Skilletor::State;
my $state = Skilletor::State->for_home( $ENV{HOME} ); # ~/.claude/skilletor
$state->trust( team => { kind => 'git', address => 'https://example.com/team/skills' } );
my $ok = $state->is_trusted( team => { kind => 'git', address => '…', origin => 'project' } );
DESCRIPTION
The reference's state.ts: trust (spec §4.3), the sync lock (spec §6.5) and the records a sync keeps for check (spec §14.3). Both implementations read and write the same files, the same bytes: entries keep their order, a new key is appended, a file is written only when its content changes, and an unreadable file counts as empty.
trust.json: a source only a project config declares is not fetched until the user trusts it – name, backend kind and address.unreached.json,sources-read.json,render-inputs.json: per scope, keyed by its lock path – the drift the last sync left in place with every source at hand (k70), what it read of each source and through which backend (k80), the hash of what it rendered with (k76). Skilletor::Engine writes and reads them.last-check.json: when the in-session check last ran per key.pending-report.json: per project, the hook output a background sync left for one of its next prompts to show.session-cwd.json: per session id, the cwd its hook last looked at and when ({ cwd, at }), for the 256 sessions recorded last.hermes-home.json: the Hermes home the user scope was synced under ({ home }), while Hermes is a target and the home is not Hermes' default.
root
The state directory; created when the object is.
read_once
True: the object parses each file once and hands out that object from then on (k250) – one run's view, for a check, which only reads, and for the holder of the sync lock, the one writer of the records a sync keeps. A write, or the removal of hermes-home.json, drops the file from the view, so the next read parses what was written; "with_lock" empties the view as it takes the lock and as it gives it up. Off by default: a hook's records (last-check.json, pending-report.json, session-cwd.json) are written outside the lock, and each read sees what another run wrote.
for_home
Skilletor::State->for_home($home);
default_root
<home>/.claude/skilletor.
trust
$state->trust( $name, { kind => 'git', address => $url } );
Replaces an earlier entry of the name.
is_trusted
$state->is_trusted( $name, { kind => ..., address => ..., origin => 'user' | 'project' } );
unreached
my $ids = $state->unreached($lock_path); # [ 'missing:skills/x@shared', ... ]
put_unreached
$state->put_unreached( $lock_path, \@ids ); # sorted, deduplicated; none drops the key
It drops the records of scopes that are gone, as "put_sources_read" does (k255).
sources_read
my $read = $state->sources_read($lock_path);
# { shared => { kind, address, version, ref?, path? } } – malformed entries left out
put_sources_read
$state->put_sources_read( $lock_path, \%read ); # names sorted; none drops the key
It drops the records of scopes that are gone, too: a key that is no absolute path, or whose lock's directory no longer exists (k254). The scope written stays, and so does one whose directory holds no lock.
render_inputs
my $hash = $state->render_inputs($lock_path); # 'sha256:…' or undef
put_render_inputs
$state->put_render_inputs( $lock_path, $hash ); # undef drops it
It drops the records of scopes that are gone, as "put_sources_read" does (k255).
is_due
$state->is_due( $key, $interval_seconds );
True when no check was marked for the key, or the interval has passed.
mark_checked
$state->mark_checked($key); # the project dir; is_due is false for the interval
It drops the marks of projects that are gone, too: a key that is no absolute path, or whose directory itself no longer exists (k255) – a project without .claude keeps its mark. The key marked stays. "is_due" and "clear_checked" drop nothing.
clear_checked
$state->clear_checked($key); # the next is_due is true; nothing written for a key not marked
due_again
$state->due_again($key);
"clear_checked", best effort: a sync that timed out on the sync lock synced nothing, so the next prompt is due and retries. Never throws.
put_pending_report
$state->put_pending_report( $project_dir, { systemMessage => '…' } );
take_pending_report
my $output = $state->take_pending_report($project_dir); # undef: none
Returns the project's pending report and removes it from the file.
session_cwd
my $cwd = $state->session_cwd($session_id); # undef: none recorded
put_session_cwd
$state->put_session_cwd( $session_id, $cwd );
Records the session's cwd with the time in ms; writes nothing when it is the recorded one. Keeps the 256 sessions recorded last: the others are dropped, oldest first.
hermes_home
put_hermes_home
my $home = $state->hermes_home; # undef: none recorded
$state->put_hermes_home('/home/me/hermes-b'); # record it
$state->put_hermes_home(undef); # drop the record
The Hermes home the user scope's hermes: entries were synced under (spec §16.2). A record that is no non-empty string is none. The file is written, or removed, only when the record changes.
with_lock
my $result = $state->with_lock( sub { ... }, timeout_ms => 5000 );
Runs the code holding <root>/sync.lock/, the mutex the reference takes around every resolve, sync and read of the source cache – the same directory, taken the same way, so the two implementations exclude each other. It waits for another holder up to timeout_ms (default 5000), breaking a lock a dead run left (no refresh for stale_ms, default 300000; an owner-less directory after grace_ms, default 2000), then throws Skilletor::Error::LockTimeout. While the code runs, a forked child refreshes the owner record every refresh_ms (default 10000). On Windows, which has no fork to spare, the holder refreshes it itself, at most every refresh_ms, each time it waits on a program through Skilletor::Process – a resolve's git runs, not an HTTP download; win32 => 1 takes this way on any system, for a test. The lock is released however the code ends; its result (in the caller's context) is returned and its exception rethrown. A "read_once" object reads every file afresh under the lock, and once more after it.
A stop the process can catch while it takes or holds the lock – SIGTERM, SIGINT, SIGHUP, each where it would end the process: no handler of the program's own, not ignored – releases every lock the process holds, then ends it by that signal (k251). Not on Windows, where a process is ended without a signal it can catch. A SIGKILL leaves the lock: the next run breaks it once its record, of this host and a pid that is gone, missed two refreshes.
SUPPORT
Issues
Please report bugs and feature requests at https://github.com/Getty/skilletor/issues.
CONTRIBUTING
Contributions are welcome! Please fork the repository and submit a pull request.
AUTHOR
Torsten Raudssus <torsten@raudssus.de>
COPYRIGHT AND LICENSE
This software is Copyright (c) 2026 by Torsten Raudssus <torsten@raudssus.de> https://raudssus.de/.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)