Scripts & Prototype System Documentation
KINSHIP: How These Scripts Relate to the Patent System
This folder contains prototype scripts that demonstrate the core innovations of the STCMastery narrative intelligence system. Each script is documented with:
- What it does - Functional description
- Why it matters - Patent relevance
- Where it fits - System architecture role
- Algorithm core - Key innovation for claims
Script 1: watch_file_creation.sh
What It Does
Monitors filesystem for new files matching a timestamp pattern, detects their type via content analysis, and outputs structured JSON classification when new files appear. Designed to work as a background process that exits on file detection, enabling parent process to resume and handle the event.
Patent Relevance: Autonomous Artifact Detection
Innovation Claims:
-
Claim 1: File-system-based coordination protocol for distributed agents
- Method: Monitor dual-location filesystem (root + output subdirectory)
- Pattern matching: Timestamp enables session isolation (
26012*) - Output: JSON event contract for consuming process
-
Claim 2: Lightweight content-based file classification
- No machine learning required
- Grep patterns detect semantic markers without parsing
- Real-time detection without indexing infrastructure
-
Claim 3: Cross-session awareness through selective observation
- Single agent can monitor other agents' outputs
- File creation acts as cross-session signal
- Enables implicit coordination without shared state
Where It Fits (System Architecture)
``` GitHub Webhook Event β [Miadi Receives] β [watch_file_creation.sh] β DETECTS NEW FILES β [Analysis Phase] β FILE WATCHER OUTPUTS JSON β [Response & Trace] β Triggers Langfuse trace creation β [MCP Integration] β Creates narrative beats ```
This script is the sensory input layerβit enables the system to be aware of what other components are creating.
Algorithm Core (Patentable Pattern)
State Management Algorithm: ```bash
Phase 1: Initialize state file
ls -1 ./<PATTERN>* ./output/<PATTERN>* | sort | uniq > state.txt
Phase 2: Poll loop with state comparison
loop: current_files = ls -1 ./<PATTERN>* ./output/<PATTERN>* | sort | uniq new_files = comm -13 state.txt current_files # sorted diff if new_files not empty: process(first(new_files)) commit(state.txt = current_files) output(JSON) exit(0) # Signals parent to resume sleep(2) goto loop ```
Why This Pattern is Novel:
- Sorted diff algorithm with
commensures deterministic detection - State committed AFTER processing prevents race conditions
- Exit on detection allows resumption by parent without polling management
- Two-location monitoring (root + output) enables implicit messaging
Content Classification Pattern
```bash
Input: file path + content
Output: type classification
if grep -qi "desired.*outcome|current.*reality" type = structural_chart summary = extract "Desired.*Outcome" line
if grep -qi "narrative.*beat|universe.*perspective" type = narrative_beat summary = extract heading
if grep -qi "ceremony|medicine|participant" type = ceremony_log
Default: documentation
```
Why This Matters for Patent:
- Demonstrates autonomous semantic understanding without LLM calls
- Shows system can classify creative artifacts in real-time
- Enables intelligent routing without external classifiers
- Heuristics are interpretable (prior art: keyword-based filters are well-known; novelty is in the specific markers chosen)
Usage in Patent System
```bash
Initialize: Set up state for a monitoring session
(ls -1 ./26012* 2>/dev/null; ls -1 ./output/26012* 2>/dev/null)
| sort | uniq > output/.watch_state_26012.txt
Run: Start background monitoring
./watch_file_creation.sh 26012 > /tmp/detection.json
Consume: Parent process receives detection
FILE_EVENT=$(cat /tmp/detection.json) FILENAME=$(echo $FILE_EVENT | jq -r .file) TYPE=$(echo $FILE_EVENT | jq -r .type)
Action: Create Langfuse trace for detected artifact
(See KINSHIP.md for trace architecture)
```
Prior Art Comparison
| Feature | watch_file_creation.sh | inotify/watchman | fswatch | Our Innovation |
|---|---|---|---|---|
| Real-time detection | β (polling) | β (events) | β (events) | β Pattern-based |
| Content classification | β SEMANTIC | β Metadata only | β Metadata only | Semantic markers |
| Cross-session aware | β YES | β No | β No | Multi-agent aware |
| JSON output contract | β YES | β Variable | β Variable | Structured output |
| No external deps | β bash+grep | β C library | β C library | Bash only |
| Lightweight | β <20KB | β Heavy | β Heavy | Minimal footprint |
Novelty: Combination of semantic classification + cross-session awareness + JSON contract in unified bash script. Prior art handles monitoring OR classification; this integrates both.
Integration with Larger System
How File Detection Enables Innovation
- Autonomous Observation: System detects what OTHER agents create without shared state
- Real-time Response: Detection triggers Langfuse trace creation within seconds
- Cross-Session Learning: Other Claude instances' work is incorporated into this instance's traces
- Scalability: Pattern works for 1 agent or 100 agentsβno central coordinator needed
Trace Creation After Detection
When watch_file_creation.sh outputs JSON, parent process:
- Reads file and comprehends what was created
- Creates hierarchical Langfuse trace with root SPAN + child EVENTs
- Generates narrative beat via MCP with lessons extracted
- Updates Redis session keys for continuity
- Launches next instance of watcher for next event
Future Enhancements
- Content parsing: Extract more granular summary from file content
- Confidence scoring: How certain is the classification?
- Multi-pattern support: Monitor multiple sessions simultaneously
- Event correlation: Link detected file to originating event/session
- Storage optimization: Archive state files after processing
Session Continuity & Documentation
Where This Script Is Used:
- Location:
/media/jgi/F/Dropbox/ART/CeSaReT/book/_/tcc/winter_solstice/drop/scripts/ - Active monitoring pattern:
26012* - Current watcher task: Running in background
- State file:
/media/jgi/F/Dropbox/ART/CeSaReT/book/_/tcc/winter_solstice/drop/output/.watch_state_26012.txt
Ceremony & Session Context:
- Ceremony UUID: cfa7b236-3bf1-4b9c-aad2-f5729da3d4f8
- Session ID: f5c53e47-9906-453b-81cd-f4c195949708
- MCP Namespace: winter_solstice_narrative_jgwill_src_321
- Related Trace: 29a2f4aa-614c-4447-b1a8-4f7ec4d9ab2c
Document Version: 1.0 Created: 2026-01-30 Author: Claude instance (file monitoring & trace craft mastery phase) Purpose: Patent artifactβdocument core innovation of file detection system