/* sensor.h — filesystem perception: TWO cheap features (no open) + costly observation. */
#ifndef BASAL_SENSOR_H
#define BASAL_SENSOR_H
#include <stddef.h>
/* The thing predicted: is this file hand-written SOURCE or a build artifact
* (GENERATED)? Determined by whether any ANCESTOR directory is a build marker
* (node_modules, dist, __pycache__, ...) — context the two cheap features
* (extension + immediate-parent name) cannot see directly. */
enum { CLASS_SOURCE = 0, CLASS_GENERATED = 1, NUM_CLASSES = 2 };
/* One file. Two features knowable WITHOUT opening: extension and parent-dir name.
* `klass` is the observation, computed lazily on the first open. */
typedef struct {
char *path;
int f_ext; /* extension feature id */
int f_dir; /* parent-directory-name feature id */
int klass; /* -1 until opened */
} File;
/* A growing table mapping strings <-> small integer feature ids. */
typedef struct {
char **names;
size_t count, cap;
} FeatureTable;
typedef struct {
File *files;
size_t count, cap;
FeatureTable ext; /* extension vocabulary */
FeatureTable dir; /* parent-dir-name vocabulary */
} Corpus;
int corpus_collect(Corpus *c, const char *root);
void corpus_free(Corpus *c);
int sensor_open(Corpus *c, size_t i); /* the costly act */
const char *ext_name(const Corpus *c, int f);
const char *dir_name(const Corpus *c, int f);
#endif