Learn R Programming

aisdk (version 1.1.0)

ProjectMemory: Project Memory Class

Description

R6 class for managing persistent project memory using SQLite. Stores code snippets, error fixes, and execution graphs for resuming failed long-running jobs.

Arguments

Public fields

db_path

Path to the SQLite database file.

project_root

Root directory of the project.

Methods


Method new()

Create or connect to a project memory database.

Usage

ProjectMemory$new(project_root = tempdir(), db_name = "memory.sqlite")

Arguments

project_root

Project root directory. Defaults to tempdir().

db_name

Database filename. Defaults to "memory.sqlite".

Returns

A new ProjectMemory object.


Method store_snippet()

Store a successful code snippet for future reference.

Usage

ProjectMemory$store_snippet(
  code,
  description = NULL,
  tags = NULL,
  context = NULL
)

Arguments

code

The R code that was executed successfully.

description

Optional description of what the code does.

tags

Optional character vector of tags for categorization.

context

Optional context about when/why this code was used.

Returns

The ID of the stored snippet.


Method store_fix()

Store an error fix for learning.

Usage

ProjectMemory$store_fix(
  original_code,
  error,
  fixed_code,
  fix_description = NULL
)

Arguments

original_code

The code that produced the error.

error

The error message.

fixed_code

The corrected code.

fix_description

Description of what was fixed.

Returns

The ID of the stored fix.


Method find_similar_fix()

Find a similar fix from memory.

Usage

ProjectMemory$find_similar_fix(error)

Arguments

error

The error message to match.

Returns

A list with the fix details, or NULL if not found.


Method search_snippets()

Search for relevant code snippets.

Usage

ProjectMemory$search_snippets(query, limit = 10)

Arguments

query

Search query (matches description, tags, or code).

limit

Maximum number of results.

Returns

A data frame of matching snippets.


Method store_workflow_node()

Store execution graph node for workflow persistence.

Usage

ProjectMemory$store_workflow_node(
  workflow_id,
  node_id,
  node_type,
  code,
  status = "pending",
  result = NULL,
  dependencies = NULL
)

Arguments

workflow_id

Unique identifier for the workflow.

node_id

Unique identifier for this node.

node_type

Type of node (e.g., "transform", "model", "output").

code

The code for this node.

status

Node status ("pending", "running", "completed", "failed").

result

Optional serialized result.

dependencies

Character vector of node IDs this depends on.

Returns

The database row ID.


Method update_node_status()

Update workflow node status.

Usage

ProjectMemory$update_node_status(workflow_id, node_id, status, result = NULL)

Arguments

workflow_id

Workflow identifier.

node_id

Node identifier.

status

New status.

result

Optional result to store.


Method get_workflow()

Get workflow state for resuming.

Usage

ProjectMemory$get_workflow(workflow_id)

Arguments

workflow_id

Workflow identifier.

Returns

A list with workflow nodes and their states.


Method get_resumable_nodes()

Resume a failed workflow from the last successful point.

Usage

ProjectMemory$get_resumable_nodes(workflow_id)

Arguments

workflow_id

Workflow identifier.

Returns

List of node IDs that need to be re-executed.


Method store_conversation()

Store a conversation turn for context.

Usage

ProjectMemory$store_conversation(session_id, role, content, metadata = NULL)

Arguments

session_id

Session identifier.

role

Message role ("user", "assistant", "system").

content

Message content.

metadata

Optional metadata list.


Method get_conversation()

Get conversation history for a session.

Usage

ProjectMemory$get_conversation(session_id, limit = 100)

Arguments

session_id

Session identifier.

limit

Maximum number of messages.

Returns

A data frame of conversation messages.


Method store_review()

Store or update a human review for an AI-generated chunk.

Usage

ProjectMemory$store_review(
  chunk_id,
  file_path,
  chunk_label,
  prompt,
  response,
  status = "pending",
  ai_agent = NULL,
  uncertainty = NULL,
  session_id = NULL,
  review_mode = NULL,
  runtime_mode = NULL,
  artifact_json = NULL,
  execution_status = NULL,
  execution_output = NULL,
  final_code = NULL,
  error_message = NULL
)

Arguments

chunk_id

Unique identifier for the chunk.

file_path

Path to the source file.

chunk_label

Chunk label from knitr.

prompt

The prompt sent to the AI.

response

The AI's response.

status

Review status ("pending", "approved", "rejected").

ai_agent

Optional agent name.

uncertainty

Optional uncertainty level.

session_id

Optional session identifier for transcript/provenance.

review_mode

Optional normalized review mode.

runtime_mode

Optional normalized runtime mode.

artifact_json

Optional JSON review artifact payload.

execution_status

Optional execution state.

execution_output

Optional execution output text.

final_code

Optional finalized executable code.

error_message

Optional execution or generation error.

Returns

The database row ID.


Method store_review_artifact()

Store structured review artifact metadata for a chunk.

Usage

ProjectMemory$store_review_artifact(
  chunk_id,
  artifact,
  session_id = NULL,
  review_mode = NULL,
  runtime_mode = NULL
)

Arguments

chunk_id

Chunk identifier.

artifact

A serializable list representing the review artifact.

session_id

Optional session identifier.

review_mode

Optional normalized review mode.

runtime_mode

Optional normalized runtime mode.

Returns

Invisible TRUE.


Method get_review()

Get a review by chunk ID.

Usage

ProjectMemory$get_review(chunk_id)

Arguments

chunk_id

Chunk identifier.

Returns

A list with review details, or NULL if not found.


Method get_review_artifact()

Get a parsed review artifact by chunk ID.

Usage

ProjectMemory$get_review_artifact(chunk_id)

Arguments

chunk_id

Chunk identifier.

Returns

A list artifact, or NULL if none is stored.


Method get_review_runtime_record()

Get a review together with its parsed artifact.

Usage

ProjectMemory$get_review_runtime_record(chunk_id)

Arguments

chunk_id

Chunk identifier.

Returns

A list with review and artifact, or NULL if not found.


Method get_reviews_for_file()

Get all reviews for a given source file.

Usage

ProjectMemory$get_reviews_for_file(file_path)

Arguments

file_path

Source document path.

Returns

A data frame of reviews ordered by updated time.


Method record_review_saveback()

Record a saveback lifecycle event for one or more chunk reviews.

Usage

ProjectMemory$record_review_saveback(
  chunk_ids,
  source_path,
  html_path = NULL,
  status = "requested",
  rerendered = FALSE,
  message = NULL
)

Arguments

chunk_ids

Character vector of chunk identifiers.

source_path

Source document path.

html_path

Optional rendered HTML path.

status

Saveback status string.

rerendered

Whether a rerender occurred.

message

Optional message.

Returns

Invisible TRUE.


Method update_execution_result()

Update execution result fields for a chunk review.

Usage

ProjectMemory$update_execution_result(
  chunk_id,
  execution_status,
  execution_output = NULL,
  final_code = NULL,
  error_message = NULL
)

Arguments

chunk_id

Chunk identifier.

execution_status

Execution state string.

execution_output

Optional execution output text.

final_code

Optional finalized executable code.

error_message

Optional execution error.

Returns

Invisible TRUE.


Method append_review_event()

Append an audit event for a reviewed chunk.

Usage

ProjectMemory$append_review_event(chunk_id, event_type, payload = NULL)

Arguments

chunk_id

Chunk identifier.

event_type

Event type string.

payload

Optional serializable payload list.

Returns

The database row ID.


Method update_review_status()

Update review status.

Usage

ProjectMemory$update_review_status(chunk_id, status)

Arguments

chunk_id

Chunk identifier.

status

New status ("approved" or "rejected").


Method get_pending_reviews()

Get pending reviews, optionally filtered by file.

Usage

ProjectMemory$get_pending_reviews(file_path = NULL)

Arguments

file_path

Optional file path filter.

Returns

A data frame of pending reviews.


Method stats()

Get memory statistics.

Usage

ProjectMemory$stats()

Returns

A list with counts and sizes.


Method clear()

Clear all memory (use with caution).

Usage

ProjectMemory$clear(confirm = FALSE)

Arguments

confirm

Must be TRUE to proceed.


Method print()

Print method for ProjectMemory.

Usage

ProjectMemory$print()


Method clone()

The objects of this class are cloneable with this method.

Usage

ProjectMemory$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.