Skip to content
suit Documentation
Login

Documentation

#ifndef SUIT_RESOLVE_H
#define SUIT_RESOLVE_H

#include "conf.h"

#include <stddef.h>
#include <stdint.h>

// Resolve works out the placements of the User scope from a parsed config and
// a listing of the store. It reads nothing and changes nothing.

typedef enum { AK_SKILL, AK_AGENT, AK_COMMAND, AK_INSTRUCTIONS, AK_FILE, AK_SLOT, AK_COUNT } AssetKind;

constexpr uint32_t ASSET_MAX = 2048;       // names per kind
constexpr uint32_t PLACE_MAX = 4096;       // placements
constexpr uint32_t SKIP_MAX = 1024;        // skipped lines
constexpr size_t SKIP_LEN = 256;
constexpr size_t PLAN_TEXT_MAX = 524288;   // paths in a plan

// What the store holds: for a skill the name is the folder's name; for an
// agent or a command the name is the file's name without a trailing ".md".
typedef struct {
    uint32_t n;
    const char *name[ASSET_MAX];
    const char *file[ASSET_MAX];
} NameList;

typedef struct {
    NameList list[AK_COMMAND + 1];  // skills, agents, commands
} Assets;

typedef struct {
    const char *dest;
    const char *src;
    const char *harness;  // "-" for a file or a slot
    AssetKind kind;
} Placement;

typedef struct {
    uint32_t n;
    Placement p[PLACE_MAX];
    uint32_t nskips;
    char skips[SKIP_MAX][SKIP_LEN];  // "skipped ..." lines
    char text[PLAN_TEXT_MAX];
    size_t used;
    bool overflow;  // a path did not fit in text
} Plan;

typedef struct {
    char msg[512];
} ResolveError;

// HOME expands a leading ~; STORE is the store's folder and SUIT_HOME holds
// slots/. On success P is sorted by destination with no duplicates.
[[nodiscard]] bool resolve(const Conf *conf, const Assets *assets, const char *home,
    const char *suit_home, const char *store, Plan *p, ResolveError *err);

// The kind's name as the config and the reports spell it.
const char *asset_kind_name(AssetKind kind);

// True if NAME matches PATTERN, where * matches any run of characters.
bool glob_match(const char *pattern, const char *name);

#endif