ausername-12345 commited on
Commit
eb0bb4e
·
1 Parent(s): 0b2dd22

add project file names to prompt; handle <css> and <javascript> tags

Browse files
Files changed (1) hide show
  1. src/agent.js +32 -2
src/agent.js CHANGED
@@ -12,7 +12,7 @@ const fs = require('fs');
12
  const projectRoot = path.resolve(__dirname, '..');
13
 
14
  function systemPrompt() {
15
- return `${AGENT_NAME}. To edit files, use <write path/to/file>content</write>. To read, use <read path/to/file>. Be concise.`;
16
  }
17
 
18
  function makeLogEntry(type, fields = {}) {
@@ -62,7 +62,37 @@ function processFileActions(content) {
62
  actions.push({ type: 'write', path: filePath });
63
  } catch (err) { actions.push({ type: 'ignored', message: `could not write ${filePath}: ${err.message}` }); }
64
  }
65
- text = text.replace(writeRe, '').trim();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
 
67
  return { cleanText: text, actions };
68
  }
 
12
  const projectRoot = path.resolve(__dirname, '..');
13
 
14
  function systemPrompt() {
15
+ return `${AGENT_NAME}. Project files: public/index.html, public/styles.css, public/app.js, src/*.js, server.js. To edit: <write path>content</write>. To read: <read path>. Tactical and concise.`;
16
  }
17
 
18
  function makeLogEntry(type, fields = {}) {
 
62
  actions.push({ type: 'write', path: filePath });
63
  } catch (err) { actions.push({ type: 'ignored', message: `could not write ${filePath}: ${err.message}` }); }
64
  }
65
+ text = text.replace(writeRe, '');
66
+
67
+ // Handle <css> as write to public/styles.css
68
+ const cssRe = /<css>([\s\S]*?)<\/css>/g;
69
+ while ((m = cssRe.exec(content)) !== null) {
70
+ const cssContent = m[1];
71
+ const absPath = path.resolve(projectRoot, 'public/styles.css');
72
+ try {
73
+ const existing = fs.readFileSync(absPath, 'utf8');
74
+ fs.writeFileSync(absPath, existing + '\n' + cssContent, 'utf8');
75
+ } catch {
76
+ fs.writeFileSync(absPath, cssContent, 'utf8');
77
+ }
78
+ actions.push({ type: 'write', path: 'public/styles.css (appended)' });
79
+ }
80
+ text = text.replace(cssRe, '');
81
+
82
+ // Handle <javascript> as write to public/app.js
83
+ const jsRe = /<javascript>([\s\S]*?)<\/javascript>/g;
84
+ while ((m = jsRe.exec(content)) !== null) {
85
+ const jsContent = m[1];
86
+ const absPath = path.resolve(projectRoot, 'public/app.js');
87
+ try {
88
+ const existing = fs.readFileSync(absPath, 'utf8');
89
+ fs.writeFileSync(absPath, existing + '\n' + jsContent, 'utf8');
90
+ } catch {
91
+ fs.writeFileSync(absPath, jsContent, 'utf8');
92
+ }
93
+ actions.push({ type: 'write', path: 'public/app.js (appended)' });
94
+ }
95
+ text = text.replace(jsRe, '').trim();
96
 
97
  return { cleanText: text, actions };
98
  }