@aiyiran/myclaw 1.1.202 → 1.1.204
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/myclaw-artifacts.js +499 -11
- package/assets/myclaw-inject.js +110 -9
- package/create_agent.js +15 -11
- package/index.js +8 -0
- package/package.json +1 -1
- package/server/sync_workspace.py +12 -5
- package/skills/yiran-playground-template-use/SKILL.md +4 -4
- package/skills/yiran-playground-template-use/scripts/deploy_to_workspace.py +51 -5
- package/skills/yiran-playground-template-use/scripts/start_tui_handoff.py +22 -4
|
@@ -105,7 +105,7 @@
|
|
|
105
105
|
btn.id = 'myclaw-artifacts-btn';
|
|
106
106
|
btn.style.cssText = [
|
|
107
107
|
'position: fixed',
|
|
108
|
-
'top:
|
|
108
|
+
'top: 0',
|
|
109
109
|
'right: 0',
|
|
110
110
|
'padding: 3px 10px',
|
|
111
111
|
'background: rgba(100, 100, 100, 0.7)',
|
|
@@ -143,19 +143,19 @@
|
|
|
143
143
|
panelVisible = true;
|
|
144
144
|
|
|
145
145
|
var btn = document.querySelector('#myclaw-artifacts-btn');
|
|
146
|
-
if (btn) btn.style.
|
|
146
|
+
if (btn) btn.style.display = 'none';
|
|
147
147
|
|
|
148
148
|
// 面板
|
|
149
149
|
var panel = document.createElement('div');
|
|
150
150
|
panel.id = 'myclaw-artifacts-panel';
|
|
151
151
|
panel.style.cssText = [
|
|
152
152
|
'position: fixed',
|
|
153
|
-
'top:
|
|
153
|
+
'top: 0',
|
|
154
154
|
'right: 0',
|
|
155
155
|
'width: 380px',
|
|
156
|
-
'height:
|
|
156
|
+
'height: calc(100vh - 50px)',
|
|
157
157
|
'background: #1e1e2e',
|
|
158
|
-
'border-radius:
|
|
158
|
+
'border-radius: 0 0 0 8px',
|
|
159
159
|
'overflow: hidden',
|
|
160
160
|
'display: flex',
|
|
161
161
|
'flex-direction: column',
|
|
@@ -311,9 +311,13 @@
|
|
|
311
311
|
panelFooter.appendChild(historyFooterBtn);
|
|
312
312
|
panelFooter.appendChild(forkPanelBtn);
|
|
313
313
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
314
|
+
var workSection = document.createElement('section');
|
|
315
|
+
workSection.className = 'myclaw-artifacts-work-section';
|
|
316
|
+
workSection.appendChild(header);
|
|
317
|
+
workSection.appendChild(content);
|
|
318
|
+
workSection.appendChild(panelFooter);
|
|
319
|
+
panel.appendChild(workSection);
|
|
320
|
+
panel.appendChild(createTrainingCard(null));
|
|
317
321
|
document.body.appendChild(panel);
|
|
318
322
|
|
|
319
323
|
// 立即拉一次,后续由轮询更新
|
|
@@ -323,11 +327,20 @@
|
|
|
323
327
|
// ═══ 关闭右侧面板 ═══
|
|
324
328
|
function closeArtifactsPanel() {
|
|
325
329
|
var panel = document.querySelector('#myclaw-artifacts-panel');
|
|
326
|
-
if (panel)
|
|
330
|
+
if (panel) {
|
|
331
|
+
var trainingCard = panel.querySelector('.myclaw-training-card');
|
|
332
|
+
if (trainingCard && typeof trainingCard._destroyVoiceInputs === 'function') {
|
|
333
|
+
try { trainingCard._destroyVoiceInputs(); } catch (e) {}
|
|
334
|
+
}
|
|
335
|
+
panel.remove();
|
|
336
|
+
}
|
|
327
337
|
panelVisible = false;
|
|
328
338
|
|
|
329
339
|
var btn = document.querySelector('#myclaw-artifacts-btn');
|
|
330
|
-
if (btn)
|
|
340
|
+
if (btn) {
|
|
341
|
+
btn.style.display = '';
|
|
342
|
+
btn.style.background = 'rgba(100, 100, 100, 0.7)';
|
|
343
|
+
}
|
|
331
344
|
}
|
|
332
345
|
|
|
333
346
|
// ═══ 请求数据 ═══
|
|
@@ -674,6 +687,382 @@
|
|
|
674
687
|
return asset.type && IMAGE_TYPES.indexOf(asset.type.toLowerCase()) !== -1;
|
|
675
688
|
}
|
|
676
689
|
|
|
690
|
+
var TRAINING_CARD_STORAGE_PREFIX = 'myclaw-training-card-records-v1:';
|
|
691
|
+
var TRAINING_CARD_STORAGE_LIMIT = 200;
|
|
692
|
+
|
|
693
|
+
function buildTrainingCardPrompt(values) {
|
|
694
|
+
var sections = [];
|
|
695
|
+
function addSection(title, value) {
|
|
696
|
+
if (!value) return;
|
|
697
|
+
sections.push(title, value, '');
|
|
698
|
+
}
|
|
699
|
+
addSection('我最想解决的一个问题是:', values.problem);
|
|
700
|
+
addSection('我想在 10 分钟后达成的目标是:', values.goal);
|
|
701
|
+
addSection('我选择的方案是:', values.plan);
|
|
702
|
+
addSection('我验收的结果是:', values.acceptance);
|
|
703
|
+
sections.push('请只围绕我填写的内容帮助我,不要顺便修改其他内容。');
|
|
704
|
+
return sections.join('\n');
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
function createTrainingRecord(asset, values) {
|
|
708
|
+
var now = new Date();
|
|
709
|
+
return {
|
|
710
|
+
version: 1,
|
|
711
|
+
recordId: 'training-' + now.getTime() + '-' + Math.random().toString(36).slice(2, 8),
|
|
712
|
+
submittedAt: now.toISOString(),
|
|
713
|
+
claw: lastKnownClawName || '',
|
|
714
|
+
workspace: getWorkspaceId(),
|
|
715
|
+
studentAgent: getAgentName(),
|
|
716
|
+
asset: asset ? {
|
|
717
|
+
name: asset.name || '',
|
|
718
|
+
path: asset.path || ''
|
|
719
|
+
} : null,
|
|
720
|
+
problem: values.problem,
|
|
721
|
+
goal: values.goal,
|
|
722
|
+
plan: values.plan,
|
|
723
|
+
acceptance: values.acceptance
|
|
724
|
+
};
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
function loadTrainingRecords(workspace) {
|
|
728
|
+
var key = TRAINING_CARD_STORAGE_PREFIX + workspace;
|
|
729
|
+
var records = [];
|
|
730
|
+
try {
|
|
731
|
+
var stored = JSON.parse(localStorage.getItem(key) || '[]');
|
|
732
|
+
if (Array.isArray(stored)) records = stored;
|
|
733
|
+
} catch (e) {
|
|
734
|
+
records = [];
|
|
735
|
+
}
|
|
736
|
+
return records;
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
function saveTrainingRecordLocally(asset, values, recordId) {
|
|
740
|
+
var workspace = getWorkspaceId();
|
|
741
|
+
var key = TRAINING_CARD_STORAGE_PREFIX + workspace;
|
|
742
|
+
var records = loadTrainingRecords(workspace);
|
|
743
|
+
var recordIndex = -1;
|
|
744
|
+
if (recordId) {
|
|
745
|
+
recordIndex = records.findIndex(function (item) {
|
|
746
|
+
return item && item.recordId === recordId;
|
|
747
|
+
});
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
var isUpdate = recordIndex !== -1;
|
|
751
|
+
var record;
|
|
752
|
+
if (isUpdate) {
|
|
753
|
+
record = Object.assign({}, records[recordIndex], {
|
|
754
|
+
updatedAt: new Date().toISOString(),
|
|
755
|
+
claw: lastKnownClawName || '',
|
|
756
|
+
studentAgent: getAgentName(),
|
|
757
|
+
asset: asset ? {
|
|
758
|
+
name: asset.name || '',
|
|
759
|
+
path: asset.path || ''
|
|
760
|
+
} : null,
|
|
761
|
+
problem: values.problem,
|
|
762
|
+
goal: values.goal,
|
|
763
|
+
plan: values.plan,
|
|
764
|
+
acceptance: values.acceptance
|
|
765
|
+
});
|
|
766
|
+
records[recordIndex] = record;
|
|
767
|
+
} else {
|
|
768
|
+
record = createTrainingRecord(asset, values);
|
|
769
|
+
records.push(record);
|
|
770
|
+
recordIndex = records.length - 1;
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
if (records.length > TRAINING_CARD_STORAGE_LIMIT) {
|
|
774
|
+
records = records.slice(records.length - TRAINING_CARD_STORAGE_LIMIT);
|
|
775
|
+
recordIndex = records.findIndex(function (item) {
|
|
776
|
+
return item && item.recordId === record.recordId;
|
|
777
|
+
});
|
|
778
|
+
}
|
|
779
|
+
localStorage.setItem(key, JSON.stringify(records));
|
|
780
|
+
return {
|
|
781
|
+
record: record,
|
|
782
|
+
index: recordIndex,
|
|
783
|
+
isUpdate: isUpdate
|
|
784
|
+
};
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
function formatTrainingCardNumber(index) {
|
|
788
|
+
var number = index + 1;
|
|
789
|
+
var digits = ['', '一', '二', '三', '四', '五', '六', '七', '八', '九'];
|
|
790
|
+
if (number <= 9) return digits[number];
|
|
791
|
+
if (number === 10) return '十';
|
|
792
|
+
if (number < 20) return '十' + digits[number % 10];
|
|
793
|
+
if (number < 100) {
|
|
794
|
+
return digits[Math.floor(number / 10)] + '十' + digits[number % 10];
|
|
795
|
+
}
|
|
796
|
+
return String(number);
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
function createTrainingCard(asset) {
|
|
800
|
+
var section = document.createElement('section');
|
|
801
|
+
section.className = 'myclaw-training-card';
|
|
802
|
+
var voiceDestroyers = [];
|
|
803
|
+
|
|
804
|
+
var fields = document.createElement('div');
|
|
805
|
+
fields.className = 'myclaw-training-card__fields';
|
|
806
|
+
|
|
807
|
+
function makeField(number, label, prompt, hints, target) {
|
|
808
|
+
var field = document.createElement('label');
|
|
809
|
+
field.className = 'myclaw-training-card__field';
|
|
810
|
+
var fieldHeader = document.createElement('span');
|
|
811
|
+
fieldHeader.className = 'myclaw-training-card__field-header';
|
|
812
|
+
var fieldTitle = document.createElement('span');
|
|
813
|
+
fieldTitle.className = 'myclaw-training-card__field-title';
|
|
814
|
+
fieldTitle.textContent = number + '、' + prompt;
|
|
815
|
+
var hintRow = null;
|
|
816
|
+
if (hints && hints.length) {
|
|
817
|
+
hintRow = document.createElement('span');
|
|
818
|
+
hintRow.className = 'myclaw-training-card__hints';
|
|
819
|
+
hints.forEach(function (hint) {
|
|
820
|
+
var hintTag = document.createElement('span');
|
|
821
|
+
hintTag.className = 'myclaw-training-card__hint';
|
|
822
|
+
hintTag.textContent = hint;
|
|
823
|
+
hintRow.appendChild(hintTag);
|
|
824
|
+
});
|
|
825
|
+
}
|
|
826
|
+
var input = document.createElement('textarea');
|
|
827
|
+
input.rows = 2;
|
|
828
|
+
input.maxLength = 1000;
|
|
829
|
+
input.setAttribute('aria-label', label);
|
|
830
|
+
|
|
831
|
+
var inputWrap = document.createElement('span');
|
|
832
|
+
inputWrap.className = 'myclaw-training-card__input-wrap';
|
|
833
|
+
var micBtn = document.createElement('button');
|
|
834
|
+
micBtn.type = 'button';
|
|
835
|
+
micBtn.className = 'myclaw-training-card__mic';
|
|
836
|
+
micBtn.title = '语音输入';
|
|
837
|
+
micBtn.setAttribute('aria-label', label + '语音输入');
|
|
838
|
+
micBtn.innerHTML = [
|
|
839
|
+
'<svg width="14" height="14" viewBox="0 0 24 24" fill="none"',
|
|
840
|
+
' stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">',
|
|
841
|
+
' <path d="M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z"/>',
|
|
842
|
+
' <path d="M19 10v2a7 7 0 0 1-14 0v-2"/>',
|
|
843
|
+
' <line x1="12" x2="12" y1="19" y2="22"/>',
|
|
844
|
+
'</svg>'
|
|
845
|
+
].join('');
|
|
846
|
+
inputWrap.appendChild(input);
|
|
847
|
+
inputWrap.appendChild(micBtn);
|
|
848
|
+
fieldHeader.appendChild(fieldTitle);
|
|
849
|
+
if (hintRow) fieldHeader.appendChild(hintRow);
|
|
850
|
+
field.appendChild(fieldHeader);
|
|
851
|
+
field.appendChild(inputWrap);
|
|
852
|
+
(target || fields).appendChild(field);
|
|
853
|
+
|
|
854
|
+
if (typeof window.myclawBindVoiceInput === 'function') {
|
|
855
|
+
voiceDestroyers.push(window.myclawBindVoiceInput(input, micBtn));
|
|
856
|
+
} else {
|
|
857
|
+
micBtn.disabled = true;
|
|
858
|
+
micBtn.title = '语音输入暂不可用,请刷新页面';
|
|
859
|
+
}
|
|
860
|
+
return input;
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
var problemInput = makeField(
|
|
864
|
+
'1', '问题',
|
|
865
|
+
'我最想解决的一个问题是:',
|
|
866
|
+
['一个', '具体', '够小']
|
|
867
|
+
);
|
|
868
|
+
var goalInput = makeField(
|
|
869
|
+
'2', '目标',
|
|
870
|
+
'我想在 10 分钟后达成的目标是:',
|
|
871
|
+
['10分钟', '很清楚', '能检查']
|
|
872
|
+
);
|
|
873
|
+
var planInput = makeField(
|
|
874
|
+
'3', '方案',
|
|
875
|
+
'我选择的方案是:',
|
|
876
|
+
['为什么喜欢这个 / 其他的为什么不好']
|
|
877
|
+
);
|
|
878
|
+
section.appendChild(fields);
|
|
879
|
+
|
|
880
|
+
var footer = document.createElement('div');
|
|
881
|
+
footer.className = 'myclaw-training-card__footer';
|
|
882
|
+
var metaRow = document.createElement('div');
|
|
883
|
+
metaRow.className = 'myclaw-training-card__meta-row';
|
|
884
|
+
var status = document.createElement('div');
|
|
885
|
+
status.className = 'myclaw-training-card__status';
|
|
886
|
+
status.setAttribute('role', 'status');
|
|
887
|
+
status.setAttribute('aria-live', 'polite');
|
|
888
|
+
var actions = document.createElement('div');
|
|
889
|
+
actions.className = 'myclaw-training-card__actions';
|
|
890
|
+
var cardActions = document.createElement('div');
|
|
891
|
+
cardActions.className = 'myclaw-training-card__actions myclaw-training-card__card-actions';
|
|
892
|
+
var aiBtn = document.createElement('button');
|
|
893
|
+
aiBtn.type = 'button';
|
|
894
|
+
aiBtn.className = 'myclaw-training-card__button myclaw-training-card__button--ai';
|
|
895
|
+
aiBtn.textContent = '提交 AI';
|
|
896
|
+
var cardBtn = document.createElement('button');
|
|
897
|
+
cardBtn.type = 'button';
|
|
898
|
+
cardBtn.className = 'myclaw-training-card__button myclaw-training-card__button--teacher';
|
|
899
|
+
cardBtn.textContent = '提交卡片';
|
|
900
|
+
actions.appendChild(aiBtn);
|
|
901
|
+
cardActions.appendChild(cardBtn);
|
|
902
|
+
|
|
903
|
+
var history = document.createElement('div');
|
|
904
|
+
history.className = 'myclaw-training-card__history';
|
|
905
|
+
var historyList = document.createElement('div');
|
|
906
|
+
historyList.className = 'myclaw-training-card__history-list';
|
|
907
|
+
history.appendChild(historyList);
|
|
908
|
+
metaRow.appendChild(status);
|
|
909
|
+
footer.appendChild(metaRow);
|
|
910
|
+
footer.appendChild(actions);
|
|
911
|
+
section.appendChild(footer);
|
|
912
|
+
|
|
913
|
+
var acceptanceFields = document.createElement('div');
|
|
914
|
+
acceptanceFields.className = 'myclaw-training-card__fields myclaw-training-card__acceptance';
|
|
915
|
+
var acceptanceInput = makeField(
|
|
916
|
+
'4', '验收',
|
|
917
|
+
'验收',
|
|
918
|
+
['我预期是什么?', '实际是什么?', '问题在哪里?'],
|
|
919
|
+
acceptanceFields
|
|
920
|
+
);
|
|
921
|
+
section.appendChild(acceptanceFields);
|
|
922
|
+
section.appendChild(cardActions);
|
|
923
|
+
section.appendChild(history);
|
|
924
|
+
|
|
925
|
+
var editingRecordId = '';
|
|
926
|
+
|
|
927
|
+
function readValues() {
|
|
928
|
+
return {
|
|
929
|
+
problem: problemInput.value.trim(),
|
|
930
|
+
goal: goalInput.value.trim(),
|
|
931
|
+
plan: planInput.value.trim(),
|
|
932
|
+
acceptance: acceptanceInput.value.trim()
|
|
933
|
+
};
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
function validate(values, includeAcceptance) {
|
|
937
|
+
var missing = [];
|
|
938
|
+
if (!values.problem) missing.push('问题');
|
|
939
|
+
if (!values.goal) missing.push('目标');
|
|
940
|
+
if (!values.plan) missing.push('方案');
|
|
941
|
+
if (includeAcceptance && !values.acceptance) missing.push('验收');
|
|
942
|
+
if (missing.length) {
|
|
943
|
+
status.className = 'myclaw-training-card__status myclaw-training-card__status--error';
|
|
944
|
+
status.textContent = '请先填写:' + missing.join('、');
|
|
945
|
+
return false;
|
|
946
|
+
}
|
|
947
|
+
return true;
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
function updateCardButtonState() {
|
|
951
|
+
var values = readValues();
|
|
952
|
+
var ready = !!(values.problem && values.goal && values.plan && values.acceptance);
|
|
953
|
+
cardBtn.disabled = !ready;
|
|
954
|
+
cardBtn.title = ready ? '保存这张卡片' : '填写问题、目标、方案和验收后即可提交';
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
function clearInputs() {
|
|
958
|
+
problemInput.value = '';
|
|
959
|
+
goalInput.value = '';
|
|
960
|
+
planInput.value = '';
|
|
961
|
+
acceptanceInput.value = '';
|
|
962
|
+
editingRecordId = '';
|
|
963
|
+
updateCardButtonState();
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
function renderHistory() {
|
|
967
|
+
var records = loadTrainingRecords(getWorkspaceId());
|
|
968
|
+
historyList.textContent = '';
|
|
969
|
+
history.hidden = records.length === 0;
|
|
970
|
+
records.forEach(function (record, index) {
|
|
971
|
+
if (!record) return;
|
|
972
|
+
var cardName = '卡片' + formatTrainingCardNumber(index);
|
|
973
|
+
var item = document.createElement('button');
|
|
974
|
+
item.type = 'button';
|
|
975
|
+
item.className = 'myclaw-training-card__history-item';
|
|
976
|
+
if (record.recordId === editingRecordId) {
|
|
977
|
+
item.classList.add('myclaw-training-card__history-item--active');
|
|
978
|
+
}
|
|
979
|
+
item.setAttribute('aria-label', '打开' + cardName);
|
|
980
|
+
|
|
981
|
+
var name = document.createElement('span');
|
|
982
|
+
name.className = 'myclaw-training-card__history-name';
|
|
983
|
+
name.textContent = cardName;
|
|
984
|
+
var preview = document.createElement('span');
|
|
985
|
+
preview.className = 'myclaw-training-card__history-preview';
|
|
986
|
+
preview.textContent = record.problem || '未填写问题';
|
|
987
|
+
item.appendChild(name);
|
|
988
|
+
item.appendChild(preview);
|
|
989
|
+
|
|
990
|
+
item.addEventListener('click', function () {
|
|
991
|
+
problemInput.value = record.problem || '';
|
|
992
|
+
goalInput.value = record.goal || '';
|
|
993
|
+
planInput.value = record.plan || '';
|
|
994
|
+
acceptanceInput.value = record.acceptance || '';
|
|
995
|
+
editingRecordId = record.recordId || '';
|
|
996
|
+
status.className = 'myclaw-training-card__status';
|
|
997
|
+
status.textContent = record.acceptance
|
|
998
|
+
? '正在编辑' + cardName + ',再次提交会更新原卡片。'
|
|
999
|
+
: '正在编辑' + cardName + ',请补充验收后更新。';
|
|
1000
|
+
renderHistory();
|
|
1001
|
+
updateCardButtonState();
|
|
1002
|
+
problemInput.focus();
|
|
1003
|
+
});
|
|
1004
|
+
historyList.appendChild(item);
|
|
1005
|
+
});
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
aiBtn.addEventListener('click', function () {
|
|
1009
|
+
var values = readValues();
|
|
1010
|
+
if (!(values.problem || values.goal || values.plan || values.acceptance)) {
|
|
1011
|
+
status.className = 'myclaw-training-card__status myclaw-training-card__status--error';
|
|
1012
|
+
status.textContent = '请至少填写一项再提交 AI。';
|
|
1013
|
+
return;
|
|
1014
|
+
}
|
|
1015
|
+
if (typeof window.myclawSendPrompt !== 'function') {
|
|
1016
|
+
status.className = 'myclaw-training-card__status myclaw-training-card__status--error';
|
|
1017
|
+
status.textContent = 'AI 提交功能还没有准备好,请刷新页面后重试。';
|
|
1018
|
+
return;
|
|
1019
|
+
}
|
|
1020
|
+
aiBtn.disabled = true;
|
|
1021
|
+
var sent = window.myclawSendPrompt(buildTrainingCardPrompt(values));
|
|
1022
|
+
aiBtn.disabled = false;
|
|
1023
|
+
if (sent) {
|
|
1024
|
+
status.className = 'myclaw-training-card__status myclaw-training-card__status--success';
|
|
1025
|
+
status.textContent = '已提交 AI。可以关闭作品窗口查看回复。';
|
|
1026
|
+
} else {
|
|
1027
|
+
status.className = 'myclaw-training-card__status myclaw-training-card__status--error';
|
|
1028
|
+
status.textContent = '暂时无法发送。请确认 AI 没有正在回复,然后重试。';
|
|
1029
|
+
}
|
|
1030
|
+
});
|
|
1031
|
+
|
|
1032
|
+
cardBtn.addEventListener('click', function () {
|
|
1033
|
+
var values = readValues();
|
|
1034
|
+
if (!validate(values, true)) return;
|
|
1035
|
+
cardBtn.disabled = true;
|
|
1036
|
+
try {
|
|
1037
|
+
var saved = saveTrainingRecordLocally(asset, values, editingRecordId);
|
|
1038
|
+
var cardName = '卡片' + formatTrainingCardNumber(saved.index);
|
|
1039
|
+
clearInputs();
|
|
1040
|
+
renderHistory();
|
|
1041
|
+
status.className = 'myclaw-training-card__status myclaw-training-card__status--success';
|
|
1042
|
+
status.textContent = cardName + (saved.isUpdate ? '已更新' : '已保存') + ',输入框已清空。';
|
|
1043
|
+
} catch (e) {
|
|
1044
|
+
console.error('[myclaw-training-card] 本地归档失败:', e);
|
|
1045
|
+
status.className = 'myclaw-training-card__status myclaw-training-card__status--error';
|
|
1046
|
+
status.textContent = '提交失败,填写内容仍然保留,请重试。';
|
|
1047
|
+
}
|
|
1048
|
+
updateCardButtonState();
|
|
1049
|
+
});
|
|
1050
|
+
|
|
1051
|
+
[problemInput, goalInput, planInput, acceptanceInput].forEach(function (input) {
|
|
1052
|
+
input.addEventListener('input', updateCardButtonState);
|
|
1053
|
+
});
|
|
1054
|
+
updateCardButtonState();
|
|
1055
|
+
renderHistory();
|
|
1056
|
+
|
|
1057
|
+
section._destroyVoiceInputs = function () {
|
|
1058
|
+
voiceDestroyers.forEach(function (destroy) {
|
|
1059
|
+
try { destroy(); } catch (e) {}
|
|
1060
|
+
});
|
|
1061
|
+
voiceDestroyers = [];
|
|
1062
|
+
};
|
|
1063
|
+
return section;
|
|
1064
|
+
}
|
|
1065
|
+
|
|
677
1066
|
function openPreviewModal(data, asset) {
|
|
678
1067
|
if (document.querySelector('#myclaw-artifacts-preview')) return;
|
|
679
1068
|
|
|
@@ -3074,6 +3463,104 @@
|
|
|
3074
3463
|
' from { transform: rotate(0deg); }',
|
|
3075
3464
|
' to { transform: rotate(360deg); }',
|
|
3076
3465
|
'}',
|
|
3466
|
+
'.myclaw-training-card {',
|
|
3467
|
+
' box-sizing: border-box; width: 100%; padding: 5px 10px;',
|
|
3468
|
+
' color: #e5e7eb; background: #191927; border-top: 1px solid #35354d;',
|
|
3469
|
+
' font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;',
|
|
3470
|
+
'}',
|
|
3471
|
+
'.myclaw-artifacts-work-section {',
|
|
3472
|
+
' box-sizing: border-box; min-height: 0; flex: 1 1 0;',
|
|
3473
|
+
' display: flex; flex-direction: column; overflow: hidden;',
|
|
3474
|
+
'}',
|
|
3475
|
+
'.myclaw-artifacts-work-section > #myclaw-artifacts-content { min-height: 0; }',
|
|
3476
|
+
'#myclaw-artifacts-panel > .myclaw-training-card {',
|
|
3477
|
+
' min-height: 0; flex: 1 1 0; overflow: hidden;',
|
|
3478
|
+
'}',
|
|
3479
|
+
'.myclaw-training-card__fields {',
|
|
3480
|
+
' display: grid; grid-template-columns: 1fr; gap: 7px;',
|
|
3481
|
+
'}',
|
|
3482
|
+
'.myclaw-training-card__field {',
|
|
3483
|
+
' min-width: 0; display: flex; flex-direction: column; align-items: stretch; gap: 3px;',
|
|
3484
|
+
'}',
|
|
3485
|
+
'.myclaw-training-card__field-header {',
|
|
3486
|
+
' min-width: 0; display: flex; align-items: center; justify-content: flex-start; gap: 6px;',
|
|
3487
|
+
'}',
|
|
3488
|
+
'.myclaw-training-card__field-title {',
|
|
3489
|
+
' min-width: 0; font-size: 12px; line-height: 1.3; font-weight: 700; color: #d8d8e5;',
|
|
3490
|
+
' white-space: nowrap;',
|
|
3491
|
+
'}',
|
|
3492
|
+
'.myclaw-training-card__hints { display: flex; align-items: center; gap: 3px; flex: 0 0 auto; }',
|
|
3493
|
+
'.myclaw-training-card__hint {',
|
|
3494
|
+
' padding: 0 5px; border: 1px solid #67558f; border-radius: 999px;',
|
|
3495
|
+
' color: #e9ddff; background: rgba(124, 58, 237, 0.22); font-size: 10px; font-weight: 650;',
|
|
3496
|
+
' line-height: 1.35; white-space: nowrap;',
|
|
3497
|
+
'}',
|
|
3498
|
+
'.myclaw-training-card__acceptance {',
|
|
3499
|
+
' margin-top: 4px; padding-top: 4px; border-top: 1px solid #323247;',
|
|
3500
|
+
'}',
|
|
3501
|
+
'.myclaw-training-card__input-wrap {',
|
|
3502
|
+
' min-width: 0; width: 100%; display: flex; align-items: center; gap: 6px;',
|
|
3503
|
+
'}',
|
|
3504
|
+
'.myclaw-training-card__field textarea {',
|
|
3505
|
+
' box-sizing: border-box; flex: 1; min-width: 0; width: auto; height: 32px; min-height: 32px; max-height: 32px;',
|
|
3506
|
+
' resize: none; padding: 3px 7px; border: 1px solid #3d3d55; border-radius: 6px;',
|
|
3507
|
+
' outline: none; color: #f4f4f5; background: #232334;',
|
|
3508
|
+
' overflow-y: auto; scrollbar-width: none;',
|
|
3509
|
+
' font: 13px/1.25 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;',
|
|
3510
|
+
'}',
|
|
3511
|
+
'.myclaw-training-card__field textarea::-webkit-scrollbar { display: none; }',
|
|
3512
|
+
'.myclaw-training-card__field textarea:focus { border-color: #8b5cf6; background: #27273a; }',
|
|
3513
|
+
'.myclaw-training-card__mic {',
|
|
3514
|
+
' width: 28px; height: 28px; flex: 0 0 28px; padding: 0; border-radius: 50%;',
|
|
3515
|
+
' border: 1px solid #45455f; background: #232334; color: #9a9bad; cursor: pointer;',
|
|
3516
|
+
' display: inline-flex; align-items: center; justify-content: center; transition: all .15s ease;',
|
|
3517
|
+
'}',
|
|
3518
|
+
'.myclaw-training-card__mic:hover { color: #ddd6fe; border-color: #7c3aed; background: #292940; }',
|
|
3519
|
+
'.myclaw-training-card__mic:disabled { cursor: not-allowed; opacity: .4; }',
|
|
3520
|
+
'.myclaw-training-card__footer {',
|
|
3521
|
+
' margin: 4px 0 0; display: flex; flex-direction: column; gap: 2px;',
|
|
3522
|
+
'}',
|
|
3523
|
+
'.myclaw-training-card__meta-row { min-width: 0; display: flex; align-items: center; gap: 6px; }',
|
|
3524
|
+
'.myclaw-training-card__status {',
|
|
3525
|
+
' min-width: 0; max-width: 44%; overflow: hidden; color: #9ca3af; font-size: 10px;',
|
|
3526
|
+
' white-space: nowrap; text-overflow: ellipsis; flex: 0 1 auto;',
|
|
3527
|
+
'}',
|
|
3528
|
+
'.myclaw-training-card__status:empty { display: none; }',
|
|
3529
|
+
'.myclaw-training-card__status--success { color: #6ee7b7; }',
|
|
3530
|
+
'.myclaw-training-card__status--error { color: #fca5a5; }',
|
|
3531
|
+
'.myclaw-training-card__actions { display: flex; gap: 8px; width: 100%; }',
|
|
3532
|
+
'.myclaw-training-card__card-actions { margin-top: 4px; }',
|
|
3533
|
+
'.myclaw-training-card__button {',
|
|
3534
|
+
' flex: 1; min-width: 0; padding: 6px 9px; border: 0; border-radius: 6px; cursor: pointer;',
|
|
3535
|
+
' color: #fff; font-size: 12px; font-weight: 700;',
|
|
3536
|
+
' transition: transform .15s ease, opacity .15s ease, filter .15s ease;',
|
|
3537
|
+
'}',
|
|
3538
|
+
'.myclaw-training-card__button:hover { transform: translateY(-1px); filter: brightness(1.08); }',
|
|
3539
|
+
'.myclaw-training-card__button:disabled { cursor: wait; opacity: .55; transform: none; }',
|
|
3540
|
+
'.myclaw-training-card__button--ai { background: #7c3aed; }',
|
|
3541
|
+
'.myclaw-training-card__button--teacher { background: #2563eb; }',
|
|
3542
|
+
'.myclaw-training-card__history {',
|
|
3543
|
+
' min-width: 0; margin-top: 4px; padding-top: 4px; border-top: 1px solid #323247;',
|
|
3544
|
+
'}',
|
|
3545
|
+
'.myclaw-training-card__history[hidden] { display: none; }',
|
|
3546
|
+
'.myclaw-training-card__history-list {',
|
|
3547
|
+
' min-width: 0; max-height: 48px; display: flex; flex-flow: row wrap; align-content: flex-start;',
|
|
3548
|
+
' gap: 4px; overflow-x: hidden; overflow-y: auto;',
|
|
3549
|
+
' scrollbar-width: thin; scrollbar-color: #4b4b65 transparent;',
|
|
3550
|
+
'}',
|
|
3551
|
+
'.myclaw-training-card__history-item {',
|
|
3552
|
+
' box-sizing: border-box; min-width: 78px; max-width: 155px; flex: 0 0 auto;',
|
|
3553
|
+
' display: flex; align-items: center; gap: 6px;',
|
|
3554
|
+
' padding: 3px 7px; border: 1px solid #3a3a51; border-radius: 6px;',
|
|
3555
|
+
' color: #d4d4df; background: #222232; cursor: pointer; text-align: left;',
|
|
3556
|
+
'}',
|
|
3557
|
+
'.myclaw-training-card__history-item:hover { border-color: #625f88; background: #29293b; }',
|
|
3558
|
+
'.myclaw-training-card__history-item--active { border-color: #8b5cf6; background: #30284a; }',
|
|
3559
|
+
'.myclaw-training-card__history-name { color: #c4b5fd; font-size: 11px; font-weight: 700; }',
|
|
3560
|
+
'.myclaw-training-card__history-preview {',
|
|
3561
|
+
' min-width: 0; flex: 1; overflow: hidden; color: #9293a7; font-size: 10px;',
|
|
3562
|
+
' white-space: nowrap; text-overflow: ellipsis;',
|
|
3563
|
+
'}',
|
|
3077
3564
|
].join('\n');
|
|
3078
3565
|
document.head.appendChild(style);
|
|
3079
3566
|
}
|
|
@@ -3083,8 +3570,9 @@
|
|
|
3083
3570
|
injectStyles();
|
|
3084
3571
|
createArtifactsButton();
|
|
3085
3572
|
var templateFloatBtn = document.createElement('div');
|
|
3573
|
+
templateFloatBtn.id = 'myclaw-template-btn';
|
|
3086
3574
|
templateFloatBtn.textContent = '📋 模板';
|
|
3087
|
-
templateFloatBtn.style.cssText = 'position:fixed;right:
|
|
3575
|
+
templateFloatBtn.style.cssText = 'position:fixed;right:5px;bottom:8px;z-index:99999;cursor:pointer;padding:3px 10px;border-radius:4px;font-size:11px;font-weight:bold;font-family:monospace;color:#cdd6f4;background:rgba(37,37,54,0.92);border:1px solid #3d3d5c;text-align:center;transition:all 0.2s;letter-spacing:0.5px;';
|
|
3088
3576
|
templateFloatBtn.onmouseenter = function () { templateFloatBtn.style.background = 'rgba(255,255,255,0.14)'; };
|
|
3089
3577
|
templateFloatBtn.onmouseleave = function () { templateFloatBtn.style.background = 'rgba(37,37,54,0.92)'; };
|
|
3090
3578
|
templateFloatBtn.onclick = function () { openTemplateModal(); };
|
package/assets/myclaw-inject.js
CHANGED
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
var suppressNextClipboardCopy = false;
|
|
32
32
|
var VOICE_STOP_WAIT_MS = 1500;
|
|
33
33
|
var VOICE_STOP_WAIT_SECONDS = VOICE_STOP_WAIT_MS / 1000;
|
|
34
|
+
var activeBoundVoiceStop = null;
|
|
34
35
|
|
|
35
36
|
// ═══ 1. 右下角版本入口(打开快捷命令) ═══
|
|
36
37
|
function createVersionBar() {
|
|
@@ -41,7 +42,7 @@
|
|
|
41
42
|
bar.style.cssText = [
|
|
42
43
|
"position: fixed",
|
|
43
44
|
"bottom: 8px",
|
|
44
|
-
"right:
|
|
45
|
+
"right: 75px",
|
|
45
46
|
"padding: 3px 10px",
|
|
46
47
|
"background: rgba(59, 130, 246, 0.85)",
|
|
47
48
|
"color: #fff",
|
|
@@ -85,7 +86,7 @@
|
|
|
85
86
|
btn.style.cssText = [
|
|
86
87
|
"position: fixed",
|
|
87
88
|
"bottom: 8px",
|
|
88
|
-
"right:
|
|
89
|
+
"right: 175px",
|
|
89
90
|
"padding: 3px 10px",
|
|
90
91
|
"background: rgba(120, 120, 120, 0.18)",
|
|
91
92
|
"color: rgba(170, 170, 170, 0.9)",
|
|
@@ -235,24 +236,32 @@
|
|
|
235
236
|
*/
|
|
236
237
|
function setTextareaValue(fullText) {
|
|
237
238
|
var ta = document.querySelector(".agent-chat__input textarea");
|
|
238
|
-
if (!ta) return;
|
|
239
|
+
if (!ta) return false;
|
|
239
240
|
|
|
240
241
|
var setter = Object.getOwnPropertyDescriptor(
|
|
241
242
|
HTMLTextAreaElement.prototype, "value"
|
|
242
243
|
).set;
|
|
243
244
|
setter.call(ta, fullText);
|
|
244
245
|
ta.dispatchEvent(new Event("input", { bubbles: true }));
|
|
246
|
+
return true;
|
|
245
247
|
}
|
|
246
248
|
|
|
247
249
|
function sendGeneratedPrompt(text) {
|
|
250
|
+
if (!setTextareaValue(text)) {
|
|
251
|
+
console.warn("[myclaw-send] 找不到聊天输入框");
|
|
252
|
+
return false;
|
|
253
|
+
}
|
|
248
254
|
suppressNextClipboardCopy = true;
|
|
249
|
-
|
|
250
|
-
trySend();
|
|
255
|
+
var sent = trySend();
|
|
251
256
|
setTimeout(function () {
|
|
252
257
|
suppressNextClipboardCopy = false;
|
|
253
258
|
}, 3000);
|
|
259
|
+
return sent;
|
|
254
260
|
}
|
|
255
261
|
|
|
262
|
+
// 给其他 MyClaw 前端模块复用统一的聊天发送能力。
|
|
263
|
+
window.myclawSendPrompt = sendGeneratedPrompt;
|
|
264
|
+
|
|
256
265
|
/**
|
|
257
266
|
* 获取 textarea 当前值
|
|
258
267
|
*/
|
|
@@ -524,6 +533,97 @@
|
|
|
524
533
|
};
|
|
525
534
|
}
|
|
526
535
|
|
|
536
|
+
// 为其他 MyClaw 模块已有的 textarea 绑定一枚独立语音按钮。
|
|
537
|
+
function bindVoiceInput(input, micBtn) {
|
|
538
|
+
if (!input || !micBtn) return function () {};
|
|
539
|
+
|
|
540
|
+
var localVoice = null;
|
|
541
|
+
var localRecording = false;
|
|
542
|
+
var localStopping = false;
|
|
543
|
+
|
|
544
|
+
function setMicUI(isRecording) {
|
|
545
|
+
if (isRecording) {
|
|
546
|
+
micBtn.style.background = "#ef4444";
|
|
547
|
+
micBtn.style.borderColor = "#ef4444";
|
|
548
|
+
micBtn.style.color = "#fff";
|
|
549
|
+
micBtn.title = "停止录音";
|
|
550
|
+
input.style.borderColor = "#ef4444";
|
|
551
|
+
} else {
|
|
552
|
+
micBtn.style.background = "#232334";
|
|
553
|
+
micBtn.style.borderColor = "#45455f";
|
|
554
|
+
micBtn.style.color = "#9a9bad";
|
|
555
|
+
micBtn.title = "语音输入";
|
|
556
|
+
input.style.borderColor = "";
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
function initVoiceForField() {
|
|
561
|
+
if (typeof window.VoiceInput === "undefined") return false;
|
|
562
|
+
localVoice = new window.VoiceInput({
|
|
563
|
+
onResult: function (text) {
|
|
564
|
+
if (!localRecording && !localStopping) return;
|
|
565
|
+
input.value = String(text || "").slice(0, input.maxLength || 1000);
|
|
566
|
+
input.dispatchEvent(new Event("input", { bubbles: true }));
|
|
567
|
+
},
|
|
568
|
+
onStatusChange: function (oldStatus, newStatus) {
|
|
569
|
+
if (newStatus === "idle" && localRecording && !localStopping) {
|
|
570
|
+
setTimeout(function () {
|
|
571
|
+
if (localRecording && localVoice) localVoice.start();
|
|
572
|
+
}, 300);
|
|
573
|
+
}
|
|
574
|
+
},
|
|
575
|
+
onError: function (err) {
|
|
576
|
+
console.error("[myclaw-training-card] voice error:", err);
|
|
577
|
+
localRecording = false;
|
|
578
|
+
localStopping = false;
|
|
579
|
+
if (activeBoundVoiceStop === stopVoiceForField) activeBoundVoiceStop = null;
|
|
580
|
+
setMicUI(false);
|
|
581
|
+
},
|
|
582
|
+
});
|
|
583
|
+
return true;
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
function startVoiceForField() {
|
|
587
|
+
if (!localVoice && !initVoiceForField()) {
|
|
588
|
+
console.warn("[myclaw-training-card] VoiceInput SDK 未加载");
|
|
589
|
+
micBtn.title = "语音输入暂不可用";
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
if (activeBoundVoiceStop && activeBoundVoiceStop !== stopVoiceForField) {
|
|
593
|
+
activeBoundVoiceStop();
|
|
594
|
+
}
|
|
595
|
+
activeBoundVoiceStop = stopVoiceForField;
|
|
596
|
+
localStopping = false;
|
|
597
|
+
localRecording = true;
|
|
598
|
+
setMicUI(true);
|
|
599
|
+
localVoice.start();
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
function stopVoiceForField() {
|
|
603
|
+
if (!localRecording && !localStopping) return;
|
|
604
|
+
localStopping = true;
|
|
605
|
+
localRecording = false;
|
|
606
|
+
setMicUI(false);
|
|
607
|
+
setTimeout(function () {
|
|
608
|
+
localStopping = false;
|
|
609
|
+
if (localVoice) localVoice.stop();
|
|
610
|
+
if (activeBoundVoiceStop === stopVoiceForField) activeBoundVoiceStop = null;
|
|
611
|
+
}, VOICE_STOP_WAIT_MS);
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
micBtn.addEventListener("click", function () {
|
|
615
|
+
if (localRecording) stopVoiceForField();
|
|
616
|
+
else if (!localStopping) startVoiceForField();
|
|
617
|
+
});
|
|
618
|
+
setMicUI(false);
|
|
619
|
+
|
|
620
|
+
return function destroyVoiceBinding() {
|
|
621
|
+
stopVoiceForField();
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
window.myclawBindVoiceInput = bindVoiceInput;
|
|
626
|
+
|
|
527
627
|
function showDebugModal() {
|
|
528
628
|
if (document.getElementById("myclaw-debug-modal")) return;
|
|
529
629
|
|
|
@@ -1207,13 +1307,14 @@ btn.addEventListener("click", function () {
|
|
|
1207
1307
|
var btn = document.querySelector("button.chat-send-btn");
|
|
1208
1308
|
if (!btn) {
|
|
1209
1309
|
console.log("[myclaw-send] 找不到发送按钮");
|
|
1210
|
-
return;
|
|
1310
|
+
return false;
|
|
1211
1311
|
}
|
|
1212
1312
|
if (btn.classList.contains("chat-send-btn--stop")) {
|
|
1213
1313
|
console.log("[myclaw-send] AI 生成中,禁止发送");
|
|
1214
|
-
return;
|
|
1314
|
+
return false;
|
|
1215
1315
|
}
|
|
1216
1316
|
btn.click();
|
|
1317
|
+
return true;
|
|
1217
1318
|
}
|
|
1218
1319
|
|
|
1219
1320
|
/**
|
|
@@ -1769,7 +1870,7 @@ btn.addEventListener("click", function () {
|
|
|
1769
1870
|
btn.style.cssText = [
|
|
1770
1871
|
"position: fixed",
|
|
1771
1872
|
"bottom: 8px",
|
|
1772
|
-
"right:
|
|
1873
|
+
"right: 260px",
|
|
1773
1874
|
"padding: 3px 10px",
|
|
1774
1875
|
"background: rgba(139, 92, 246, 0.85)",
|
|
1775
1876
|
"color: #fff",
|
|
@@ -1804,7 +1905,7 @@ btn.addEventListener("click", function () {
|
|
|
1804
1905
|
btn.style.cssText = [
|
|
1805
1906
|
"position: fixed",
|
|
1806
1907
|
"bottom: 8px",
|
|
1807
|
-
"right:
|
|
1908
|
+
"right: 355px",
|
|
1808
1909
|
"padding: 3px 10px",
|
|
1809
1910
|
"background: rgba(59, 130, 246, 0.85)",
|
|
1810
1911
|
"color: #fff",
|
package/create_agent.js
CHANGED
|
@@ -278,20 +278,23 @@ function createAgent(rawName, opts) {
|
|
|
278
278
|
fail('配置文件写入失败: ' + err.message + '\n备份文件: ' + normalizePath(backupPath));
|
|
279
279
|
}
|
|
280
280
|
|
|
281
|
-
//
|
|
281
|
+
// 发送首条消息:普通 mc new 保持生日初始化逻辑;
|
|
282
|
+
// 模板部署可传 skipFirstMessage,等文件就绪后再发模板提示词。
|
|
282
283
|
const birthMessage = opts.firstMessage || buildBirthMessage();
|
|
283
284
|
let firstMessageSent = false;
|
|
284
285
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
286
|
+
if (!opts.skipFirstMessage) {
|
|
287
|
+
try {
|
|
288
|
+
const { spawn } = require('child_process');
|
|
289
|
+
spawn('openclaw', ['agent', '--agent', agentId, '--message', birthMessage, '--json'], {
|
|
290
|
+
detached: true,
|
|
291
|
+
stdio: 'ignore',
|
|
292
|
+
shell: true,
|
|
293
|
+
}).unref();
|
|
294
|
+
firstMessageSent = true;
|
|
295
|
+
} catch (err) {
|
|
296
|
+
firstMessageSent = false;
|
|
297
|
+
}
|
|
295
298
|
}
|
|
296
299
|
|
|
297
300
|
// 返回结果
|
|
@@ -305,6 +308,7 @@ function createAgent(rawName, opts) {
|
|
|
305
308
|
configBackup: normalizePath(backupPath),
|
|
306
309
|
birthMessage: birthMessage,
|
|
307
310
|
firstMessageSent: firstMessageSent,
|
|
311
|
+
firstMessageSkipped: !!opts.skipFirstMessage,
|
|
308
312
|
};
|
|
309
313
|
}
|
|
310
314
|
|
package/index.js
CHANGED
|
@@ -319,9 +319,16 @@ function runNew() {
|
|
|
319
319
|
// mc new → 交互输入名字
|
|
320
320
|
// mc new <name> → 直接使用传入的名字
|
|
321
321
|
// mc new <name> --first-message "..." → 自定义首条消息
|
|
322
|
+
// mc new <name> --no-first-message → 仅创建,不发送首条消息(供模板部署使用)
|
|
322
323
|
const rawName = args[1];
|
|
323
324
|
const firstMessageIdx = args.indexOf('--first-message');
|
|
324
325
|
const customFirstMessage = firstMessageIdx !== -1 ? args[firstMessageIdx + 1] : null;
|
|
326
|
+
const skipFirstMessage = args.includes('--no-first-message');
|
|
327
|
+
|
|
328
|
+
if (customFirstMessage && skipFirstMessage) {
|
|
329
|
+
console.error(R + '--first-message 和 --no-first-message 不能同时使用。' + NC);
|
|
330
|
+
process.exit(1);
|
|
331
|
+
}
|
|
325
332
|
|
|
326
333
|
if (rawName) {
|
|
327
334
|
doCreate(rawName);
|
|
@@ -402,6 +409,7 @@ function runNew() {
|
|
|
402
409
|
var result;
|
|
403
410
|
try {
|
|
404
411
|
const createOpts = customFirstMessage ? { firstMessage: customFirstMessage } : {};
|
|
412
|
+
createOpts.skipFirstMessage = skipFirstMessage;
|
|
405
413
|
createOpts.agentId = agentId;
|
|
406
414
|
createOpts.displayName = displayName;
|
|
407
415
|
result = require('./create_agent').createAgent(input, createOpts);
|
package/package.json
CHANGED
package/server/sync_workspace.py
CHANGED
|
@@ -1425,7 +1425,8 @@ class MyclawAPIHandler(BaseHTTPRequestHandler):
|
|
|
1425
1425
|
def _handle_template_deploy(self):
|
|
1426
1426
|
"""POST /api/template/deploy Body: {"folder": "a100_...", "agent": "playgrounds"}
|
|
1427
1427
|
agent 默认 "playgrounds";不传则自动生成唯一名 tpl-MMDDHHMM。
|
|
1428
|
-
流程:mc new {agent}
|
|
1428
|
+
流程:mc new {agent} --no-first-message(已存在忽略)
|
|
1429
|
+
→ 复制模板 → 同步发送模板提示词
|
|
1429
1430
|
"""
|
|
1430
1431
|
try:
|
|
1431
1432
|
length = int(self.headers.get('Content-Length', 0))
|
|
@@ -1448,9 +1449,15 @@ class MyclawAPIHandler(BaseHTTPRequestHandler):
|
|
|
1448
1449
|
version_str = os.path.basename(template_path) # template_path 末段就是 v1/v2...
|
|
1449
1450
|
agent_name = '{}-{}-{}'.format(series_num, version_str, datetime.now().strftime('%H%M'))
|
|
1450
1451
|
|
|
1451
|
-
#
|
|
1452
|
+
# 模板流程不发送生日初始化消息;文件复制完成后再发模板提示词。
|
|
1453
|
+
# 普通的 `mc new <name>` 行为不受影响。
|
|
1452
1454
|
try:
|
|
1453
|
-
ret = subprocess.run(
|
|
1455
|
+
ret = subprocess.run(
|
|
1456
|
+
['mc', 'new', agent_name, '--no-first-message'],
|
|
1457
|
+
capture_output=True,
|
|
1458
|
+
text=True,
|
|
1459
|
+
timeout=30,
|
|
1460
|
+
)
|
|
1454
1461
|
output = (ret.stdout or '') + (ret.stderr or '')
|
|
1455
1462
|
if ret.returncode != 0 and '已存在' not in output and 'exists' not in output.lower():
|
|
1456
1463
|
self._send_json({'ok': False, 'error': 'mc new 失败: ' + output.strip()}, 500)
|
|
@@ -1464,7 +1471,7 @@ class MyclawAPIHandler(BaseHTTPRequestHandler):
|
|
|
1464
1471
|
|
|
1465
1472
|
data, err = self._run_skill_script(
|
|
1466
1473
|
[sys.executable, script, template_path, workspace_path, '--with-tui'],
|
|
1467
|
-
timeout=
|
|
1474
|
+
timeout=90
|
|
1468
1475
|
)
|
|
1469
1476
|
if err:
|
|
1470
1477
|
self._send_json({'ok': False, 'error': err}, 500)
|
|
@@ -1731,4 +1738,4 @@ if __name__ == "__main__":
|
|
|
1731
1738
|
try:
|
|
1732
1739
|
reconcile_loop()
|
|
1733
1740
|
except KeyboardInterrupt:
|
|
1734
|
-
print("\n[exit] 收到中断,退出")
|
|
1741
|
+
print("\n[exit] 收到中断,退出")
|
|
@@ -46,9 +46,9 @@ python3 scripts/run_playgrounds_flow.py <template_path>
|
|
|
46
46
|
- 只收 1 个参数:模板路径
|
|
47
47
|
- 内部自动执行 A + B + C
|
|
48
48
|
- 固定使用 `playgrounds`
|
|
49
|
-
-
|
|
49
|
+
- 自动准备 `playgrounds` Agent
|
|
50
50
|
- 自动复制到 `workspace-playgrounds/remix/实例名`
|
|
51
|
-
-
|
|
51
|
+
- 自动通过 `openclaw agent --session-key ... --json` 发送提示词,并校验发送结果
|
|
52
52
|
|
|
53
53
|
### 入口 2,指定 workspace 投放
|
|
54
54
|
```bash
|
|
@@ -58,14 +58,14 @@ python3 scripts/deploy_to_workspace.py <template_path> <workspace_path> --with-t
|
|
|
58
58
|
|
|
59
59
|
特点:
|
|
60
60
|
- 只 deploy 时,不进入 tui
|
|
61
|
-
- 加 `--with-tui` 时,deploy
|
|
61
|
+
- 加 `--with-tui` 时,deploy 后继续发送模板提示词(参数名为了兼容保留)
|
|
62
62
|
- 不暴露 `--agent`
|
|
63
63
|
- 不暴露 `--session`
|
|
64
64
|
- agent 从 `workspace-xxx` 自动推导
|
|
65
65
|
|
|
66
66
|
## 统一规则
|
|
67
67
|
|
|
68
|
-
- `实例名 =
|
|
68
|
+
- `实例名 = 目标文件夹名`;session 名在 ASCII 场景下按 OpenClaw 规则转为小写
|
|
69
69
|
- 实例名在 deploy 阶段生成
|
|
70
70
|
- 命名规则默认是:`月日_原模板名_时分`
|
|
71
71
|
- 如果同一分钟同名冲突,会自动加 `_2`、`_3`
|
|
@@ -130,8 +130,8 @@ def parse_args(argv):
|
|
|
130
130
|
return source_dir, workspace, agent, do_tui
|
|
131
131
|
|
|
132
132
|
|
|
133
|
-
def run(cmd):
|
|
134
|
-
return subprocess.run(cmd, capture_output=True, text=True)
|
|
133
|
+
def run(cmd, timeout=None):
|
|
134
|
+
return subprocess.run(cmd, capture_output=True, text=True, timeout=timeout)
|
|
135
135
|
|
|
136
136
|
|
|
137
137
|
def choose_entry_file(target_dir: Path):
|
|
@@ -197,9 +197,54 @@ def main():
|
|
|
197
197
|
if not agent:
|
|
198
198
|
fail({'ok': False, 'error': 'workspace_agent_not_inferable', 'message': 'workspace 路径必须形如 workspace-xxx,才能启用 --with-tui'})
|
|
199
199
|
message = build_message(folder_rel_path, entry_rel_path, target_dir)
|
|
200
|
-
|
|
200
|
+
# OpenClaw 会将 ASCII session key 标准化为小写;返回同样的值,
|
|
201
|
+
# 避免前端跳转到一个大小写不一致的空会话。
|
|
202
|
+
session_name = instance_name.lower()
|
|
203
|
+
session_key = f'agent:{agent}:{session_name}'
|
|
204
|
+
try:
|
|
205
|
+
result = run([
|
|
206
|
+
'openclaw', 'agent',
|
|
207
|
+
'--agent', agent,
|
|
208
|
+
'--session-key', session_key,
|
|
209
|
+
'--message', message,
|
|
210
|
+
'--thinking', 'off',
|
|
211
|
+
'--timeout', '60',
|
|
212
|
+
'--json',
|
|
213
|
+
], timeout=75)
|
|
214
|
+
except subprocess.TimeoutExpired as exc:
|
|
215
|
+
fail({
|
|
216
|
+
'ok': False,
|
|
217
|
+
'error': 'template_prompt_timeout',
|
|
218
|
+
'agent': agent,
|
|
219
|
+
'session': session_name,
|
|
220
|
+
'details': str(exc),
|
|
221
|
+
})
|
|
201
222
|
if result.returncode != 0:
|
|
202
|
-
fail({
|
|
223
|
+
fail({
|
|
224
|
+
'ok': False,
|
|
225
|
+
'error': 'template_prompt_failed',
|
|
226
|
+
'agent': agent,
|
|
227
|
+
'session': session_name,
|
|
228
|
+
'details': result.stderr or result.stdout,
|
|
229
|
+
})
|
|
230
|
+
try:
|
|
231
|
+
response = json.loads(result.stdout)
|
|
232
|
+
except Exception:
|
|
233
|
+
fail({
|
|
234
|
+
'ok': False,
|
|
235
|
+
'error': 'template_prompt_invalid_response',
|
|
236
|
+
'agent': agent,
|
|
237
|
+
'session': session_name,
|
|
238
|
+
'details': result.stdout or result.stderr,
|
|
239
|
+
})
|
|
240
|
+
if not isinstance(response, dict):
|
|
241
|
+
fail({
|
|
242
|
+
'ok': False,
|
|
243
|
+
'error': 'template_prompt_invalid_response',
|
|
244
|
+
'agent': agent,
|
|
245
|
+
'session': session_name,
|
|
246
|
+
'details': result.stdout,
|
|
247
|
+
})
|
|
203
248
|
tui_started = True
|
|
204
249
|
|
|
205
250
|
print(json.dumps({
|
|
@@ -212,7 +257,8 @@ def main():
|
|
|
212
257
|
'folder_rel_path': folder_rel_path,
|
|
213
258
|
'entry_rel_path': entry_rel_path,
|
|
214
259
|
'tui_started': tui_started,
|
|
215
|
-
'
|
|
260
|
+
'prompt_sent': tui_started,
|
|
261
|
+
'session': session_name if do_tui else instance_name,
|
|
216
262
|
'message': message,
|
|
217
263
|
}, ensure_ascii=False))
|
|
218
264
|
|
|
@@ -46,8 +46,8 @@ def parse_args(argv):
|
|
|
46
46
|
return agent, folder_rel_path, entry_rel_path, session_name
|
|
47
47
|
|
|
48
48
|
|
|
49
|
-
def run(cmd):
|
|
50
|
-
return subprocess.run(cmd, capture_output=True, text=True)
|
|
49
|
+
def run(cmd, timeout=None):
|
|
50
|
+
return subprocess.run(cmd, capture_output=True, text=True, timeout=timeout)
|
|
51
51
|
|
|
52
52
|
|
|
53
53
|
def main():
|
|
@@ -59,9 +59,27 @@ def main():
|
|
|
59
59
|
prompt_template = PROMPT_TEMPLATE_PATH.read_text(encoding='utf-8')
|
|
60
60
|
message = prompt_template.replace('{{FOLDER_REL_PATH}}', folder_rel_path).replace('{{ENTRY_REL_PATH}}', entry_rel_path)
|
|
61
61
|
|
|
62
|
-
|
|
62
|
+
session_name = session_name.lower()
|
|
63
|
+
try:
|
|
64
|
+
result = run([
|
|
65
|
+
'openclaw', 'agent',
|
|
66
|
+
'--agent', agent,
|
|
67
|
+
'--session-key', f'agent:{agent}:{session_name}',
|
|
68
|
+
'--message', message,
|
|
69
|
+
'--thinking', 'off',
|
|
70
|
+
'--timeout', '60',
|
|
71
|
+
'--json',
|
|
72
|
+
], timeout=75)
|
|
73
|
+
except subprocess.TimeoutExpired as exc:
|
|
74
|
+
fail({'started': False, 'error': 'template_prompt_timeout', 'agent': agent, 'session': session_name, 'details': str(exc)})
|
|
63
75
|
if result.returncode != 0:
|
|
64
|
-
fail({'started': False, 'error': '
|
|
76
|
+
fail({'started': False, 'error': 'template_prompt_failed', 'agent': agent, 'session': session_name, 'details': result.stderr or result.stdout})
|
|
77
|
+
try:
|
|
78
|
+
response = json.loads(result.stdout)
|
|
79
|
+
except Exception:
|
|
80
|
+
fail({'started': False, 'error': 'template_prompt_invalid_response', 'agent': agent, 'session': session_name, 'details': result.stdout or result.stderr})
|
|
81
|
+
if not isinstance(response, dict):
|
|
82
|
+
fail({'started': False, 'error': 'template_prompt_invalid_response', 'agent': agent, 'session': session_name, 'details': result.stdout})
|
|
65
83
|
|
|
66
84
|
print(json.dumps({
|
|
67
85
|
'started': True,
|