/*
 * Copyright 2026, Jaime Terrats.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import { existsSync } from 'node:fs';
import { join } from 'node:path';
import { ensureDir } from './file-writer.js';
const LOCAL_STATE_FILES = ['decisions.jsonl', 'handoffs.jsonl', 'evidence.jsonl', 'tasks.jsonl'];
export function setupLocalState(cwd, writer) {
    const stateDir = join(cwd, '.setup-agents', 'state');
    ensureDir(stateDir);
    writer.write(join(stateDir, 'README.md'), localStateReadme());
    for (const file of LOCAL_STATE_FILES) {
        const fullPath = join(stateDir, file);
        if (!existsSync(fullPath))
            writer.write(fullPath, '');
    }
    return { path: stateDir, files: [...LOCAL_STATE_FILES] };
}
function localStateReadme() {
    return [
        '# Setup Agents Local State',
        '',
        'This directory stores lightweight project-local coordination records for AI agents.',
        'Files use JSON Lines so agents can append entries without rewriting the full history.',
        '',
        '## Files',
        '',
        '- `decisions.jsonl` — key decisions, rationale, owner, and timestamp.',
        '- `handoffs.jsonl` — role-to-role handoff summaries, changed files, risks, and next actions.',
        '- `evidence.jsonl` — command, file, screenshot, trace, report, or validation evidence.',
        '- `tasks.jsonl` — append-only task create, claim, and completion records.',
        '',
        '## Entry Contract',
        '',
        'Each line should be a JSON object with these common fields:',
        '',
        '```json',
        '{"id":"local-<timestamp>","task":"optional-task-id","role":"developer","summary":"short summary","createdAt":"2026-05-06T00:00:00.000Z"}',
        '```',
        '',
        'Tools may add type-specific fields, but they should preserve the common fields above.',
        'Do not store secrets, credentials, tokens, or raw sensitive customer data in local state.',
    ].join('\n');
}
//# sourceMappingURL=local-state.js.map