Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions core/include/gitmind/attribution.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* SPDX-License-Identifier: LicenseRef-MIND-UCAL-1.0 */
/* © 2025 J. Kirby Ross / Neuroglyph Collective */

#ifndef GITMIND_ATTRIBUTION_H
#define GITMIND_ATTRIBUTION_H

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

#ifdef __cplusplus
extern "C" {
#endif

/**
* @file attribution.h
* @brief Attribution metadata for edge tracking
*/

/* Buffer sizes for attribution fields */
#define GM_ATTRIBUTION_AUTHOR_SIZE 64
#define GM_ATTRIBUTION_SESSION_ID_SIZE 32

/* Source types for edge attribution */
typedef enum {
GM_SOURCE_HUMAN = 0, /**< Human-created edge */
GM_SOURCE_AI_CLAUDE = 1, /**< Claude AI via MCP */
GM_SOURCE_AI_GPT = 2, /**< GPT-4 or similar */
GM_SOURCE_AI_OTHER = 3, /**< Other AI systems */
GM_SOURCE_SYSTEM = 4, /**< System-generated (e.g., AUGMENTS) */
GM_SOURCE_IMPORT = 5, /**< Imported from external source */
GM_SOURCE_UNKNOWN = 255 /**< Unknown source */
} gm_source_type_t;

/* Attribution metadata */
typedef struct {
gm_source_type_t source_type; /**< Who created this edge */
char author[GM_ATTRIBUTION_AUTHOR_SIZE]; /**< Email or identifier */
char session_id[GM_ATTRIBUTION_SESSION_ID_SIZE]; /**< Session/conversation ID */
uint32_t flags; /**< Future expansion */
} gm_attribution_t;

#ifdef __cplusplus
}
#endif

#endif /* GITMIND_ATTRIBUTION_H */
32 changes: 32 additions & 0 deletions core/include/gitmind/constants.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* SPDX-License-Identifier: LicenseRef-MIND-UCAL-1.0 */
/* © 2025 J. Kirby Ross / Neuroglyph Collective */

#ifndef GITMIND_CONSTANTS_H
#define GITMIND_CONSTANTS_H

/**
* @file constants.h
* @brief String and numeric constants for git-mind
*/

/* String constants for relationship types */
#define GM_STR_IMPLEMENTS "implements"
#define GM_STR_REFERENCES "references"
#define GM_STR_DEPENDS_ON "depends_on"
#define GM_STR_AUGMENTS "augments"
#define GM_STR_CUSTOM "custom"

/* Environment variable values for source types */
#define GM_ENV_VAL_HUMAN "human"
#define GM_ENV_VAL_CLAUDE "claude"
#define GM_ENV_VAL_GPT "gpt"
#define GM_ENV_VAL_SYSTEM "system"

/* Confidence range constants */
#define GM_CONFIDENCE_MIN 0.0f
#define GM_CONFIDENCE_MAX 1.0f

/* Format buffer sizes */
#define GM_FORMAT_BUFFER_SIZE 512

#endif /* GITMIND_CONSTANTS_H */
49 changes: 49 additions & 0 deletions core/include/gitmind/context.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* SPDX-License-Identifier: LicenseRef-MIND-UCAL-1.0 */
/* © 2025 J. Kirby Ross / Neuroglyph Collective */

#ifndef GITMIND_CONTEXT_H
#define GITMIND_CONTEXT_H

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

#ifdef __cplusplus
extern "C" {
#endif

/**
* @file context.h
* @brief Context structure for dependency injection
*/

/* Time operations for testing */
typedef struct gm_time_ops {
time_t (*time)(time_t *tloc);
int (*clock_gettime)(int clk_id, struct timespec *timespec);
} gm_time_ops_t;

/* Context for dependency injection */
typedef struct gm_context {
/* Git operations */
struct {
int (*resolve_blob)(void *repo, const char *path, uint8_t *sha);
int (*create_commit)(void *repo, const char *ref, const void *data,
size_t len);
int (*read_commits)(void *repo, const char *ref, void *callback,
void *userdata);
} git_ops;

/* Time operations for dependency injection */
const gm_time_ops_t *time_ops;

/* User data */
void *git_repo;
void *user_data;
} gm_context_t;

#ifdef __cplusplus
}
#endif

#endif /* GITMIND_CONTEXT_H */
106 changes: 106 additions & 0 deletions core/include/gitmind/edge.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/* SPDX-License-Identifier: LicenseRef-MIND-UCAL-1.0 */
/* © 2025 J. Kirby Ross / Neuroglyph Collective */

#ifndef GITMIND_EDGE_H
#define GITMIND_EDGE_H

#include "gitmind/result.h"
#include "gitmind/types.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
* @file edge.h
* @brief Edge operations for the git-mind knowledge graph
*
* This module provides functionality for creating, manipulating, and
* serializing edges in the knowledge graph. Edges represent relationships
* between git objects (typically file blobs).
*/

/* Forward declarations */
typedef struct gm_context gm_context_t;

/**
* Edge structure representing a directed relationship between two git objects
*/
typedef struct gm_edge {
uint8_t src_sha[GM_SHA1_SIZE]; /**< Source object SHA-1 */
uint8_t tgt_sha[GM_SHA1_SIZE]; /**< Target object SHA-1 */
uint16_t rel_type; /**< Relationship type */
uint16_t confidence; /**< Confidence (IEEE-754 half float) */
uint64_t timestamp; /**< Creation time (Unix millis) */
char src_path[GM_PATH_MAX]; /**< Source file path */
char tgt_path[GM_PATH_MAX]; /**< Target file path */
char ulid[GM_ULID_SIZE + 1]; /**< Unique identifier */
} gm_edge_t;

/* Define result type for edge operations */
GM_RESULT_DEF(gm_result_edge, gm_edge_t);

/**
* Create an edge between two files
*
* Resolves paths to Git blob SHAs and generates a ULID for the edge.
*
* @param ctx Context with Git repository
* @param src_path Source file path
* @param tgt_path Target file path
* @param rel_type Relationship type
* @return Result containing edge on success, error on failure
*/
gm_result_edge_t gm_edge_create(gm_context_t *ctx, const char *src_path,
const char *tgt_path, gm_rel_type_t rel_type);

/**
* Compare two edges for equality
*
* Edges are considered equal if they have the same source SHA, target SHA,
* and relationship type.
*
* @param edge_a First edge
* @param edge_b Second edge
* @return true if edges are equal, false otherwise
*/
bool gm_edge_equal(const gm_edge_t *edge_a, const gm_edge_t *edge_b);

/**
* Format an edge as a human-readable string
*
* @param edge Edge to format
* @param[out] buffer Output buffer
* @param len Buffer length
* @return Result containing success or error
*/
gm_result_void_t gm_edge_format(const gm_edge_t *edge, char *buffer, size_t len);

/**
* Encode edge to CBOR format
*
* @param edge Edge to encode
* @param[out] buffer Output buffer
* @param[in,out] len In: buffer size, Out: bytes written
* @return Result containing success or error
*/
gm_result_void_t gm_edge_encode_cbor(const gm_edge_t *edge, uint8_t *buffer,
size_t *len);

/**
* Decode edge from CBOR format
*
* @param buffer CBOR data
* @param len Buffer length
* @return Result containing edge on success, error on failure
*/
gm_result_edge_t gm_edge_decode_cbor(const uint8_t *buffer, size_t len);

#ifdef __cplusplus
}
#endif

#endif /* GITMIND_EDGE_H */
126 changes: 126 additions & 0 deletions core/include/gitmind/edge_attributed.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/* SPDX-License-Identifier: LicenseRef-MIND-UCAL-1.0 */
/* © 2025 J. Kirby Ross / Neuroglyph Collective */

#ifndef GITMIND_EDGE_ATTRIBUTED_H
#define GITMIND_EDGE_ATTRIBUTED_H

#include "gitmind/attribution.h"
#include "gitmind/edge.h"
#include "gitmind/result.h"
#include "gitmind/types.h"
#include <stddef.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
* @file edge_attributed.h
* @brief Attributed edge operations for the git-mind knowledge graph
*
* This module extends basic edges with attribution metadata, including
* author information, source type (human/AI), and confidence scores.
*/

/**
* Lane types for edge organization
*/
typedef enum {
GM_LANE_PRIMARY = 0, /**< Primary knowledge lane */
GM_LANE_EXPLORATION = 1,/**< Exploratory connections */
GM_LANE_REVIEW = 2, /**< Under review */
GM_LANE_ARCHIVED = 3 /**< Archived/deprecated */
} gm_lane_type_t;

/**
* Attributed edge structure with full metadata
*/
typedef struct gm_edge_attributed {
/* Base edge fields */
uint8_t src_sha[GM_SHA1_SIZE]; /**< Source object SHA-1 */
uint8_t tgt_sha[GM_SHA1_SIZE]; /**< Target object SHA-1 */
uint16_t rel_type; /**< Relationship type */
uint16_t confidence; /**< Confidence (IEEE-754 half float) */
uint64_t timestamp; /**< Creation time (Unix millis) */
char src_path[GM_PATH_MAX]; /**< Source file path */
char tgt_path[GM_PATH_MAX]; /**< Target file path */
char ulid[GM_ULID_SIZE + 1]; /**< Unique identifier */

/* Attribution fields */
gm_attribution_t attribution; /**< Author and source metadata */
gm_lane_type_t lane; /**< Knowledge lane */
} gm_edge_attributed_t;

/* Define result types for attributed edge operations */
GM_RESULT_DEF(gm_result_edge_attributed, gm_edge_attributed_t);
GM_RESULT_DEF(gm_result_uint16, uint16_t);

/**
* Convert float confidence to IEEE 754 half-float representation
*
* @param confidence Confidence value (0.0 to 1.0)
* @return Half-float representation
*/
uint16_t gm_confidence_to_half_float(float confidence);

/**
* Convert IEEE 754 half-float to regular float
*
* @param half_float Half-float value
* @return Confidence value (0.0 to 1.0)
*/
float gm_confidence_from_half_float(uint16_t half_float);

/**
* Parse confidence string to half-float
*
* @param str String representation of confidence (e.g., "0.95")
* @return Result containing half-float value on success, error on failure
*/
gm_result_uint16_t gm_confidence_parse(const char *str);

/**
* Create an attributed edge with full metadata
*
* @param ctx Context with Git repository
* @param src_path Source file path
* @param tgt_path Target file path
* @param rel_type Relationship type
* @param confidence Confidence score (half-float)
* @param attribution Attribution metadata
* @param lane Knowledge lane
* @return Result containing edge on success, error on failure
*/
gm_result_edge_attributed_t gm_edge_attributed_create(
gm_context_t *ctx, const char *src_path, const char *tgt_path,
gm_rel_type_t relationship_type, uint16_t confidence_value,
const gm_attribution_t *attribution, gm_lane_type_t lane);

/**
* Format attributed edge without attribution info (legacy format)
*
* @param edge Edge to format
* @param[out] buffer Output buffer
* @param len Buffer length
* @return Result containing success or error
*/
gm_result_void_t gm_edge_attributed_format(const gm_edge_attributed_t *edge,
char *buffer, size_t len);

/**
* Format attributed edge with full attribution information
*
* @param edge Edge to format
* @param[out] buffer Output buffer
* @param len Buffer length
* @return Result containing success or error
*/
gm_result_void_t gm_edge_attributed_format_with_attribution(
const gm_edge_attributed_t *edge, char *buffer, size_t len);

#ifdef __cplusplus
}
#endif

#endif /* GITMIND_EDGE_ATTRIBUTED_H */
4 changes: 2 additions & 2 deletions core/include/gitmind/security/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static inline int gm_vsnprintf(char *str, size_t size, const char *format, va_li
}

/* Safe snprintf wrapper that suppresses security warnings */
static inline int gm_snprintf(char *str, size_t size, const char *format, ...) {
static int gm_snprintf(char *str, size_t size, const char *format, ...) {
va_list args;
va_start(args, format);
int result = gm_vsnprintf(str, size, format, args);
Expand All @@ -35,7 +35,7 @@ static inline int gm_snprintf(char *str, size_t size, const char *format, ...) {
}

/* Safe fprintf wrapper for stderr output */
static inline int gm_fprintf_stderr(const char *format, ...) {
__attribute__((unused)) static int gm_fprintf_stderr(const char *format, ...) {
assert(format != nullptr && "gm_fprintf_stderr: format cannot be null");
va_list args;
va_start(args, format);
Expand Down
Loading
Loading